]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
4 months ago[PR119270][IRA]: Ignore equiv init insns for cost calculation for invariants only
Vladimir N. Makarov [Wed, 19 Mar 2025 20:06:41 +0000 (16:06 -0400)] 
[PR119270][IRA]: Ignore equiv init insns for cost calculation for invariants only

My previous patch for PR114991 contains code ignoring equiv init insns
for increasing cost of usage the equivalence.  Although common sense says
it is right thing to do, this results in more aggressive usage of
memory equivalence and significant performance degradation of SPEC2017
cactuBSSM.  Given patch restores previous cost calculation for all
equivalences except for invariant ones.

gcc/ChangeLog:

PR target/119270
* ira-costs.cc (calculate_equiv_gains): Ignore equiv init insns
only for invariants.

4 months agoUpdate gcc fr.po
Joseph Myers [Wed, 19 Mar 2025 19:41:43 +0000 (19:41 +0000)] 
Update gcc fr.po

* fr.po: Update.

4 months agodiagnostics: fix crash in urlifier with -Wfatal-errors [PR119366]
David Malcolm [Wed, 19 Mar 2025 19:03:42 +0000 (15:03 -0400)] 
diagnostics: fix crash in urlifier with -Wfatal-errors [PR119366]

diagnostic_context's dtor assumed that it owned the m_urlifier pointer
and would delete it.

As of r15-5988-g5a022062d22e0b this isn't always the case -
auto_urlify_attributes is used in various places in the C/C++ frontends
and in the middle-end to temporarily override the urlifier with an
on-stack instance, which would lead to delete-of-on-stack-buffer crashes
with -Wfatal-errors as the global_dc was cleaned up.

Fix by explicitly tracking the stack of urlifiers within
diagnostic_context, tracking for each node whether the pointer is
owned or borrowed.

gcc/ChangeLog:
PR c/119366
* diagnostic-format-sarif.cc (test_message_with_embedded_link):
Convert diagnostic_context from one urlifier to a stack of
urlifiers, where each node in the stack tracks whether the
urlifier is owned or borrowed.
* diagnostic.cc (diagnostic_context::initialize): Likewise.
(diagnostic_context::finish): Likewise.
(diagnostic_context::set_urlifier): Delete.
(diagnostic_context::push_owned_urlifier): New.
(diagnostic_context::push_borrowed_urlifier): New.
(diagnostic_context::pop_urlifier): New.
(diagnostic_context::get_urlifier): Reimplement in terms of stack.
(diagnostic_context::override_urlifier): Delete.
* diagnostic.h (diagnostic_context::set_urlifier): Delete decl.
(diagnostic_context::override_urlifier): Delete decl.
(diagnostic_context::push_owned_urlifier): New decl.
(diagnostic_context::push_borrowed_urlifier): New decl.
(diagnostic_context::pop_urlifier): New decl.
(diagnostic_context::get_urlifier): Make return value const; hide
implementation.
(diagnostic_context::m_urlifier): Replace with...
(diagnostic_context::urlifier_stack_node): ... this and...
(diagnostic_context::m_urlifier_stack): ...this.
* gcc-urlifier.cc
(auto_override_urlifier::auto_override_urlifier): Reimplement.
(auto_override_urlifier::~auto_override_urlifier): Reimplement.
* gcc-urlifier.h (class auto_override_urlifier): Reimplement.
(auto_urlify_attributes::auto_urlify_attributes): Update for
pass-by-reference.
* gcc.cc (driver::global_initializations): Update for
reimplementation of urlifiers in terms of a stack.
* toplev.cc (general_init): Likewise.

gcc/testsuite/ChangeLog:
PR c/119366
* gcc.dg/Wfatal-bad-attr-pr119366.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
4 months agoc: pedwarn on flexible array member initialization with {} for C23+ [PR119350]
Jakub Jelinek [Wed, 19 Mar 2025 18:21:38 +0000 (19:21 +0100)] 
c: pedwarn on flexible array member initialization with {} for C23+ [PR119350]

Even in C23/C2Y any initialization of flexible array member is still
invalid, so we should emit a pedwarn on it.  But we no longer do for
initialization with {}.  The reason is that for C17 and earlier,
we already emitted a pedwarn on the {} initializer and so emitting
another pedwarn on the flexible array member initialization would
be diagnosing the same thing multiple times.

In C23 we no longer pedwarn on {}, it is standard.
The following patch arranges a pedwarning for that for C23+, so that
at least one pedwarning is emitted.

So that we don't "regress" from C17 to C23 on nested flexible array
member initialization with no -pedantic/-pedantic-errors/-Wpedantic,
the patch emits even the
initialization of flexible array member in a nested context
diagnostic as pedwarn in the {} case, after all, it doesn't cause
much trouble, we just ignore it like before, it wouldn't initialize
anything.

2025-03-19  Jakub Jelinek  <jakub@redhat.com>

PR c/119350
* c-typeck.cc (pop_init_level): Don't ignore empty brackets for
flag_isoc23, still set constructor_type to NULL in that case but
emit a pedwarn_init in that case.

* gcc.dg/pr119350-1.c: New test.
* gcc.dg/pr119350-2.c: New test.
* gcc.dg/pr119350-3.c: New test.

4 months agotestsuite/113634 - fixup declarations of calloc/realloc
Richard Biener [Wed, 19 Mar 2025 17:48:09 +0000 (18:48 +0100)] 
testsuite/113634 - fixup declarations of calloc/realloc

Then we can also remove the added -std=gnu17

PR testsuite/113634
* gcc.dg/Wfree-nonheap-object-7.c: Adjust calloc and realloc
declarations, remove -std=gnu17.

4 months agoFix formatting of version message for gnat driver
Eric Botcazou [Wed, 19 Mar 2025 17:15:29 +0000 (18:15 +0100)] 
Fix formatting of version message for gnat driver

Like the main driver (as well as gccgo, gccrs, gcov, etc) the gnat driver
prints the standard version message in response to the --version switch,
but it is not properly formatted.

gcc/ada
* gnatvsn.adb (Gnat_Free_Software): Fix message formatting.

4 months agos390: testsuite: Fix autovec-double-signaling-eq-z13.c
Stefan Schulze Frielinghaus [Wed, 19 Mar 2025 15:35:12 +0000 (16:35 +0100)] 
s390: testsuite: Fix autovec-double-signaling-eq-z13.c

Since r15-3992-g698e0ec89bc096 we optimize x<=y && x>=y to x==y.
Honour signaling NaNs by using option -fsignaling-nans in order to
prevent this.

gcc/testsuite/ChangeLog:

* gcc.target/s390/zvector/autovec-double-signaling-eq-z13.c:
Honour sNaNs.

4 months agos390: testsuite: Fix vcond-shift.c
Stefan Schulze Frielinghaus [Wed, 19 Mar 2025 15:35:12 +0000 (16:35 +0100)] 
s390: testsuite: Fix vcond-shift.c

Previously we optimized expressions of the form a < 0 ? -1 : 0 to
(signed)a >> 31 during vcond expanding.  Since r15-1638-gaac00d09859cc5
this is done in match.pd.  The implementation in the back end as well as
in match.pd are basically the same but still distinct.  For the tests in
vcond-shift.c the back end emitted

  (xx - (xx >> 31)) >> 1

whereas now via match.pd

  ((int) ((unsigned int) xx >> 31) + xx) >> 1

