]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
3 months agoDaily bump.
GCC Administrator [Tue, 29 Apr 2025 00:20:16 +0000 (00:20 +0000)] 
Daily bump.

3 months agolibstdc++: centralize and improve testing of shared_ptr/weak_ptr conversions
Giuseppe D'Angelo [Sat, 15 Mar 2025 15:04:45 +0000 (16:04 +0100)] 
libstdc++: centralize and improve testing of shared_ptr/weak_ptr conversions

Since the conversions are under the same constraints, centralize the
test in one file instead of two, testing both smart pointer classes, to
ease future maintenance. This is used right away: more tests are added.
Amends r15-8048-gdf0e6509bf7442.

libstdc++-v3/ChangeLog:

* testsuite/20_util/shared_ptr/requirements/1.cc: Test both
shared_ptr and weak_ptr.
Add more tests.
* testsuite/20_util/weak_ptr/requirements/1.cc: Removed as
superseded by the other test.

Signed-off-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
3 months agoanalyzer: handle NRVO and DECL_BY_REFERENCE [PR111536]
David Malcolm [Mon, 28 Apr 2025 22:21:25 +0000 (18:21 -0400)] 
analyzer: handle NRVO and DECL_BY_REFERENCE [PR111536]

The analyzer was issuing false warnings about uninitialized variables
in C++ in places where NRVO was marking DECL_RESULT with
DECL_BY_REFERENCE.

Fixed thusly.

gcc/analyzer/ChangeLog:
PR analyzer/111536
* engine.cc (maybe_update_for_edge): Update for new call_stmt
param to region_model::push_frame.
* program-state.cc (program_state::push_frame): Likewise.
* region-model.cc (region_model::update_for_gcall): Likewise.
(region_model::push_frame): Add "call_stmt" param.
Handle DECL_RESULT with DECL_BY_REFERENCE set on it by stashing
the region of the lhs of the call_stmt in the caller frame,
and writing a reference to it within the "result" in the callee
frame.
(region_model::pop_frame): Don't write back to the LHS for
DECL_BY_REFERENCE results.
(selftest::test_stack_frames): Update for new call_stmt param to
region_model::push_frame.
(selftest::test_get_representative_path_var): Likewise.
(selftest::test_state_merging): Likewise.
(selftest::test_alloca): Likewise.
* region-model.h (region_model::push_frame): Add "call_stmt"
param.
* region.cc: Include "tree-ssa.h".
(region::can_have_initial_svalue_p): Use ssa_defined_default_def_p
for ssa names, rather than special-casing it for just parameters.
This should now also cover DECL_RESULT with DECL_BY_REFERENCE and
hard registers.
* sm-signal.cc (update_model_for_signal_handler): Update for new
call_stmt param to region_model::push_frame.
* state-purge.cc (state_purge_per_decl::process_worklists):
Likewise.

gcc/testsuite/ChangeLog:
PR analyzer/111536
* c-c++-common/analyzer/hard-reg-1.c: New test.
* g++.dg/analyzer/nrvo-1.C: New test.
* g++.dg/analyzer/nrvo-2.C: New test.
* g++.dg/analyzer/nrvo-pr111536-1.C: New test.
* g++.dg/analyzer/nrvo-pr111536-1b.C: New test.
* g++.dg/analyzer/nrvo-pr111536-2.C: New test.
* g++.dg/analyzer/nrvo-pr111536-2b.C: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
3 months agoanalyzer: fix null deref false negative on std::unique_ptr [PR109366]
David Malcolm [Mon, 28 Apr 2025 22:21:24 +0000 (18:21 -0400)] 
analyzer: fix null deref false negative on std::unique_ptr [PR109366]

gcc/analyzer/ChangeLog:
PR analyzer/109366
* region-model-manager.cc
(region_model_manager::maybe_fold_sub_svalue): Sub-values of zero
constants are zero.

gcc/testsuite/ChangeLog:
PR analyzer/109366
* g++.dg/analyzer/unique_ptr-1.C: New test.
* g++.dg/analyzer/unique_ptr-2.C: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
3 months agoanalyzer: initial implementation of exception handling [PR97111]
David Malcolm [Mon, 28 Apr 2025 22:21:24 +0000 (18:21 -0400)] 
analyzer: initial implementation of exception handling [PR97111]

This patch adds initial support for exception-handling to -fanalyzer,
handling eh_dispatch for regions of type ERT_TRY and
ERT_ALLOWED_EXCEPTIONS.   I haven't managed yet seen eh_dispatch for
regions of type ERT_CLEANUP and ERT_MUST_NOT_THROW in the analyzer; with
this patch it will ICE if it sees those.

Additionally, this patch only checks for exact matches of exception
types, rather than supporting subclasses and references.  I'm deferring
fixing this for now whilst figuring out how best to interact with the C++
type system; I'm tracking it as PR analyzer/119697.

The patch adds event classes for throwing and catching exceptions, and
seems to generate readable warnings for the kinds of leak that might
occur due to trying to manage resources manually and forgetting about
exceptions; for example:

exception-leak-1.C: In function ‘int test()’:
exception-leak-1.C:7:9: warning: leak of ‘ptr’ [CWE-401] [-Wanalyzer-malloc-leak]
    7 |   throw 42;
      |         ^~
  ‘int test()’: events 1-3
    5 |   void *ptr = __builtin_malloc (1024);
      |               ~~~~~~~~~~~~~~~~~^~~~~~
      |                                |
      |                                (1) allocated here
    6 |
    7 |   throw 42;
      |         ~~
      |         |
      |         (2) throwing exception of type ‘int’ here...
      |         (3) ⚠️  ‘ptr’ leaks here; was allocated at (1)

Although dynamic exception specifications are only available in C++14
and earlier, the need to support them meant it seemed relatively easy to
add a warning to check them, hence the patch adds a new warning
for code paths that throw an exception that doesn't match a dynamic
exception specification:  -Wanalyzer-throw-of-unexpected-type.

gcc/analyzer/ChangeLog:
PR analyzer/97111
* analyzer.cc (is_cxa_throw_p): New.
(is_cxa_rethrow_p): New.
* analyzer.opt (Wanalyzer-throw-of-unexpected-type): New.
* analyzer.opt.urls: Regenerate.
* call-info.cc (custom_edge_info::create_enode): New.
* call-info.h (call_info::print): Drop "final".
(call_info::add_events_to_path): Likewise.
* checker-event.cc (event_kind_to_string): Add cases for
event_kind::catch_, event_kind::throw_, and event_kind::unwind.
(explicit_throw_event::print_desc): New.
(throw_from_call_to_external_fn_event::print_desc): New.
(unwind_event::print_desc): New.
* checker-event.h (enum class event_kind): Add catch_, throw_,
and unwind.
(class catch_cfg_edge_event): New.
(class throw_event): New.
(class explicit_throw_event): New.
(class throw_from_call_to_external_fn_event): New.
(class unwind_event): New.
* common.h (class eh_dispatch_cfg_superedge): New forward decl.
(class eh_dispatch_try_cfg_superedge): New forward decl.
(class eh_dispatch_allowed_cfg_superedge): New forward decl.
(custom_edge_info::create_enode): New vfunc decl.
(is_cxa_throw_p): New decl.
(is_cxa_rethrow_p): New decl.
* diagnostic-manager.cc
(diagnostic_manager::add_events_for_superedge): Special-case edges
for eh_dispach_try.
(diagnostic_manager::prune_path): Call consolidate_unwind_events.
(diagnostic_manager::prune_for_sm_diagnostic): Don't filter the new
event_kinds.
(diagnostic_manager::consolidate_unwind_events): New.
* diagnostic-manager.h
(diagnostic_manager::consolidate_unwind_events): New decl.
* engine.cc (exploded_node::on_stmt_pre): Handle "__cxa_throw",
"__cxa_rethrow", and resx statements.
(class throw_custom_edge): New.
(class unwind_custom_edge): New.
(get_eh_outedge): New.
(exploded_graph::unwind_from_exception): New.
(exploded_node::on_throw): New.
(exploded_node::on_resx): New.
(exploded_graph::get_or_create_node): Add "add_to_worklist" param
and use it.
(exploded_graph::process_node): Use edge_info's create_enode vfunc
to create enodes, rather than calling get_or_create_node directly.
Ignore CFG edges in the sgraph flagged with EH whilst we're
exploring the egraph.
(exploded_graph_annotator::print_enode): Handle case
exploded_node::status::special.
* exploded-graph.h (exploded_node::status): Add value "special".
(exploded_node::on_throw): New decl.
(exploded_node::on_resx): New decl.
(exploded_graph::get_or_create_node): Add optional
"add_to_worklist" param.
(exploded_graph::unwind_from_exception): New decl.
* kf-lang-cp.cc (class kf_cxa_allocate_exception): New.
(class kf_cxa_begin_catch): New.
(class kf_cxa_end_catch): New.
(class throw_of_unexpected_type): New.
(class kf_cxa_call_unexpected): New.
(register_known_functions_lang_cp): Register known functions
"__cxa_allocate_exception", "__cxa_begin_catch",
"__cxa_end_catch", and "__cxa_call_unexpected".
* kf.cc (class kf_eh_pointer): New.
(register_known_functions): Register it for BUILT_IN_EH_POINTER.
* region-model.cc: Include "analyzer/function-set.h".
(exception_node::operator==): New.
(exception_node::dump_to_pp): New.
(exception_node::dump): New.
(exception_node::to_json): New.
(exception_node::make_dump_widget): New.
(exception_node::maybe_get_type): New.
(exception_node::add_to_reachable_regions): New.
(region_model::region_model): Initialize
m_thrown_exceptions_stack and m_caught_exceptions_stack.
(region_model::operator=): Likewise.
(region_model::operator==): Compare them.
(region_model::dump_to_pp): Dump exception stacks.
(region_model::to_json): Add exception stacks.
(region_model::make_dump_widget): Likewise.
(class exception_thrown_from_unrecognized_call): New.
(get_fns_assumed_not_to_throw): New.
(can_throw_p): New.
(region_model::check_for_throw_inside_call): New.
(region_model::on_call_pre): Call check_for_throw_inside_call
on unknown fns or those we don't have a body for.
(region_model::maybe_update_for_edge): Handle eh_dispatch_stmt
statements.  Drop old code that called
apply_constraints_for_exception on EDGE_EH edges.
(class rejected_eh_dispatch): New.
(exception_matches_type_p): New.
(matches_any_exception_type_p): New.
(region_model::apply_constraints_for_eh_dispatch): New.
(region_model::apply_constraints_for_eh_dispatch_try): New.
(region_model::apply_constraints_for_eh_dispatch_allowed): New.
(region_model::apply_constraints_for_exception): Delete.
(region_model::can_merge_with_p): Don't merge models with
non-equal exception stacks.
(region_model::get_referenced_base_regions): Add regions from
exception stacks.
* region-model.h (struct exception_node): New.
(region_model::push_thrown_exception): New.
(region_model::get_current_thrown_exception): New.
(region_model::pop_thrown_exception): New.
(region_model::push_caught_exception): New.
(region_model::get_current_caught_exception): New.
(region_model::pop_caught_exception): New.
(region_model::apply_constraints_for_eh_dispatch_try): New decl.
(region_model::apply_constraints_for_eh_dispatch_allowed) New decl.
(region_model::apply_constraints_for_exception): Delete.
(region_model::apply_constraints_for_eh_dispatch): New decl.
(region_model::check_for_throw_inside_call): New decl.
(region_model::m_thrown_exceptions_stack): New field.
(region_model::m_caught_exceptions_stack): New field.
* supergraph.cc: Include "except.h" and "analyzer/region-model.h".
(supergraph::add_cfg_edge): Special-case eh_dispatch edges.
(superedge::get_description): Use default_tree_printer.
(get_catch): New.
(eh_dispatch_cfg_superedge::make): New.
(eh_dispatch_cfg_superedge::eh_dispatch_cfg_superedge): New.
(eh_dispatch_cfg_superedge::get_eh_status): New.
(eh_dispatch_try_cfg_superedge::dump_label_to_pp): New.
(eh_dispatch_try_cfg_superedge::apply_constraints): New.
(eh_dispatch_allowed_cfg_superedge::eh_dispatch_allowed_cfg_superedge):
New.
(eh_dispatch_allowed_cfg_superedge::dump_label_to_pp): New.
(eh_dispatch_allowed_cfg_superedge::apply_constraints): New.
* supergraph.h: Include "except.h".
(superedge::dyn_cast_eh_dispatch_cfg_superedge): New vfunc.
(superedge::dyn_cast_eh_dispatch_try_cfg_superedge): New vfunc.
(superedge::dyn_cast_eh_dispatch_allowed_cfg_superedge): New
vfunc.
(class eh_dispatch_cfg_superedge): New.
(is_a_helper <const eh_dispatch_cfg_superedge *>::test): New.
(class eh_dispatch_try_cfg_superedge): New.
(is_a_helper <const eh_dispatch_try_cfg_superedge *>::test): New.
(class eh_dispatch_allowed_cfg_superedge): New.
(is_a_helper <const eh_dispatch_allowed_cfg_superedge *>::test):
New.
* svalue.cc (svalue::maybe_get_type_from_typeinfo): New.
* svalue.h (svalue::maybe_get_type_from_typeinfo): New decl.

