]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
2 weeks agoRISC-V: Read extension data from riscv-ext*.def for arch-canonicalize
Kito Cheng [Thu, 31 Jul 2025 08:25:52 +0000 (16:25 +0800)] 
RISC-V: Read extension data from riscv-ext*.def for arch-canonicalize

Previously, arch-canonicalize used hardcoded data to handle IMPLIED_EXT.
But this data often got out of sync with the actual C++ implementation.
Earlier, we introduced riscv-ext.def to keep track of all extension info
and generate docs. Now, arch-canonicalize also uses this same data to handle
extension implication rules directly.

One limitation is that conditional implication rules still need to be written
manually. Luckily, there aren't many of them for now, so it's still manageable.
I really wanted to avoid writing a C++ + Python binding or trying to parse C++
logic in Python...

This version also adds a `--selftest` option to run some unit tests.

gcc/ChangeLog:

* config/riscv/arch-canonicalize: Read extension data from
riscv-ext*.def and adding unittest.

2 weeks agoRISC-V: Support -march=unset
Kito Cheng [Mon, 28 Jul 2025 12:49:39 +0000 (20:49 +0800)] 
RISC-V: Support -march=unset

This patch introduces a new `-march=unset` option for RISC-V GCC that
allows users to explicitly ignore previous `-march` options and derive
the architecture string from the `-mcpu` option instead.

This feature is particularly useful for build systems and toolchain
configurations where you want to ensure the architecture is always
derived from the CPU specification rather than relying on potentially
conflicting `-march` options.

gcc/ChangeLog:

* common/config/riscv/riscv-common.cc (riscv_expand_arch):
Ignore `unset`.
* config/riscv/riscv.h (OPTION_DEFAULT_SPECS): Handle
`-march=unset`.
(ARCH_UNSET_CLEANUP_SPECS): New.
(DRIVER_SELF_SPECS): Handle -march=unset.
* doc/invoke.texi (RISC-V Options): Update documentation for
`-march=unset`.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/arch-unset-1.c: New test.
* gcc.target/riscv/arch-unset-2.c: New test.
* gcc.target/riscv/arch-unset-3.c: New test.
* gcc.target/riscv/arch-unset-4.c: New test.
* gcc.target/riscv/arch-unset-5.c: New test.

2 weeks agoopenmp: Add support for iterators in 'target update' clauses (C/C++)
Kwok Cheung Yeung [Wed, 6 Aug 2025 00:07:46 +0000 (01:07 +0100)] 
openmp: Add support for iterators in 'target update' clauses (C/C++)

This adds support for iterators in 'to' and 'from' clauses in the
'target update' OpenMP directive.

gcc/c/

* c-parser.cc (c_parser_omp_clause_from_to): Parse 'iterator' modifier.
* c-typeck.cc (c_finish_omp_clauses): Finish iterators for to/from
clauses.

gcc/cp/

* parser.cc (cp_parser_omp_clause_from_to): Parse 'iterator' modifier.
* semantics.cc (finish_omp_clauses): Finish iterators for to/from
clauses.

gcc/

* gimplify.cc (remove_unused_omp_iterator_vars): Display unused
variable warning for 'to' and 'from' clauses.
(gimplify_scan_omp_clauses): Add argument for iterator loop sequence.
Gimplify the clause decl and size into the iterator loop if iterators
are used.
(gimplify_omp_workshare): Add argument for iterator loops sequence
in call to gimplify_scan_omp_clauses.
(gimplify_omp_target_update): Call remove_unused_omp_iterator_vars and
build_omp_iterators_loops.  Add loop sequence as argument when calling
gimplify_scan_omp_clauses, gimplify_adjust_omp_clauses and building
the Gimple statement.
* tree-pretty-print.cc (dump_omp_clause): Call dump_omp_iterators
for to/from clauses with iterators.
* tree.cc (omp_clause_num_ops): Add extra operand for OMP_CLAUSE_FROM
and OMP_CLAUSE_TO.
* tree.h (OMP_CLAUSE_HAS_ITERATORS): Add check for OMP_CLAUSE_TO and
OMP_CLAUSE_FROM.
(OMP_CLAUSE_ITERATORS): Likewise.

gcc/testsuite/

* c-c++-common/gomp/target-update-iterators-1.c: New.
* c-c++-common/gomp/target-update-iterators-2.c: New.
* c-c++-common/gomp/target-update-iterators-3.c: New.

libgomp/

* target.c (gomp_update): Call gomp_merge_iterator_maps.  Free
allocated variables.
* testsuite/libgomp.c-c++-common/target-update-iterators-1.c: New.
* testsuite/libgomp.c-c++-common/target-update-iterators-2.c: New.
* testsuite/libgomp.c-c++-common/target-update-iterators-3.c: New.

2 weeks agoopenmp: Add support for iterators in map clauses (C/C++)
Kwok Cheung Yeung [Wed, 6 Aug 2025 00:07:34 +0000 (01:07 +0100)] 
openmp: Add support for iterators in map clauses (C/C++)

This adds preliminary support for iterators in map clauses within OpenMP
'target' constructs (which includes constructs such as 'target enter data').

Iterators with non-constant loop bounds are not currently supported.

gcc/c/

* c-parser.cc (c_parser_omp_variable_list): Use location of the
map expression as the clause location.
(c_parser_omp_clause_map): Parse 'iterator' modifier.
* c-typeck.cc (c_finish_omp_clauses): Finish iterators.  Apply
iterators to generated clauses.

gcc/cp/

* parser.cc (cp_parser_omp_clause_map): Parse 'iterator' modifier.
* semantics.cc (finish_omp_clauses): Finish iterators.  Apply
iterators to generated clauses.

gcc/

* gimple-pretty-print.cc (dump_gimple_omp_target): Print expanded
iterator loops.
* gimple.cc (gimple_build_omp_target): Add argument for iterator
loops sequence.  Initialize iterator loops field.
* gimple.def (GIMPLE_OMP_TARGET): Set GSS symbol to GSS_OMP_TARGET.
* gimple.h (gomp_target): Set GSS symbol to GSS_OMP_TARGET.  Add extra
field for iterator loops.
(gimple_build_omp_target): Add argument for iterator loops sequence.
(gimple_omp_target_iterator_loops): New.
(gimple_omp_target_iterator_loops_ptr): New.
(gimple_omp_target_set_iterator_loops): New.
* gimplify.cc (find_var_decl): New.
(copy_omp_iterator): New.
(remap_omp_iterator_var_1): New.
(remap_omp_iterator_var): New.
(remove_unused_omp_iterator_vars): New.
(struct iterator_loop_info_t): New type.
(iterator_loop_info_map_t): New type.
(build_omp_iterators_loops): New.
(enter_omp_iterator_loop_context_1): New.
(enter_omp_iterator_loop_context): New.
(enter_omp_iterator_loop_context): New.
(exit_omp_iterator_loop_context): New.
(gimplify_adjust_omp_clauses): Add argument for iterator loop
sequence.  Gimplify the clause decl and size into the iterator
loop if iterators are used.
(gimplify_omp_workshare): Call remove_unused_omp_iterator_vars and
build_omp_iterators_loops for OpenMP target expressions.  Add
loop sequence as argument when calling gimplify_adjust_omp_clauses
and building the Gimple statement.
* gimplify.h (enter_omp_iterator_loop_context): New prototype.
(exit_omp_iterator_loop_context): New prototype.
* gsstruct.def (GSS_OMP_TARGET): New.
* omp-low.cc (lower_omp_map_iterator_expr): New.
(lower_omp_map_iterator_size): New.
(finish_omp_map_iterators): New.
(lower_omp_target): Add sorry if iterators used with deep mapping.
Call lower_omp_map_iterator_expr before assigning to sender ref.
Call lower_omp_map_iterator_size before setting the size.  Insert
iterator loop sequence before the statements for the target clause.
* tree-nested.cc (convert_nonlocal_reference_stmt): Walk the iterator
loop sequence of OpenMP target statements.
(convert_local_reference_stmt): Likewise.
(convert_tramp_reference_stmt): Likewise.
* tree-pretty-print.cc (dump_omp_iterators): Dump extra iterator
information if present.
(dump_omp_clause): Call dump_omp_iterators for iterators in map
clauses.
* tree.cc (omp_clause_num_ops): Add operand for OMP_CLAUSE_MAP.
(walk_tree_1): Do not walk last operand of OMP_CLAUSE_MAP.
* tree.h (OMP_CLAUSE_HAS_ITERATORS): New.
(OMP_CLAUSE_ITERATORS): New.

gcc/testsuite/

* c-c++-common/gomp/map-6.c (foo): Amend expected error message.
* c-c++-common/gomp/target-map-iterators-1.c: New.
* c-c++-common/gomp/target-map-iterators-2.c: New.
* c-c++-common/gomp/target-map-iterators-3.c: New.
* c-c++-common/gomp/target-map-iterators-4.c: New.

libgomp/

* target.c (kind_to_name): New.
(gomp_merge_iterator_maps): New.
(gomp_map_vars_internal): Call gomp_merge_iterator_maps.  Copy
address of only the first iteration to target vars.  Free allocated
variables.
* testsuite/libgomp.c-c++-common/target-map-iterators-1.c: New.
* testsuite/libgomp.c-c++-common/target-map-iterators-2.c: New.
* testsuite/libgomp.c-c++-common/target-map-iterators-3.c: New.

Co-authored-by: Andrew Stubbs <ams@baylibre.com>
2 weeks agoFortran: Fix runtime bogus diagnostic with ';'
Jerry DeLisle [Tue, 5 Aug 2025 19:10:24 +0000 (12:10 -0700)] 
Fortran: Fix runtime bogus diagnostic with ';'

PR libfortran/121234

libgfortran/ChangeLog:

* io/list_read.c (read_character): Add checks to bypass eating
semicolons when reading strings with decimal mode 'point'
(list_formatted_read_scalar): Likewise.

gcc/testsuite/ChangeLog:

* gfortran.dg/pr121234.f90: New test.