which is basically the same.  We just have to adapt the scan-assembler
directives w.r.t. signed/unsigned shifts which is done by this patch.

gcc/testsuite/ChangeLog:

* gcc.target/s390/vector/vcond-shift.c: Adapt to new match.pd
rule and change scan-assembler-times for shifts.

4 months agogccrs: Handle external static items in toplevel resolver 2.0
Owen Avery [Wed, 16 Oct 2024 03:42:41 +0000 (23:42 -0400)] 
gccrs: Handle external static items in toplevel resolver 2.0

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Handle ExternalStaticItem.
* resolve/rust-toplevel-name-resolver-2.0.h
(TopLevel::visit): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Use name resolver 2.0 in pattern checker
Owen Avery [Tue, 15 Oct 2024 19:34:06 +0000 (15:34 -0400)] 
gccrs: Use name resolver 2.0 in pattern checker

gcc/rust/ChangeLog:

* checks/errors/rust-hir-pattern-analysis.cc: Add includes.
(PatternChecker::visit): Use name resolver 2.0 when enabled.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Use name resolver 2.0 for compiling break/continue
Owen Avery [Tue, 15 Oct 2024 18:56:04 +0000 (14:56 -0400)] 
gccrs: Use name resolver 2.0 for compiling break/continue

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc
(CompileExpr::visit): Use name resolver 2.0 to lookup label
definitions for break and continue statements when name
resolution 2.0 is enabled.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Use name resolver 2.0 in const checker
Owen Avery [Tue, 15 Oct 2024 19:33:46 +0000 (15:33 -0400)] 
gccrs: Use name resolver 2.0 in const checker

gcc/rust/ChangeLog:

* checks/errors/rust-const-checker.cc: Add includes.
(ConstChecker::visit): Use name resolver 2.0 to lookup
function definitions when name resolution 2.0 is enabled.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Load unloaded modules during toplevel resolution 2.0
Owen Avery [Wed, 16 Oct 2024 02:24:29 +0000 (22:24 -0400)] 
gccrs: Load unloaded modules during toplevel resolution 2.0

This may load conditionally compiled modules too eagerly.

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Load unloaded modules before attempting to
visit their items.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove issue-1089.rs.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Make const references to ForeverStack more useful
Owen Avery [Mon, 21 Oct 2024 22:35:30 +0000 (18:35 -0400)] 
gccrs: Make const references to ForeverStack more useful

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.h
(ForeverStack::to_canonical_path): Make const.
(ForeverStack::to_rib): Add const overload.
(ForeverStack::reverse_iter): Add const overloads.
(ForeverStack::ConstDfsResult): Add.
(ForeverStack::dfs): Add const overload.
(ForeverStack::dfs_rib): Likewise.
* resolve/rust-forever-stack.hxx
(ForeverStack::reverse_iter): Add const overloads.
(ForeverStack::dfs): Add const overload.
(ForeverStack::to_canonical_path): Make const.
(ForeverStack::dfs_rib): Likewise.
(ForeverStack::to_rib): Add const overload.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Use name resolver 2.0 in MarkLive
Owen Avery [Tue, 15 Oct 2024 19:34:28 +0000 (15:34 -0400)] 
gccrs: Use name resolver 2.0 in MarkLive

gcc/rust/ChangeLog:

* checks/lints/rust-lint-marklive.cc
(MarkLive::visit_path_segment): Use name resolver 2.0 when
enabled.
(MarkLive::visit): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Handle const generic parameters during resolution 2.0
Owen Avery [Wed, 16 Oct 2024 02:10:35 +0000 (22:10 -0400)] 
gccrs: Handle const generic parameters during resolution 2.0

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Handle ConstGenericParam.
* resolve/rust-toplevel-name-resolver-2.0.h
(TopLevel::visit): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Disambiguate generic args during name resolution 2.0
Owen Avery [Wed, 16 Oct 2024 03:16:23 +0000 (23:16 -0400)] 
gccrs: Disambiguate generic args during name resolution 2.0

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Visit GenericArgs and GenericArg, the former
because the latter involves a non-virtual member function call.
* resolve/rust-late-name-resolver-2.0.h
(Late::visit): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Fix compiler error on ast wrong implicit construct push_back
badumbatish [Thu, 17 Oct 2024 05:41:47 +0000 (22:41 -0700)] 
gccrs: Fix compiler error on ast wrong implicit construct push_back

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-asm.cc (parse_reg_operand_in): Fix
compiler error on ast wrong implicit construct push_back

4 months agogccrs: Provide input operand for gccrs
badumbatish [Thu, 5 Sep 2024 06:59:36 +0000 (23:59 -0700)] 
gccrs: Provide input operand for gccrs

gcc/rust/ChangeLog:

* backend/rust-compile-asm.cc (CompileAsm::asm_construct_inputs):
Provide input operand for gccrs
* expand/rust-macro-builtins-asm.cc (parse_reg_operand_in):
Move expr to In
(expand_inline_asm_strings):
Add comments to debug strings

gcc/testsuite/ChangeLog:

* rust/compile/inline_asm_parse_operand.rs:
Remove inout, functionality not supported. Remove redundant {}
* rust/execute/torture/inline_asm_mov_x_5_ARM.rs: Add operand in
* rust/execute/torture/inline_asm_mov_x_5_x86_64.rs: Likewise

4 months agogccrs: Use name resolver 2.0 during pattern typechecking
Owen Avery [Tue, 15 Oct 2024 19:35:21 +0000 (15:35 -0400)] 
gccrs: Use name resolver 2.0 during pattern typechecking

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-pattern.cc: Add includes.
(TypeCheckPattern::visit): Use name resolver 2.0 if enabled.

* resolve/rust-name-resolution-context.cc
(NameResolutionContext::lookup): Make const qualified.
* resolve/rust-name-resolution-context.h
(NameResolutionContext::lookup): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Allow identifiers and paths to reference types during nr2.0
Owen Avery [Tue, 15 Oct 2024 02:07:54 +0000 (22:07 -0400)] 
gccrs: Allow identifiers and paths to reference types during nr2.0

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Allow IdentifierExpr and PathInExpression to
reference types as well as values, remove ability for
IdentifierExpr to reference labels.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Improve handling of InlineAsm in DefaultASTVisitor
Owen Avery [Thu, 10 Oct 2024 01:47:02 +0000 (21:47 -0400)] 
gccrs: Improve handling of InlineAsm in DefaultASTVisitor

gcc/rust/ChangeLog:

* ast/rust-ast-visitor.cc
(DefaultASTVisitor::visit): Visit fields of InlineAsm.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove
inline_asm_parse_output_operand.rs.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Insert static items into the value namespace
Owen Avery [Fri, 11 Oct 2024 05:24:14 +0000 (01:24 -0400)] 
gccrs: Insert static items into the value namespace

gcc/rust/ChangeLog:

* backend/rust-compile-item.cc
(CompileItem::visit): Check canonical path of StaticItem
properly when name resolution 2.0 is enabled.
* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Insert static items into the value namespace.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Rework InlineAsmOperand
Owen Avery [Fri, 11 Oct 2024 01:24:50 +0000 (21:24 -0400)] 
gccrs: Rework InlineAsmOperand

Not thrilled with some of this boilerplate, but it does seem like an
improvement.

gcc/rust/ChangeLog:

* ast/rust-expr.h
(InlineAsmOperand): Replace multiple mutually-exclusive tl::optional
fields with a std::unique_ptr and modify nested classes to allow
this. Also, make getters return references where possible.
* expand/rust-macro-builtins-asm.cc
(parse_reg_operand_out): Pass location when constructing
InlineAsmOperand.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Handle TypeAlias during toplevel resolution 2.0
Owen Avery [Thu, 10 Oct 2024 04:46:01 +0000 (00:46 -0400)] 
gccrs: Handle TypeAlias during toplevel resolution 2.0

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Handle TypeAlias.
* resolve/rust-toplevel-name-resolver-2.0.h
(TopLevel::visit): Likewise.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove type-alias1.rs.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Fix some issues with canonical path fetching in name resolution 2.0
Owen Avery [Wed, 9 Oct 2024 03:29:27 +0000 (23:29 -0400)] 
gccrs: Fix some issues with canonical path fetching in name resolution 2.0

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-enumitem.cc: Add includes.
(TypeCheckEnumItem::visit): Fetch canonical paths properly when
name resolution 2.0 is enabled.
* typecheck/rust-hir-type-check-implitem.cc: Add includes.
(TypeCheckImplItem::visit): Fetch canonical paths properly when
name resolution 2.0 is enabled.
* typecheck/rust-hir-type-check-item.cc: Add include.
(TypeCheckItem::visit): Fetch canonical paths properly when name
resolution 2.0 is enabled.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Improve Rib::Definition shadowing
Owen Avery [Fri, 4 Oct 2024 21:33:42 +0000 (17:33 -0400)] 
gccrs: Improve Rib::Definition shadowing

gcc/rust/ChangeLog:

* resolve/rust-finalize-imports-2.0.cc
(GlobbingVisitor::visit): Replace calls to insert_shadowable with
insert_globbed.
* resolve/rust-forever-stack.h
(ForeverStack::insert_globbed): Add.
* resolve/rust-forever-stack.hxx
(ForeverStack::insert_globbed): Add.
(ForeverStack::dfs): Handle modifications to Rib::Definition
fields.
* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Make IdentifierPattern-based declarations
shadowable.
* resolve/rust-name-resolution-context.cc
(NameResolutionContext::insert_globbed): Add.
* resolve/rust-name-resolution-context.h
(NameResolutionContext::insert_globbed): Add.
* resolve/rust-rib.cc
(Rib::Definition::Definition): Use Rib::Definition::Mode to
indicate shadowing mode instead of boolean, handle modifications
to Rib::Definition fields.
(Rib::Definition::is_ambiguous): Handle modifications to
Rib::Definition fields.
(Rib::Definition::to_string): Likewise.
(Rib::Definition::Shadowable): Handle changed constructor
signature.
(Rib::Definition::NonShadowable): Likewise.
(Rib::Definition::Globbed): Add.
(Rib::insert): Handle changes to Rib::Definition fields.
* resolve/rust-rib.h
(Rib::Definition::Globbed): Add.
(Rib::Definition::ids): Remove.
(Rib::Definition::ids_shadowable): Add.
(Rib::Definition::ids_non_shadowable): Add.
(Rib::Definition::ids_globbed): Add.
(Rib::Definition::get_node_id): Handle modifications to
Rib::Definition fields.
(Rib::Definition::Mode): Add.
(Rib::Definition::Definition): Use Rib::Definition::Mode to
indicate shadowing mode instead of boolean.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove shadow1.rs.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Fix ICE when typechecking non-trait item when we expect one
Philip Herron [Wed, 2 Oct 2024 14:47:33 +0000 (15:47 +0100)] 
gccrs: Fix ICE when typechecking non-trait item when we expect one

We just had an assertion here for this case where we expect a trait.
This changes the assertion into error handling producing the correct
error code with fixit suggestion like rustc.

Fixes #2499

gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_path_to_trait):
use error handling instead of assertion
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): reuse trait reference
* typecheck/rust-hir-type-check-item.h: update prototype

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/issue-2499.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: Add test case to show ICE is fixed
Philip Herron [Wed, 2 Oct 2024 13:23:26 +0000 (14:23 +0100)] 
gccrs: Add test case to show ICE is fixed

This was resolved in: 18422c9c386 which was missing the name
resolution step for unit-types.

Fixes #2203

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude:
* rust/compile/issue-2203.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: add test case to show impl block on ! works
Philip Herron [Thu, 26 Sep 2024 14:25:21 +0000 (15:25 +0100)] 
gccrs: add test case to show impl block on ! works

The resolution with ! was fixed in: 09cfe530f9c this adds a
test case to show the other issue is also fixed.

Fixes #2951

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 is crashing here
* rust/compile/issue-2951.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agorust: fix ICE during name resolution for impls on unit-types
Philip Herron [Fri, 20 Sep 2024 16:38:14 +0000 (17:38 +0100)] 
rust: fix ICE during name resolution for impls on unit-types

The canonical paths need to support unit-types which are technically a
TupleType with no fields. This handles this case and adds an unreachable.

Fixes #3036

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-type.cc (ResolveTypeToCanonicalPath::visit): add unit-type catch
* resolve/rust-ast-resolve-type.h: likewise

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/issue-3036.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agorust: Add support for Clone and Copy derive on generic types
Philip Herron [Thu, 19 Sep 2024 15:45:54 +0000 (16:45 +0100)] 
rust: Add support for Clone and Copy derive on generic types

When we generate derivations for Copy and Clone we need to make sure
the associated impl block sets up the generic parameters and arguments
correctly. This patch introduces the framework to copy chunks of the AST
because we need to make sure these new AST nodes have their own associated
id, calling clone on the nodes will just confuse name-resolution and
subsequent mappings.

Fixes #3139

gcc/rust/ChangeLog:

* Make-lang.in: new objects
* ast/rust-ast-builder.cc (Builder::generic_type_path_segment): new helper
(Builder::single_generic_type_path): likewise
(Builder::new_type): likewise
(Builder::new_lifetime_param): likewise
(Builder::new_type_param): likewise
(Builder::new_lifetime): likewise
(Builder::new_generic_args): likewise
* ast/rust-ast-builder.h: new helper decls
* ast/rust-ast.h: new const getters
* ast/rust-path.h: likewise
* ast/rust-type.h: likewise
* expand/rust-derive-clone.cc (DeriveClone::clone_impl): take the types generics
(DeriveClone::visit_tuple): likewise
(DeriveClone::visit_struct): likewise
(DeriveClone::visit_union): likewise
* expand/rust-derive-clone.h: update header
* expand/rust-derive-copy.cc (DeriveCopy::copy_impl): similarly take type generics
(DeriveCopy::visit_struct): likewise
(DeriveCopy::visit_tuple): likewise
(DeriveCopy::visit_enum): likewise
(DeriveCopy::visit_union): likewise
* expand/rust-derive-copy.h: likewse
* ast/rust-ast-builder-type.cc: New file.
* ast/rust-ast-builder-type.h: New file.

gcc/testsuite/ChangeLog:

* rust/compile/issue-3139-1.rs: New test.
* rust/compile/issue-3139-2.rs: New test.
* rust/compile/issue-3139-3.rs: New test.
* rust/compile/nr2/exclude: these all break nr2

4 months agogccrs: Remove some passing test from nr2 passing list
Pierre-Emmanuel Patry [Thu, 26 Sep 2024 21:37:35 +0000 (23:37 +0200)] 
gccrs: Remove some passing test from nr2 passing list

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove cast_generics.rs, issue-1131.rs,
issue-1383.rs and unsafe10.rs

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Postpone break on error after name resolution
Pierre-Emmanuel Patry [Thu, 26 Sep 2024 21:17:59 +0000 (23:17 +0200)] 
gccrs: Postpone break on error after name resolution