gcc/ChangeLog:
PR analyzer/97111
* doc/invoke.texi: Add -Wanalyzer-throw-of-unexpected-type.
* gimple.h (gimple_call_nothrow_p): Make arg const.

gcc/testsuite/ChangeLog:
PR analyzer/97111
* c-c++-common/analyzer/analyzer-verbosity-2a.c: Add
-fno-exceptions.
* c-c++-common/analyzer/analyzer-verbosity-3a.c: Likewise.
* c-c++-common/analyzer/attr-const-2.c: Add
__attribute__((nothrow)).
* c-c++-common/analyzer/attr-malloc-4.c: Likewise.
* c-c++-common/analyzer/attr-malloc-5.c: Likewise.
* c-c++-common/analyzer/attr-malloc-6.c: Add -fno-exceptions.
* c-c++-common/analyzer/attr-malloc-CVE-2019-19078-usb-leak.c:
Likewise.
* c-c++-common/analyzer/attr-malloc-exception.c: New test.
* c-c++-common/analyzer/call-summaries-pr107158-2.c: Add
-fno-exceptions.
* c-c++-common/analyzer/call-summaries-pr107158.c: Likewise.
* c-c++-common/analyzer/capacity-2.c: Likewise.
* c-c++-common/analyzer/coreutils-sum-pr108666.c: Likewise.
* c-c++-common/analyzer/data-model-22.c: Likewise.
* c-c++-common/analyzer/data-model-5d.c: Likewise.
* c-c++-common/analyzer/deref-before-check-pr108455-git-pack-revindex.c:
Likewise.
* c-c++-common/analyzer/deref-before-check-pr108475-haproxy-tcpcheck.c:
Likewise.
* c-c++-common/analyzer/edges-2.c: Likewise.
* c-c++-common/analyzer/fd-2.c: Likewise.
* c-c++-common/analyzer/fd-3.c: Likewise.
* c-c++-common/analyzer/fd-meaning.c: Likewise.
* c-c++-common/analyzer/file-1.c: Likewise.
* c-c++-common/analyzer/file-3.c: Likewise.
* c-c++-common/analyzer/file-meaning-1.c: Likewise.
* c-c++-common/analyzer/infinite-recursion.c: Likewise.
* c-c++-common/analyzer/leak-3.c: Likewise.
* c-c++-common/analyzer/malloc-dedupe-1.c: Likewise.
* c-c++-common/analyzer/malloc-in-loop.c: Likewise.
* c-c++-common/analyzer/malloc-many-paths-3.c: Likewise.
* c-c++-common/analyzer/malloc-paths-5.c: Likewise.
* c-c++-common/analyzer/malloc-paths-7.c: Likewise.
* c-c++-common/analyzer/malloc-paths-8.c: Likewise.
* c-c++-common/analyzer/malloc-vs-local-1a.c: Likewise.
* c-c++-common/analyzer/malloc-vs-local-2.c: Likewise.
* c-c++-common/analyzer/malloc-vs-local-3.c: Likewise.
* c-c++-common/analyzer/paths-7.c: Likewise.
* c-c++-common/analyzer/pr110830.c: Likewise.
* c-c++-common/analyzer/pr93032-mztools-simplified.c: Likewise.
* c-c++-common/analyzer/pr93355-localealias-feasibility-3.c:
Likewise.
* c-c++-common/analyzer/pr93355-localealias-simplified.c:
Likewise.
* c-c++-common/analyzer/pr96650-1-trans.c: Likewise.
* c-c++-common/analyzer/pr97072.c: Add __attribute__((nothrow)).
* c-c++-common/analyzer/pr98575-1.c: Likewise.
* c-c++-common/analyzer/pr99716-1.c: Add -fno-exceptions.
* c-c++-common/analyzer/pr99716-2.c: Likewise.
* c-c++-common/analyzer/pr99716-3.c: Likewise.
* c-c++-common/analyzer/pragma-2.c: Likewise.
* c-c++-common/analyzer/rhbz1878600.c: Likewise.
* c-c++-common/analyzer/strndup-1.c: Likewise.
* c-c++-common/analyzer/write-to-string-literal-4-disabled.c:
Likewise.
* c-c++-common/analyzer/write-to-string-literal-4.c: Likewise.
* c-c++-common/analyzer/write-to-string-literal-5.c: Likewise.
* c-c++-common/analyzer/zlib-5.c: Likewise.
* g++.dg/analyzer/exception-could-throw-1.C: New test.
* g++.dg/analyzer/exception-could-throw-2.C: New test.
* g++.dg/analyzer/exception-dynamic-spec.C: New test.
* g++.dg/analyzer/exception-leak-1.C: New test.
* g++.dg/analyzer/exception-leak-2.C: New test.
* g++.dg/analyzer/exception-leak-3.C: New test.
* g++.dg/analyzer/exception-leak-4.C: New test.
* g++.dg/analyzer/exception-leak-5.C: New test.
* g++.dg/analyzer/exception-leak-6.C: New test.
* g++.dg/analyzer/exception-nothrow.C: New test.
* g++.dg/analyzer/exception-path-1.C: New test.
* g++.dg/analyzer/exception-path-catch-all-1.C: New test.
* g++.dg/analyzer/exception-path-catch-all-2.C: New test.
* g++.dg/analyzer/exception-path-unwind-multiple-2.C: New test.
* g++.dg/analyzer/exception-path-unwind-multiple.C: New test.
* g++.dg/analyzer/exception-path-unwind-single.C: New test.
* g++.dg/analyzer/exception-path-with-cleanups.C: New test.
* g++.dg/analyzer/exception-rethrow-1.C: New test.
* g++.dg/analyzer/exception-rethrow-2.C: New test.
* g++.dg/analyzer/exception-stack-1.C: New test.
* g++.dg/analyzer/exception-stack-2.C: New test.
* g++.dg/analyzer/exception-subclass-1.C: New test.
* g++.dg/analyzer/exception-subclass-2.C: New test.
* g++.dg/analyzer/exception-value-1.C: New test.
* g++.dg/analyzer/exception-value-2.C: New test.
* g++.dg/analyzer/fno-exception.C: New test.
* g++.dg/analyzer/pr94028.C: Drop xfail.
* g++.dg/analyzer/std-unexpected.C: New test.
* g++.dg/coroutines/pr105287.C: Drop dg-excess-errors.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
3 months agoanalyzer,c++: add placeholder implementation of ana::translation_unit for C++
David Malcolm [Mon, 28 Apr 2025 22:21:23 +0000 (18:21 -0400)] 
analyzer,c++: add placeholder implementation of ana::translation_unit for C++

Implement ana::translation_unit for the C++ frontend with a
no-op placeholder implementation, for now.

No functional change intended; a follow-up may implement
things further.

gcc/cp/ChangeLog:
* parser.cc: Include "analyzer/analyzer-language.h".
(ana::cp_translation_unit): New class.
(cp_parser_translation_unit): Add call to
ana::on_finish_translation_unit.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
3 months agoEliminate make-unique.h and ::make_unique
David Malcolm [Mon, 28 Apr 2025 22:21:23 +0000 (18:21 -0400)] 
Eliminate make-unique.h and ::make_unique

C++11 does not provide a std::make_unique so in
r13-3627-g00d7c8ff16e683 I added a make-unique.h
declaring a ::make_unique.

As of r15-4719-ga9ec1bc06bd3cc we can use C++14, so make-unique.h is no
longer needed: we can use simply use std::make_unique instead.

This patch removes make-unique.h and updates every place using it
to use std::make_unique.

No functional change intended.

gcc/analyzer/ChangeLog:
* access-diagram.cc: Replace uses of ::make_unique with
std::make_unique.
* analyzer.cc: Likewise.
* bounds-checking.cc: Likewise.
* call-details.cc: Likewise.
* call-info.cc: Likewise.
* call-string.cc: Likewise.
* checker-path.cc: Likewise.
* common.h: Drop include of "make-unique.h".
* constraint-manager.cc: Replace uses of ::make_unique with
std::make_unique.
* diagnostic-manager.cc: Likewise.
* engine.cc: Likewise.
* infinite-loop.cc: Likewise.
* infinite-recursion.cc: Likewise.
* kf-analyzer.cc: Likewise.
* kf-lang-cp.cc: Likewise.
* kf.cc: Likewise.
* pending-diagnostic.cc: Likewise.
* program-point.cc: Likewise; drop #include.
* program-state.cc: Likewise.
* ranges.cc: Likewise.
* region-model.cc: Likewise.
* region.cc: Likewise; drop #include.
* sm-fd.cc: Likewise.
* sm-file.cc: Likewise.
* sm-malloc.cc: Likewise.
* sm-pattern-test.cc: Likewise.
* sm-sensitive.cc: Likewise.
* sm-signal.cc: Likewise.
* sm-taint.cc: Likewise.
* sm.cc: Likewise.
* store.cc: Likewise.
* supergraph.cc: Likewise.
* svalue.cc: Likewise; drop #include.
* varargs.cc: Likewise.

gcc/c-family/ChangeLog:
* c-pretty-print.cc: Drop include of "make-unique.h".
Replace uses of ::make_unique with std::make_unique.

gcc/c/ChangeLog:
* c-decl.cc: Drop include of "make-unique.h".
Replace uses of ::make_unique with std::make_unique.
* c-objc-common.cc: Likewise.
* c-parser.cc: Likewise.

gcc/cp/ChangeLog:
* cxx-pretty-print.cc: Drop include of "make-unique.h".
Replace uses of ::make_unique with std::make_unique.
* error.cc: Likewise.
* name-lookup.cc: Likewise.
* parser.cc: Likewise.

gcc/ChangeLog:
* diagnostic-format-json.cc: Drop include of "make-unique.h".
Replace uses of ::make_unique with std::make_unique.
* diagnostic-format-sarif.cc: Likewise.
* diagnostic-format-text.cc: Likewise.
* diagnostic.cc: Likewise.
* dumpfile.cc: Likewise.
* gcc-attribute-urlifier.cc: Likewise.
* gcc-urlifier.cc: Likewise.
* json-parsing.cc: Likewise.
* json.cc: Likewise.
* lazy-diagnostic-path.cc: Likewise.
* libgdiagnostics.cc: Likewise.
* libsarifreplay.cc: Likewise.
* lto-wrapper.cc: Likewise.
* make-unique.h: Delete.
* opts-diagnostic.cc: Drop include of "make-unique.h".
Replace uses of ::make_unique with std::make_unique.
* pretty-print.cc: Likewise.
* text-art/style.cc: Likewise.
* text-art/styled-string.cc: Likewise.
* text-art/table.cc: Likewise.
* text-art/tree-widget.cc: Likewise.
* text-art/widget.cc: Likewise.
* timevar.cc: Likewise.
* toplev.cc: Likewise.
* tree-diagnostic-client-data-hooks.cc: Likewise.

gcc/jit/ChangeLog:
* dummy-frontend.cc: Drop include of "make-unique.h".
Replace uses of ::make_unique with std::make_unique.

gcc/testsuite/ChangeLog:
* gcc.dg/plugin/analyzer_cpython_plugin.cc: Drop include of
"make-unique.h".  Replace uses of ::make_unique with
std::make_unique.
* gcc.dg/plugin/analyzer_gil_plugin.cc: Likewise.
* gcc.dg/plugin/analyzer_kernel_plugin.cc: Likewise.
* gcc.dg/plugin/analyzer_known_fns_plugin.cc: Likewise.
* gcc.dg/plugin/diagnostic_group_plugin.cc: Likewise.
* gcc.dg/plugin/diagnostic_plugin_xhtml_format.cc: Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
3 months agoanalyzer: use unique_ptr for state_machine instances
David Malcolm [Mon, 28 Apr 2025 22:21:22 +0000 (18:21 -0400)] 
analyzer: use unique_ptr for state_machine instances