2 weeks agoDaily bump.
GCC Administrator [Wed, 6 Aug 2025 00:21:26 +0000 (00:21 +0000)] 
Daily bump.

2 weeks agoc++: clobber object on placement new [PR121068]
Jason Merrill [Tue, 5 Aug 2025 22:16:50 +0000 (15:16 -0700)] 
c++: clobber object on placement new [PR121068]

My r16-2432 patch addressed the original testcase involving an array of
scalars, but not this additional testcase involving an array of classes.

This patch addresses the issue more thoroughly, by having placement new
first clobber the new object, and improving cxx_eval_store_expression to
implement initial clobbers as well.

My earlier attempt to do this clobbered the array as a whole, which broke
construct_at after the resolution of LWG3436 due to trying to create a
multidimensional array over the top of a single-dimensional array.  To
side-step that issue, this patch instead clobbers the individual elements of
an array, taking advantage of the earlier change to let that activate the
array member of a union.

PR c++/121068

gcc/cp/ChangeLog:

* constexpr.cc (cxx_eval_store_expression): Handle clobbers.
(potential_constant_expression_1): Handle clobbers more.
* decl.cc (build_clobber_this): Use INIT_EXPR for initial clobber.
* init.cc (build_new_1): Clobber on placement new.
(build_vec_init): Don't clean up after clobber.

gcc/testsuite/ChangeLog:

* g++.dg/cpp26/constexpr-new5.C: New test.

2 weeks agofortran: Remove overwrite of polymorphic associate variable offset
Mikael Morin [Tue, 5 Aug 2025 12:58:03 +0000 (14:58 +0200)] 
fortran: Remove overwrite of polymorphic associate variable offset

The array descriptor returned by gfc_conv_expr_descriptor should be
usable as is.  No need to overwrite the offset.

gcc/fortran/ChangeLog:

* trans-stmt.cc (trans_associate_var): Remove overwrite of
the polymorphic associate variable's array descriptor offset.

2 weeks agofortran: Remove array bound update after constructor expansion
Mikael Morin [Tue, 5 Aug 2025 12:58:02 +0000 (14:58 +0200)] 
fortran: Remove array bound update after constructor expansion

The array constructor expansion extends the size of the array
dynamically, and sets the upper bound appropriately every time it
does.  There is no need to do it again at the end of expansion.

gcc/fortran/ChangeLog:

* trans-array.cc (trans_array_constructor): Remove the update of
the array descriptor upper bound after array constructor
expansion.

2 weeks agofortran: Remove premature initialization of a function result's span
Mikael Morin [Tue, 5 Aug 2025 12:58:01 +0000 (14:58 +0200)] 
fortran: Remove premature initialization of a function result's span

Setting just the span in an otherwise uninitialized array descriptor to
pass to a function that will use the descriptor for its result (thus do
the initialization) doesn't seem to be useful.

gcc/fortran/ChangeLog:

* trans-array.cc (gfc_conv_expr_descriptor): Remove
isolated initialization of the span field before passing to
the function that will do the initialization.

2 weeks agofortran: Remove default initialization of local pointers's span
Mikael Morin [Tue, 5 Aug 2025 12:58:00 +0000 (14:58 +0200)] 
fortran: Remove default initialization of local pointers's span

A pointer has no default initialization; it is invalid to use it before
it is associated to a target.  We can just as well leave its span field
uninitialized, and wait for the first pointer association to define a
span value.  The value of zero was an invalid span value anyway.

gcc/fortran/ChangeLog:

* trans-decl.cc (gfc_trans_deferred_vars): Don't default
initialize the span of local pointer arrays.

2 weeks agofortran: Remove redundant initialisation of associate variable span
Mikael Morin [Tue, 5 Aug 2025 12:57:59 +0000 (14:57 +0200)] 
fortran: Remove redundant initialisation of associate variable span

In the initialization of associate variable array descriptors, remove
an overwrite of the span field.  The descriptor that is returned by
gfc_conv_expr_descriptor should already be usable without it.

The range of cases where the code was in effect is not completely
clear.  The span overwrite looks redundant, and the conditional guarding
it seems to make it dead.  However, the conditions governing
gfc_conv_expr_descriptor, gfc_get_array_span and trans_associate_var
make it difficult to track what is possible and what isn't.  Trying to
investigate the case where the target is an array subreference wrapped
in parenthesis, I encountered a wrong-code issue, PR121384.  Let's
remove all this and see what happens.

gcc/fortran/ChangeLog:

* trans-stmt.cc (trans_associate_var): Remove overwrite of the
span field of the associate variable's array descriptor.

2 weeks agofortran: Remove span overwrite with pointer assignments
Mikael Morin [Tue, 5 Aug 2025 12:57:58 +0000 (14:57 +0200)] 
fortran: Remove span overwrite with pointer assignments

Remove an overwrite of the array descriptor span field when pointer-
assigning from a polymorphic function result to a non-polymorphic
pointer.  That overwrite doesn't make sense because the span is
determined by the memory layout of the array; we can't change it
without also changing the data pointer.

gcc/fortran/ChangeLog:

* trans-expr.cc (gfc_trans_pointer_assignment): Remove overwrite
of the span after assignment of the array descriptor in the
polymorphic function result to non-polymorphic pointer case.

gcc/testsuite/ChangeLog:

* gfortran.dg/pointer_assign_16.f90: New test.

2 weeks agox86: Get the widest vector mode from STORE_MAX_PIECES for memset
H.J. Lu [Tue, 5 Aug 2025 13:27:15 +0000 (06:27 -0700)] 
x86: Get the widest vector mode from STORE_MAX_PIECES for memset

commit 050b1708ea532ea4840e97d85fad4ca63d4cd631
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Thu Jun 19 05:03:48 2025 +0800

    x86: Get the widest vector mode from MOVE_MAX

gets the widest vector mode from MOVE_MAX.  But for memset, it should
use STORE_MAX_PIECES.

gcc/

PR target/121410
* config/i386/i386-expand.cc (ix86_expand_set_or_cpymem): Use
STORE_MAX_PIECES to get the widest vector mode in vector loop
for memset.

gcc/testsuite/

PR target/121410
* gcc.target/i386/pr121410.c: New test.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2 weeks agoAVR: Allow combination of sign_extend with ashift.
Georg-Johann Lay [Tue, 5 Aug 2025 15:48:43 +0000 (17:48 +0200)] 
AVR: Allow combination of sign_extend with ashift.

gcc/
* config/avr/avr.cc (avr_rtx_costs_1) [SIGN_EXTEND]: Adjust cost.
* config/avr/avr.md (*sext.ashift<QIPSI:mode><HISI:mode>2): New
insn and a cc split.

2 weeks agofortran: Remove unused field use_offset
Mikael Morin [Tue, 5 Aug 2025 15:11:03 +0000 (17:11 +0200)] 
fortran: Remove unused field use_offset

The gfc_se::use_offset field is set in a few places, but is nowhere
used.  Remove it.

gcc/fortran/ChangeLog:

* trans.h (gfc_se): Remove field use_offset.
* trans-expr.cc (gfc_conv_intrinsic_to_class): Remove use_offset
initialization.
(gfc_conv_procedure_call): Likewise.
* trans-stmt.cc (trans_associate_var): Likewise.

2 weeks agogccrs: Add read-only check on HIR
Ryutaro Okada [Mon, 21 Jul 2025 16:27:08 +0000 (09:27 -0700)] 
gccrs: Add read-only check on HIR

gcc/rust/ChangeLog:

* Make-lang.in (rust-readonly-check2.cc):
Add read-only check on HIR
* checks/errors/rust-readonly-check2.cc (ReadonlyChecker):
Add read-only check on HIR
* checks/errors/rust-readonly-check2.h (ReadonlyChecker):
Add read-only check on HIR

Signed-off-by: Ryutaro Okada <1015ryu88@gmail.com>
2 weeks agogccrs: Call base class's accept_vis method
Ryutaro Okada [Thu, 17 Jul 2025 12:32:43 +0000 (05:32 -0700)] 
gccrs: Call base class's  accept_vis method

gcc/rust/ChangeLog:

* hir/tree/rust-hir-visitor.cc (DefaultHIRVisitor::walk):
Call base class's  accept_vis method

Signed-off-by: Ryutaro Okada <1015ryu88@gmail.com>
2 weeks agogccrs: Add check before calling `get_trait_ref()`
Ryutaro Okada [Thu, 17 Jul 2025 12:28:44 +0000 (05:28 -0700)] 
gccrs: Add check before calling  `get_trait_ref()`

gcc/rust/ChangeLog:

* hir/tree/rust-hir-visitor.cc (DefaultHIRVisitor::walk):
Add check before calling  `get_trait_ref()`

Signed-off-by: Ryutaro Okada <1015ryu88@gmail.com>
2 weeks agogccrs: Remove undefined behavior with static_cast
Owen Avery [Tue, 15 Jul 2025 16:04:53 +0000 (12:04 -0400)] 
gccrs: Remove undefined behavior with static_cast

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-helpers.cc
(try_extract_string_literal_from_fragment): Perform static_cast
to AST::LiteralExpr only after it's verified that an AST::Expr
is a literal.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 weeks agogccrs: Recognize rustc_args_required_const attribute
Owen Avery [Sat, 12 Jul 2025 02:47:01 +0000 (22:47 -0400)] 
gccrs: Recognize rustc_args_required_const attribute

This doesn't handle rustc_args_required_const, but it does allow us to
recognize it as a valid attribute.

gcc/rust/ChangeLog:

* util/rust-attribute-values.h
(Attributes::RUSTC_ARGS_REQUIRED_CONST): New constexpr variable.
* util/rust-attributes.cc (__definitions): New entry for
RUSTC_ARGS_REQUIRED_CONST.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 weeks agogccrs: Make AttributeParser rely more on Parser
Owen Avery [Tue, 8 Jul 2025 23:38:22 +0000 (19:38 -0400)] 
gccrs: Make AttributeParser rely more on Parser

gcc/rust/ChangeLog:

* ast/rust-ast.cc (AttributeParser::parse_meta_item_inner):
Handle removal of AttributeParser-specific functions.
(AttributeParser::parse_path_meta_item): Likewise.
(AttributeParser::parse_meta_item_seq): Likewise.
(AttributeParser::parse_meta_item_lit): Likewise.
(AttributeParser::parse_literal): Remove function.
(AttributeParser::parse_simple_path): Likewise.
(AttributeParser::parse_simple_path_segment): Likewise.
(AttributeParser::peek_token): Likewise.
(AttributeParser::skip_token): Likewise.
* ast/rust-macro.h (AttributeParser::parse_simple_path):
Likewise.
(AttributeParser::parse_simple_path_segment): Likewise.
(AttributeParser::parse_literal): Likewise.
(AttributeParser::peek_token): Likewise.
(AttributeParser::skip_token): Likewise.
* parse/rust-parse.h (Parser): Make AttributeParser a friend
class.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 weeks agogccrs: offset_of: Compile the offset properly
Arthur Cohen [Wed, 30 Jul 2025 09:57:45 +0000 (11:57 +0200)] 
gccrs: offset_of: Compile the offset properly

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): Add proper handling
of the node.
* rust-backend.h (lookup_field): Declare it.
* rust-gcc.cc (lookup_field): Add forked implementation from gcc/c/.

gcc/testsuite/ChangeLog:

* rust/execute/torture/offset_of1.rs: New test.

2 weeks agogccrs: Catch parse failure in parse_path_meta_item
Owen Avery [Sat, 2 Aug 2025 01:27:28 +0000 (21:27 -0400)] 
gccrs: Catch parse failure in parse_path_meta_item

gcc/rust/ChangeLog:

* ast/rust-ast.cc (AttributeParser::parse_path_meta_item): Catch
parse_expr returning nullptr and remove defunct comment.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 weeks agogccrs: Avoid including rust-parse-impl.h in rust-parse.h
Owen Avery [Sat, 2 Aug 2025 03:04:01 +0000 (23:04 -0400)] 
gccrs: Avoid including rust-parse-impl.h in rust-parse.h

This should reduce incremental compile times when modifying
rust-parse-impl.h and not rust-parse.h.

gcc/rust/ChangeLog:

* Make-lang.in (GRS_OBJS): Add entries.
* parse/rust-parse-impl.h: Adjust header comment.
(Parser::parse_lifetime_params_objs): Fix bug and add comment.
(Parser::unexpected_token): Likewise.
* parse/rust-parse.h: Remove inclusion of "rust-parse-impl.h".
* parse/rust-parse-impl-lexer.cc: New file.
* parse/rust-parse-impl-macro.cc: New file.
* parse/rust-parse-impl-proc-macro.cc: New file.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 weeks agogccrs: Fix object copying issue causing pointer inconsistency
Ryutaro Okada [Sun, 3 Aug 2025 06:04:49 +0000 (23:04 -0700)] 
gccrs: Fix object copying issue causing pointer inconsistency

gcc/rust/ChangeLog:

* hir/rust-ast-lower-implitem.cc (ASTLowerTraitItem::visit):
Fix object copying issue causing pointer inconsistency

Signed-off-by: Ryutaro Okada <1015ryu88@gmail.com>
2 weeks agogccrs: Parse expression instead of literal in attributes
Pierre-Emmanuel Patry [Wed, 30 Jul 2025 12:24:41 +0000 (14:24 +0200)] 
gccrs: Parse expression instead of literal in attributes

gcc/rust/ChangeLog:

* ast/rust-ast.cc (AttributeParser::parse_path_meta_item): Parse
expression instead of literal. Update variant name.
(MetaItemPathLit::to_attribute): Remove function.
(AttributeParser::parse_path_meta_item): Update name.
(MetaItemPathLit::check_cfg_predicate): Likewise.
(MetaItemPathExpr::check_cfg_predicate): Likewise.
(MetaItemPathLit::accept_vis): Likewise.
(MetaItemPathExpr::accept_vis): Likewise.
* ast/rust-ast-collector.h: Update prototype and adapt code to new
expression.
* ast/rust-ast-collector.cc: Update code to expr.
* ast/rust-ast-full-decls.h (class MetaItemPathLit): Likewise.
(class MetaItemPathExpr): Likewise.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise.
* ast/rust-ast-visitor.h: Likewise.
* ast/rust-ast.h (class MetaItemPathLit): Rename class from here...
(class MetaItemPathExpr): ... to here.
* ast/rust-expr.h (class MetaItemPathLit): Rename class from here...
(class MetaItemPathExpr): ...to here.
* expand/rust-derive.h: Update class name.
* expand/rust-expand-visitor.cc (ExpandVisitor::visit): Likewise.
* expand/rust-expand-visitor.h: Likewise.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise.
* hir/rust-ast-lower-base.h: Likewise.
* resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise.
* resolve/rust-ast-resolve-base.h: Likewise.
* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
Likewise.
* resolve/rust-early-name-resolver.h: Likewise.
* util/rust-attributes.cc (AttributeChecker::visit): Likewise.
* util/rust-attributes.h: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 weeks agogccrs: Add test case showing method resolution with const-generics
Philip Herron [Fri, 1 Aug 2025 20:54:36 +0000 (21:54 +0100)] 
gccrs: Add test case showing method resolution with const-generics

gcc/testsuite/ChangeLog:

* rust/execute/torture/const-generics-1.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 weeks agogccrs: remove old debug
Philip Herron [Fri, 1 Aug 2025 20:49:29 +0000 (21:49 +0100)] 
gccrs: remove old debug

gcc/rust/ChangeLog:

* typecheck/rust-tyty-subst.cc (SubstitutionRef::infer_substitions): remove debug

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 weeks agogccrs: improve debug logging for unify site
Philip Herron [Fri, 1 Aug 2025 20:48:35 +0000 (21:48 +0100)] 
gccrs: improve debug logging for unify site

gcc/rust/ChangeLog:

* typecheck/rust-type-util.cc (unify_site_and): improve debug

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 weeks agogccrs: Remove more calls to the old TyTy::BaseType::can_eq interface
Philip Herron [Fri, 1 Aug 2025 10:54:52 +0000 (11:54 +0100)] 
gccrs: Remove more calls to the old TyTy::BaseType::can_eq interface

This old can_eq interface was an old method to try and check if types can match up
by taking into account generics but its not maintained properly and we already have
a new wrapper Resolver::types_compatable (type, type, locus, emit_errors) which
just calls unify_site_and infer with commit false. There are only a few places left
to update.

One minor downside is that i need to remove const in some places because the unify
interface is non const. Ideally we would want to avoid writing a seperate const unify
anyway so i think this is not ideal but fine for us.

gcc/rust/ChangeLog:

* typecheck/rust-autoderef.cc: remove useless assertion
* typecheck/rust-coercion.cc (TypeCoercionRules::coerce_unsafe_ptr): refactor
(TypeCoercionRules::coerce_borrowed_pointer): remove FIXME this is fine
* typecheck/rust-hir-inherent-impl-overlap.h: use types_compatable
* typecheck/rust-hir-path-probe.cc (PathProbeType::PathProbeType): remove const
(PathProbeType::Probe): likewise
(PathProbeImplTrait::PathProbeImplTrait): likewise
(PathProbeImplTrait::Probe): likewise
* typecheck/rust-hir-path-probe.h: likewise
* typecheck/rust-hir-type-check-base.cc (walk_types_to_constrain): likewise
* typecheck/rust-hir-type-check-base.h: likewise
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): use types_compatable
* typecheck/rust-hir-type-check.h: remove const
* typecheck/rust-typecheck-context.cc (TypeCheckContext::insert_associated_impl_mapping):
likewise
(TypeCheckContext::lookup_associated_impl_mapping_for_self): remove can_Eq
* typecheck/rust-tyty-bounds.cc (TypeBoundPredicate::is_equal): likewise
* typecheck/rust-tyty-subst.cc (SubstitutionArg::get_tyty): remove const version
* typecheck/rust-tyty-subst.h: likewise
* typecheck/rust-tyty.cc (BaseType::get_root): likewise
* typecheck/rust-tyty.h: likewise

gcc/testsuite/ChangeLog:

* rust/compile/generics8.rs: extra error message

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 weeks agogccrs: Ensure we track the const generic substitution on the param mappings
Philip Herron [Fri, 1 Aug 2025 10:52:16 +0000 (11:52 +0100)] 
gccrs: Ensure we track the const generic substitution on the param mappings

gcc/rust/ChangeLog:

* typecheck/rust-tyty-subst.cc: track the const generic
* typecheck/rust-tyty.cc (ConstType::is_equal): finish the is_equal

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 weeks agogccrs: Initialize boolean flag correctly
Pierre-Emmanuel Patry [Fri, 1 Aug 2025 15:39:35 +0000 (17:39 +0200)] 
gccrs: Initialize boolean flag correctly

Flag was left uninitialized within default constructor.

gcc/rust/ChangeLog:

* hir/rust-hir-dump.cc (Dump::Dump): Initialize flag.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 weeks agogccrs: Initialize boolean flag correctly
Pierre-Emmanuel Patry [Fri, 1 Aug 2025 15:34:36 +0000 (17:34 +0200)] 
gccrs: Initialize boolean flag correctly

gcc/rust/ChangeLog:

* hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::ASTLoweringPattern):
flag was not initialized in the constructor.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 weeks agogccrs: Prevent used after move on self param
Pierre-Emmanuel Patry [Fri, 1 Aug 2025 15:31:36 +0000 (17:31 +0200)] 
gccrs: Prevent used after move on self param

gcc/rust/ChangeLog:

* hir/rust-ast-lower-implitem.cc (ASTLowerTraitItem::visit): Remove
use after move.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 weeks agogccrs: Retrieve token stream before vector move
Pierre-Emmanuel Patry [Fri, 1 Aug 2025 14:43:18 +0000 (16:43 +0200)] 
gccrs: Retrieve token stream before vector move

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-helpers.cc: Remove use after move.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 weeks agogccrs: Add rest pattern support for AST::SlicePattern
Yap Zhi Heng [Wed, 30 Jul 2025 15:37:43 +0000 (23:37 +0800)] 
gccrs: Add rest pattern support for AST::SlicePattern