We need the top level to run at least once before breaking because it
will be required by the other name resolution steps.

gcc/rust/ChangeLog:

* rust-session-manager.cc (Session::expansion): Break on error after
top level name resolution.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Resolve TypeParam with name resolution 2.0
Pierre-Emmanuel Patry [Thu, 26 Sep 2024 21:16:21 +0000 (23:16 +0200)] 
gccrs: Resolve TypeParam with name resolution 2.0

Resolve TypeParam unless it is Self.

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Resolve
TypeParam.
* resolve/rust-toplevel-name-resolver-2.0.h: Add visit function
prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add box definition to avoid error
Pierre-Emmanuel Patry [Thu, 26 Sep 2024 20:59:48 +0000 (22:59 +0200)] 
gccrs: Add box definition to avoid error

Box definition is part of the standard library and cannot be found during
name resolution. This simple definition prevent any error from being
emitted.

gcc/testsuite/ChangeLog:

* rust/compile/box_syntax_feature_gate.rs: Add box land item
definition.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: This test requires the standard library
Pierre-Emmanuel Patry [Thu, 26 Sep 2024 20:51:17 +0000 (22:51 +0200)] 
gccrs: This test requires the standard library

It requires the standard library and Copy to work correctly which we
cannot provide. Stopping the compiler before the name resolution allow us
to prevent an error whilst resolving Copy and keep the test's goal.

gcc/testsuite/ChangeLog:

* rust/compile/functions_without_body.rs: Add compile step argument.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Make node id getter const.
Pierre-Emmanuel Patry [Thu, 26 Sep 2024 20:46:16 +0000 (22:46 +0200)] 
gccrs: Make node id getter const.

gcc/rust/ChangeLog:

* ast/rust-ast.h: Node id getter could be const.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Change resolved type segment
Pierre-Emmanuel Patry [Thu, 26 Sep 2024 20:43:18 +0000 (22:43 +0200)] 
gccrs: Change resolved type segment

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.h: Add visit function prototype.
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Change resolved
type segment.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Update exclude list with working tests
Pierre-Emmanuel Patry [Tue, 17 Sep 2024 13:25:41 +0000 (15:25 +0200)] 
gccrs: Update exclude list with working tests

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove working tests from nr2 exclude list.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Do not assert insertion result
Pierre-Emmanuel Patry [Tue, 17 Sep 2024 14:15:40 +0000 (16:15 +0200)] 
gccrs: Do not assert insertion result

We might have some duplicated name in some pattern and we should
therefore not assert the non duplication of identifiers.

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Remove
assertion and explicitely tells why we ignore the insertion result.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Move bir builder function implementation
Pierre-Emmanuel Patry [Fri, 6 Sep 2024 10:16:22 +0000 (12:16 +0200)] 
gccrs: Move bir builder function implementation

Move function implementation to their own file.

gcc/rust/ChangeLog:

* Make-lang.in: Add new rust-bir-builder-pattern file.
* checks/errors/borrowck/rust-bir-builder-pattern.h: Remove
implementation.
* checks/errors/borrowck/rust-bir-builder-pattern.cc: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Move failing test to xfail
Pierre-Emmanuel Patry [Wed, 4 Sep 2024 15:13:04 +0000 (17:13 +0200)] 
gccrs: Move failing test to xfail

We want to begin experimenting with this new name resolution 2.0
algorithm as soon as possible. This test highlight a problem where the
compiler should emit an error and should be fixed soon.

gcc/testsuite/ChangeLog:

* rust/compile/name_resolution21.rs: Move to...
* rust/compile/xfail/name_resolution21.rs: ...here.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Make AST default visitor visit functions public
Pierre-Emmanuel Patry [Thu, 5 Sep 2024 14:13:30 +0000 (16:13 +0200)] 
gccrs: Make AST default visitor visit functions public

Make those functions public so they can be used within a lambda on GCC
4.8.

gcc/rust/ChangeLog:

* ast/rust-ast-visitor.h: Make visit functions public.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add default resolver parent functions by default
Pierre-Emmanuel Patry [Thu, 5 Sep 2024 13:39:59 +0000 (15:39 +0200)] 
gccrs: Add default resolver parent functions by default

gcc/rust/ChangeLog:

* resolve/rust-finalize-imports-2.0.h: Add parent member functions
from default resolver.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Change lambda content with default visitor call
Pierre-Emmanuel Patry [Thu, 5 Sep 2024 11:54:48 +0000 (13:54 +0200)] 
gccrs: Change lambda content with default visitor call

We can reduce code duplication by using the default visitor functions
from within the scoped lambda function.

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc (DefaultResolver::visit): Use
default visitor instead.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Remove regular visit code
Pierre-Emmanuel Patry [Thu, 5 Sep 2024 11:37:51 +0000 (13:37 +0200)] 
gccrs: Remove regular visit code

Regular visit code can be replaced with default visit functions.

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc (DefaultResolver::visit): Remove
default visit code and replace it with call to default visitor.
* resolve/rust-default-resolver.h: Remove removed function's
prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Remove empty visit functions
Pierre-Emmanuel Patry [Thu, 5 Sep 2024 11:23:52 +0000 (13:23 +0200)] 
gccrs: Remove empty visit functions

We can let the default visitor visit those nodes anyway so we're sure
all nodes can be reached.

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc (DefaultResolver::visit): Remove
empty visit function implementations.
* resolve/rust-default-resolver.h: Remove corresponding prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Mark virtual function override in default resolver
Pierre-Emmanuel Patry [Thu, 5 Sep 2024 11:01:07 +0000 (13:01 +0200)] 
gccrs: Mark virtual function override in default resolver

Those function prototype were not marked as override and throwing
warning.

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.h: Make most visit function override.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Loop on expansion if a new export has been defined
Pierre-Emmanuel Patry [Wed, 21 Aug 2024 15:14:46 +0000 (17:14 +0200)] 
gccrs: Loop on expansion if a new export has been defined

When a use statement requires a reexported item it cannot find it in
the same pass, an additional pass shall be performed. This means we need
to detect whether a new item has been reexported and resolve until the
end.

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc (Early::Early): Add dirty
flag initialization.
(Early::go): Set dirty flag using top level resolver.
* resolve/rust-early-name-resolver-2.0.h: Add dirty flag.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::TopLevel):
Initialize dirty flag.
(TopLevel::insert_or_error_out): Set dirty flag on successful
namespace modification.
* resolve/rust-toplevel-name-resolver-2.0.h: Add dirty flag.
* rust-session-manager.cc (Session::expansion): Modify fixed point
condition to include name resolution modifications.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Fix missing error on duplicated nodes
Pierre-Emmanuel Patry [Wed, 21 Aug 2024 15:01:29 +0000 (17:01 +0200)] 
gccrs: Fix missing error on duplicated nodes

When we tried to insert a shadowable node and another shadowable node has
been inserted before, we didn't emit any error if the node has already
been inserted previously and failed silently.

gcc/rust/ChangeLog:

* resolve/rust-rib.cc (Rib::insert): Emit an error when trying to
insert an already inserted node.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: nr2.0: Cleanup import mappings and factor into a class.
Arthur Cohen [Wed, 10 Apr 2024 15:38:19 +0000 (17:38 +0200)] 
gccrs: nr2.0: Cleanup import mappings and factor into a class.

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.h: New class for imports.
* resolve/rust-finalize-imports-2.0.cc (finalize_simple_import): Use
the new API.
(finalize_glob_import): Likewise.
(finalize_rebind_import): Likewise.
(FinalizeImports::FinalizeImports): Likewise.
(FinalizeImports::visit): Likewise.
* resolve/rust-finalize-imports-2.0.h: Likewise.
* resolve/rust-early-name-resolver-2.0.cc (Early::resolve_glob_import): Likewise.
(Early::resolve_simple_import): Likewise.
(Early::resolve_rebind_import): Likewise.

4 months agogccrs: Insert imports in all namespaces they were resolved in
Arthur Cohen [Mon, 8 Apr 2024 16:44:15 +0000 (18:44 +0200)] 
gccrs: Insert imports in all namespaces they were resolved in

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc (Early::resolve_simple_import):
Insert import in all namespaces where they were resolved.
(Early::resolve_rebind_import): Likewise.
* resolve/rust-early-name-resolver-2.0.h: Improve APIs, make them
accept multiple resolutions.
* resolve/rust-finalize-imports-2.0.cc: Handle multiple resolutions.
* resolve/rust-name-resolution-context.h (resolve_path): Remove function.

4 months agogccrs: early: Do not emit errors for unresolved imports, store them instead
Arthur Cohen [Sat, 6 Apr 2024 21:23:39 +0000 (23:23 +0200)] 
gccrs: early: Do not emit errors for unresolved imports, store them instead

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc (Early::visit_attributes):
Store errors for later.

4 months agogccrs: imports: Make FinalizeImports a resolver visitor as well
Arthur Cohen [Sat, 6 Apr 2024 21:02:51 +0000 (23:02 +0200)] 
gccrs: imports: Make FinalizeImports a resolver visitor as well

gcc/rust/ChangeLog:

* resolve/rust-finalize-imports-2.0.cc (FinalizeImports::go): Turn
static method into method.
(FinalizeImports::visit): New.
* resolve/rust-finalize-imports-2.0.h (class FinalizeImports): Make
FinalizeImports a visitor.
* resolve/rust-early-name-resolver-2.0.cc (Early::go): Use new FinalizeImports API.
(Early::resolve_glob_import): Use new API.
(Early::resolve_simple_import): Likewise.
(Early::resolve_rebind_import): Likewise.
(Early::build_import_mapping): Likewise.
* resolve/rust-early-name-resolver-2.0.h: Likewise.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Likewise.
* resolve/rust-toplevel-name-resolver-2.0.h: Likewise.

4 months agogccrs: imports: Start storing Ribs in ImportKind
Arthur Cohen [Fri, 5 Apr 2024 22:32:57 +0000 (00:32 +0200)] 
gccrs: imports: Start storing Ribs in ImportKind

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add debug call.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Store
imports using the new classes.
* resolve/rust-toplevel-name-resolver-2.0.h: Use new classes.

4 months agogccrs: imports: Create ImportData class and use it in import_mappings
Arthur Cohen [Fri, 5 Apr 2024 22:00:49 +0000 (00:00 +0200)] 
gccrs: imports: Create ImportData class and use it in import_mappings

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc (Early::resolve_glob_import):
Use ImportData class.
(Early::resolve_simple_import): Likewise.
(Early::resolve_rebind_import): Likewise.
(Early::build_import_mapping): Likewise.
* resolve/rust-early-name-resolver-2.0.h: Likewise.
* resolve/rust-finalize-imports-2.0.cc (finalize_simple_import): Likewise.
(finalize_glob_import): Likewise.
(finalize_rebind_import): Likewise.
(FinalizeImports::go): Likewise.
* resolve/rust-finalize-imports-2.0.h: Likewise.
* resolve/rust-name-resolution-context.h: Likewise.
* resolve/rust-rib.h: Define ImportData class.

4 months agogccrs: imports: Add FinalizeImports class
Arthur Cohen [Thu, 4 Apr 2024 15:07:54 +0000 (17:07 +0200)] 
gccrs: imports: Add FinalizeImports class

gcc/rust/ChangeLog:

* Make-lang.in: Add new object file.
* ast/rust-item.h: Constify method.
* resolve/rust-early-name-resolver-2.0.cc (Early::go): Call into
the imports finalizer.
(Early::resolve_glob_import): Remove old resolution.
(Early::resolve_rebind_import): Likewise.
* resolve/rust-toplevel-name-resolver-2.0.cc (GlobbingVisitor::go):
New function.
(GlobbingVisitor::visit): Likewise.
(TopLevel::visit): Do not call into handle_use_* functions anymore.
* resolve/rust-toplevel-name-resolver-2.0.h (class GlobbingVisitor):
New.
* resolve/rust-finalize-imports-2.0.cc: New file.
* resolve/rust-finalize-imports-2.0.h: New file.

4 months agogccrs: early: Resolve imports and create import mappings
Arthur Cohen [Thu, 4 Apr 2024 14:25:30 +0000 (16:25 +0200)] 
gccrs: early: Resolve imports and create import mappings

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc (Early::resolve_glob_import): New function.
(Early::resolve_simple_import): Likewise.
(Early::resolve_rebind_import): Likewise.
(Early::build_import_mapping): Likewise.
* resolve/rust-early-name-resolver-2.0.h: Add declarations and list of imports to
resolve.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::handle_use_glob): Remove function,
which is now being handled by the Early name resolver.
(TopLevel::handle_use_dec): Likewise.
(TopLevel::handle_rebind): Likewise.
* resolve/rust-toplevel-name-resolver-2.0.h: Likewise, and add functions for creating
import list and fetching it.

4 months agogccrs: toplevel: Build list of imports for Early to resolve
Arthur Cohen [Thu, 4 Apr 2024 13:42:29 +0000 (15:42 +0200)] 
gccrs: toplevel: Build list of imports for Early to resolve

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc: Comment out handle_use
call and error emission.
* resolve/rust-toplevel-name-resolver-2.0.h: Create ImportKind class.

4 months agogccrs: toplevel: Add note for resolving use declarations
Arthur Cohen [Wed, 3 Apr 2024 15:41:47 +0000 (17:41 +0200)] 
gccrs: toplevel: Add note for resolving use declarations

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::handle_use_dec):
Add notes on the problem.
* resolve/rust-toplevel-name-resolver-2.0.h: Likewise.

4 months agogccrs: nr2.0: default-visitor: Conditionally visit type in self parameters.
Arthur Cohen [Wed, 27 Mar 2024 16:20:15 +0000 (17:20 +0100)] 
gccrs: nr2.0: default-visitor: Conditionally visit type in self parameters.

This could trigger an assertions as `get_type` on `SelfParam` asserts that
the self param does have a given type, which is not always the case.

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc (DefaultResolver::visit): Do not
visit self's type if it does not have one.

4 months agogccrs: rust fix ICE when hir lowering qualified path expressions without an as
Philip Herron [Fri, 20 Sep 2024 16:13:38 +0000 (17:13 +0100)] 
gccrs: rust fix ICE when hir lowering qualified path expressions without an as

Qualified path expressions usually are <X as Y>::... but the as is optional
this adds the extra checking in hir lowering to not hit that nullptr.

Fixes #3082

gcc/rust/ChangeLog:

* hir/rust-ast-lower-type.cc (ASTLowerQualifiedPathInType::visit):
check for valid as segment

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/issue-3082.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agorust: fix ICE when compiling impl block for !
Philip Herron [Fri, 20 Sep 2024 17:45:12 +0000 (18:45 +0100)] 
rust: fix ICE when compiling impl block for !

We need to resolve the never type which is its own special AST node so it
doesnt magically get handled like the regular builtin type paths such as
i32.

Fixes #3035

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-type.cc (ResolveType::visit):
handle never type
(ResolveTypeToCanonicalPath::visit): likewise
* resolve/rust-ast-resolve-type.h: missing never type
* resolve/rust-name-resolver.cc (Resolver::generate_builtins):
track never type node_id
(Resolver::setup_builtin): likewise
* resolve/rust-name-resolver.h: new never type getter

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/issue-3035.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: Remove some overloaded methods from DefaultResolver.
Owen Avery [Mon, 23 Sep 2024 21:44:19 +0000 (17:44 -0400)] 
gccrs: Remove some overloaded methods from DefaultResolver.

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc
(DefaultResolver::visit): Remove some empty overloads which
DefaultASTVisitor::visit should be able to handle.
* resolve/rust-default-resolver.h
(DefaultResolver::visit): Likewise.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Add extra assertions to tl::optional
Owen Avery [Wed, 18 Sep 2024 20:05:31 +0000 (16:05 -0400)] 
gccrs: Add extra assertions to tl::optional

gcc/rust/ChangeLog:

* util/optional.h
(optional): Add assertions to dereference operator overloads
when C++14 is available.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: adjust hir dump of BlockExpr
Marc Poulhiès [Sat, 21 Sep 2024 08:44:12 +0000 (10:44 +0200)] 
gccrs: adjust hir dump of BlockExpr

Add tail_reachable and label fields to the dump.

gcc/rust/ChangeLog:

* hir/rust-hir-dump.cc (Dump::visit): Add missing fields.

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
4 months agorust: negative polarity removes restrictions on validation of impl blocks
Philip Herron [Fri, 20 Sep 2024 16:49:36 +0000 (17:49 +0100)] 
rust: negative polarity removes restrictions on validation of impl blocks

Negative polarity means we can just ignore if any trait items are not
implemented.

Fxies #3030

gcc/rust/ChangeLog:

* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): the polarity was reversed
* typecheck/rust-hir-type-check-item.cc: check the polarity

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/issue-3030.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: Fix ICE on error propagation with generic
benjamin.thos [Thu, 12 Sep 2024 17:10:49 +0000 (17:10 +0000)] 
gccrs: Fix ICE on error propagation with generic

add a resolve expr visitor on error propagation to avoid internal
compiler error when used with generics

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Add
implementation of error propagation visitor
* resolve/rust-ast-resolve-expr.h: Add prototype of error
propagation

Signed-off-by: benjamin.thos <benjamin.thos@epita.fr>
4 months agogccrs: Check if the type has been correctly resolved
Pierre-Emmanuel Patry [Thu, 19 Sep 2024 12:38:48 +0000 (14:38 +0200)] 
gccrs: Check if the type has been correctly resolved

We did not check the optional was valid, this lead to rogue dereference
and undefined behaviors.

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add optional
check.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Create new test system for name resolution 2.0
Owen Avery [Mon, 16 Sep 2024 22:27:19 +0000 (18:27 -0400)] 
gccrs: Create new test system for name resolution 2.0