gcc/analyzer/ChangeLog:
* engine.cc (class plugin_analyzer_init_impl): Convert
"m_checkers" to use std::vector of std::unique_ptr.  Convert
"m_known_fn_mgr" to a reference.
(impl_run_checkers): Convert "checkers" to use std::vector of
std::unique_ptr and move it into the extrinsic_state.
* program-state.cc (extrinsic_state::dump_to_pp): Update for
changes to m_checkers.
(extrinsic_state::to_json): Likewise.
(extrinsic_state::get_sm_idx_by_name): Likewise.
(selftest::test_sm_state_map): Update to use std::unique_ptr
for state machines.
(selftest::test_program_state_1): Likewise.
(selftest::test_program_state_2): Likewise.
(selftest::test_program_state_merging): Likewise.
(selftest::test_program_state_merging_2): Likewise.
* program-state.h (class extrinsic_state): Convert "m_checkers" to
use std::vector of std::unique_ptr and to be owned by this object,
rather than a reference.  Add ctor for use in selftests.
* sm-fd.cc (make_fd_state_machine): Update to use std::unique_ptr.
* sm-file.cc (make_fileptr_state_machine): Likewise.
* sm-malloc.cc (make_malloc_state_machine): Likewise.
* sm-pattern-test.cc (make_pattern_test_state_machine): Likewise.
* sm-sensitive.cc (make_sensitive_state_machine): Likewise.
* sm-signal.cc (make_signal_state_machine): Likewise.
* sm-taint.cc (make_taint_state_machine): Likewise.
* sm.cc: Define INCLUDE_LIST.
(make_checkers): Return the vector directly, rather than pass it
in by reference.  Update to use std::unique_ptr throughout.  Use
an intermediate list, and use that to filter with
flag_analyzer_checker, fixing memory leak for this case.
* sm.h: (make_checkers): Return the vector directly, rather than
pass it in by reference, and use std::vector of std::unique_ptr.
(make_malloc_state_machine): Convert return type to use std::unique_ptr.
(make_fileptr_state_machine): Likewise.
(make_taint_state_machine): Likewise.
(make_sensitive_state_machine): Likewise.
(make_signal_state_machine): Likewise.
(make_pattern_test_state_machine): Likewise.
(make_va_list_state_machine): Likewise.
(make_fd_state_machine): Likewise.
* varargs.cc (make_va_list_state_machine): Update to use
std::unique_ptr.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
3 months agoanalyzer: convert various call_summary * to call_summary &
David Malcolm [Mon, 28 Apr 2025 22:21:22 +0000 (18:21 -0400)] 
analyzer: convert various call_summary * to call_summary &

No functional change intended.

gcc/analyzer/ChangeLog:
* call-summary.cc (call_summary_replay::call_summary_replay):
Convert "summary" from call_summary * to call_summary &.
(call_summary_replay::dump_to_pp): Likewise for m_summary.
* call-summary.h (call_summary_replay::call_summary_replay):
Likewise for "summary".
(call_summary_replay::m_summary): Likewise.
* engine.cc (call_summary_edge_info::call_summary_edge_info):
Likewise.
(call_summary_edge_info::update_state): Likewise.
(call_summary_edge_info::update_model): Likewise.
(call_summary_edge_info::print_desc): Likewise for m_summary.
(call_summary_edge_info::m_summary): Likewise.
(exploded_node::replay_call_summaries): Update for change to
replay_call_summary.
(exploded_node::replay_call_summary): Convert "summary" from
call_summary * to call_summary &.
* exploded-graph.h (exploded_node::replay_call_summary): Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
3 months agoanalyzer: convert gcall * to gcall & in many places
David Malcolm [Mon, 28 Apr 2025 22:21:21 +0000 (18:21 -0400)] 
analyzer: convert gcall * to gcall & in many places

No functional change intended.

gcc/analyzer/ChangeLog:
* analyzer.cc: Convert gcall * to gcall & where we know the
pointer must be non-null.
* call-details.cc: Likewise.
* call-details.h: Likewise.
* call-info.cc: Likewise.
* call-info.h: Likewise.
* call-summary.h: Likewise.
* checker-event.cc: Likewise.
* checker-event.h: Likewise.
* common.h: Likewise.
* diagnostic-manager.cc: Likewise.
* engine.cc: Likewise.
* exploded-graph.h: Likewise.
* kf-analyzer.cc: Likewise.
* kf-lang-cp.cc: Likewise.
* kf.cc: Likewise.
* known-function-manager.cc: Likewise.
* program-state.cc: Likewise.
* program-state.h: Likewise.
* region-model.cc: Likewise.
* region-model.h: Likewise.
* sm-fd.cc: Likewise.
* sm-file.cc: Likewise.
* sm-malloc.cc: Likewise.
* sm-sensitive.cc: Likewise.
* sm-signal.cc: Likewise.
* sm-taint.cc: Likewise.
* sm.h: Likewise.
* store.cc: Likewise.
* store.h: Likewise.
* supergraph.cc: Likewise.
* supergraph.h: Likewise.
* svalue.h: Likewise.
* varargs.cc: Likewise.

gcc/testsuite/ChangeLog:
* gcc.dg/plugin/analyzer_gil_plugin.cc: Convert gcall * to gcall &
where we know the pointer must be non-null.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
3 months agoanalyzer: convert various enums to "enum class"
David Malcolm [Mon, 28 Apr 2025 22:21:21 +0000 (18:21 -0400)] 
analyzer: convert various enums to "enum class"

Modernization; no functional change intended.

gcc/analyzer/ChangeLog:
* access-diagram.cc: Convert enum access_direction to
"enum class".
* bounds-checking.cc: Likewise.
* checker-event.cc: Convert enum event_kind to "enum class".
* checker-event.h: Likewise.
* checker-path.cc: Likewise.
* common.h: Convert enum access_direction to "enum class".
* constraint-manager.cc: Convert enum bound_kind to "enum class".
* constraint-manager.h: Likewise.
* diagnostic-manager.cc: Convert enum event_kind to "enum class".
* engine.cc: Convert enum status to "enum class".
* exploded-graph.h: Likewise.
* infinite-loop.cc: Likewise.
* kf-lang-cp.cc: Convert enum poison_kind to "enum class".
* kf.cc: Likewise.
* region-model-manager.cc: Likewise.
* region-model.cc: Likewise; also for enum access_direction.
* svalue.cc: Likewise.
* svalue.h: Likewise.

gcc/testsuite/ChangeLog:
* gcc.dg/plugin/analyzer_cpython_plugin.cc: Convert
enum poison_kind to "enum class".

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
3 months agoanalyzer: use analyzer/common.h as a common header
David Malcolm [Mon, 28 Apr 2025 22:21:21 +0000 (18:21 -0400)] 
analyzer: use analyzer/common.h as a common header

Our headers are a major pain to work with: many require certain other
headers to be included in a particular (undocumented) order in order
to be includable.

Simplify includes in the analyzer by renaming analyzer/analyzer.h to
analyzer/common.h and have it include all the common headers needed
throughout the analyzer, thus encapsulating the rules about e.g. being
able to include "gimple.h" in one place in the analyzer subdirectory.

Doing so also makes it easier to e.g. define INCLUDE_SET in one place,
rather than in many source files.

gcc/analyzer/ChangeLog:
* analyzer.h: Rename to...
* common.h: ...this.  Add define of INCLUDE_VECTOR, includes of
"config.h", "system.h", "coretypes.h", "make-unique.h", "tree.h",
"function.h", "basic-block.h", "gimple.h", "options.h",
"bitmap.h", "diagnostic-core.h", and "diagnostic-path.h".
* access-diagram.h: Don't include "analyzer/analyzer.h".
* access-diagram.cc: Reorganize includes to #include
"analyzer/common.h" first, then group by subsystem, dropping
redundant headers.
* analysis-plan.cc: Likewise.
* analyzer-language.cc: Likewise.
* analyzer-pass.cc: Likewise.
* analyzer-selftests.cc: Likewise.
* analyzer.cc: Likewise.
* bounds-checking.cc: Likewise.
* call-details.cc: Likewise.
* call-info.cc: Likewise.
* call-string.cc: Likewise.
* call-summary.cc: Likewise.
* checker-event.cc: Likewise.
* checker-path.cc: Likewise.
* complexity.cc: Likewise.
* constraint-manager.cc: Likewise.
* diagnostic-manager.cc: Likewise.
* engine.cc: Likewise.
* feasible-graph.cc: Likewise.
* infinite-loop.cc: Likewise.
* infinite-recursion.cc: Likewise.
* kf-analyzer.cc: Likewise.
* kf-lang-cp.cc: Likewise.
* kf.cc: Likewise.
* known-function-manager.cc: Likewise.
* pending-diagnostic.cc: Likewise.
* program-point.cc: Likewise.
* program-state.cc: Likewise.
* ranges.cc: Likewise.
* record-layout.cc: Likewise.
* region-model-asm.cc: Likewise.
* region-model-manager.cc: Likewise.
* region-model-reachability.cc: Likewise.
* region-model.cc: Likewise.
* region.cc: Likewise.
* sm-fd.cc: Likewise.
* sm-file.cc: Likewise.
* sm-malloc.cc: Likewise.
* sm-pattern-test.cc: Likewise.
* sm-sensitive.cc: Likewise.
* sm-signal.cc: Likewise.
* sm-taint.cc: Likewise.
* sm.cc: Likewise.
* state-purge.cc: Likewise.
* store.cc: Likewise.
* supergraph.cc: Likewise.
* svalue.cc: Likewise.
* symbol.cc: Likewise.
* trimmed-graph.cc: Likewise.
* varargs.cc: Likewise.

gcc/testsuite/ChangeLog:
* gcc.dg/plugin/analyzer_cpython_plugin.cc: Update for renaming
of analyzer/analyzer.h to analyzer/common.h.
* gcc.dg/plugin/analyzer_gil_plugin.cc: Likewise.
* gcc.dg/plugin/analyzer_kernel_plugin.cc: Likewise.
* gcc.dg/plugin/analyzer_known_fns_plugin.cc: Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
3 months agoanalyzer: fail if we see unexpected gimple stmt codes
David Malcolm [Mon, 28 Apr 2025 22:21:20 +0000 (18:21 -0400)] 
analyzer: fail if we see unexpected gimple stmt codes

gcc/analyzer/ChangeLog:
* region-model.cc (region_model::on_stmt_pre): Use internal_error
if we see an unexpected gimple stmt code.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
3 months agoanalyzer: add a call_details::dump (using text_art)
David Malcolm [Mon, 28 Apr 2025 22:21:20 +0000 (18:21 -0400)] 
analyzer: add a call_details::dump (using text_art)

Add a new function to help debugging -fanalyzer.

No functional change intended.

gcc/analyzer/ChangeLog:
* call-details.cc (call_details::dump): New overload.
(call_details::make_dump_widget): New.
* call-details.h (call_details::dump): Declare new overload.
(call_details::make_dump_widget): New decl.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
3 months agopass_manager: add m_ prefix to pass fields accessed via passes.def
David Malcolm [Mon, 28 Apr 2025 22:21:19 +0000 (18:21 -0400)] 
pass_manager: add m_ prefix to pass fields accessed via passes.def

Make it clearer when we're accessing member data of pass_manager by
adding an "m"_ prefix to the fields handled via passes.def macros.

No functional change intended.

gcc/ChangeLog:
* pass_manager.h (class pass_manager): Add "m_" prefix to all pass
fields.
* passes.cc (pass_manager::execute_early_local_passes): Update
for added "m_" prefix.
(pass_manager::execute_pass_mode_switching): Likewise.
(pass_manager::finish_optimization_passes): Likewise.
(pass_manager::pass_manager): Likewise.
(pass_manager::dump_profile_report): Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
3 months agoc,c++: use unique_ptr in name_hint to reduce naked 'new'
David Malcolm [Mon, 28 Apr 2025 22:21:19 +0000 (18:21 -0400)] 
c,c++: use unique_ptr in name_hint to reduce naked 'new'

gcc/c-family/ChangeLog:
* name-hint.h (name_hint::name_hint): Use std::unique_ptr for
param.

gcc/c/ChangeLog:
* c-decl.cc: Include "make-unique.h".
(lookup_name_fuzzy): Use ::make_unique rather than "new" when
making suggest_missing_header and suggest_missing_option.
* c-parser.cc: Include "make-unique.h"
(c_parser_error_richloc): Use ::make_unique rather than "new" when
making suggest_missing_header.

gcc/cp/ChangeLog:
* name-lookup.cc: Include "make-unique.h".
(namespace_hints::convert_candidates_to_name_hint): Use
::make_unique rather than "new" when making
show_candidate_location and suggest_alternatives.
(namespace_hints::maybe_decorate_with_limit): Likewise when making
namespace_limit_reached.
(suggest_alternatives_for_1): Likewise when making
suggest_missing_option.
(maybe_suggest_missing_std_header): Likewise when making
missing_std_header.
(macro_use_before_def::maybe_make): Use std::unique_ptr.
(macro_use_before_def::macro_use_before_def): Make public.
(lookup_name_fuzzy): Use ::make_unique rather than "new" when
making suggest_missing_header.
* parser.cc: Include "make-unique.h".
(cp_parser_error_1): Use ::make_unique rather than "new" when
making suggest_missing_header.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
3 months agodiagnostics: use diagnostic_option_id for m_opt_permissive
David Malcolm [Mon, 28 Apr 2025 22:21:18 +0000 (18:21 -0400)] 
diagnostics: use diagnostic_option_id for m_opt_permissive