The main change can be found in ast/rust-pattern.h, which introduces 2 item types for
AST::SlicePattern - one without rest pattern (SlicePatternItemsNoRest) & the other with
it (SlicePatternItemsHasRest). This led to a number of cascading changes as seen in the
changelog.

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc: Add support for the 2 new classes.
* ast/rust-ast-collector.h: Header file update for above.
* ast/rust-ast-full-decls.h: Add forward decls for the 2 new classes.
* ast/rust-ast-visitor.cc: Add visit support for the 2 new classes.
* ast/rust-ast-visitor.h: Header file update for above.
* ast/rust-pattern.cc: Implementation of certain methods for the 2 new classes.
* ast/rust-pattern.h: Define the 2 new classes. Update SlicePattern to be able to hold
2 kinds of items - SlicePatternItemsNoRest or SlicePatternItemsRest.
* expand/rust-cfg-strip.cc: Add support for the 2 new classes.
* expand/rust-cfg-strip.h: Header file update for above.
* expand/rust-derive.h: Add visits for the 2 new classes.
* hir/rust-ast-lower-base.cc: Add visits for the 2 new classes.
* hir/rust-ast-lower-base.h: Header file update for above.
* hir/rust-ast-lower-pattern.cc: Update lowering of SlicePattern to support
SlicePatternItemsNoRest.
* parse/rust-parse-impl.h (parse_slice_pattern()): Add support for parsing DOT_DOT into
respective SlicePatternItems.
* resolve/rust-ast-resolve-base.cc: Add visits for the 2 new classes.
* resolve/rust-ast-resolve-base.h: Header file update for above.
* resolve/rust-ast-resolve-pattern.cc: Update SlicePattern resolution to support new
classes.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2 weeks agogccrs: Fix ICE when extra const arguments supplied
Philip Herron [Thu, 31 Jul 2025 20:29:02 +0000 (21:29 +0100)] 
gccrs: Fix ICE when extra const arguments supplied

The substitution code was not taking into account the const generic
arguments for checking the max bounds of total available parameters.

Fixes Rust-GCC#3546

gcc/rust/ChangeLog:

* typecheck/rust-tyty-subst.cc: fix check for total arguments

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 weeks agogccrs: Support const generic inference variables
Philip Herron [Thu, 31 Jul 2025 20:18:56 +0000 (21:18 +0100)] 
gccrs: Support const generic inference variables

We already support const infer so this just creates a fresh tyty::infer_var
for the const element type and then a ConstKind::Infer type for the const
type wrapper and the existing plumbing handles this.

Fixes Rust-GCC#3885

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): create infer variable

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 weeks agogccrs: Fix ICE during hir dump of deferred anon constant
Philip Herron [Thu, 31 Jul 2025 20:17:18 +0000 (21:17 +0100)] 
gccrs: Fix ICE during hir dump of deferred anon constant

gcc/rust/ChangeLog:

* hir/rust-hir-dump.cc (Dump::visit): check for expression
* hir/tree/rust-hir.cc (AnonConst::as_string): likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 weeks agogccrs: Fix ICE for ast dump of deferred anon const
Philip Herron [Thu, 31 Jul 2025 20:16:36 +0000 (21:16 +0100)] 
gccrs: Fix ICE for ast dump of deferred anon const

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): check for value

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 weeks agogccrs: fix clang formatting
Philip Herron [Thu, 31 Jul 2025 16:26:14 +0000 (17:26 +0100)] 
gccrs: fix clang formatting

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): formatting
* typecheck/rust-tyty-variance-analysis-private.h: likewise
* typecheck/rust-tyty.cc (VariantDef::clone): likewise
(VariantDef::monomorphized_clone): likewise
* typecheck/rust-tyty.h: likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 weeks agogccrs: Add initial support for const generics
Philip Herron [Sun, 27 Jul 2025 20:47:54 +0000 (21:47 +0100)] 
gccrs: Add initial support for const generics

In order to support const generics we map the declarations to a ConstType this
means we reuse all our existing type coercion, unification code and generic
substitutions code to support this with minimal impact.

This patch adds support for:

1. Default const generics
2. Infer const generics
3. ADTType suport
4. unconstrained checks
5. ensure types of the const generic and default
6. validation if passing a const argument to a type argument

Lots of test cases now work and new ones added. More work is needed to support this
on functions and method resolution of impls like Foo<1> vs Foo<2> once thats in we
can look to support some of the const generic array impls next.

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc: useful debug
* backend/rust-compile-stmt.cc (CompileStmt::visit): likewise
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): fold the capacity into ConstType
* hir/tree/rust-hir-generic-param.h: make const
* hir/tree/rust-hir-path.h: take into account const arguments now
* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::resolve_literal): needs const
* typecheck/rust-hir-type-check-base.h: add error handling for const supported locations
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): const type the arrays
* typecheck/rust-hir-type-check-implitem.cc (TypeCheckTopLevelExternItem::visit): update
(TypeCheckImplItem::visit): likewise
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): likewise
(TypeCheckItem::resolve_impl_block_substitutions): likewise
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): wrap up const type
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): likewise
(TypeResolveGenericParam::visit): likewise
(TypeResolveGenericParam::apply_trait_bounds): remove HIR::Generic from Param
* typecheck/rust-hir-type-check.cc (TraitItemReference::get_type_from_fn): cleanup
* typecheck/rust-tyty-subst.cc (SubstitutionParamMapping::SubstitutionParamMapping):
handle const generics
(SubstitutionParamMapping::get_type_representation): likewise
(SubstitutionParamMapping::param_has_default_ty): likewise
(SubstitutionParamMapping::get_default_ty): likewise
(SubstitutionRef::infer_substitions): likewise
* typecheck/rust-tyty-subst.h: likewise
* typecheck/rust-tyty-util.cc (TyVar::get_implicit_const_infer_var): new helper
* typecheck/rust-tyty-util.h (class ConstType): likewise
* typecheck/rust-tyty.cc (BaseType::is_concrete): check for array const concrete
(ArrayType::as_string): update to const
(ArrayType::handle_substitions): likewise
(ParamType::ParamType): likewise
(ParamType::get_generic_param): likewise
(ParamType::clone): likewise
(ConstType::ConstType): likewise
(ConstType::set_value): likewise
(ConstType::clone): likewise
(ConstType::get_generic_param): likewise
(generate_tree_str): new helper to pretty print gimple
(ConstType::get_name): uses the generate_tree_str
(ConstType::handle_substitions): handle const infer's
* typecheck/rust-tyty.h (RUST_TYTY): likewise
* typecheck/rust-unify.cc (UnifyRules::expect_array): likewise
(UnifyRules::expect_const): likewise

gcc/testsuite/ChangeLog:

* rust/compile/const_generics_3.rs: this works now
* rust/compile/const_generics_5.rs: likewise
* rust/compile/const_generics_8.rs: move the failure to another test case
* rust/compile/const_generics_10.rs: New test.
* rust/compile/const_generics_11.rs: New test.
* rust/compile/const_generics_12.rs: New test.
* rust/compile/const_generics_13.rs: New test.
* rust/compile/const_generics_14.rs: New test.
* rust/compile/const_generics_15.rs: New test.
* rust/compile/const_generics_16.rs: New test.
* rust/compile/const_generics_9.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 weeks agogccrs: Add ConstType boiler plate to handle const generics
Philip Herron [Sun, 27 Jul 2025 19:19:41 +0000 (20:19 +0100)] 
gccrs: Add ConstType boiler plate to handle const generics

This patch is all about just putting in the boiler plate for the new
BaseGeneric TyTy::ConstType. Nothing is really change but just the
nessecary cogs added to the machine.

gcc/rust/ChangeLog:

* backend/rust-compile-type.cc (TyTyResolveCompile::visit): error_mark_node for const types
* backend/rust-compile-type.h: boilerplate
* checks/errors/borrowck/rust-bir-fact-collector.h: likewise
* checks/errors/borrowck/rust-bir-place.h: likewise
* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::check_base_type_privacy):
likewise
* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit): likewise
* typecheck/rust-substitution-mapper.h: likewise
* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::assemble_marker_builtins): likewise
* typecheck/rust-tyty-call.h: likewise
* typecheck/rust-tyty-cmp.h (class ConstCmp): likewise
* typecheck/rust-tyty-variance-analysis-private.h: likewise
* typecheck/rust-tyty-visitor.h: likewise
* typecheck/rust-tyty.cc (TypeKindFormat::to_string): likewise
(BaseType::is_unit): likewise
(BaseType::has_substitutions_defined): likewise
(BaseType::needs_generic_substitutions): likewise
(ConstType::ConstType): likewise
(ConstType::accept_vis): likewise
(ConstType::as_string): likewise
(ConstType::can_eq): likewise
(ConstType::clone): likewise
(ConstType::get_symbol): likewise
(ConstType::get_generic_param): likewise
(ConstType::can_resolve): likewise
(ConstType::resolve): likewise
(ConstType::get_name): likewise
(ConstType::is_equal): likewise
(ConstType::handle_substitions): likewise
* typecheck/rust-tyty.h (enum TypeKind): new tyty_kind
(class ConstType): new type
* typecheck/rust-unify.cc (UnifyRules::go): Handle a const type unify
(UnifyRules::expect_inference_variable): likewise
(UnifyRules::expect_adt): likewise
(UnifyRules::expect_str): likewise
(UnifyRules::expect_reference): likewise
(UnifyRules::expect_pointer): likewise
(UnifyRules::expect_param): likewise
(UnifyRules::expect_array): likewise
(UnifyRules::expect_slice): likewise
(UnifyRules::expect_fndef): likewise
(UnifyRules::expect_fnptr): likewise
(UnifyRules::expect_tuple): likewise
(UnifyRules::expect_bool): likewise
(UnifyRules::expect_char): likewise
(UnifyRules::expect_int): likewise
(UnifyRules::expect_uint): likewise
(UnifyRules::expect_float): likewise
(UnifyRules::expect_isize): likewise
(UnifyRules::expect_usize): likewise
(UnifyRules::expect_placeholder): likewise
(UnifyRules::expect_projection): likewise
(UnifyRules::expect_dyn): likewise
(UnifyRules::expect_closure): likewise
(UnifyRules::expect_const): likewise
* typecheck/rust-unify.h: new expect_const_type handler

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 weeks agogccrs: Refactor the ParamType to a BaseGeneric base-type
Philip Herron [Fri, 25 Jul 2025 16:49:15 +0000 (17:49 +0100)] 
gccrs: Refactor the ParamType to a BaseGeneric base-type