This runs the standard compile/**.rs tests
with name resolution 2.0 enabled. The exclude file
can be used to exclude tests which are not yet working
with name resolution 2.0.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/compile.exp: New test.
* rust/compile/nr2/exclude: New.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: [gccrs#3141] Remove double negation by returning CompileExpr::Compile early
JoanVC [Sun, 15 Sep 2024 13:59:34 +0000 (15:59 +0200)] 
gccrs: [gccrs#3141] Remove double negation by returning CompileExpr::Compile early

Fixes gccrs#3141.

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc

Signed-off-by: Joan Vilardaga <github-91yu@joanvc.cat>
4 months agogccrs: [gccrs#3141] Fix incorrect handling of overflow in numeric types
JoanVC [Tue, 10 Sep 2024 19:52:50 +0000 (21:52 +0200)] 
gccrs: [gccrs#3141] Fix incorrect handling of overflow in numeric types

Fixes gccrs#3141.

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc: Fix range checking for both integers and floats.
* hir/tree/rust-hir-expr.h: Add "negative_number" boolean to LiteralExpr class.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Joan Vilardaga <github-91yu@joanvc.cat>
4 months agogccrs: session-manager: Fix typos in -frust-incomplete message
Arthur Cohen [Thu, 5 Sep 2024 14:17:57 +0000 (16:17 +0200)] 
gccrs: session-manager: Fix typos in -frust-incomplete message

gcc/rust/ChangeLog:

* rust-session-manager.cc (Session::compile_crate): Use less repetition,
fix a typo in `reports`, fix word order.

4 months agogccrs: Emit error on auto-traits
benjamin.thos [Wed, 11 Sep 2024 14:31:20 +0000 (14:31 +0000)] 
gccrs: Emit error on auto-traits

Throw an error when auto-traits used without feature attribute.

gcc/rust/ChangeLog:

* checks/errors/rust-feature-gate.cc (FeatureGate::visit): Emit error
on trait when auto field member true.
* checks/errors/rust-feature-gate.h: add prototype of trait visitor.
* checks/errors/rust-feature.cc (Feature::create): add
optin_builtin_traits in match of feature.

gcc/testsuite/ChangeLog:

* rust/compile/auto_trait_super_trait.rs: Add feature attribute.
* rust/compile/generic_auto_trait.rs: likewise.
* rust/compile/auto_trait.rs: add test for error without
feature attribute

Signed-off-by: benjamin.thos <benjamin.thos@epita.fr>
4 months agogccrs: Implement initial pattern analysis pass.
Raiki Tamura [Wed, 7 Aug 2024 17:25:05 +0000 (02:25 +0900)] 
gccrs: Implement initial pattern analysis pass.

gcc/rust/ChangeLog:

* Make-lang.in: Add rust-hir-pattern-analysis.o.
* rust-session-manager.cc (Session::compile_crate):
Add pattern analysis pass.
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
Do typecheck for subpatterns.
* checks/errors/rust-hir-pattern-analysis.cc: New file.
* checks/errors/rust-hir-pattern-analysis.h: New file.

gcc/testsuite/ChangeLog:

* rust/compile/exhaustiveness1.rs: New test.
* rust/compile/exhaustiveness2.rs: New test.
* rust/compile/exhaustiveness3.rs: New test.

Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
4 months agogccrs: Dynamic dispatch with supertraits
Liam Naddell [Thu, 8 Aug 2024 09:31:58 +0000 (05:31 -0400)] 
gccrs: Dynamic dispatch with supertraits

gcc/rust/ChangeLog:

* backend/rust-compile.cc:
Modify compute_address_for_trait_item to support supertraits
* typecheck/rust-tyty.cc:
Remove auto

gcc/testsuite/ChangeLog:

* rust/compile/trait13.rs:
Add test for supertraits of supertraits
* rust/compile/trait14.rs:
Diamond problem with supertraits test
* rust/execute/torture/trait14.rs:
Add test for dynamic dispatch with supertraits
* rust/execute/torture/trait15.rs:
Add test for dynamic dispatch with generics
* rust/execute/torture/trait16.rs:
Add test for dynamic dispatch with lifetime params 1
* rust/execute/torture/trait17.rs:
Add test for dynamic dispatch with lifetime params 2
* rust/execute/torture/trait18.rs:
Add test for default implementations with dynamic dispatch and
supertraits

Signed-off-by: Liam Naddell <liam.naddell@mail.utoronto.ca>
4 months agogccrs: Used `IndexVec` for place_map
Kushal Pal [Wed, 28 Aug 2024 06:39:28 +0000 (06:39 +0000)] 
gccrs: Used `IndexVec` for place_map

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-dump.cc (Dump::go): Use strong
type instead of size_t.
(Dump::visit_place): Likewise.
(Dump::visit_scope): Likewise.
* checks/errors/borrowck/rust-bir-dump.h (class Dump): Use
IndeVec for place_map.

Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
4 months agogccrs: Use `IndexVec` for bb_fold_map
Kushal Pal [Wed, 28 Aug 2024 06:16:11 +0000 (06:16 +0000)] 
gccrs: Use `IndexVec` for bb_fold_map

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-dump.cc (simplify_cfg):
Used `IndexVec` for bb_fold_map.
(Dump::go): Use strong type as index instead of value as now we
are using `IndexVec`.
(Dump::visit): Likewise.
* checks/errors/borrowck/rust-bir-dump.h (class Dump): Use
`IndexVec` for bb_fold_map.
* checks/errors/borrowck/rust-bir-place.h: Add constructor for
`IndexVec` that can reserve size.

Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
4 months agogccrs: Used `IndexVec` for Places
Kushal Pal [Tue, 20 Aug 2024 06:09:51 +0000 (06:09 +0000)] 
gccrs: Used `IndexVec` for Places

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-place.h: Use strong types as
index.

Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
4 months agogccrs: Used `IndexVec` for BasicBlocks
Kushal Pal [Mon, 19 Aug 2024 10:06:49 +0000 (10:06 +0000)] 
gccrs: Used `IndexVec` for BasicBlocks

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
(ExprStmtBuilder::visit): Use strong type as index and
remove access to numeric value.
* checks/errors/borrowck/rust-bir-builder-internal.h
(struct BuilderContext): Likewise.
* checks/errors/borrowck/rust-bir-dump.cc (simplify_cfg):
Likewise.
(Dump::go): Likewise.
(Dump::visit): Likewise.
* checks/errors/borrowck/rust-bir-fact-collector.h
(class FactCollector): Likewise.
(points): Likewise.
* checks/errors/borrowck/rust-bir.h (struct BasicBlockId): Used
IndexVec for BasicBlocks.
(struct Function): Likewise.
* checks/errors/borrowck/rust-borrow-checker-diagnostics.cc
(BorrowCheckerDiagnostics::get_statement): Change the extracted
index to strong type.

Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
4 months agogccrs: Used `IndexVec` for Loans
Kushal Pal [Mon, 19 Aug 2024 09:48:49 +0000 (09:48 +0000)] 
gccrs: Used `IndexVec` for Loans

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-place.h: Used `IndexVec` with
ScopeId as index.
* checks/errors/borrowck/rust-borrow-checker-diagnostics.cc
(BorrowCheckerDiagnostics::get_loan): Convert Polonius::Loan to
BIR::Loan, so we can use it as index.

Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
4 months agogccrs: Used `IndexVec` for Scopes
Kushal Pal [Mon, 19 Aug 2024 09:38:52 +0000 (09:38 +0000)] 
gccrs: Used `IndexVec` for Scopes

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-place.h:
Used `IndexVec` with ScopeId as index.

Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
4 months agogccrs: Introduce `IndexVec`
Kushal Pal [Mon, 19 Aug 2024 09:28:25 +0000 (09:28 +0000)] 
gccrs: Introduce `IndexVec`

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-place.h (struct Loan):
Introduce new class `IndexVec` inspired from IndexVec of rust.
It acts as a wrapper around `std::vector` and lets user specify
a strong type to use as index.

Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
4 months agogccrs: Strong type BasicBlockId
Kushal Pal [Wed, 7 Aug 2024 10:58:17 +0000 (10:58 +0000)] 
gccrs: Strong type BasicBlockId

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit):
Use value of BasicBlockId as index.
* checks/errors/borrowck/rust-bir-builder-internal.h (struct BuilderContext):
Likewise.
* checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h:
Initialize with ENTRY_BASIC_BLOCK.
* checks/errors/borrowck/rust-bir-dump.cc (simplify_cfg):
Use value of BasicBlockId as index.
(Dump::go): Likewise.
(Dump::visit): Likewise.
* checks/errors/borrowck/rust-bir-fact-collector.h (class FactCollector):
Initialize with ENTRY_BASIC_BLOCK.
(points): Use value of BasicBlockId as index.
* checks/errors/borrowck/rust-bir.h (struct BasicBlockId):
BasicBlockId is a struct now.

Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
4 months agogccrs: Strong type ScopeId
Kushal Pal [Wed, 7 Aug 2024 10:16:24 +0000 (10:16 +0000)] 
gccrs: Strong type ScopeId

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
(ExprStmtBuilder::setup_loop): Use value of ScopeId.
(ExprStmtBuilder::visit): Use continue scope id instead of
continue basic block id.
* checks/errors/borrowck/rust-bir-builder-internal.h: Use value
of ScopeId.
* checks/errors/borrowck/rust-bir-dump.cc (Dump::go): Use
ROOT_VALUE instead of hardcoded 0.
(Dump::visit_scope): Use value of ScopeId.
* checks/errors/borrowck/rust-bir-place.h (struct ScopeId):
ScopeId is now a struct.
(std::numeric_limits::max): Set invalid ScopeId.

Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
4 months agogccrs: Strong type LoanId
Kushal Pal [Wed, 7 Aug 2024 08:44:03 +0000 (08:44 +0000)] 
gccrs: Strong type LoanId

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-dump.cc (Dump::visit): Use new
API, i.e get_loan_id() instead of get_loan().
* checks/errors/borrowck/rust-bir-fact-collector.h (points): Use
value of LoanId in Polonius facts.
* checks/errors/borrowck/rust-bir-place.h (struct LoanId):
LoanId is a struct now.
* checks/errors/borrowck/rust-bir.h (class AbstractExpr): Use
new API, as we are getting a LoanId and not a loan itself.

Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
4 months agogccrs: Use FreeRegions inplace of `std::vector<FreeRegion>`
Kushal Pal [Thu, 8 Aug 2024 07:12:00 +0000 (07:12 +0000)] 
gccrs: Use FreeRegions inplace of `std::vector<FreeRegion>`

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder-internal.h: Use
FreeRegions instead of making a temporary vector of FreeRegion.
* checks/errors/borrowck/rust-bir-builder.h: Likewise.
* checks/errors/borrowck/rust-bir-fact-collector.h (class FactCollector):
Likewise.
(points): Likewise.
* checks/errors/borrowck/rust-bir-free-region.h: Remove obsolete
set_from() helpers, add push_back().
* checks/errors/borrowck/rust-bir-place.h: Use FreeRegions
instead of making a temporary vector of Origin.
* typecheck/rust-tyty-variance-analysis-private.h: Change type
of `regions`.
* typecheck/rust-tyty-variance-analysis.cc (CrateCtx::query_type_regions):
Use new type.
(GenericTyPerCrateCtx::query_generic_variance): Likewise.
(TyVisitorCtx::add_constraints_from_generic_args): Likewise.
(FieldVisitorCtx::add_constraints_from_region): Likewise.
(FieldVisitorCtx::add_constrints_from_param): Likewise.
* typecheck/rust-tyty-variance-analysis.h: Likewise.

Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
4 months agogccrs: Strong type FreeRegion
Kushal Pal [Wed, 7 Aug 2024 05:19:28 +0000 (05:19 +0000)] 
gccrs: Strong type FreeRegion

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder-internal.h: Use
STATIC_FREE_REGION, use value of FreeRegion for origin.
* checks/errors/borrowck/rust-bir-builder.h: Use free region
value.
* checks/errors/borrowck/rust-bir-dump.cc (Dump::visit_scope):
Likewise.
* checks/errors/borrowck/rust-bir-fact-collector.h (points):
Likewise.
* checks/errors/borrowck/rust-bir-free-region.h (struct FreeRegion):
Make FreeRegion a struct.
* checks/errors/borrowck/rust-bir-place.h: Use FreeRegion
instead of Origin in PlaceDB.
* typecheck/rust-tyty-variance-analysis.cc (FieldVisitorCtx::add_constraints_from_region):
Use value of FreeRegion for origin.
(FieldVisitorCtx::add_constrints_from_param): Likewise.
(Term::make_transform): Likewise.

Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
4 months agogccrs: Strong type PlaceId
Kushal Pal [Mon, 5 Aug 2024 10:50:55 +0000 (10:50 +0000)] 
gccrs: Strong type PlaceId

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-dump.cc (renumber_places):
Use value of PlaceId as index.
(Dump::visit_place): Likewise.
(Dump::visit_scope): Likewise.
(Dump::go): Refill `place_map` with for loop instead of
using std::iota().
* checks/errors/borrowck/rust-bir-fact-collector.h (points): Use
value as index.
* checks/errors/borrowck/rust-bir-place.h (struct PlaceId):
PlaceId is now a class holding a uint32_t value. Overloaded
comparision operators for easier comparision.

Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
4 months agogccrs: Avoid accidental insertion into map
Owen Avery [Thu, 5 Sep 2024 23:44:55 +0000 (19:44 -0400)] 
gccrs: Avoid accidental insertion into map

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-pattern.cc
(PatternDeclaration::check_bindings_consistency): Check if
outer_bindings_map contains an entry before indexing.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Fix v0-mangle1.rs test when run with ASAN
Owen Avery [Wed, 4 Sep 2024 02:49:15 +0000 (22:49 -0400)] 
gccrs: Fix v0-mangle1.rs test when run with ASAN

gcc/rust/ChangeLog:

* util/rust-canonical-path.h
(CanonicalPath::CanonicalPath): Properly initialize crate_num
with copy constructor.

gcc/testsuite/ChangeLog:

* rust/compile/v0-mangle1.rs: Make v0-mangle test more crate_num
agnostic.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Provide new asm test case for amd64
badumbatish [Sun, 1 Sep 2024 06:37:19 +0000 (23:37 -0700)] 
gccrs: Provide new asm test case for amd64

gcc/testsuite/ChangeLog:

* rust/execute/torture/inline_asm_mov_x_5.rs: Move to...
* rust/execute/torture/inline_asm_mov_x_5_ARM.rs: ...here.
* rust/execute/torture/inline_asm_mov_x_5_x86_64.rs: New test.

4 months agogccrs: Rehaul, Apply code review from Arthur
badumbatish [Thu, 29 Aug 2024 17:07:19 +0000 (10:07 -0700)] 
gccrs: Rehaul, Apply code review from Arthur

gcc/rust/ChangeLog:

* backend/rust-compile-asm.cc (CompileAsm::visit):
Change API, public/private, comments, formatting from code
review
(CompileAsm::asm_build_expr): Likewise.
(CompileAsm::tree_codegen_asm): Likewise.
* backend/rust-compile-asm.h (class CompileAsm): Likewise.
* backend/rust-compile-expr.cc (CompileExpr::visit): Likewise.
* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): Likewise.
* expand/rust-macro-builtins-asm.cc (strip_double_quotes): Likewise.
(parse_options): Likewise.
(parse_asm_arg): Likewise.
(expand_inline_asm_strings): Likewise.
(parse_asm): Likewise.
* expand/rust-macro-builtins-asm.h (strip_double_quotes): Likewise.
(expand_inline_asm_strings): Likewise.
(expand_inline_asm_string): Likewise.
* hir/tree/rust-hir-expr.h: Likewise.

gcc/testsuite/ChangeLog:

* rust/compile/inline_asm_typecheck.rs: Change comments

4 months agogccrs: Fix return type of asm mov 5 to i32:0, tortured
badumbatish [Wed, 28 Aug 2024 07:15:14 +0000 (00:15 -0700)] 
gccrs: Fix return type of asm mov 5 to i32:0, tortured

gcc/testsuite/ChangeLog:

* rust/execute/inline_asm_mov_x_5.rs: Move to...
* rust/execute/torture/inline_asm_mov_x_5.rs: ...here.

4 months agogccrs: Make inline mov compiles
badumbatish [Wed, 28 Aug 2024 01:15:26 +0000 (18:15 -0700)] 
gccrs: Make inline mov compiles

gcc/rust/ChangeLog:

* backend/rust-compile-asm.cc (CompileAsm::asm_build_expr):
Remove debug
* expand/rust-macro-builtins-asm.cc (expand_inline_asm_strings):
properly formatted via rust instead of c
(parse_asm): formatted comment
(parse_format_strings): formatted comment
* hir/tree/rust-hir-expr.h: fix is_simple_asm()

gcc/testsuite/ChangeLog:

* rust/compile/inline_asm_parse_operand.rs: Fix format asm
* rust/compile/inline_asm_parse_output_operand.rs:
Fix format asm
* rust/execute/torture/inline_asm_mov_x_5.rs: Move to...
* rust/execute/inline_asm_mov_x_5.rs: ...here.

4 months agogccrs: Use's array type when constring string tree
badumbatish [Thu, 8 Aug 2024 21:22:05 +0000 (14:22 -0700)] 
gccrs: Use's array type when constring string tree

gcc/rust/ChangeLog:

* backend/rust-compile-asm.cc (CompileAsm::asm_build_expr):
Use's array type when constring string tree
(CompileAsm::asm_construct_string_tree):
Use's array type when constring string tree

4 months agogccrs: Added noreturn checking for nevertype, new test
badumbatish [Fri, 2 Aug 2024 18:36:04 +0000 (11:36 -0700)] 
gccrs: Added noreturn checking for nevertype, new test

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
Added noreturn checking for nevertype

gcc/testsuite/ChangeLog:

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

4 months agogccrs: Perform lowering hir output operand to tree
badumbatish [Thu, 1 Aug 2024 23:22:32 +0000 (16:22 -0700)] 
gccrs: Perform lowering hir output operand to tree

gcc/rust/ChangeLog:

* backend/rust-compile-asm.cc (CompileAsm::asm_build_expr):
Add debug comment
(CompileAsm::asm_construct_outputs):
Perform lowering hir output operand to tree

4 months agogccrs: Perform type check on InlineAsm's operand
badumbatish [Thu, 1 Aug 2024 23:18:38 +0000 (16:18 -0700)] 
gccrs: Perform type check on InlineAsm's operand

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
Perform type check on InlineAsm's operand
(typecheck_inline_asm_operand): Likewise