gcc/ChangeLog:
* diagnostic.h (diagnostic_context::m_opt_permissive): Convert
from int to diagnostic_option_id.  Update comment.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
3 months agodiagnostics: make diagnostic_context::m_abort_on_error private
David Malcolm [Mon, 28 Apr 2025 22:21:18 +0000 (18:21 -0400)] 
diagnostics: make diagnostic_context::m_abort_on_error private

No functional change intended.

gcc/ChangeLog:
* diagnostic.h (diagnostic_context::set_abort_on_error): New.
(diagnostic_context::m_abort_on_error): Make private.
(diagnostic_abort_on_error): Delete.
* opts.cc (setup_core_dumping): Update for above changes.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
3 months agosarif output: introduce sarif_generation_options
David Malcolm [Mon, 28 Apr 2025 22:21:18 +0000 (18:21 -0400)] 
sarif output: introduce sarif_generation_options

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
gcc/ChangeLog:
* diagnostic-format-sarif.cc (sarif_builder::get_opts): New
accessor.
(sarif_builder::get_version): Update for...
(sarif_builder::m_version): Replace this field...
(sarif_builder::m_m_sarif_gen_opts): ...with this.
(sarif_builder::sarif_builder): Replace version with
sarif_gen_opts throughout.
(sarif_builder::make_top_level_object): Use get_version.
(sarif_output_format::sarif_output_format): Replace version with
sarif_gen_opts throughout.
(sarif_stream_output_format::sarif_stream_output_format):
Likewise.
(sarif_file_output_format::sarif_file_output_format): Likewise.
(diagnostic_output_format_init_sarif_stderr): Drop version param
and use default for sarif_generation_options instead.
(diagnostic_output_format_init_sarif_file): Likewise.
(diagnostic_output_format_init_sarif_stream): Likewise.
(make_sarif_sink): Replace version with sarif_gen_opts throughout.
(sarif_generation_options::sarif_generation_options): New.
(selftest::test_sarif_diagnostic_context::test_sarif_diagnostic_context):
Replace version with sarif_gen_opts throughout.
(selftest::test_make_location_object): Likewise.
(selftest::test_simple_log): Likewise.
(selftest::test_simple_log_2): Likewise.
(selftest::test_message_with_embedded_link): Likewise.
(selftest::test_message_with_braces): Likewise.
(selftest::test_buffering): Likewise.
(selftest::run_tests_per_version): Replace with...
(selftest::for_each_sarif_gen_option): ...this...
(selftest::run_line_table_case_tests_per_version): ...and this.
(selftest::diagnostic_format_sarif_cc_tests): Update to use
for_each_sarif_gen_option and
run_line_table_case_tests_per_version.
* diagnostic-format-sarif.h (enum class sarif_version): Move lower
down.
(diagnostic_output_format_init_sarif_stderr): Drop "version"
param.
(diagnostic_output_format_init_sarif_file): Likewise.
(diagnostic_output_format_init_sarif_stream): Likewise.
(struct sarif_generation_options): New.
(make_sarif_sink): Add "formatted" param.  Replace version param
with sarif_gen_opts.
* diagnostic.cc (diagnostic_output_format_init): Drop hardcoded
sarif_version::v2_1_0 arguments from calls, which instead use
the default ctor for sarif_generation_options internally.
* libgdiagnostics.cc (sarif_sink::sarif_sink): Replace version
param with sarif_gen_opts, and update for changes to
make_sarif_sink.
(diagnostic_manager_add_sarif_sink): Use sarif_gen_opts rather
than version.
* opts-diagnostic.cc (sarif_scheme_handler::make_sink): Likewise.
Pass "true" for "formatted" param.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
3 months agoAdd a Relation iterator to the relation oracle.
Andrew MacLeod [Mon, 10 Feb 2025 21:14:17 +0000 (16:14 -0500)] 
Add a Relation iterator to the relation oracle.

This patch adds a relation iterator to query the oracle to list either
all the relations on exit to a block, or just ones involving a specified
SSA_NAME.   The oracle then uses this iterator internally as well.

* value-relation.cc (value_relation::swap): New.
(value_relation::negate): Remove.
(dom_oracle::next_relation): New.
(block_relation_iterator::block_relation_iterator): New.
(block_relation_iterator::get_next_relation): New.
(dom_oracle::dump): Use iterator.
* value-relation.h (relation_oracle::next_relation): New.
(dom_oracle::next_relation): New prototype.
(class block_relation_iterator): New.
(FOR_EACH_RELATION_BB): New.
(FOR_EACH_RELATION_NAME): New.

3 months agoAdd lhs_op1 relation to pointer_plus
Andrew MacLeod [Tue, 22 Apr 2025 14:36:26 +0000 (10:36 -0400)] 
Add lhs_op1 relation to pointer_plus

When prange was split from irange, the functionality of lhs_op1_relation
did not get ported.  This patch adds that functionality back, and is
also good example of how to add new dispatch patterns to range-ops
as lhs_op1_relation had no prange/prange/irange combination.

* range-op-ptr.cc (range_operator::lhs_op1_relation): Add
prange/prange/irange (PPI) default.
(pointer_plus_operator::lhs_op1_relation): New.
* range-op.cc (range_op_handler::lhs_op1_relation): Add RO_PPI case.
* range-op.h (range_op_handler::lhs_op1_relation): Add prototype.

3 months agoDo not overwrite relation in range_of_range_op.
Andrew MacLeod [Tue, 22 Apr 2025 17:52:45 +0000 (13:52 -0400)] 
Do not overwrite relation in range_of_range_op.

when registering reltions between the lhs and op1/op2, the relation
between op1 and op2 is being overwritten by the result.  This could
result in either an incorrect relation being registered between lhs and op2,
or a correct relation not being recognized.

* gimple-range-fold.cc (fold_using_range::range_of_range_op): Use a
new local variable for intermediate relation results.

3 months agoUse the current cache when creating inferred ranges.
Andrew MacLeod [Mon, 31 Mar 2025 15:18:22 +0000 (11:18 -0400)] 
Use the current cache when creating inferred ranges.

Infer range processing was adjusted to allow a query to be specified,
but during VRP folding, ranger was not providing a query.  This results
in contextual ranges being missed.   Pass the cache in as the query
which provide a read-only query of the current state.

* gimple-range-cache.cc (ranger_cache::apply_inferred_ranges): Pass
'this' as the range-query to the inferred range constructor.

3 months agoInfer non-zero for integral division RHS.
Andrew MacLeod [Tue, 21 Jan 2025 16:49:12 +0000 (11:49 -0500)] 
Infer non-zero for integral division RHS.

Adding op2_range for operator_div allows ranger to notice the divisor
is non-zero after execution.

PR tree-optimization/95801
gcc/
* range-op.cc (operator_div::op2_range): New.

gcc/testsuite/
* gcc.dg/tree-ssa/pr95801.c: New.

3 months agoAlways reflect lower bits from mask in subranges.
Andrew MacLeod [Mon, 14 Apr 2025 20:25:15 +0000 (16:25 -0400)] 
Always reflect lower bits from mask in subranges.

During intersection, we expand the subranges to exclude the lower values
from a bitmask with trailing zeros.  This leads to inconsistant evaluations
and in this case of this PR, that lead to an infinite cycle.

Always expand the lower subranges in set_range_from_bitmask instead.

PR tree-optimization/119712
gcc/
* value-range.cc (range_bitmask::adjust_range): Delete.
(irange::set_range_from_bitmask): Integrate adjust_range.
(irange::update_bitmask): Do nothing if bitmask doesnt change.
(irange:intersect_bitmask): Do not call adjust_range. Exit if there
is no second bitmask.
* value-range.h (adjust_range): Remove prototype.

gcc/testsuite/
* gcc.dg/pr119712.c: New.
* gcc.dg/pr83072-2.c: Adjust.
* gcc.dg/tree-ssa/phi-opt-value-5.c: Adjust.
* gcc.dg/tree-ssa/vrp122.c: Adjust

3 months agotailcall: Support ERF_RETURNS_ARG for tailcall [PR67797]
Andrew Pinski [Sat, 19 Apr 2025 23:41:32 +0000 (16:41 -0700)] 
tailcall: Support ERF_RETURNS_ARG for tailcall [PR67797]

r15-6943-g9c4397cafc5ded added support to undo IPA-VRP return value optimization for tail calls,
using the same code ERF_RETURNS_ARG can be supported for functions which return one of their arguments.
This allows for tail calling of memset/memcpy in some cases which were not handled before.

Note this is very similar to https://gcc.gnu.org/legacy-ml/gcc-patches/2016-11/msg02485.html except
it has a few more checks.  Also on the question of expand vs tail call here is that this path is also
used by the IPA-VRP return value path and yes we get a tail call.
Note in the review in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83142#c2 mentions about
re-instantiate a LHS on the call & propagate to dominating uses. Even though that can be done
for the ERF_RETURNS_ARG case, it is not done for the IPA-VRP return value case already so I don't think
there is anything to be done there.

Changes since v1:
* v2: Add an useless_type_conversion_p check as suggested by Jakub
      and add a testcase for that.
* v3: Fix the order of arguments to useless_type_conversion_p.

Bootstrapped and tested on x86_64-linux-gnu.

PR tree-optimization/67797

gcc/ChangeLog:

* tree-tailcall.cc (find_tail_calls): Add support for ERF_RETURNS_ARG.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/tailcall-14.c: New test.
* gcc.dg/tree-ssa/tailcall-15.c: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
3 months agoMAINTAINERS: Add my gcc.gnu.org username
Kwok Cheung Yeung [Mon, 28 Apr 2025 18:27:59 +0000 (19:27 +0100)] 
MAINTAINERS: Add my gcc.gnu.org username

ChangeLog:

* MAINTAINERS (kcy): Add gcc.gnu.org username.

3 months agogimple-verifier: Add check that comparison in GIMPLE_COND does not throw
Andrew Pinski [Thu, 24 Apr 2025 16:45:16 +0000 (09:45 -0700)] 
gimple-verifier: Add check that comparison in GIMPLE_COND does not throw

While working on PR 119903, I noticed that there is code in replace_stmt_with_simplification
which makes sure that the comparison of a GIMPLE_COND does not throw
(non-call exceptions and trapping math) but the gimple verifier does not
verify this. So let's add it.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

* tree-cfg.cc (verify_gimple_cond): Error out if the comparison
throws.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
3 months agogimplefe: Round trip of rotates [PR119432]
Andrew Pinski [Sat, 26 Apr 2025 12:49:23 +0000 (05:49 -0700)] 
gimplefe: Round trip of rotates [PR119432]

This adds support for rotate left/right to the GIMPLE front-end
via __ROTATE_LEFT/__ROTATE_RIGHT oeprators.

PR c/119432
gcc/c/ChangeLog:

* gimple-parser.cc (gimple_binary_identifier_code): Add
__ROTATE_LEFT and __ROTATE_RIGHT.

gcc/ChangeLog:

* tree-pretty-print.cc (op_symbol_code): For LROTATE_EXPR,
output __ROTATE_LEFT for gimple.
For RROTATE_EXPR output __ROTATE_RIGHT for gimple.

gcc/testsuite/ChangeLog:

* gcc.dg/gimplefe-57.c: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
3 months agogimplefe: Simplify handling of identifier based binary operations
Andrew Pinski [Sat, 26 Apr 2025 06:22:15 +0000 (23:22 -0700)] 
gimplefe: Simplify handling of identifier based binary operations

While looking into adding __ROTATE_LEFT and __ROTATE_RIGHT, I noticed
this code is just a bunch of if statments repeated. Instead we could just
use a simple lookup array to do the same thinga and it would be easier to
add to the array instead of duplicating the if sequence again.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/c/ChangeLog:

* gimple-parser.cc (gimple_binary_identifier_code): New variable.
(c_parser_gimple_binary_expression): Use gimple_binary_identifier_code
instead of doing if statements on the strings.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
3 months agoAdd testcase for bogus Warray-bounds warning dealing with __builtin_unreachable ...
Andrew Pinski [Sat, 5 Apr 2025 11:47:59 +0000 (04:47 -0700)] 
Add testcase for bogus Warray-bounds warning dealing with __builtin_unreachable [PR100038]

After EVRP was switched to the ranger (r12-2305-g398572c1544d8b), we are better handling the case
where __builtin_unreachable comes after a loop. Instead of removing __builtin_unreachable and having
the loop become an infinite one; it is kept around longer and allows GCC to unroll the loop 2 times instead
of 3 times. When GCC unrolled the loop 3 times, GCC would produce a bogus Warray-bounds warning for the 3rd
iteration.
This adds the testcase to make sure we don't regress on this case. It is originally extracted from LLVM source
code too.

PR tree-optimization/100038

gcc/testsuite/ChangeLog:

* g++.dg/tree-ssa/pr100038.C: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
3 months agogccrs: Fix narrowing conversion warnings
Owen Avery [Thu, 17 Apr 2025 02:53:18 +0000 (22:53 -0400)] 
gccrs: Fix narrowing conversion warnings

Fixes PR#119641

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-place.h
(IndexVec::size_type): Add.
(IndexVec::MAX_INDEX): Add.
(IndexVec::size): Change the return type to the type of the
internal value used by the index type.
(PlaceDB::lookup_or_add_variable): Use the return value from the
PlaceDB::add_place call.
* checks/errors/borrowck/rust-bir.h
(struct BasicBlockId): Move this definition before the
definition of the struct Function.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
3 months agogccrs: Visit visibility in UseDeclaration
Pierre-Emmanuel Patry [Mon, 28 Apr 2025 11:05:49 +0000 (13:05 +0200)] 
gccrs: Visit visibility in UseDeclaration

Default visitor should visit all it's children.

gcc/rust/ChangeLog:

* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Visit visibility.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
3 months agogccrs: Some assorted tweaks and bug fixes
Owen Avery [Sat, 11 Jan 2025 05:15:05 +0000 (00:15 -0500)] 
gccrs: Some assorted tweaks and bug fixes

gcc/rust/ChangeLog:

* ast/rust-ast-visitor.cc
(DefaultASTVisitor::visit): Visit the loop labels of
WhileLetLoopExpr instances before visiting their scrutinee
expressions.
* resolve/rust-early-name-resolver-2.0.cc
(Early::resolve_glob_import): Pass the glob import's path
directly to NameResolutionContext::resolve_path.
* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Remove unnecessary call to
Identifier::as_string.
(flatten_glob): Improve handling of cases where a glob use tree
has no path.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
3 months agogccrs: Completely duplicate path node
Pierre-Emmanuel Patry [Fri, 25 Apr 2025 14:02:12 +0000 (16:02 +0200)] 
gccrs: Completely duplicate path node

Both nodes had the same id, this led to a resolution conflict.

gcc/rust/ChangeLog:

* expand/rust-derive-clone.cc (DeriveClone::clone_enum_struct): Clone
path to avoid using the same nodeid.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove now passing test from exclusion
list.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
3 months agogccrs: Use specialized param visit function for params
Pierre-Emmanuel Patry [Sat, 19 Apr 2025 12:14:25 +0000 (14:14 +0200)] 
gccrs: Use specialized param visit function for params

This commit introduce a new public function to visit function parameters
in the default visitor. It allows visitors derived from DefaultVisitor
to override only a small part of the default visitor.

gcc/rust/ChangeLog:

* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit_function_params):
Add specialized function to visit function parameters.
(DefaultASTVisitor::visit): Remove parameter visit and call specialized
function instead.
* ast/rust-ast-visitor.h: Add function prototye.
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Remove
function.
(Late::visit_function_params): Override specialized visit function.
* resolve/rust-late-name-resolver-2.0.h: Add overriden function
prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
3 months agogccrs: Remove passing test from exclusion list
Pierre-Emmanuel Patry [Sun, 6 Apr 2025 17:54:06 +0000 (19:54 +0200)] 
gccrs: Remove passing test from exclusion list

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove passing test from exclusion list.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
3 months agogccrs: Use stacked context for nested bindings.
Pierre-Emmanuel Patry [Sun, 6 Apr 2025 16:49:11 +0000 (18:49 +0200)] 
gccrs: Use stacked context for nested bindings.

Binding context may be stacked when a new binding group is introduced
within a const expression.

gcc/rust/ChangeLog:

* resolve/rust-name-resolution-context.h: Use BindingLayer instead.
* resolve/rust-name-resolution-context.cc (BindingLayer::BindingLayer):
Add new constructor for binding layer.
(BindingLayer::bind_test): Add a function to test a binding constraint.
(BindingLayer::push): Push a new binding group.
(BindingLayer::and_binded): Add function to test and-binding
constraint.
(BindingLayer::or_binded): Add function to test or-binding constraints.
(BindingLayer::insert_ident): Insert a new identifier in the current
binding group.
(BindingLayer::merge): Merge current binding group with it's parent.
(BindingLayer::get_source): Get the source of the current binding
group.
* resolve/rust-late-name-resolver-2.0.cc: Use stacked context for
binding group.
* util/rust-stacked-contexts.h: Add mutable peek function.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
3 months agogccrs: Add pattern bindings
Pierre-Emmanuel Patry [Sun, 6 Apr 2025 16:17:41 +0000 (18:17 +0200)] 
gccrs: Add pattern bindings

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add binding
creation in visitor.
* resolve/rust-late-name-resolver-2.0.h: Add function prototypes.
* resolve/rust-name-resolution-context.h: Add binding context.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
3 months agogccrs: Add binding context class
Pierre-Emmanuel Patry [Sun, 6 Apr 2025 15:09:42 +0000 (17:09 +0200)] 
gccrs: Add binding context class

We need to differentiate bindings types, so the same binding cannot be
reused multiple time in a product binding.

gcc/rust/ChangeLog:

* resolve/rust-name-resolution-context.h (struct Binding): Add Binding
struct to differentiate Or and Product bindings in patterns.
(enum class): Add Binding kind.
(class BindingContext): Add binding context with Binding stack.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
3 months agogccrs: Add hash function for Identifiers
Pierre-Emmanuel Patry [Sat, 5 Apr 2025 23:44:18 +0000 (01:44 +0200)] 
gccrs: Add hash function for Identifiers

gcc/rust/ChangeLog:

* ast/rust-ast.h: Add hash function.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
3 months agogccrs: Add equality operator for identifiers
Pierre-Emmanuel Patry [Sat, 5 Apr 2025 23:43:20 +0000 (01:43 +0200)] 
gccrs: Add equality operator for identifiers

gcc/rust/ChangeLog:

* ast/rust-ast.h: Add equality operator.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
3 months agogccrs: Add fn_once and Sized lang items to the test
Pierre-Emmanuel Patry [Fri, 4 Apr 2025 13:35:15 +0000 (15:35 +0200)] 
gccrs: Add fn_once and Sized lang items to the test

gcc/testsuite/ChangeLog:

* rust/compile/multiple_bindings1.rs: Add missing lang items.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
3 months agogccrs: Change expected error output to match nr2
Pierre-Emmanuel Patry [Thu, 24 Apr 2025 12:28:59 +0000 (14:28 +0200)] 
gccrs: Change expected error output to match nr2

Name resolution 2.0 message describes the context around the unresolved
items and should therefore be kept.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove test from exclusion list.
* rust/compile/use_1.rs: Change expected output and remove test from
nr1.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
3 months agogccrs: Update generics9 expected error message
Pierre-Emmanuel Patry [Wed, 23 Apr 2025 12:41:24 +0000 (14:41 +0200)] 
gccrs: Update generics9 expected error message

gcc/testsuite/ChangeLog:

* rust/compile/generics9.rs: Change expected error message.
* rust/compile/nr2/exclude: Remove test from exclusion list.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
3 months agogccrs: Prevent forward declaration in type parameters
Pierre-Emmanuel Patry [Wed, 23 Apr 2025 12:40:22 +0000 (14:40 +0200)] 
gccrs: Prevent forward declaration in type parameters

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc (DefaultResolver::visit): Add visit
function for TypeParam.
* resolve/rust-default-resolver.h: Add function prototype.
* resolve/rust-forever-stack.h: Add function to check for forward
declaration ban.
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Check forward
declarations.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
3 months agogccrs: Remove error state for GenericArg
Pierre-Emmanuel Patry [Mon, 7 Apr 2025 13:59:15 +0000 (15:59 +0200)] 
gccrs: Remove error state for GenericArg

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): Remove error kind
and change function call.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Change call name.
* ast/rust-path.cc (ConstGenericParam::as_string): Likewise.
* ast/rust-path.h: Remove error kind.
* hir/rust-ast-lower-type.cc (ASTLowerGenericParam::visit): Change call
name.
* parse/rust-parse-impl.h (Parser::parse_generic_param): Use optional
on parsing failure.
(Parser::parse_generic_arg): Likewise.
(Parser::parse_path_generic_args): Likewise.
* parse/rust-parse.h: Likewise.
* resolve/rust-ast-resolve-type.h: Change call name.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
3 months agogccrs: Change error message to match expected test output
Pierre-Emmanuel Patry [Wed, 23 Apr 2025 15:24:04 +0000 (17:24 +0200)] 
gccrs: Change error message to match expected test output

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Change error
message.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove passing test from exclusion list.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
3 months agogccrs: nr2.0: Improve error handling
Owen Avery [Thu, 17 Apr 2025 17:51:43 +0000 (13:51 -0400)] 
gccrs: nr2.0: Improve error handling

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc
(Early::build_import_mapping): Avoid outputting an "unresolved
import" error if other errors are outputted during resolution.
* resolve/rust-early-name-resolver-2.0.h
(Early::resolve_path_in_all_ns): Collect path resolution errors
while avoiding duplicate errors for resolutions in each
namespace.
* resolve/rust-forever-stack.h
(ForeverStack::resolve_path): Add parameter for collecting
errors.
(ForeverStack::find_starting_point): Likewise.
(ForeverStack::resolve_segments): Likewise.
* resolve/rust-forever-stack.hxx
(check_leading_kw_at_start): Likewise.
(ForeverStack::find_starting_point): Likewise.
(ForeverStack::resolve_segments): Likewise.
(ForeverStack::resolve_path): Likewise.
* resolve/rust-name-resolution-context.h
(NameResolutionContext::resolve_path): Add optional parameter
for collecting errors.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entry.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
3 months agogccrs: nr2.0: Fix derive-debug1.rs
Owen Avery [Sun, 6 Apr 2025 22:48:58 +0000 (18:48 -0400)] 
gccrs: nr2.0: Fix derive-debug1.rs

gcc/testsuite/ChangeLog:

* rust/compile/derive-debug1.rs: Adjust a path.
* rust/compile/nr2/exclude: Remove derive-debug1.rs.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
3 months agogccrs: prealloc the initilizer vector
Philip Herron [Thu, 17 Apr 2025 15:19:35 +0000 (16:19 +0100)] 
gccrs: prealloc the initilizer vector

There are two cases when initilizing an array, this is the
const context which means we need to build the array ctor,
which means using lots of memory, its super inefficient
because we are using a big wrapper over the GCC internals here
but preallocating the vectors here causes a:

  terminate called after throwing an instance of 'std::bad_alloc'

So this is a handy error condition to rely on for this senario.

Fixes Rust-GCC#3713
Fixes Rust-GCC#3727

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::array_copied_expr): prealloc the vector

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
3 months agogccrs: Fix ICE with empty generic arguments
Philip Herron [Thu, 17 Apr 2025 14:53:58 +0000 (15:53 +0100)] 
gccrs: Fix ICE with empty generic arguments

We have an assertion when accessing generic args if there are any which
is really useful so this adds the missing guards for the case where
they are specified but empty.

Fixes Rust-GCC#3649

gcc/rust/ChangeLog:

* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): add guard
* expand/rust-expand-visitor.cc (ExpandVisitor::visit): add guard

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 is missing error for this
* rust/compile/issue-3649.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
3 months agogccrs: Adjust segment start position errors
Owen Avery [Thu, 17 Apr 2025 20:51:21 +0000 (16:51 -0400)] 
gccrs: Adjust segment start position errors

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-path.cc
(ResolvePath::resolve_path): Adjust error messages.
* resolve/rust-ast-resolve-type.cc
(ResolveRelativeTypePath::go): Likewise.
* resolve/rust-forever-stack.hxx
(check_leading_kw_at_start): Likewise.

gcc/testsuite/ChangeLog:

* rust/compile/issue-3568.rs: Adjust expected errors.
* rust/compile/name_resolution9.rs: Likewise.
* rust/compile/self-path2.rs: Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
3 months agogccrs: Fix ICE when handling case of unknown field in HIR::FieldAccess
Philip Herron [Thu, 17 Apr 2025 12:50:55 +0000 (13:50 +0100)] 
gccrs: Fix ICE when handling case of unknown field in HIR::FieldAccess

We were wrongly adding the assertion that this must not be an enum but
this is a pointless assertion we only care that there are variant in the
ADT and if the field exists in the first variant.

Fixes Rust-GCC#3581

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): fix bad assertion

gcc/testsuite/ChangeLog:

* rust/compile/nonexistent-field.rs: fix bad error message
* rust/compile/issue-3581-1.rs: New test.
* rust/compile/issue-3581-2.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
3 months agogccrs: Add test case to show ice is fixed
Philip Herron [Fri, 18 Apr 2025 10:37:55 +0000 (11:37 +0100)] 
gccrs: Add test case to show ice is fixed