In order to support const generics we need to abstract away some of the specific
ParamType to a BaseGeneric type so we can easily reuse our existing substitution
bits for const generics which will mean creating a TyTy::ConstType to wrap up
the gcc tree but also represent a const inference and the const decl.

gcc/rust/ChangeLog:

* backend/rust-compile-intrinsic.cc (sizeof_handler): refactor types
(op_with_overflow_inner): likewise
(uninit_handler): likewise
(move_val_init_handler): likewise
* backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): likewise
* typecheck/rust-hir-trait-resolve.cc: likewise
* typecheck/rust-hir-type-check-base.cc: likewise
* typecheck/rust-hir-type-check-item.cc: likewise
* typecheck/rust-tyty-bounds.cc (TypeBoundPredicate::is_equal): likewise
* typecheck/rust-tyty-subst.cc (SubstitutionParamMapping::get_param_ty): likewise
(SubstitutionArg::get_param_mapping): likewise
(SubstitutionRef::prepare_higher_ranked_bounds): likewise
(SubstitutionRef::monomorphize): likewise
* typecheck/rust-tyty-subst.h (class BaseGeneric): new generic base
* typecheck/rust-tyty.cc (VariantDef::clone): likewise
(VariantDef::monomorphized_clone): refactor
(ADTType::is_equal): likewise
(FnType::is_equal): likewise
(ParamType::ParamType): likewise
* typecheck/rust-tyty.h (class ParamType): likewise
(class BaseGeneric): new base class impl

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 weeks agogccrs: simplify the is_eq on ADTType
Philip Herron [Fri, 25 Jul 2025 16:19:14 +0000 (17:19 +0100)] 
gccrs: simplify the is_eq on ADTType

We dont need to do this resolve we can just let the ParamType's sort this
out.

gcc/rust/ChangeLog:

* typecheck/rust-tyty.cc (ADTType::is_equal): let param::is_eq do this
(FnType::is_equal): remove whitespace

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 weeks agogccrs: Refactor substitution param mapping to be more abstract
Philip Herron [Fri, 25 Jul 2025 15:56:17 +0000 (16:56 +0100)] 
gccrs: Refactor substitution param mapping to be more abstract

This is an initial patch required to refactor our generics code to be
simpler and more abstract so we return the HIR::GenericParam in ParamMappings
instead of assuming its a TypeParam so we can slowly introduce ConstGenericParam
into this same flow.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-base.cc: check for type param
* typecheck/rust-tyty-subst.cc (SubstitutionParamMapping::SubstitutionParamMapping):
return HIR::GenericParam base class
(SubstitutionParamMapping::get_generic_param): likewise
(SubstitutionParamMapping::get_type_representation): new helper
(SubstitutionParamMapping::param_has_default_ty): check for param type
(SubstitutionParamMapping::get_default_ty): likewise
* typecheck/rust-tyty-subst.h: get the locus from the subst HIR::GenericParam now
* typecheck/rust-tyty-variance-analysis.cc (GenericTyPerCrateCtx::debug_print_solutions):
likwise
(GenericTyVisitorCtx::process_type): likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 weeks agogccrs: Fix ICE during const eval of const capacity
Philip Herron [Thu, 31 Jul 2025 20:46:42 +0000 (21:46 +0100)] 
gccrs: Fix ICE during const eval of const capacity

We assert that struct expressions during code-gen must be of TyTy::ADTType
but we can simply just check for this and return error_mark_node to make
this safe.

Fixes Rust-GCC#3960

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): check for ADTType instead of assert

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 weeks agogccrs: Remove warning for unused `self` parameter
Ryutaro Okada [Thu, 31 Jul 2025 10:57:11 +0000 (03:57 -0700)] 
gccrs: Remove warning for unused `self` parameter

gcc/testsuite/ChangeLog:

* rust/compile/auto_traits2.rs:
emove warning for unused `self` parameter
* rust/compile/derive-debug1.rs:
emove warning for unused `self` parameter
* rust/compile/derive_macro1.rs:
Remove warning for unused `self` parameter
* rust/compile/format_args_basic_expansion.rs:
Remove warning for unused `self` parameter
* rust/compile/format_args_extra_comma.rs:
Remove warning for unused `self` parameter
* rust/compile/issue-2043.rs:
Remove warning for unused `self` parameter
* rust/compile/issue-2166.rs:
Remove warning for unused `self` parameter
* rust/compile/issue-2238.rs:
Remove warning for unused `self` parameter
* rust/compile/issue-2907.rs:
Remove warning for unused `self` parameter
* rust/compile/min_specialization1.rs:
Remove warning for unused `self` parameter
* rust/compile/name_resolution2.rs:
Remove warning for unused `self` parameter
* rust/compile/name_resolution4.rs:
Remove warning for unused `self` parameter
* rust/compile/torture/generics29.rs:
Remove warning for unused `self` parameter
* rust/compile/torture/generics30.rs:
Remove warning for unused `self` parameter
* rust/compile/torture/traits3.rs:
Remove warning for unused `self` parameter
* rust/compile/torture/traits7.rs:
Remove warning for unused `self` parameter
* rust/execute/torture/impl_trait3.rs:
Remove warning for unused `self` parameter
* rust/execute/torture/min_specialization2.rs:
Remove warning for unused `self` parameter
* rust/execute/torture/trait10.rs:
Remove warning for unused `self` parameter
* rust/execute/torture/trait11.rs:
Remove warning for unused `self` parameter
* rust/execute/torture/trait12.rs:
Remove warning for unused `self` parameter
* rust/execute/torture/trait13.rs:
Remove warning for unused `self` parameter
* rust/execute/torture/trait9.rs:
Remove warning for unused `self` parameter

Signed-off-by: Ryutaro Okada <1015ryu88@gmail.com>
2 weeks agogccrs: Do not warn about unused `self` parameter
Ryutaro Okada [Thu, 31 Jul 2025 10:54:49 +0000 (03:54 -0700)] 
gccrs: Do not warn about unused `self` parameter

gcc/rust/ChangeLog:

* checks/lints/rust-lint-unused-var.cc (check_decl):
Do not warn about unused `self` parameter.

Signed-off-by: Ryutaro Okada <1015ryu88@gmail.com>
2 weeks agogccrs: desugar: Add base for desugaring while-let loops
Arthur Cohen [Tue, 22 Jul 2025 15:16:02 +0000 (17:16 +0200)] 
gccrs: desugar: Add base for desugaring while-let loops

gcc/rust/ChangeLog:

* Make-lang.in:
* ast/rust-expression-yeast.cc (ExpressionYeast::dispatch_loops): Call DesugarWhileLet.
* ast/rust-desugar-while-let.cc: New file.
* ast/rust-desugar-while-let.h: New file.

gcc/testsuite/ChangeLog:

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

2 weeks agogccrs: Fix AttrInputMacro operator= overloading.
Pierre-Emmanuel Patry [Thu, 31 Jul 2025 11:19:22 +0000 (13:19 +0200)] 
gccrs: Fix AttrInputMacro operator= overloading.

gcc/rust/ChangeLog:

* ast/rust-ast.cc (AttrInputMacro::operator=): Add return type.
* ast/rust-expr.h: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 weeks agogccrs: desugar: Cleanup for-loop desugar implementation.
Arthur Cohen [Tue, 22 Jul 2025 15:16:29 +0000 (17:16 +0200)] 
gccrs: desugar: Cleanup for-loop desugar implementation.

gcc/rust/ChangeLog:

* ast/rust-desugar-for-loops.cc: Remove functions implemented in AST::Builder.
* ast/rust-desugar-for-loops.h: Likewise.

2 weeks agogccrs: lower: Add assertions for desugared nodes
Arthur Cohen [Tue, 22 Jul 2025 14:47:55 +0000 (16:47 +0200)] 
gccrs: lower: Add assertions for desugared nodes

gcc/rust/ChangeLog:

* hir/rust-ast-lower-base.cc: Add rust_unreachable() when lowering desugared exprs.
* hir/rust-ast-lower-base.h: Mention this.
* hir/rust-ast-lower-block.h: Remove existing definitions.
* hir/rust-ast-lower-expr.cc: Likewise.
* hir/rust-ast-lower-expr.h: Likewise.
* hir/rust-ast-lower.cc: Likewise.

2 weeks agogccrs: desugar: Add assertions for try-blocks and question-mark
Arthur Cohen [Tue, 22 Jul 2025 14:29:09 +0000 (16:29 +0200)] 
gccrs: desugar: Add assertions for try-blocks and question-mark

gcc/rust/ChangeLog:

* ast/rust-desugar-question-mark.cc (DesugarQuestionMark::go): Add assertion for the
expr's type.
* ast/rust-desugar-try-block.cc (DesugarTryBlock::go): Likewise.

2 weeks agogccrs: desugar: Add for-loop desugar to ExpressionYeast
Arthur Cohen [Tue, 22 Jul 2025 13:00:32 +0000 (15:00 +0200)] 
gccrs: desugar: Add for-loop desugar to ExpressionYeast

gcc/rust/ChangeLog:

* ast/rust-desugar-for-loops.h: Adapt API and remove visitor.
* ast/rust-desugar-for-loops.cc: Likewise.
* ast/rust-expression-yeast.cc: Call DesugarForLoop.
* ast/rust-expression-yeast.h: Declare dispatch_loops function.
* rust-session-manager.cc (Session::expansion): Do not call for-loop desugar.