Fixes Rust-GCC#3652

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 does not error on the T it should require Self::T
* rust/compile/issue-3652.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
3 months agogccrs: nr2.0: Remove unnecessary copy of Node
Owen Avery [Thu, 17 Apr 2025 23:23:12 +0000 (19:23 -0400)] 
gccrs: nr2.0: Remove unnecessary copy of Node

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.hxx
(ForeverStack::resolve_path): Pass instance of Node to lambda by
reference instead of by value.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
3 months agogccrs: Fix ICE in struct expressions
Philip Herron [Thu, 17 Apr 2025 13:38:04 +0000 (14:38 +0100)] 
gccrs: Fix ICE in struct expressions

The error handling here was done long ago when we didnt know how to do
any error handling very well. This removed bad fatal_errors and adds in
some nice rich_location error diagnostics instead.

Fixes Rust-GCC#3628

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-struct-field.h: keep reference to parent expression
* typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::TypeCheckStructExpr):
update ctor
(TypeCheckStructExpr::resolve): remove bad rust_fatal_errors
(TypeCheckStructExpr::visit): cleanup errors

gcc/testsuite/ChangeLog:

* rust/compile/macros/mbe/macro-issue2983_2984.rs: cleanup error diagnotics
* rust/compile/struct_init1.rs: likewise
* rust/compile/issue-3628.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
3 months agogccrs: nr2.0: Handle StructPatternFieldIdent
Owen Avery [Thu, 17 Apr 2025 18:02:45 +0000 (14:02 -0400)] 
gccrs: nr2.0: Handle StructPatternFieldIdent

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Handle StructPatternFieldIdent.
* resolve/rust-late-name-resolver-2.0.h
(Late::visit): Likewise.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entry.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
3 months agogccrs: Add test case to show ICE is fixed
Philip Herron [Thu, 17 Apr 2025 15:29:05 +0000 (16:29 +0100)] 
gccrs: Add test case to show ICE is fixed

Fixes Rust-GCC#3662

gcc/testsuite/ChangeLog:

* rust/compile/issue-3662.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
3 months agogccrs: Add test case to show issue is fixed
Philip Herron [Thu, 17 Apr 2025 15:04:55 +0000 (16:04 +0100)] 
gccrs: Add test case to show issue is fixed

This was already fixed in: bb01719f0e1 but we require fn_once lang item
to be defined as we are working on libcore support still.

Fixes Rust-GCC#3711

gcc/testsuite/ChangeLog:

* rust/compile/issue-3711.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
3 months agogccrs: Add gimple test for black box intrinsic
Pierre-Emmanuel Patry [Thu, 17 Apr 2025 16:28:52 +0000 (18:28 +0200)] 
gccrs: Add gimple test for black box intrinsic

gcc/testsuite/ChangeLog:

* rust/compile/black_box.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
3 months agogccrs: Add execute test for black_box intrinsic
Pierre-Emmanuel Patry [Thu, 17 Apr 2025 15:53:15 +0000 (17:53 +0200)] 
gccrs: Add execute test for black_box intrinsic

gcc/testsuite/ChangeLog:

* rust/execute/black_box.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
3 months agogccrs: Add LlvmInlineAsm node dump
Pierre-Emmanuel Patry [Thu, 17 Apr 2025 12:27:11 +0000 (14:27 +0200)] 
gccrs: Add LlvmInlineAsm node dump

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): Dump llvm inline
asm tokens.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
3 months agogccrs: Parse and lower llvm asm node
Pierre-Emmanuel Patry [Tue, 15 Apr 2025 09:38:29 +0000 (11:38 +0200)] 
gccrs: Parse and lower llvm asm node

Add a new HIR LlvmInlineAsm HIR node as well as some structures to
represent it's options and operands. Lower AST::LlvmInlineAsm node to it
and then create a tree from that node.

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): Remove unreachable
code.
* ast/rust-expr.h (struct LlvmOperand): Add LlvmOperand struct to
represent input and outputs.
(class LlvmInlineAsm): Add input, output and clobber operands.
(struct TupleTemplateStr): Add locus getter.
* backend/rust-compile-block.h: Add visit for LlvmInlineAsm.
* backend/rust-compile-expr.cc (CompileExpr::visit): Add llvm inline
asm stmt compilation.
* backend/rust-compile-expr.h: Add function prototype.
* backend/rust-compile-asm.h (class CompileLlvmAsm): Add llvm asm hir
not to gimple.
* backend/rust-compile-asm.cc (CompileLlvmAsm::CompileLlvmAsm): Add
constructor.
(CompileLlvmAsm::construct_operands): Add function to construct operand
tree.
(CompileLlvmAsm::construct_clobbers): Add function to construct clobber
tree.
(CompileLlvmAsm::tree_codegen_asm): Generate the whole tree for a given
llvm inline assembly node.
* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit):
Add visit function.
* checks/errors/borrowck/rust-bir-builder-expr-stmt.h: Add function
prototype.
* checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: Add visit
function.
* checks/errors/borrowck/rust-bir-builder-struct.h: Likewise.
* checks/errors/borrowck/rust-function-collector.h: Likewise.
* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit):
Likewise.
* checks/errors/privacy/rust-privacy-reporter.h: Add visit function
prototype.
* checks/errors/rust-const-checker.cc (ConstChecker::visit): Add visit
function.
* checks/errors/rust-const-checker.h: Add visit function prototype.
* checks/errors/rust-hir-pattern-analysis.cc (PatternChecker::visit):
Add visit function.
* checks/errors/rust-hir-pattern-analysis.h: Add visit function
prototype.
* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Add
visit function.
* checks/errors/rust-unsafe-checker.h: Add function prototype.
* expand/rust-macro-builtins-asm.cc (parse_llvm_templates): Parse
templates.
(parse_llvm_arguments): Add function to parse non template tokens.
(parse_llvm_operands): Add function to parse operands, either input or
output.
(parse_llvm_outputs): Add function to parse and collect llvm asm
outputs.
(parse_llvm_inputs): Likewise with inputs.
(parse_llvm_clobbers): Add function to parse llvm asm clobbers.
(parse_llvm_options): Add function to parse llvm asm options.
(parse_llvm_asm): Add function to parse llvm asm.
* expand/rust-macro-builtins-asm.h (class LlvmAsmContext): Add context
for llvm asm parser.
(parse_llvm_outputs): Add function prototype.
(parse_llvm_inputs): Likewise.
(parse_llvm_clobbers): Likewise.
(parse_llvm_options): Likewise.
* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Lower AST llvm
asm node to HIR.
* hir/rust-ast-lower-expr.h: Add function prototype.
* hir/rust-hir-dump.cc (Dump::visit): Add visit function.
* hir/rust-hir-dump.h: Add function prototype.
* hir/tree/rust-hir-expr-abstract.h: Add HIR llvm asm node kind.
* hir/tree/rust-hir-expr.h (struct LlvmOperand): Add LlvmOperand type
to represent input and outputs.
(class LlvmInlineAsm): Add LlvmInlineAsm hir node.
* hir/tree/rust-hir-full-decls.h (class LlvmInlineAsm): Add
LlvmInlineAsm hir node forward declaration.
* hir/tree/rust-hir-visitor.h: Add visit functions for LlvmInlineAsm
hir node.
* hir/tree/rust-hir.cc (LlvmInlineAsm::accept_vis): Add hir node
visitor related functions.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
Type check input and output operands.
* typecheck/rust-hir-type-check-expr.h: Add function prototype.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Visit input and
output operand expressions.
* resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Resolve input
and output expressions.
* resolve/rust-ast-resolve-expr.h: Add function prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
3 months agogccrs: Add llvmInlineAsm node
Pierre-Emmanuel Patry [Thu, 10 Apr 2025 11:05:15 +0000 (13:05 +0200)] 
gccrs: Add llvmInlineAsm node

InlineAsm node does not support memory clobbers.

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): Make visitor
unreachable.
* ast/rust-ast-collector.h: Add visit for LlvmInlineAsmNode.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Add visit
function for the default ast visitor.
* ast/rust-ast-visitor.h: Add function prototype.
* ast/rust-ast.cc (LlvmInlineAsm::accept_vis): Add accept_vis to
LlvmInlineAsm node.
* ast/rust-ast.h: Add LlvmInlineAsm node kind.
* ast/rust-expr.h (class LlvmInlineAsm): Add LlvmInlineAsm node.
* expand/rust-derive.h: Add visit function for LlvmInlineAsm node.
* expand/rust-macro-builtins-asm.cc (MacroBuiltin::llvm_asm_handler):
Add handler for llvm inline assembly nodes.
(parse_llvm_asm): Add function to parse llvm assembly nodes.
* expand/rust-macro-builtins-asm.h (parse_llvm_asm): Add function
prototypes.
* expand/rust-macro-builtins.cc (inline_llvm_asm_maker): Add macro
transcriber.
* expand/rust-macro-builtins.h: Add transcriber function prototype.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Add visit
function for LlvmInlineAsm node.
* hir/rust-ast-lower-base.h: Add visit function prototype.
* resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Add visit
function for LlvmInlineAsm node.
* resolve/rust-ast-resolve-base.h: Add visit function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
3 months agogccrs: Emit error with old asm syntax in new asm blocks
Pierre-Emmanuel Patry [Wed, 9 Apr 2025 15:41:24 +0000 (17:41 +0200)] 
gccrs: Emit error with old asm syntax in new asm blocks

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-asm.cc (parse_asm_arg): Emit error
message.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
3 months agogccrs: Add check for placeholder (infer) type in return position
Philip Herron [Wed, 16 Apr 2025 19:38:17 +0000 (20:38 +0100)] 
gccrs: Add check for placeholder (infer) type in return position

It is not allowed to have a declared inference variable in the return
position of a function as this may never get infered you need good points
of truth.

Ideally if we get a student for GSoC 25 we will get the Default Hir Visitor
so that we can grab the HIR::InferredType locus instead of using the ref
location lookups.

Fixes Rust-GCC#402

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): add diagnostic
* typecheck/rust-tyty.cc (BaseType::contains_infer): new helper to grab first infer var
* typecheck/rust-tyty.h: prototype

gcc/testsuite/ChangeLog:

* rust/compile/issue-402.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
3 months agogccrs: Fix ICE when checking shift's which are behind array refs
Philip Herron [Wed, 16 Apr 2025 16:13:04 +0000 (17:13 +0100)] 
gccrs: Fix ICE when checking shift's which are behind array refs

I copied a bad form of this check from the c front-end this updates it
to ensure the rhs is an INTEGER_CST and the lhs needs checked in the first
place.

Fixes Rust-GCC#3664

gcc/rust/ChangeLog:

* rust-gcc.cc (arithmetic_or_logical_expression): Ensure this is an integer

gcc/testsuite/ChangeLog:

* rust/compile/issue-3664.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
3 months agogccrs: Fix crash in hir dump as labels are optional
Philip Herron [Wed, 16 Apr 2025 16:00:28 +0000 (17:00 +0100)] 
gccrs: Fix crash in hir dump as labels are optional

gcc/rust/ChangeLog:

* hir/rust-hir-dump.cc (Dump::visit): add guard for optional label

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
3 months agogccrs: Update comments in repr parsing code
Yap Zhi Heng [Fri, 4 Apr 2025 11:37:03 +0000 (19:37 +0800)] 
gccrs: Update comments in repr parsing code

gcc/rust/ChangeLog:

* typecheck/rust-tyty.h: Remove extra redundant comment.
* typecheck/rust-hir-type-check-base.cc: Update comment on repr
handling.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
3 months agogccrs: Implement integer representation for enums
Zhi Heng [Thu, 3 Apr 2025 15:02:59 +0000 (23:02 +0800)] 
gccrs: Implement integer representation for enums

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-base.cc: Set enum representing
type properly if repr is an integer type.
* typecheck/rust-hir-type-check-item.cc: Update comments.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
3 months agogccrs: Implement typecheck for zero-variant enums
Zhi Heng [Thu, 3 Apr 2025 12:23:46 +0000 (20:23 +0800)] 
gccrs: Implement typecheck for zero-variant enums

gcc/rust/ChangeLog:

* typecheck/rust-tyty.h: Add new `ReprKind` enum to
`ReprOptions`.
* typecheck/rust-hir-type-check-base.cc: Handle setting of
`repr_kind`.
* typecheck/rust-hir-type-check-item.cc: New check for
zero-variant enums.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
3 months agogccrs: Fix segv in unsafe chcker
Philip Herron [Fri, 4 Apr 2025 15:35:13 +0000 (16:35 +0100)] 
gccrs: Fix segv in unsafe chcker

Trait constants were missing type resolution step, this adds that
as if it was a normal constant. The unsafe checker was missing a
null check.

Fixes Rust-GCC#3612

gcc/rust/ChangeLog:

* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): add null check
* hir/tree/rust-hir-item.h: add has_type helper
* typecheck/rust-hir-trait-resolve.cc (TraitItemReference::resolve_item):
add missing type checking