2 weeks agogccrs: hir: Add OffsetOf node
Arthur Cohen [Mon, 28 Jul 2025 08:05:04 +0000 (10:05 +0200)] 
gccrs: hir: Add OffsetOf node

gcc/rust/ChangeLog:

* hir/tree/rust-hir-expr.h (class OffsetOf): New.
* hir/tree/rust-hir-expr.cc: Define its methods.
* hir/tree/rust-hir-expr-abstract.h: Add ExprType::OffsetOf.
* hir/tree/rust-hir-full-decls.h (class OffsetOf): Declare it.
* backend/rust-compile-block.h: Add handling for OffsetOf.
* backend/rust-compile-expr.cc (CompileExpr::visit): Likewise.
* backend/rust-compile-expr.h: Likewise.
* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Likewise.
* checks/errors/borrowck/rust-bir-builder-expr-stmt.h (RUST_BIR_BUILDER_EXPR_H): Likewise.
* checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: Likewise.
* 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 (RUST_PRIVACY_REPORTER_H): Likewise.
* checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise.
* checks/errors/rust-const-checker.h: Likewise.
* checks/errors/rust-hir-pattern-analysis.cc (PatternChecker::visit): Likewise.
* checks/errors/rust-hir-pattern-analysis.h: Likewise.
* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise.
* checks/errors/rust-unsafe-checker.h: Likewise.
* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise.
* hir/rust-hir-dump.cc (Dump::visit): Likewise.
* hir/rust-hir-dump.h: Likewise.
* hir/tree/rust-hir-visitor.cc (DefaultHIRVisitor::walk): Likewise.
* hir/tree/rust-hir-visitor.h: Likewise.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise.
* typecheck/rust-hir-type-check-expr.h (RUST_HIR_TYPE_CHECK_EXPR): Likewise.

gcc/testsuite/ChangeLog:

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

2 weeks agogccrs: expand: Add parser for offset_of!() and builtin resolution.
Arthur Cohen [Thu, 24 Jul 2025 09:32:43 +0000 (11:32 +0200)] 
gccrs: expand: Add parser for offset_of!() and builtin resolution.

gcc/rust/ChangeLog:

* Make-lang.in: Compile the offset_of handler.
* lang.opt: Add -frust-assume-builtin-offset-of option.
* ast/rust-ast.h: Add has_str() for const_TokenPtr.
* expand/rust-macro-builtins.cc: Map offset_of as builtin.
* expand/rust-macro-builtins.h: Declare it.
* expand/rust-macro-expand.cc (MacroExpander::expand_invoc): Add hack for calling builtin
offset_of!().
* resolve/rust-early-name-resolver-2.0.cc (Early::visit):  Likewise.
* expand/rust-macro-builtins-offset-of.cc: New file.

gcc/testsuite/ChangeLog:

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

2 weeks agogccrs: ast: Add OffsetOf node
Arthur Cohen [Thu, 24 Jul 2025 09:03:35 +0000 (11:03 +0200)] 
gccrs: ast: Add OffsetOf node

gcc/rust/ChangeLog:

* ast/rust-ast.h: Add OffsetOf expression kind.
* ast/rust-builtin-ast-nodes.h (class OffsetOf): Add node.
* ast/rust-ast.cc: Define it.
* ast/rust-ast-collector.cc: Add visitor for OffsetOf.
* ast/rust-ast-collector.h: Likewise.
* ast/rust-ast-visitor.cc: Likewise.
* ast/rust-ast-visitor.h: Likewise.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise.
* hir/rust-ast-lower-base.h: Likewise.
* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise.
* hir/rust-ast-lower-expr.h: Likewise.
* resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise.
* resolve/rust-ast-resolve-base.h: Likewise.
* resolve/rust-early-name-resolver-2.0.cc: Likewise.
* expand/rust-derive.h:

2 weeks agogccrs: Error message field member was not properly updated
Pierre-Emmanuel Patry [Wed, 30 Jul 2025 17:37:45 +0000 (19:37 +0200)] 
gccrs: Error message field member was not properly updated

gcc/rust/ChangeLog:

* rust-diagnostics.h (struct Error): Add disambiguation.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 weeks agogccrs: Fix infinite loop with missing comma
Pierre-Emmanuel Patry [Wed, 30 Jul 2025 11:11:52 +0000 (13:11 +0200)] 
gccrs: Fix infinite loop with missing comma

A missing comma between inline assembly templates did not throw an error
and looped indefinitely.

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-asm.cc (parse_format_strings): Emit an
error when expecting a comma.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 weeks agogccrs: Fix semicolon after some namespace
Pierre-Emmanuel Patry [Tue, 29 Jul 2025 15:33:18 +0000 (17:33 +0200)] 
gccrs: Fix semicolon after some namespace

Remove namespace comment after classes and structs.

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-fact-collector.h: Remove spurious
comment.
* checks/errors/rust-feature.cc: Likewise.
* util/optional.h: Likewise.
* expand/rust-token-tree-desugar.cc (TokenTreeDesugar::visit): Remove
semicolons on namespace.
* expand/rust-token-tree-desugar.h: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 weeks agogccrs: nr1.0: Remove rust/typecheck support
Owen Avery [Thu, 3 Jul 2025 21:48:22 +0000 (17:48 -0400)] 
gccrs: nr1.0: Remove rust/typecheck support

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-base.cc
(TypeCheckBase::TypeCheckBase): Remove initialization of
resolver field.
* typecheck/rust-hir-type-check-base.h
(TypeCheckBase::resolver): Remove field.
* typecheck/rust-hir-trait-resolve.cc: Remove "options.h"
include.
(TraitResolver::resolve_path_to_trait): Assume name resolution
2.0 is always enabled.
* typecheck/rust-hir-type-check-enumitem.cc: Remove "options.h"
include.
(TypeCheckEnumItem::visit): Assume name resolution 2.0 is always
enabled.
* typecheck/rust-hir-type-check-expr.cc: Remove "options.h"
include.
(TypeCheckExpr::visit): Assume name resolution 2.0 is always
enabled.
(TypeCheckExpr::resolve_operator_overload): Likewise.
(TypeCheckExpr::resolve_fn_trait_call): Likewise.
* typecheck/rust-hir-type-check-implitem.cc: Remove "options.h"
include.
(TypeCheckImplItem::visit): Assume name resolution 2.0 is always
enabled.
* typecheck/rust-hir-type-check-item.cc: Remove "options.h"
include.
(TypeCheckItem::visit): Assume name resolution 2.0 is always
enabled.
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::visit):
Likewise.
(TypeCheckExpr::resolve_root_path): Likewise.
(TypeCheckExpr::resolve_segments): Likewise.
* typecheck/rust-hir-type-check-pattern.cc: Remove "options.h"
include.
(TypeCheckPattern::visit): Assume name resolution 2.0 is always
enabled.
* typecheck/rust-hir-type-check-type.cc
(TypeCheckType::resolve_root_path): Likewise.
(ResolveWhereClauseItem::visit): Likewise.
* typecheck/rust-hir-type-check.cc: Remove "options.h" include.
(TraitItemReference::get_type_from_fn): Assume name resolution
2.0 is always enabled.
* typecheck/rust-type-util.cc (query_type): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 weeks agogccrs: Add execute test for variable and identifiers
Pierre-Emmanuel Patry [Tue, 29 Jul 2025 13:15:31 +0000 (15:15 +0200)] 
gccrs: Add execute test for variable and identifiers

gcc/testsuite/ChangeLog:

* rust/execute/inline_asm_inout_ident.rs: New test.
* rust/execute/inline_asm_inout_var.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 weeks agogccrs: Add input/output from inout and split in out
Pierre-Emmanuel Patry [Tue, 29 Jul 2025 11:48:17 +0000 (13:48 +0200)] 
gccrs: Add input/output from inout and split in out

Inline assembly was incomplete and input/output from inout or split in
out were not handled.

gcc/rust/ChangeLog:

* backend/rust-compile-asm.cc (get_out_expr): Return valid output from
an operand.
(CompileAsm::asm_construct_outputs): Handle every output
(get_in_expr): Return valid input from an operand.
(CompileAsm::asm_construct_inputs): Handle every input

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 weeks agogccrs: Parse input and output expression
Pierre-Emmanuel Patry [Tue, 29 Jul 2025 11:53:58 +0000 (13:53 +0200)] 
gccrs: Parse input and output expression

Previously inline assembly expected identifiers instead of expression.

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-asm.cc (parse_reg_operand_inout): Parse
expressions and build split in out.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 weeks agogccrs: Add pretty hir dump for inline assembly
Pierre-Emmanuel Patry [Tue, 29 Jul 2025 11:42:14 +0000 (13:42 +0200)] 
gccrs: Add pretty hir dump for inline assembly

gcc/rust/ChangeLog:

* hir/rust-hir-dump.cc (Dump::visit): Dump inline assembly fields
* hir/tree/rust-hir-expr.h: Add non const getter and avoid operand copy
from getters.
* hir/tree/rust-hir-visitor.cc (DefaultHIRVisitor::walk): Use non const
reference.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 weeks agogccrs: Add indexed positional argument support in asm
Pierre-Emmanuel Patry [Wed, 23 Jul 2025 12:40:46 +0000 (14:40 +0200)] 
gccrs: Add indexed positional argument support in asm

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-asm.cc (expand_inline_asm_strings): Handle
transformation for indexed positional arguments.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 weeks agogccrs: Implement compilation for SlicePattern against SliceType scrutinee
Yap Zhi Heng [Wed, 23 Jul 2025 00:24:18 +0000 (08:24 +0800)] 
gccrs: Implement compilation for SlicePattern against SliceType scrutinee

006t.original output from compiling testsuite/rust/compile/match-slicepattern-slice.rs:

...
  RUSTTMP.3 = slice;
  if (RUSTTMP.3.len == 1 && *(RUSTTMP.3.data + 0 * 4) == 1)
    {
      {
                struct () RUSTTMP.4;
        {

        }
        goto <D.129>;
      }
    }
  if (RUSTTMP.3.len == 2 && *(RUSTTMP.3.data + 1 * 4) == 2)
    {
      {
                struct () RUSTTMP.5;
        {

        }
        goto <D.129>;
      }
    }
  if (1)
    {
      {
                struct () RUSTTMP.6;
        {

        }
        goto <D.129>;
      }
    }
  <D.129>:;
...

gcc/rust/ChangeLog:

* rust-backend.h: New slice_index_expression function.
* rust-gcc.cc: Implementation of slice_index_expression to generate tree node for
accessing slice elements.
* backend/rust-compile-pattern.cc: Implement SlicePattern check expression & binding
compilation against SliceType scrutinee.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2 weeks agogccrs: Update SlicePattern typechecking against slice reference parents
Yap Zhi Heng [Sun, 20 Jul 2025 07:55:51 +0000 (15:55 +0800)] 
gccrs: Update SlicePattern typechecking against slice reference parents

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit(SlicePattern)):
Add new type check case for SliceType wrapped in ReferenceType.
* backend/rust-compile-pattern.cc: Adjusted the asserts accordingly for
CompilePatternCheckExpr(SlicePattern) & CompilePatternBindings(SlicePattern).

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2 weeks agogccrs: desugar: Handle try-blocks
Arthur Cohen [Tue, 22 Jul 2025 11:30:11 +0000 (13:30 +0200)] 
gccrs: desugar: Handle try-blocks

gcc/rust/ChangeLog:

* Make-lang.in: Compile it.
* ast/rust-expression-yeast.cc (ExpressionYeast::dispatch): Dispatch to try-block
desugar.
* ast/rust-desugar-try-block.cc: New file.
* ast/rust-desugar-try-block.h: New file.

gcc/testsuite/ChangeLog:

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

2 weeks agogccrs: ast: Add Expr::Kind::Try
Arthur Cohen [Tue, 22 Jul 2025 11:38:26 +0000 (13:38 +0200)] 
gccrs: ast: Add Expr::Kind::Try

gcc/rust/ChangeLog:

* ast/rust-ast.h: Add the new variant.
* ast/rust-expr.h: Use it for TryExpr class.

2 weeks agogccrs: Handle IfLetExprConseqElse in DefaultResolver
Owen Avery [Tue, 22 Jul 2025 02:32:29 +0000 (22:32 -0400)] 
gccrs: Handle IfLetExprConseqElse in DefaultResolver

This relies on the DefaultASTVisitor visitor for IfLetExprConseqElse
performing a virtual call of the visitor for IfLetExpr, which doesn't
hold when DefaultASTVisitor is generated by the X-macro-DSL-system I
have in another patch.

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc (DefaultResolver::visit): Add
visitor for IfLetExprConseqElse.
* resolve/rust-default-resolver.h (DefaultResolver::visit):
Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 weeks agogccrs: ast: Visit block labels if they are present
Arthur Cohen [Mon, 21 Jul 2025 08:12:13 +0000 (10:12 +0200)] 
gccrs: ast: Visit block labels if they are present

gcc/rust/ChangeLog:

* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Visit a block's loop label if it
exists.

2 weeks agogccrs: desugar: Add desugar dispatch for all desugars
Arthur Cohen [Mon, 21 Jul 2025 09:27:01 +0000 (11:27 +0200)] 
gccrs: desugar: Add desugar dispatch for all desugars

Since we are doing more and more "external" desugars, as in desugars
that take a pointer and replace it with another one, rather than
modifying it from within, having an external visitor dispatch to the
proper desugar helps with code clarity.

gcc/rust/ChangeLog:

* Make-lang.in: Compile it.
* rust-session-manager.cc: Call the expression desugar dispatcher.
* ast/rust-desugar-question-mark.cc: Rework class API.
* ast/rust-desugar-question-mark.h: Likewise.
* ast/rust-expression-yeast.cc: New file.
* ast/rust-expression-yeast.h: New file.

2 weeks agogccrs: chore: ast: Fix formatting in rust-expr.h
Arthur Cohen [Mon, 21 Jul 2025 07:38:44 +0000 (09:38 +0200)] 
gccrs: chore: ast: Fix formatting in rust-expr.h

gcc/rust/ChangeLog:

* ast/rust-expr.h: Fix formatting.

2 weeks agogccrs: hir: Handle deferred const inference variables
Arthur Cohen [Tue, 8 Jul 2025 12:34:04 +0000 (14:34 +0200)] 
gccrs: hir: Handle deferred const inference variables

gcc/rust/ChangeLog:

* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Handle defered consts.
* hir/tree/rust-hir-expr.cc (AnonConst::AnonConst): Likewise.
(AnonConst::operator=): Likewise.
* hir/tree/rust-hir-expr.h: Likewise.
* hir/tree/rust-hir-visitor.cc (DefaultHIRVisitor::walk): Likewise.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise.

gcc/testsuite/ChangeLog:

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

2 weeks agogccrs: ast: Use AnonConst for array type sizes
Arthur Cohen [Mon, 21 Jul 2025 07:36:16 +0000 (09:36 +0200)] 
gccrs: ast: Use AnonConst for array type sizes

gcc/rust/ChangeLog:

* ast/rust-expr.h: Add handling for deferred consts.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise.
* ast/rust-ast.cc (AnonConst::as_string): Likewise.
(ArrayType::as_string): Likewise.
* ast/rust-type.h (class ArrayType): Use AnonConst for sizes.
* parse/rust-parse-impl.h (Parser::parse_anon_const): New function.
(Parser::parse_slice_or_array_type): Call it.
* parse/rust-parse.h: Declare it.

2 weeks agogccrs: nr2.0: Handle glob imports of enum variants.
Arthur Cohen [Wed, 9 Jul 2025 13:52:04 +0000 (15:52 +0200)] 
gccrs: nr2.0: Handle glob imports of enum variants.

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc (Early::resolve_glob_import): Adapt for enums.
(Early::finalize_glob_import): Likewise.
* resolve/rust-early-name-resolver-2.0.h: Likewise.
* resolve/rust-finalize-imports-2.0.cc (GlobbingVisitor::go): Likewise.
(GlobbingVisitor::visit_module_container): New function.
(GlobbingVisitor::visit_enum_container): New function.
* resolve/rust-finalize-imports-2.0.h: Declare them.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Insert enums as potential
containers.

gcc/testsuite/ChangeLog:

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

2 weeks agogccrs: mappings: Change mappings to allow other items as item containers.
Arthur Cohen [Wed, 9 Jul 2025 13:50:01 +0000 (15:50 +0200)] 
gccrs: mappings: Change mappings to allow other items as item containers.

This is important for importing enum variants as items.

gcc/rust/ChangeLog:

* util/rust-hir-map.cc (Mappings::insert_ast_module): Rename to...
(Mappings::insert_glob_container): ...this.
(Mappings::lookup_ast_module): Rename to...
(Mappings::lookup_glob_container): ...this.
* util/rust-hir-map.h: Change declarations.

2 weeks agogccrs: Load modules during CfgStrip phase
Owen Avery [Thu, 3 Jul 2025 01:38:56 +0000 (21:38 -0400)] 
gccrs: Load modules during CfgStrip phase

TopLevel would ignore just-loaded modules but Early and ExpandVisitor
wouldn't. The latter would produce errors when it hit attributes which
should have been indirectly CfgStrip'd away.

gcc/rust/ChangeLog:

* expand/rust-cfg-strip.cc (CfgStrip::visit): Load unloaded
modules.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit):
Assume modules have been loaded by CfgStrip.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 weeks agogccrs: Specialize ExpandVisitor::expand_macro_children
Owen Avery [Sat, 19 Jul 2025 01:44:09 +0000 (21:44 -0400)] 
gccrs: Specialize ExpandVisitor::expand_macro_children

gcc/rust/ChangeLog:

* expand/rust-expand-visitor.cc
(ExpandVisitor::expand_inner_items): Adjust call to
expand_macro_children.
(ExpandVisitor::expand_inner_stmts): Likewise.
(ExpandVisitor::visit): Likewise.
* expand/rust-expand-visitor.h
(ExpandVisitor::expand_macro_children): Take a pointer to member
function instead of a std::function.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 weeks agogccrs: fix bad monomophization of generic paths
Philip Herron [Sun, 20 Jul 2025 20:48:18 +0000 (21:48 +0100)] 
gccrs: fix bad monomophization of generic paths

When we have generic paths like T::foobar during codegen sometimes we need
to enforce an extra lookup for this generic parameter type to the mono
morphized underlying type.

Fixes Rust-GCC#3915
Fixes Rust-GCC#1247

gcc/rust/ChangeLog:

* backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): do another lookup

gcc/testsuite/ChangeLog:

* rust/compile/issue-3915.rs: New test.
* rust/execute/torture/sip-hasher.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 weeks agogccrs: Use MacroInvocLexer in AttributeParser
Owen Avery [Tue, 8 Jul 2025 21:03:49 +0000 (17:03 -0400)] 
gccrs: Use MacroInvocLexer in AttributeParser

This should make it easier for us to handle attribute meta items of the
form <SimplePath> '=' <Expression> where the expression isn't a literal.
Some low hanging fruit remains here, but I think I should keep this
patch small as I had some trouble debugging it as-is (see:
Rust::Token::as_string vs Rust::Token::get_str vs
Rust::AST::Token::as_string).

gcc/rust/ChangeLog:

* ast/rust-ast.cc: Include "rust-macro-invoc-lexer.h".
(AttributeParser::~AttributeParser): Move function definition
here.
(AttributeParser::AttributeParser): Likewise and adjust member
initialization.
(AttributeParser::parse_meta_item_inner): Handle changes to
peek_token.
(AttributeParser::parse_literal): Likewise.
(AttributeParser::parse_simple_path_segment): Likewise.
(AttributeParser::parse_meta_item_seq): Handle changes to
AttributeParser fields.
(AttributeParser::peek_token): Move function definition here and
wrap MacroInvocLexer.
(AttributeParser::skip_token): Likewise.
* ast/rust-macro.h (class MacroInvocLexer): Forward declare.
(class Parser): Likewise.
(AttributeParser::token_stream): Remove field.
(AttributeParser::stream_pos): Likewise.
(AttributeParser::lexer): New field.
(AttributeParser::parser): Likewise.
(AttributeParser::AttributeParser): Move definition to
"rust-ast.cc".
(AttributeParser::~AttributeParser): Likewise.
(AttributeParser::peek_token): Likewise.
(AttributeParser::skip_token): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 weeks agogccrs: return error node when this fails during constexpr case
Philip Herron [Fri, 18 Jul 2025 15:44:36 +0000 (16:44 +0100)] 
gccrs: return error node when this fails during constexpr case

Not adding the test case here we emit more errors than rustc for the error
type node so its just noisy and dejagnu is being a pain.

Fixes Rust-GCC#3933

gcc/rust/ChangeLog:

* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve): return error_mark_node

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 weeks agogccrs: Add initial support for deffered operator overload resolution
Philip Herron [Fri, 18 Jul 2025 14:46:59 +0000 (15:46 +0100)] 
gccrs: Add initial support for deffered operator overload resolution

In the test case:

  fn test (len: usize) -> u64 {
     let mut i = 0;
     let mut out = 0;
     if i + 3 < len {
        out = 123;
     }
     out
  }

The issue is to determine the correct type of 'i', out is simple because it hits a
coercion site in the resturn position for u64. But 'i + 3', 'i' is an integer infer
variable and the same for the literal '3'. So when it comes to resolving the type for
the Add expression we hit the resolve the operator overload code and because of this:

  macro_rules! add_impl {
      ($($t:ty)*) => ($(
          impl Add for $t {
              type Output = $t;

              #[inline]
              #[rustc_inherit_overflow_checks]
              fn add(self, other: $t) -> $t { self + other }
          }
      )*)
  }

  add_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }

This means the resolution for 'i + 3' is ambigious because it could be any of these Add
implementations. But because we unify against the '< len' where len is defined as usize
later in the resolution we determine 'i' is actually a usize. Which means if we defer the
resolution of this operator overload in the ambigious case we can simply resolve it at the
end.

Fixes Rust-GCC#3916

gcc/rust/ChangeLog:

* hir/tree/rust-hir-expr.cc (OperatorExprMeta::OperatorExprMeta): track the rhs
* hir/tree/rust-hir-expr.h: likewise
* hir/tree/rust-hir-path.h: get rid of old comments
* typecheck/rust-hir-trait-reference.cc (TraitReference::get_trait_substs): return
references instead of copy
* typecheck/rust-hir-trait-reference.h: update header
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::ResolveOpOverload): write ambigious
operator overloads to a table and try to resolve it at the end
* typecheck/rust-hir-type-check-expr.h: new static helper
* typecheck/rust-hir-type-check.h (struct DeferredOpOverload): new model to defer resolution
* typecheck/rust-typecheck-context.cc (TypeCheckContext::lookup_operator_overload): new
(TypeCheckContext::compute_ambigious_op_overload): likewise
(TypeCheckContext::compute_inference_variables): likewise

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 weeks agogccrs: Fix ICE with duplicate root item main function
Philip Herron [Fri, 18 Jul 2025 15:22:44 +0000 (16:22 +0100)] 
gccrs: Fix ICE with duplicate root item main function

Rust seems to allow duplicate HIR::Item 'main' functions but it needs
to be a root item to be the true main entry point. This means we can
use the canonical path to determine if this is a root one where
its CrateName::main or CrateName::Module::main.

Fixes Rust-GCC#3978

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc: check the canonical path

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 weeks agogccrs: Improve parsing of simple paths
Owen Avery [Tue, 15 Jul 2025 02:47:07 +0000 (22:47 -0400)] 
gccrs: Improve parsing of simple paths

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_simple_path): Be more
careful about skipping SCOPE_RESOLUTION tokens.
(Parser::parse_simple_path_segment): Allow parsing from a
starting offset.
(Parser::parse_use_tree): Handle a non-skipped SCOPE_RESOLUTION
token.
* parse/rust-parse.h (Parser::parse_simple_path_segment): Add
parameter for parsing from a starting offset.

gcc/testsuite/ChangeLog:

* rust/compile/parse_simple_path_fail_1.rs: New test.
* rust/compile/parse_simple_path_fail_2.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 weeks agogccrs: Add test case to show issue is fixed
Philip Herron [Fri, 18 Jul 2025 15:11:59 +0000 (16:11 +0100)] 
gccrs: Add test case to show issue is fixed

Fixes Rust-GCC#3524

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 weeks agogccrs: Reject loop in const/static context
lishin [Wed, 16 Jul 2025 00:39:48 +0000 (01:39 +0100)] 
gccrs: Reject loop in const/static context

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): Add a catch for const/static.

gcc/testsuite/ChangeLog:

* rust/compile/loop_constant_context.rs: New test.
* rust/compile/issue-3618.rs:

Signed-off-by: lishin <lishin1008@gmail.com>
2 weeks agogccrs: Implement compilation for SlicePattern matching against ArrayType scrutinee
Yap Zhi Heng [Thu, 17 Jul 2025 14:13:32 +0000 (22:13 +0800)] 
gccrs: Implement compilation for SlicePattern matching against ArrayType scrutinee

Example GIMPLE output from compiling testsuite/rust/compile/match-pattern-array.rs:

  ...
  a[0] = 0;
  a[1] = 1;
  RUSTTMP.3 = a;
  _1 = RUSTTMP.3[0];
  _2 = _1 == 0;
  _3 = RUSTTMP.3[1];
  _4 = _3 == 1;
  _5 = _2 & _4;
  if (_5 != 0) goto <D.122>; else goto <D.123>;
  <D.122>:
  {
    {

}
}
  goto <D.117>;
  }
  <D.123>:
...

gcc/rust/ChangeLog:

* rust-backend.h: New size_constant_expression function.
* rust-gcc.cc: Implementation of size_constant_expression function to generate tree node
for array access.
* backend/rust-compile-pattern.h: Remove empty visits for SlicePattern.
* backend/rust-compile-pattern.cc: Implement SlicePattern check expression & binding
compilation against ArrayType scrutinee.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2 weeks agogccrs: Add size checking to SlicePattern
Yap Zhi Heng [Fri, 11 Jul 2025 14:29:31 +0000 (22:29 +0800)] 
gccrs: Add size checking to SlicePattern

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-pattern.cc(TypeCheckPattern::visit(SlicePattern)):
Implement size checking for SlicePattern when type checking against array parent

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2 weeks agogccrs: Add test case showing all derives working on enum
Philip Herron [Fri, 11 Jul 2025 12:51:10 +0000 (13:51 +0100)] 
gccrs: Add test case showing all derives working on enum

We have more complex test cases already but this will close out this issue.

Fixes Rust-GCC#2005

gcc/testsuite/ChangeLog:

* rust/execute/torture/issue-2005.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 weeks agogccrs: attributes: Add #[test] and #[simd_test]
Arthur Cohen [Fri, 4 Jul 2025 14:19:44 +0000 (16:19 +0200)] 
gccrs: attributes: Add #[test] and #[simd_test]

gcc/rust/ChangeLog:

* util/rust-attribute-values.h: Add declarations for them.
* util/rust-attributes.cc: Add definitions.

2 weeks agogccrs: Add test case to show issue is fixed
Philip Herron [Fri, 11 Jul 2025 11:20:04 +0000 (12:20 +0100)] 
gccrs: Add test case to show issue is fixed

Fixes Rust-GCC#1048

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 weeks agogccrs: Add test case to show we emit better errors now
Philip Herron [Fri, 11 Jul 2025 09:35:38 +0000 (10:35 +0100)] 
gccrs: Add test case to show we emit better errors now

Fixes Rust-GCC#3144

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 weeks agogccrs: add test case to show issue is fixed
Philip Herron [Fri, 11 Jul 2025 09:16:36 +0000 (10:16 +0100)] 
gccrs: add test case to show issue is fixed

Fixes Rust-GCC#3599

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 weeks agogccrs: Fix ICE when handling bad constructor
Philip Herron [Thu, 10 Jul 2025 21:58:21 +0000 (22:58 +0100)] 
gccrs: Fix ICE when handling bad constructor

We just had a typo returning ok true when it should have been false.

Fixes Rust-GCC#3876

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::visit): fix typo

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 weeks agogccrs: Fix cast rules logic to try simple casts then fall back to coercions
Philip Herron [Thu, 10 Jul 2025 18:24:37 +0000 (19:24 +0100)] 
gccrs: Fix cast rules logic to try simple casts then fall back to coercions

This case:

    let i = 1;
    let j = i as i64;

'i' is meant to default to i32 but the inference was making both of these
i64 because the code was prefering coercion logic which can end up with a
default unify which causes the ?integer to unify with i64 making them both
i64.

But all we need to do is allow the simple cast rules to run first then
fallback to coercions but special consideration has to be made to ensure
that if there are dyn objects needed then this needs a unsize coercion, but
also we need to ensure the underlying types are a valid simple cast too
otherwise these also need to fallback to the coercion code.

Fixes Rust-GCC#2680

gcc/rust/ChangeLog:

* typecheck/rust-casts.cc (TypeCastRules::resolve): optional emit_error flag
(TypeCastRules::check): try the simple cast rules then fallback to coercions
(TypeCastRules::check_ptr_ptr_cast): ensure the underlying's
(TypeCastRules::emit_cast_error): make this a static helper
* typecheck/rust-casts.h: new emit_error prototype

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 weeks agogccrs: nr2.0: Check before visiting a for-loop's label
Arthur Cohen [Wed, 9 Jul 2025 09:46:10 +0000 (11:46 +0200)] 
gccrs: nr2.0: Check before visiting a for-loop's label

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Check for a label
before visiting it.