gcc/testsuite/ChangeLog:

* rust/compile/issue-3612.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
3 months agosimplify-rtx: Split out native_decode_int
Richard Sandiford [Mon, 28 Apr 2025 13:40:09 +0000 (14:40 +0100)] 
simplify-rtx: Split out native_decode_int

native_decode_rtx handles integer modes by building up a wide_int
and then converting it to an rtx.  This patch splits out the
wide_int part, so that callers who don't want an rtx can avoid
creating garbage rtl.

gcc/
* rtl.h (native_decode_int): Declare.
* simplify-rtx.cc (native_decode_int): New function, split out from...
(native_decode_rtx): ...here.

3 months agox86: Properly find the maximum stack slot alignment
H.J. Lu [Tue, 14 Mar 2023 18:41:51 +0000 (11:41 -0700)] 
x86: Properly find the maximum stack slot alignment

Don't assume that stack slots can only be accessed by stack or frame
registers.  We first find all registers defined by stack or frame
registers.  Then check memory accesses by such registers, including
stack and frame registers.

gcc/

PR target/109780
PR target/109093
* config/i386/i386.cc (stack_access_data): New.
(ix86_update_stack_alignment): Likewise.
(ix86_find_all_reg_use_1): Likewise.
(ix86_find_all_reg_use): Likewise.
(ix86_find_max_used_stack_alignment): Also check memory accesses
from registers defined by stack or frame registers.

gcc/testsuite/

PR target/109780
PR target/109093
* g++.target/i386/pr109780-1.C: New test.
* gcc.target/i386/pr109093-1.c: Likewise.
* gcc.target/i386/pr109780-1.c: Likewise.
* gcc.target/i386/pr109780-2.c: Likewise.
* gcc.target/i386/pr109780-3.c: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Co-Authored-By: Uros Bizjak <ubizjak@gmail.com>
3 months agoipa/119973 - IPA PTA issue with global initializers
Richard Biener [Mon, 28 Apr 2025 09:15:53 +0000 (11:15 +0200)] 
ipa/119973 - IPA PTA issue with global initializers

For global initializers with IPA PTA we initialize them from the
IPA reference data but that lacks references to the constant pool.
The following conservatively considers the whole initializer.

PR ipa/119973
* tree-ssa-structalias.cc (create_variable_info_for):
Build constraints from DECL_INITIAL directly rather than
the IPA reference list which is incomplete.

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

3 months agolto/113207 - make fld_type_variant more picky
Richard Biener [Mon, 3 Feb 2025 13:16:45 +0000 (14:16 +0100)] 
lto/113207 - make fld_type_variant more picky

The below adds additional verification to fld_type_variant that
there's only one variant matching fld_type_variant_equal_p on the
chain.  The PR shows that variants built with build_qualified_type
can be equal to others in that regard but not with regard to
what build_qualified_type does.

PR lto/113207
* ipa-free-lang-data.cc (fld_type_variant): Add extra checking.

3 months agotree-optimization/119044 - predcom fails to preserve alias info
Richard Biener [Thu, 27 Feb 2025 13:51:44 +0000 (14:51 +0100)] 
tree-optimization/119044 - predcom fails to preserve alias info

Predictive commoning fails to preserve alias info for the refs it
creates.  The following adds this to see whether it fixes the
observed regression in 436.cactusADM after r15-7665.

PR tree-optimization/119044
* tree-predcom.cc (ref_at_iteration): Copy alias info
from the original ref.

3 months agotree-optimization/119103 - missed overwidening detection for shift
Richard Biener [Tue, 4 Mar 2025 09:34:39 +0000 (10:34 +0100)] 
tree-optimization/119103 - missed overwidening detection for shift

When vectorizing a shift of u16 data by an amount that's known to
be less than 16 we currently fail to emit a vector u16 shift.  The
first reason is that the promotion of the shift amount is hoisted
only by PRE and that cannot preserve range info, the second reason
is that pattern detection doesn't use range info when computing
the precision required for an operation.

The following addresses the first issue by making LIM hoist all
expressions for the pass that runs right before PRE and the
second issue by querying ranges for the shift amount.

PR tree-optimization/119103
* tree-ssa-loop-im.cc (in_loop_pipeline): Globalize.
(compute_invariantness): Override costing when we run
right before PRE and PRE is enabled.
(pass_lim::execute): Adjust.
* tree-vect-patterns.cc (vect_determine_precisions_from_users):
For variable shift amounts use range information.

* gcc.target/i386/pr119103.c: New testcase.

3 months agomiddle-end/80342 - genmatch optimize outer conversions
Richard Biener [Tue, 21 Jan 2025 12:50:26 +0000 (13:50 +0100)] 
middle-end/80342 - genmatch optimize outer conversions

The following improves genmatch generated code so we avoid more
spurious SSA assignments to be pushed to the GIMPLE sequence or
simplifications rejected when we're not supposed to produce any
for outer and intermediate conversions.

* genmatch.cc (::gen_transform): Add in_place parameter.
Assert it isn't set in unexpected places.
(possible_noop_convert): New.
(expr::gen_transform): Support in_place and emit code to
compute a child in-place when the operation is a conversion.
(dt_simplify::gen_1): Arrange for an outermost conversion
to be elided by generating the transform of the operand
in-place.
* match.pd (__real cepxi (x) -> cos (x)): Use single_use.

3 months agomiddle-end/60779 - LTO vs. -fcx-fortran-rules and -fcx-limited-range
Richard Biener [Tue, 18 Feb 2025 11:52:34 +0000 (12:52 +0100)] 
middle-end/60779 - LTO vs. -fcx-fortran-rules and -fcx-limited-range

The following changes how flag_complex_method is managed towards
being able to record that in the optimization set so we can stream
and restore it per function.  Currently -fcx-fortran-rules and
-fcx-limited-range are separate recorded options but saving/restoring
does not restore flag_complex_method which is later used in the
middle-end.

The solution is to make -fcx-fortran-rules and -fcx-limited-range
aliases of a new -fcx-method= switch that represents flag_complex_method
directly so we can save and restore it.

PR middle-end/60779
* common.opt (fcx-method=): New, map to flag_complex_method.
(Enum complex_method): New.
(fcx-limited-range): Alias to -fcx-method=limited-range.
(fcx-fortran-rules): Alias to -fcx-medhot=fortran.
* ipa-inline-transform.cc (inline_call): Check flag_complex_method.
* ipa-inline.cc (can_inline_edge_by_limits_p): Likewise.
* opts.cc (finish_options): Adjust.
(set_fast_math_flags): Likewise.
* doc/invoke.texi (fcx-method=): Document.

* gcc.dg/lto/pr60779_0.c: New testcase.
* gcc.dg/lto/pr60779_1.c: Likewise.

3 months agomiddle-end/116083 - vectorizer slowness
Richard Biener [Tue, 3 Dec 2024 13:21:47 +0000 (14:21 +0100)] 
middle-end/116083 - vectorizer slowness

Turns out SLP discovery can end up doing a lot of vector type
builds from scalar types.  Those are all ultimatively cached but
end up built and layouted first.  The latter is particularly
expensive because it does tree node arithmetic to compute TYPE_SIZE
and TYPE_SIZE_UNIT.  The following replaces this with the appropriate
poly-int arithmetic which speeds up the testcase by 50%.

PR middle-end/116083
* stor-layout.cc (layout_type): Compute TYPE_SIZE and
TYPE_SIZE_UNIT for vector types from the component mode
sizes.

3 months agoPrune non-SLP paths from vectorizer loop analysis
Richard Biener [Thu, 30 Jan 2025 14:03:04 +0000 (15:03 +0100)] 
Prune non-SLP paths from vectorizer loop analysis

The following prunes non-SLP iteration and the parts of non-SLP
stmt analysis that is no longer necessary - we need to keep the
parts that bail on stmts not covered by SLP discovery or that
failed SLP discovery.  This will only go away when a we can build
a fully covering single-lane SLP graph to fall back to.

* tree-vect-loop.cc (vect_analyze_loop_operations): Prune
all actual analysis and only fail when we discover a not
SLP covered stmt.
(vect_analyze_loop_2): Remove path trying without SLP.

3 months agoRemove non-SLP vector loop transform
Richard Biener [Thu, 30 Jan 2025 12:45:00 +0000 (13:45 +0100)] 
Remove non-SLP vector loop transform

The following removes the stmt-based vectorization loop transform code.
This also removes some debug stmt handling (that looked incomplete)
which is also handled during peeling, and special-casing some stmts
that should be killed off early and not left to DCE.

Moving of dump from vect_transform_loop_stmt to vect_transform_stmt
is to avoid regressing a few testcases.

* tree-vect-loop.cc (vect_loop_kill_debug_uses): Remove.
(maybe_set_vectorized_backedge_value): Likewise.
(vect_transform_loop_stmt): Likewise.  Move dump printing
to vect_transform_stmt.
(vect_transform_loop): Remove loop over loop stmts transforming
them, but retain some DCE code still necessary.
* tree-vect-stmts.cc (vect_transform_stmt): Dump that
we're vectorizing a stmt.

3 months agoRemove --param vect-force-slp
Richard Biener [Thu, 30 Jan 2025 10:42:51 +0000 (11:42 +0100)] 
Remove --param vect-force-slp

The following removes the ability to switch back to non SLP-only
operation of the vectorizer - a requirement to start cleaning out
non-SLP paths without risk of regressing that case.

* params.opt (--param=vect-force-slp): Remove.
* doc/invoke.texi (--param=vect-force-slp): Likewise.
* tree-vect-loop.cc (vect_analyze_loop_2): Assume
param_vect_force_slp is 1.
* tree-vect-stmts.cc (vect_analyze_stmt): Likewise.

3 months agolibstdc++: Fix mingw build by using _M_span [PR119970]
Tomasz Kamiński [Mon, 28 Apr 2025 06:53:59 +0000 (08:53 +0200)] 
libstdc++: Fix mingw build by using _M_span [PR119970]

The r16-142-g01e5ef3e8b9128 chagned return type of _Str_sink::view()
to basic_string_view<_CharT>. The mutable access is provided by _M_span
function, that is now used for mingw path.

PR libstdc++/119970

libstdc++-v3/ChangeLog:

* include/std/ostream (vprint_unicode) [_WIN32 && !__CYGWIN__]: Call
_Str_sink::_M_span instead of view.
* include/std/print (vprint_unicode) [_WIN32 && !__CYGWIN__]: Call
_Str_sink::_M_span instead of view.

3 months agolibstdc++: Strip reference and cv-qual in range deduction guides for maps.
Tomasz Kamiński [Thu, 20 Mar 2025 08:02:03 +0000 (09:02 +0100)] 
libstdc++: Strip reference and cv-qual in range deduction guides for maps.

This implements part of LWG4223 that adjust the deduction guides for maps types
(map, unordered_map, flat_map and non-unique equivalent) from "range"
(std::from_range, iterator pair), such that referience and cv qualification are
stripped from the element of the pair-like value_type.

In combination with r15-8296-gd50171bc07006d, the LWG4223 is fully implemented now.

libstdc++-v3/ChangeLog:

* include/bits/ranges_base.h (__detail::__range_key_type):
Replace remove_const_t with remove_cvref_t.
(__detail::__range_mapped_type): Apply remove_cvref_t.
* include/bits/stl_iterator.h: (__detail::__iter_key_t):
Replace remove_const_t with __remove_cvref_t.
(__detail::__iter_val_t): Apply __remove_cvref_t.
* testsuite/23_containers/flat_map/1.cc: New tests.
* testsuite/23_containers/flat_multimap/1.cc: New tests.
* testsuite/23_containers/map/cons/deduction.cc: New tests.
* testsuite/23_containers/map/cons/from_range.cc: New tests.
* testsuite/23_containers/multimap/cons/deduction.cc: New tests.
* testsuite/23_containers/multimap/cons/from_range.cc: New tests.
* testsuite/23_containers/unordered_map/cons/deduction.cc: New tests.
* testsuite/23_containers/unordered_map/cons/from_range.cc: New tests.
* testsuite/23_containers/unordered_multimap/cons/deduction.cc:
New tests.
* testsuite/23_containers/unordered_multimap/cons/from_range.cc:
New tests.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
3 months agolibstdc++: Implement missing allocator-aware constructors for unordered containers.
Tomasz Kamiński [Tue, 18 Mar 2025 15:10:48 +0000 (16:10 +0100)] 
libstdc++: Implement missing allocator-aware constructors for unordered containers.

This patch implements remainder of LWG2713 (after r15-8293-g64f5c854597759)
by adding missing allocator aware version of unordered associative containers
constructors accepting pair of iterators or initializer_list, and corresponding
deduction guides.

libstdc++-v3/ChangeLog:

* include/bits/unordered_map.h (unordered_map):
Define constructors accepting:
(_InputIterator, _InputIterator, const allocator_type&),
(initializer_list<value_type>, const allocator_type&),
(unordered_multimap): Likewise.
* include/debug/unordered_map (unordered_map): Likewise.
(unordered_multimap): Likewise.
* include/bits/unordered_set.h (unordered_set):
Define constructors and deduction guide accepting:
(_InputIterator, _InputIterator, const allocator_type&),
(initializer_list<value_type>, const allocator_type&),
(unordered_multiset): Likewise.
* include/debug/unordered_set (unordered_set): Likewise.
(unordered_multiset): Likewise.
* testsuite/23_containers/unordered_map/cons/66055.cc: New tests.
* testsuite/23_containers/unordered_map/cons/deduction.cc: New tests.
* testsuite/23_containers/unordered_multimap/cons/66055.cc: New tests.
* testsuite/23_containers/unordered_multimap/cons/deduction.cc: New
tests.
* testsuite/23_containers/unordered_multiset/cons/66055.cc: New tests.
* testsuite/23_containers/unordered_multiset/cons/deduction.cc: New
tests.
* testsuite/23_containers/unordered_set/cons/66055.cc: New tests.
* testsuite/23_containers/unordered_set/cons/deduction.cc: New tests.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
3 months agotailc: Improve tail recursion handling [PR119493]
Jakub Jelinek [Mon, 28 Apr 2025 07:22:50 +0000 (09:22 +0200)] 
tailc: Improve tail recursion handling [PR119493]

Here is a patch to improve the tail recursion handling also for
non-musttail calls.

2025-04-28  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/119493
* tree-tailcall.cc (find_tail_calls): Handle non-gimple_reg_type
arguments which aren't just passed through for tail recursions
even for non-musttail calls.

3 months agoc-family: Improve location for -Wunknown-pragmas in a _Pragma [PR118838]
Lewis Hyatt [Tue, 11 Feb 2025 18:45:41 +0000 (13:45 -0500)] 
c-family: Improve location for -Wunknown-pragmas in a _Pragma [PR118838]

The warning for -Wunknown-pragmas is issued at the location provided by
libcpp to the def_pragma() callback. This location is
cpp_reader::directive_line, which is a location for the start of the line
only; it is also not a valid location in case the unknown pragma was lexed
from a _Pragma string. These factors make it impossible to suppress
-Wunknown-pragmas via _Pragma("GCC diagnostic...") directives on the same
source line, as in the PR and the test case. Address that by issuing the
warning at a better location returned by cpp_get_diagnostic_override_loc().
libcpp already maintains this location to handle _Pragma-related diagnostics
internally; it was needed also to make a publicly accessible version of it.

gcc/c-family/ChangeLog:

PR c/118838
* c-lex.cc (cb_def_pragma): Call cpp_get_diagnostic_override_loc()
to get a valid location at which to issue -Wunknown-pragmas, in case
it was triggered from a _Pragma.

libcpp/ChangeLog:

PR c/118838
* errors.cc (cpp_get_diagnostic_override_loc): New function.
* include/cpplib.h (cpp_get_diagnostic_override_loc): Declare.

gcc/testsuite/ChangeLog:

PR c/118838
* c-c++-common/cpp/pragma-diagnostic-loc-2.c: New test.
* g++.dg/gomp/macro-4.C: Adjust expected output.
* gcc.dg/gomp/macro-4.c: Likewise.
* gcc.dg/cpp/Wunknown-pragmas-1.c: Likewise.

3 months agogcc: For Windows x86-32, always attempt to realign stack regardless of SSE
LIU Hao [Sun, 27 Apr 2025 10:18:34 +0000 (18:18 +0800)] 
gcc: For Windows x86-32, always attempt to realign stack regardless of SSE

For Windows x86-32 targets, the Microsoft ABI only guarantees that the stack
is aligned to 4-byte boundaries. GCC knows about the default alignment of the
stack. However, before this commit, it did not realign the stack unless SSE
was also enabled.

When a stricter (larger) alignment is requested, it's always necessary to
realign the stack, as what Solaris does.

Reference: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111107#c14
Signed-off-by: LIU Hao <lh_mouse@126.com>
Signed-off-by: Jonathan Yong <10walls@gmail.com>
gcc/ChangeLog:

PR target/111107
* config/i386/cygming.h (STACK_REALIGN_DEFAULT): Copy from sol2.h.

3 months agoFix size_t in id-15.c and infoleak-net-ethtool-ioctl.c for llp64
Jonathan Yong [Thu, 24 Apr 2025 07:42:17 +0000 (07:42 +0000)] 
Fix size_t in id-15.c and infoleak-net-ethtool-ioctl.c for llp64

Use __SIZE_TYPE__ for size_t types so that it works for
llp64.

Signed-off-by: Jonathan Yong <10walls@gmail.com>
gcc/testsuite/ChangeLog:

* gcc.dg/graphite/id-15.c: Use __SIZE_TYPE__ instead of
unsigned long.
* gcc.dg/plugin/infoleak-net-ethtool-ioctl.c: ditto.

3 months agoDaily bump.
GCC Administrator [Mon, 28 Apr 2025 00:18:29 +0000 (00:18 +0000)] 
Daily bump.

3 months agoc++/modules: Ensure DECL_FRIEND_CONTEXT is streamed [PR119939]
Nathaniel Shead [Fri, 25 Apr 2025 14:10:34 +0000 (00:10 +1000)] 
c++/modules: Ensure DECL_FRIEND_CONTEXT is streamed [PR119939]

An instantiated friend function relies on DECL_FRIEND_CONTEXT being set
to be able to recover the template arguments of the class that
instantiated it, despite not being a template itself.  This patch
ensures that this data is streamed even when DECL_CLASS_SCOPE_P is not
true.

PR c++/119939

gcc/cp/ChangeLog:

* module.cc (trees_out::lang_decl_vals): Also stream
lang->u.fn.context when DECL_UNIQUE_FRIEND_P.
(trees_in::lang_decl_vals): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/modules/concept-11_a.H: New test.
* g++.dg/modules/concept-11_b.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
3 months agossa-fre-4.c: Enable for all targets and adjust scan match
H.J. Lu [Sun, 10 Nov 2024 09:55:20 +0000 (17:55 +0800)] 
ssa-fre-4.c: Enable for all targets and adjust scan match

Since the C frontend no longer promotes char argument, enable ssa-fre-4.c
for all targets and adjust scan match.

PR middle-end/112877
* gcc.dg/tree-ssa/ssa-fre-4.c: Enable for all targets and adjust
scan match.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
3 months agoscev-cast.c: Enable for all targets and adjust scan matches
H.J. Lu [Sun, 10 Nov 2024 08:50:46 +0000 (16:50 +0800)] 
scev-cast.c: Enable for all targets and adjust scan matches

Since the C frontend no longer promotes char argument, enable scev-cast.c
for all targets and adjust scan matches.

PR middle-end/112877
* gcc.dg/tree-ssa/scev-cast.c: Enable for all targets and adjust
scan match.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
3 months agovect-simd-clone-1[6-8][cd].c: Expect in-branch clones for x86
H.J. Lu [Sun, 10 Nov 2024 08:41:10 +0000 (16:41 +0800)] 
vect-simd-clone-1[6-8][cd].c: Expect in-branch clones for x86

Since the C frontend no longer promotes char and short arguments, expect
in-branch clones for x86.

PR middle-end/112877
* gcc.dg/vect/vect-simd-clone-16c.c: Expect in-branch clones for
x86.
* gcc.dg/vect/vect-simd-clone-16d.c: Likewise.
* gcc.dg/vect/vect-simd-clone-17c.c: Likewise.
* gcc.dg/vect/vect-simd-clone-17d.c: Likewise.
* gcc.dg/vect/vect-simd-clone-18c.c: Likewise.
* gcc.dg/vect/vect-simd-clone-18d.c: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
3 months agoi386: Adjust apx-ndd.c for frontend promotion removal
H.J. Lu [Sun, 10 Nov 2024 03:27:14 +0000 (11:27 +0800)] 
i386: Adjust apx-ndd.c for frontend promotion removal

Since the C frontend no longer promotes integer argument smaller than int,
the apx-ndd.c codgen is slightly different:

apx-ndd.s (original) 2024-11-10 06:07:09.894876973 +0800
apx-ndd.s (updated)  2024-11-10 06:06:59.371860565 +0800
@@ -17,7 +17,7 @@ foo_add_char:
 foo1_add_char:
 .LFB1:
  .cfi_startproc
- leal (%rsi,%rdi), %eax
+ leal (%rdi,%rsi), %eax
  ret
  .cfi_endproc
 .LFE1:
@@ -50,7 +50,7 @@ foo_add_short:
 foo1_add_short:
 .LFB4:
  .cfi_startproc
- leal (%rsi,%rdi), %eax
+ leal (%rdi,%rsi), %eax
  ret
  .cfi_endproc
 .LFE4:
@@ -413,7 +413,7 @@ foo_and_char:
 foo1_and_char:
 .LFB37:
  .cfi_startproc
- andl %edi, %esi, %eax
+ andl %esi, %edi, %eax
  ret
  .cfi_endproc
 .LFE37:
@@ -435,7 +435,7 @@ foo_and_short:
 foo1_and_short:
 .LFB39:
  .cfi_startproc
- andl %edi, %esi, %eax
+ andl %esi, %edi, %eax
  ret
  .cfi_endproc
 .LFE39:
@@ -501,7 +501,7 @@ foo_or_char:
 foo1_or_char:
 .LFB45:
  .cfi_startproc
- orl %edi, %esi, %eax
+ orl %esi, %edi, %eax
  ret
  .cfi_endproc
 .LFE45:
@@ -523,7 +523,7 @@ foo_or_short:
 foo1_or_short:
 .LFB47:
  .cfi_startproc
- orl %edi, %esi, %eax
+ orl %esi, %edi, %eax
  ret
  .cfi_endproc
 .LFE47:
@@ -589,7 +589,7 @@ foo_xor_char:
 foo1_xor_char:
 .LFB53:
  .cfi_startproc
- xorl %edi, %esi, %eax
+ xorl %esi, %edi, %eax
  ret
  .cfi_endproc
 .LFE53:
@@ -611,7 +611,7 @@ foo_xor_short:
 foo1_xor_short:
 .LFB55:
  .cfi_startproc
- xorl %edi, %esi, %eax
+ xorl %esi, %edi, %eax
  ret
  .cfi_endproc
 .LFE55:
@@ -1018,7 +1018,7 @@ foo4_rol_uint64_t:
 foo1_imul_short:
 .LFB92:
  .cfi_startproc
- imull %edi, %esi, %eax
+ imull %esi, %edi, %eax
  ret
  .cfi_endproc
 .LFE92:

Adjust the assembler scans.

PR middle-end/112877
* gcc.target/i386/apx-ndd.c: Adjusted.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
3 months agoDrop targetm.promote_prototypes from C, C++ and Ada frontends
H.J. Lu [Wed, 20 Nov 2024 23:54:35 +0000 (07:54 +0800)] 
Drop targetm.promote_prototypes from C, C++ and Ada frontends

Remove the targetm.calls.promote_prototypes call from C, C++ and Ada
frontends.

gcc/

PR c/48274
PR middle-end/112877
PR middle-end/118288
* gimple.cc (gimple_builtin_call_types_compatible_p): Remove the
targetm.calls.promote_prototypes call.
* tree.cc (tree_builtin_call_types_compatible_p): Likewise.

gcc/ada/

PR middle-end/112877
* gcc-interface/utils.cc (create_param_decl): Remove the
targetm.calls.promote_prototypes call.

gcc/c/

PR c/48274
PR middle-end/112877
PR middle-end/118288
* c-decl.cc (start_decl): Remove the
targetm.calls.promote_prototypes call.
(store_parm_decls_oldstyle): Likewise.
(finish_function): Likewise.
* c-typeck.cc (convert_argument): Likewise.
(c_safe_arg_type_equiv_p): Likewise.

gcc/cp/

PR middle-end/112877
* call.cc (type_passed_as): Remove the
targetm.calls.promote_prototypes call.
(convert_for_arg_passing): Likewise.
* typeck.cc (cxx_safe_arg_type_equiv_p): Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
3 months agoHonor TARGET_PROMOTE_PROTOTYPES during RTL expand
H.J. Lu [Thu, 21 Nov 2024 00:11:06 +0000 (08:11 +0800)] 
Honor TARGET_PROMOTE_PROTOTYPES during RTL expand

Promote integer arguments smaller than int if TARGET_PROMOTE_PROTOTYPES
returns true.

gcc/

PR middle-end/112877
* calls.cc (initialize_argument_information): Promote small integer
arguments if TARGET_PROMOTE_PROTOTYPES returns true.

gcc/testsuite/

PR middle-end/112877
* gfortran.dg/pr112877-1.f90: New test.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>