]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
7 days agogccrs: Fix crash on break outside of loop context
Philip Herron [Sun, 31 Aug 2025 22:20:03 +0000 (23:20 +0100)] 
gccrs: Fix crash on break outside of loop context

We need to add a guard to catch the case when there is no loop context
for break outside of loop.

Fixes Rust-GCC#3969

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): add guard

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
7 days agogccrs: Fix segv when handling invalid array capacities
Philip Herron [Sun, 31 Aug 2025 21:57:05 +0000 (22:57 +0100)] 
gccrs: Fix segv when handling invalid array capacities

We need to catch the error node for the array capacity and return early.
Otherwise we try to const evaluate something thats just silly. Also
when compiling array expressions we can simply reuse the array capacity
expression we already have cons folded.

Fixes Rust-GCC#3965

gcc/rust/ChangeLog:

* backend/rust-compile-context.h: add assertions for context peeks
* backend/rust-compile-expr.cc (CompileExpr::visit): check for valid loop context
(CompileExpr::array_copied_expr): just reuse array tyty capacity value
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): catch error

gcc/testsuite/ChangeLog:

* rust/compile/issue-3965-1.rs: New test.
* rust/compile/issue-3965-2.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
7 days agogccrs: Implement missing read-only checker case for TuplePatternItemsHasRest
Yap Zhi Heng [Thu, 28 Aug 2025 03:26:03 +0000 (11:26 +0800)] 
gccrs: Implement missing read-only checker case for TuplePatternItemsHasRest

gcc/rust/ChangeLog:

* checks/errors/rust-readonly-check.cc (collect_assignment_tuple): Implement
read-only checker for tuple patterns with rest pattern.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
7 days agogccrs: Implement missing var decl case for TuplePatternItemsHasRest
Yap Zhi Heng [Wed, 27 Aug 2025 13:47:34 +0000 (21:47 +0800)] 
gccrs: Implement missing var decl case for TuplePatternItemsHasRest

GIMPLE dump from compiling issue-3930.rs:

...
  const i32 b;
  const i32 a;

  D.114.__0 = 2;
  D.114.__1 = 3;
  RUSTTMP.1 = D.114;
  a = RUSTTMP.1.__0;
  b = RUSTTMP.1.__1;
...

gcc/rust/ChangeLog:

* backend/rust-compile-var-decl.h (CompileVarDecl::visit(TuplePattern)): Implement
variable declaration bindings for tuple patterns with rest pattern (i.e.
TuplePatternItemsHasRest).

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
7 days agogccrs: Recognize rustc_allow_const_fn_unstable
Owen Avery [Thu, 3 Jul 2025 01:39:10 +0000 (21:39 -0400)] 
gccrs: Recognize rustc_allow_const_fn_unstable

This doesn't actually handle the attribute, although it does allow us to
recognize it as valid.

gcc/rust/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
7 days agogccrs: Add implicit infer support for unify on const types
Philip Herron [Tue, 19 Aug 2025 18:34:38 +0000 (19:34 +0100)] 
gccrs: Add implicit infer support for unify on const types

gcc/rust/ChangeLog:

* typecheck/rust-unify.cc (UnifyRules::commit): commit hook update
(UnifyRules::go): insert implicit infer const types

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
7 days agogccrs: allow unifications against non const types
Philip Herron [Sun, 3 Aug 2025 18:53:23 +0000 (19:53 +0100)] 
gccrs: allow unifications against non const types

When type resolving a function which returns a const generic for example
this means its unifying the ConstType vs the the specified type so this
mean unwrapping the type of the const.

gcc/rust/ChangeLog:

* typecheck/rust-unify.cc (UnifyRules::go): unwrap the const type

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
7 days agogccrs: Fix bug with unconstrained const generic
Philip Herron [Sun, 3 Aug 2025 18:43:13 +0000 (19:43 +0100)] 
gccrs: Fix bug with unconstrained const generic

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-base.cc (walk_types_to_constrain): track the ref as well

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
7 days agogccrs: track generic const generics properly
Philip Herron [Sun, 3 Aug 2025 18:30:18 +0000 (19:30 +0100)] 
gccrs: track generic const generics properly

gcc/rust/ChangeLog:

* typecheck/rust-tyty-subst.cc: const generic arguments dont have a value yet

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
7 days agogccrs: Fix formatting of tyty code
Philip Herron [Fri, 29 Aug 2025 17:08:56 +0000 (18:08 +0100)] 
gccrs: Fix formatting of tyty code

gcc/rust/ChangeLog:

* typecheck/rust-tyty.cc (VariantDef::clone): fix formatting
(VariantDef::monomorphized_clone): likewise
* typecheck/rust-tyty.h: likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
7 days agogccrs: Remove fully the can_eq TyTy::BaseType::can_eq interface
Philip Herron [Fri, 29 Aug 2025 16:54:54 +0000 (17:54 +0100)] 
gccrs: Remove fully the can_eq TyTy::BaseType::can_eq interface

This was an initial helper from back in the day which was not maintained
but was a nice const simple way to check if types are compatable. But
reusing our unify code is much much more acurate and single source of
truth on the type system.

gcc/rust/ChangeLog:

* typecheck/rust-tyty.cc (InferType::can_eq): remove
(ErrorType::can_eq): likewise
(ADTType::can_eq): likewise
(TupleType::can_eq): likewise
(FnType::can_eq): likewise
(FnPtr::can_eq): likewise
(ClosureType::can_eq): likewise
(ArrayType::can_eq): likewise
(SliceType::can_eq): likewise
(BoolType::can_eq): likewise
(IntType::can_eq): likewise
(UintType::can_eq): likewise
(FloatType::can_eq): likewise
(USizeType::can_eq): likewise
(ISizeType::can_eq): likewise
(CharType::can_eq): likewise
(ReferenceType::can_eq): likewise
(PointerType::can_eq): likewise
(ParamType::can_eq): likewise
(ConstType::can_eq): likewise
(OpaqueType::can_eq): likewise
(StrType::can_eq): likewise
(NeverType::can_eq): likewise
(PlaceholderType::can_eq): likewise
(ProjectionType::can_eq): likewise
(DynamicObjectType::can_eq): likewise
* typecheck/rust-tyty.h: remove can_eq
* typecheck/rust-tyty-cmp.h: Removed.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
7 days agogccrs: get rid of last can_eq usage finally
Philip Herron [Fri, 29 Aug 2025 16:53:16 +0000 (17:53 +0100)] 
gccrs: get rid of last can_eq usage finally

gcc/rust/ChangeLog:

* typecheck/rust-tyty.cc (ParamType::is_equal): uses types_compatable

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
7 days agogccrs: reuse an error mark node instead of new ones each failure
Philip Herron [Fri, 29 Aug 2025 16:48:39 +0000 (17:48 +0100)] 
gccrs: reuse an error mark node instead of new ones each failure

During unification we denote failures using a new error mark node. This
keeps a static one and reuses it instead.

gcc/rust/ChangeLog:

* typecheck/rust-unify.cc (unify_error_type_node): new static node
(UnifyRules::go): likewise
(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_never): likewise
(UnifyRules::expect_placeholder): likewise
(UnifyRules::expect_projection): likewise
(UnifyRules::expect_dyn): likewise
(UnifyRules::expect_closure): likewise
(UnifyRules::expect_opaque): likewise
(UnifyRules::expect_const): likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
7 days agogccrs: simplify cloning of types during unify
Philip Herron [Fri, 29 Aug 2025 16:42:10 +0000 (17:42 +0100)] 
gccrs: simplify cloning of types during unify

We should only clone when we commit and it was successful. With no
cloning there is a regression in min specialization 2. Probably because
it needs to know the unify site hirid and ensure we have it set there.

gcc/rust/ChangeLog:

* typecheck/rust-unify.cc (UnifyRules::Resolve): check for success
(UnifyRules::expect_inference_variable): dont clone
(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_never): likewise
(UnifyRules::expect_placeholder): likewise
(UnifyRules::expect_projection): likewise
(UnifyRules::expect_dyn): likewise
(UnifyRules::expect_closure): likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
7 days agogccrs: remove 2nd last usage of can_eq
Philip Herron [Fri, 29 Aug 2025 15:52:34 +0000 (16:52 +0100)] 
gccrs: remove 2nd last usage of can_eq

gcc/rust/ChangeLog:

* typecheck/rust-tyty.cc (BaseType::satisfies_bound): use types_compatable instead

gcc/testsuite/ChangeLog:

* rust/compile/issue-1725-2.rs: remove bad error message

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
7 days agogccrs: Add check bounds flag to unify rules for compatability checks
Philip Herron [Fri, 29 Aug 2025 15:36:45 +0000 (16:36 +0100)] 
gccrs: Add check bounds flag to unify rules for compatability checks

We need to make the type bounds check a flag because it can turn into a
recursive type bounds check. This allows us to remove another can_eq usage

gcc/rust/ChangeLog:

* typecheck/rust-type-util.cc (types_compatable):  add check bounds flag
(unify_site_and): likewise
* typecheck/rust-type-util.h (types_compatable): likewise
(unify_site_and): likewise
* typecheck/rust-tyty-bounds.cc: likewise
* typecheck/rust-unify.cc (UnifyRules::UnifyRules): likewise
(UnifyRules::Resolve): likewise
(UnifyRules::resolve_subtype): likewise
(UnifyRules::go): likewise
* typecheck/rust-unify.h: likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
7 days agogccrs: Update can_eq to be a types_compatable interface
Philip Herron [Mon, 25 Aug 2025 19:52:29 +0000 (20:52 +0100)] 
gccrs: Update can_eq to be a types_compatable interface

Getting close to getting rid of can_eq and tyty-cmp soon.

gcc/rust/ChangeLog:

* typecheck/rust-hir-path-probe.cc (PathProbeType::process_impl_item_candidate):
refactor to types_compatable

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
7 days agogccrs: respect the unify rules commit flag
Philip Herron [Mon, 25 Aug 2025 12:30:22 +0000 (13:30 +0100)] 
gccrs: respect the unify rules commit flag

We use the types compatable interface for unify here and so if
we dont respect the commit flag the interface can have unintended
side effects with infer type hints throwing things off down the line.

gcc/rust/ChangeLog:

* typecheck/rust-unify.cc (UnifyRules::expect_inference_variable): dont commit
(UnifyRules::expect_adt): 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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
7 days agogccrs: Remove some const usage so we can get rid of more can_eq usage
Philip Herron [Mon, 25 Aug 2025 10:34:25 +0000 (11:34 +0100)] 
gccrs: Remove some const usage so we can get rid of more can_eq usage

I needed to remove som usage of const so we can get rid of can_eq in
type bounds probe. This means we can use the types_compatable interface
instead. Which is much better.

gcc/rust/ChangeLog:

* backend/rust-compile-base.h: remove const
* backend/rust-compile-expr.cc: likewise
* backend/rust-compile.cc (HIRCompileBase::coerce_to_dyn_object): likewise
* typecheck/rust-hir-type-bounds.h: likewise
* typecheck/rust-type-util.cc (lookup_associated_impl_block): likewise
* typecheck/rust-type-util.h (lookup_associated_impl_block): likewise
* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::TypeBoundsProbe): likewise
(TypeBoundsProbe::Probe): likewise
* typecheck/rust-tyty-cmp.h: likewise
* typecheck/rust-tyty-subst.cc (SubstitutionRef::monomorphize): likewise
* typecheck/rust-tyty.cc (BaseType::satisfies_bound): likewise
(BaseType::bounds_compatible): likewise
(VariantDef::clone): likewise
(VariantDef::monomorphized_clone): likewise
(OpaqueType::is_equal): likewise
(DynamicObjectType::is_equal): likewise
* typecheck/rust-tyty.h: likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
7 days agogccrs: Make the coerce borrowed pointer consistent with try flag
Philip Herron [Mon, 25 Aug 2025 19:44:16 +0000 (20:44 +0100)] 
gccrs: Make the coerce borrowed pointer consistent with try flag

This interface is not respecting the coercion api commit is always false,
we need to ensure this is respected via the try flag like the rest of the
coercion logic.

gcc/rust/ChangeLog:

* typecheck/rust-coercion.cc (TypeCoercionRules::select): respect try flag

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
7 days agogccrs: Error out on unsuffixed self list use declaration
Pierre-Emmanuel Patry [Tue, 26 Aug 2025 18:07:05 +0000 (20:07 +0200)] 
gccrs: Error out on unsuffixed self list use declaration

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc (Early::finalize_rebind_import):
Replace assert with early break and remove early return.
(Early::visit): Check for unsuffixed lower self list.
* resolve/rust-early-name-resolver-2.0.h: Add visit function prototype.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 days agogccrs: Emit error on lonely self use declaration
Pierre-Emmanuel Patry [Tue, 26 Aug 2025 15:15:47 +0000 (17:15 +0200)] 
gccrs: Emit error on lonely self use declaration

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc (Early::visit): Emit an error
on top level rebind self use declaration.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 days agogccrs: Allow early resolution to use the language prelude
Owen Avery [Sun, 10 Aug 2025 20:03:35 +0000 (16:03 -0400)] 
gccrs: Allow early resolution to use the language prelude

gcc/rust/ChangeLog:

* Make-lang.in (GRS_OBJS): Add "rust-resolve-builtins.o".
* resolve/rust-late-name-resolver-2.0.cc: Include
"rust-resolve-builtins.h".
(next_node_id): Remove function.
(next_hir_id): Likewise.
(Late::setup_builtin_types): Likewise.
(Late::go): Use Builtins::setup_type_ctx instead of
Late::setup_builtin_types.
* resolve/rust-late-name-resolver-2.0.h
(Late::setup_builtin_types): Remove function.
* rust-session-manager.cc: Include "rust-resolve-builtins.h".
(Session::expansion): Call Builtins::setup_lang_prelude.
* resolve/rust-resolve-builtins.cc: New file.
* resolve/rust-resolve-builtins.h: New file.

gcc/testsuite/ChangeLog:

* rust/compile/primitive-import.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
7 days agogccrs: Remove Parser::parse_tuple_index_expr_float
Owen Avery [Sat, 23 Aug 2025 19:32:13 +0000 (15:32 -0400)] 
gccrs: Remove Parser::parse_tuple_index_expr_float

Unlike in C, floating point literals can't start with a '.', and
therefore could never be split into a '.' followed by an integer.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::left_denotation): Remove
usage of parse_tuple_index_expr_float.
(Parser::parse_closure_expr_pratt): Remove function.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
7 days agogccrs: Do not dump the AST if the parser emit errors
Pierre-Emmanuel Patry [Tue, 26 Aug 2025 10:55:02 +0000 (12:55 +0200)] 
gccrs: Do not dump the AST if the parser emit errors

gcc/rust/ChangeLog:

* rust-session-manager.cc (Session::compile_crate): Move the AST dump
after parser error check.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 days agogccrs: desugar: Use PointerVisitor for ExpressionYeast
Arthur Cohen [Thu, 14 Aug 2025 08:29:57 +0000 (10:29 +0200)] 
gccrs: desugar: Use PointerVisitor for ExpressionYeast

gcc/rust/ChangeLog:

* ast/rust-expression-yeast.cc (ExpressionYeast::dispatch): Rename to...
(ExpressionYeast::reseat): ...this.
(ExpressionYeast::visit): Remove.
* ast/rust-expression-yeast.h: Inherit from PointerVisitor, override reseat instead
of declaring dispatch.

7 days agogccrs: ast: Add PointerVisitor
Arthur Cohen [Wed, 13 Aug 2025 12:32:41 +0000 (14:32 +0200)] 
gccrs: ast: Add PointerVisitor

gcc/rust/ChangeLog:

* Make-lang.in: Compile it.
* ast/rust-builtin-ast-nodes.h: Add missing methods for getting pointers.
* ast/rust-expr.h: Likewise.
* ast/rust-item.h: Likewise.
* ast/rust-path.h: Likewise.
* ast/rust-pattern.h: Likewise.
* ast/rust-type.h: Likewise.
* ast/rust-ast-pointer-visitor.cc: New file.
* ast/rust-ast-pointer-visitor.h: New file.

7 days agogccrs: Separate strip information from internal state
Pierre-Emmanuel Patry [Mon, 25 Aug 2025 15:16:24 +0000 (17:16 +0200)] 
gccrs: Separate strip information from internal state

Marking a TupleIndexExpr for strip makes it invalid for a generic visitor

gcc/rust/ChangeLog:

* ast/rust-expr.h (class TupleIndexExpr): Store strip information.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 days agogccrs: nr1.0: Remove support in borrow checker
Owen Avery [Sat, 23 Aug 2025 02:26:05 +0000 (22:26 -0400)] 
gccrs: nr1.0: Remove support in borrow checker

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder-internal.h: Remove
inclusion of "rust-name-resolver.h".
(BuilderContext::resolver): Change type to nr2.0 resolver.
(BuilderContext::BuilderContext): Change initialization of
resolver reference.
(AbstractBuilder::resolve_label): Assume name resolution 2.0 is
enabled.
(AbstractBuilder::resolve_variable): Likewise.
(AbstractBuilder::resolve_variable_or_fn): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
7 days agogccrs: nr1.0: Remove support in pattern checker
Owen Avery [Sat, 23 Aug 2025 02:57:05 +0000 (22:57 -0400)] 
gccrs: nr1.0: Remove support in pattern checker

gcc/rust/ChangeLog:

* checks/errors/rust-hir-pattern-analysis.cc: Remove inclusion
of "options.h".
(PatternChecker::PatternChecker): Change initialization of
resolver reference.
(PatternChecker::visit): Assume name resolution 2.0 is enabled.
* checks/errors/rust-hir-pattern-analysis.h: Include nr2.0
header instead of nr1.0 header.
(PatternChecker::resolver): Change type to nr2.0 resolver.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
7 days agogccrs: nr1.0: Remove support in rust-session-manager.cc
Owen Avery [Sat, 23 Aug 2025 02:12:35 +0000 (22:12 -0400)] 
gccrs: nr1.0: Remove support in rust-session-manager.cc

gcc/rust/ChangeLog:

* rust-session-manager.cc: Remove inclusion of name resolution
1.0 headers.
(Session::compile_crate): Assume name resolution 2.0 is enabled.
(Session::expansion): Likewise.
(Session::load_extern_crate): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
7 days agogccrs: nr1.0: Remove support in privacy checker
Owen Avery [Sat, 23 Aug 2025 17:29:54 +0000 (13:29 -0400)] 
gccrs: nr1.0: Remove support in privacy checker

gcc/rust/ChangeLog:

* checks/errors/privacy/rust-privacy-check.cc: Adjust includes.
(Resolver::resolve): Pass 2.0 name resolution context to
VisibilityResolver and PrivacyReporter.
* checks/errors/privacy/rust-privacy-reporter.cc
(PrivacyReporter::PrivacyReporter): Change type of resolver
parameter.
(is_child_module): Remove static function.
(PrivacyReporter::check_for_privacy_violation): Assume nr2.0 is
enabled and handle removal of is_child_module.
* checks/errors/privacy/rust-privacy-reporter.h: Adjust
includes.
(PrivacyReporter::PrivacyReporter): Change type of resolver
parameter.
(PrivacyReporter::resolver): Change member variable type.
* checks/errors/privacy/rust-visibility-resolver.cc: Adjust
includes.
(VisibilityResolver::VisibilityResolver): Change type of
resolver parameter.
(VisibilityResolver::resolve_module_path): Assume nr2.0 is
enabled.
* checks/errors/privacy/rust-visibility-resolver.h: Adjust
includes.
(VisibilityResolver::VisibilityResolver): Change type of
resolver parameter.
(VisibilityResolver::resolver): Change member variable type.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
7 days agogccrs: Refactor AST Patterns that hold multiple pattern items
Yap Zhi Heng [Sun, 24 Aug 2025 13:18:12 +0000 (21:18 +0800)] 
gccrs: Refactor AST Patterns that hold multiple pattern items

Patterns include TuplePattern, TupleStructPattern & SlicePattern. Besides making their pattern
items container class inherit from a common `PatternItems` base class just like in HIR for
better standardization, mentions of `Range` are also changed to `HasRest` or `NoRest`.

gcc/rust/ChangeLog:

* ast/rust-pattern.h:
- Add a new base abstract class `PatternItems` which are used by pattern items class
class derivatives for `TuplePattern`, `TupleStructPattern` & `SlicePattern`.
- Standardized the derived class names to have `HasRest` or `NoRest` as suffixes.
 - Values for the common `ItemType` enum is updated to `HAS_REST` or `NO_REST`.
* ast/rust-pattern.cc: Renamed the classes accordingly.
* ast/rust-ast-collector.cc: Renamed the classes accordingly.
* ast/rust-ast-collector.h: Renamed the classes accordingly.
* ast/rust-ast-full-decls.h: Renamed the classes accordingly.
* ast/rust-ast-visitor.cc: Renamed the classes accordingly.
* ast/rust-ast-visitor.h: Renamed the classes accordingly.
* ast/rust-desugar-for-loops.cc: Renamed the classes accordingly.
* ast/rust-desugar-question-mark.cc: Renamed the classes accordingly.
* expand/rust-cfg-strip.cc: Renamed the classes accordingly.
* expand/rust-cfg-strip.h: Renamed the classes accordingly.
* expand/rust-derive-clone.cc: Renamed the classes accordingly.
* expand/rust-derive-cmp-common.cc: Renamed the classes accordingly.
* expand/rust-derive-hash.cc: Renamed the classes accordingly.
* expand/rust-derive-ord.cc: Renamed the classes accordingly.
* expand/rust-derive-partial-eq.cc: Renamed the classes accordingly.
* expand/rust-derive.h: Renamed the classes accordingly.
* expand/rust-expand-visitor.cc: Renamed the classes accordingly.
* expand/rust-expand-visitor.h: Renamed the classes accordingly.
* hir/rust-ast-lower-base.cc: Renamed the classes accordingly.
* hir/rust-ast-lower-base.h: Renamed the classes accordingly.
* hir/rust-ast-lower-pattern.cc: Renamed the classes accordingly.
* hir/tree/rust-hir-pattern.h: Renamed the classes accordingly.
* parse/rust-parse-impl.h: Renamed the classes accordingly.
* resolve/rust-ast-resolve-base.cc: Renamed the classes accordingly.
* resolve/rust-ast-resolve-base.h: Renamed the classes accordingly.
* resolve/rust-ast-resolve-pattern.cc: Renamed the classes accordingly.
* util/rust-attributes.cc: Renamed the classes accordingly.
* util/rust-attributes.h: Renamed the classes accordingly.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
7 days agogccrs: Avoid std::unique_ptr<std::string> in Token
Owen Avery [Sun, 24 Aug 2025 23:37:45 +0000 (19:37 -0400)] 
gccrs: Avoid std::unique_ptr<std::string> in Token

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): Use
should_have_str instead of has_str.
* ast/rust-ast.cc (Token::as_string): Likewise.
* expand/rust-macro-builtins-offset-of.cc
(MacroBuiltin::offset_of_handler): Likewise.
* lex/rust-lex.cc (Lexer::dump_and_skip): Likewise.
* ast/rust-ast.h (class Token): Remove dead code.
(Token::has_str): Remove function.
(Token::should_have_str): New function.
* lex/rust-token.cc (Token::get_str): Remove function
definition.
* lex/rust-token.h: Include "rust-diagnostics.h".
(Token::str): Change type from std::unique_ptr<std::string> to
std::string.
(Token::Token): Adjust initialization of str member variable and
the type of the parameter used to initialize it.
(Token::make_identifier): Accept std::string instead of rvalue
reference to std::string.
(Token::make_int): Likewise.
(Token::make_float): Likewise.
(Token::make_string): Likewise.
(Token::make_byte_string): Likewise.
(Token::make_raw_string): Likewise.
(Token::make_inner_doc_comment): Likewise.
(Token::make_outer_doc_comment): Likewise.
(Token::make_lifetime): Likewise.
(Token::get_str): Add definition to function declaration.
(Token::has_str): Remove member function.
(Token::should_have_str): Handle INNER_DOC_COMMENT and
OUTER_DOC_COMMENT.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
7 days agogccrs: Eagerly expand format_args macro
Owen Avery [Fri, 22 Aug 2025 02:22:36 +0000 (22:22 -0400)] 
gccrs: Eagerly expand format_args macro

This allows format_args!(some_macro!(...), ...) to compile.

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-format-args.cc
(format_args_parse_arguments): Split format expression parsing
into...
(format_args_parse_expr): ...a new function here, while handling
eager expansion.
(MacroBuiltin::format_args_handler): Use format_args_parse_expr.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
7 days agogccrs: Remove Parser::parse_path_in_expression_pratt
Owen Avery [Thu, 21 Aug 2025 04:05:06 +0000 (00:05 -0400)] 
gccrs: Remove Parser::parse_path_in_expression_pratt

This improves our handling of PathInExpression and fixes
https://github.com/Rust-GCC/gccrs/issues/4056.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_expr): Avoid skipping
or splitting tokens.
(Parser::null_denotation): Assume initial token was not skipped
and adjust function signature to match. Use
parse_path_in_expression instead of
parse_path_in_expression_pratt and handle SCOPE_RESOLUTION.
(Parser::parse_path_in_expression_pratt): Remove function.
* parse/rust-parse.h (null_denotation): Remove initial token
parameter.
(parse_path_in_expression_pratt): Remove function.

gcc/testsuite/ChangeLog:

* rust/compile/global-path-array.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
7 days agogccrs: Add fn pointer implementation test
Pierre-Emmanuel Patry [Fri, 22 Aug 2025 10:35:58 +0000 (12:35 +0200)] 
gccrs: Add fn pointer implementation test

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 days agogccrs: Use as member function instead of static cast
Pierre-Emmanuel Patry [Fri, 22 Aug 2025 10:28:08 +0000 (12:28 +0200)] 
gccrs: Use as member function instead of static cast

gcc/rust/ChangeLog:

* typecheck/rust-coercion.cc (TypeCoercionRules::do_coercion): Use as
member function.
(TypeCoercionRules::coerce_borrowed_pointer): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 days agogccrs: Put nevertype cercion into it's own function
Pierre-Emmanuel Patry [Thu, 21 Aug 2025 14:09:28 +0000 (16:09 +0200)] 
gccrs: Put nevertype cercion into it's own function

gcc/rust/ChangeLog:

* typecheck/rust-coercion.cc (TypeCoercionRules::do_coercion):
Move nevertype coercion from here...
(TypeCoercionRules::coerce_never): ... to here.
* typecheck/rust-coercion.h: Add function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 days agogccrs: Change coerce_unsize error handling
Pierre-Emmanuel Patry [Thu, 21 Aug 2025 13:00:02 +0000 (15:00 +0200)] 
gccrs: Change coerce_unsize error handling

Error kind were split between error state and out bool parameter.

gcc/rust/ChangeLog:

* typecheck/rust-coercion.cc (TypeCoercionRules::do_coercion): Adapt
call to new return type.
(TypeCoercionRules::coerce_unsized): Change error handling.
* typecheck/rust-coercion.h: Update function prototype and add new
CoerceUnsizedError error type.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 days agogccrs: Refactor return statements
Pierre-Emmanuel Patry [Thu, 21 Aug 2025 12:58:25 +0000 (14:58 +0200)] 
gccrs: Refactor return statements

gcc/rust/ChangeLog:

* typecheck/rust-coercion.cc (TypeCoercionRules::do_coercion): Refactor
common return statement.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 days agogccrs: Remove unused variable assignments
Pierre-Emmanuel Patry [Thu, 21 Aug 2025 11:15:39 +0000 (13:15 +0200)] 
gccrs: Remove unused variable assignments

Multiple local variables were not read beyond their assignments.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Remove
unused assignment.
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_segments):
Likewise.
* typecheck/rust-tyty.cc (ParamType::handle_substitions): Likewise.
* typecheck/rust-unify.cc (UnifyRules::go): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 days agogccrs: Avoid copy when constructing TypeBoundPredicate
Pierre-Emmanuel Patry [Thu, 21 Aug 2025 10:59:19 +0000 (12:59 +0200)] 
gccrs: Avoid copy when constructing TypeBoundPredicate

Construct the TypeBoundPredicate in the vector instead of copying it.

gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait):
Construct value in place.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 days agogccrs: Remove unused copy
Pierre-Emmanuel Patry [Thu, 21 Aug 2025 10:47:05 +0000 (12:47 +0200)] 
gccrs: Remove unused copy

Variable path was copying the path but not using one of the copies.

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-stmt.cc (ResolveStmt::visit): Remove
unused copy.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 days agogccrs: Convert lookup return type to optional
Pierre-Emmanuel Patry [Tue, 19 Aug 2025 15:06:38 +0000 (17:06 +0200)] 
gccrs: Convert lookup return type to optional

Remove usage of error state (but not error state itelf) and use an
optional to convey the missing value meaning instead.

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::generate_closure_fntype):
Unwrap the optional.
* backend/rust-compile.cc: Change return type container. Adapt code to
new return type.
* typecheck/rust-hir-dot-operator.cc: Likewise.
* typecheck/rust-hir-path-probe.cc: Likewise.
* typecheck/rust-hir-type-check-implitem.cc (TypeCheckImplItemWithTrait::visit):
Likewise.
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit):
Likewise.
* typecheck/rust-tyty-bounds.cc (TypeBoundPredicate::contains_item):
Likewise.
(TypeBoundPredicate::lookup_associated_item): Likewise.
(TypeBoundPredicateItem::get_parent): Likewise.
(TypeBoundPredicate::lookup_associated_type): Likewise.
* typecheck/rust-tyty.cc (BaseType::satisfies_bound): Likewise.
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::visit): Change
return type.
* typecheck/rust-tyty.h: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 days agogccrs: Treat function pointers like pointers for cast
Pierre-Emmanuel Patry [Tue, 19 Aug 2025 13:18:27 +0000 (15:18 +0200)] 
gccrs: Treat function pointers like pointers for cast

Function pointers were not allowed to be cast to any integer like type
just like regular pointers were.

gcc/rust/ChangeLog:

* typecheck/rust-casts.cc (TypeCastRules::cast_rules): Authorize
cast from function pointer to integer like type.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 days agogccrs: Fix generic type constraints
Pierre-Emmanuel Patry [Tue, 19 Aug 2025 12:29:25 +0000 (14:29 +0200)] 
gccrs: Fix generic type constraints

Constrained symbols were not properly identified, this lead to erroneous
errors with generics.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-base.cc (walk_type_to_constrain): Walk
through all kind of type to collect ty leaves.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 days agogccrs: Add null check to reconstruct
Pierre-Emmanuel Patry [Mon, 18 Aug 2025 08:47:56 +0000 (10:47 +0200)] 
gccrs: Add null check to reconstruct

gcc/rust/ChangeLog:

* ast/rust-type.h: Prevent reconstruction on null pointers.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 days agogccrs: Remove #[simd_test] support
Owen Avery [Sat, 12 Jul 2025 03:41:53 +0000 (23:41 -0400)] 
gccrs: Remove #[simd_test] support

This attribute is a procedural macro defined by the crate
simd-test-macro, not a built-in macro.

gcc/rust/ChangeLog:

* util/rust-attribute-values.h (Attributes::SIMD_TEST): Remove
static constexpr member variable.
* util/rust-attributes.cc (__definitions): Remove entry for
SIMD_TEST.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
7 days agogccrs: Expect identifier subpatterns to be non-alt
Owen Avery [Mon, 18 Aug 2025 23:03:11 +0000 (19:03 -0400)] 
gccrs: Expect identifier subpatterns to be non-alt

Fixes https://github.com/Rust-GCC/gccrs/issues/4071.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_identifier_pattern):
Use parse_pattern_no_alt to parse identifier pattern
subpatterns.
(Parser::parse_ident_leading_pattern): Likewise.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
7 days agogccrs: Improve libformat_parser FFI
Owen Avery [Wed, 13 Aug 2025 00:02:55 +0000 (20:02 -0400)] 
gccrs: Improve libformat_parser FFI

This should remove a use-after-free as well as simplify the FFI
interface.

gcc/rust/ChangeLog:

* ast/rust-fmt.cc (Pieces::collect): Handle changes to ffi
interface.
(Pieces::~Pieces): Remove function definition.
(Pieces::Pieces): Likewise.
(Pieces::operator=): Likewise.
* ast/rust-fmt.h: Include "optional.h".
(rust_ffi_alloc): New extern "C" function declaration.
(rust_ffi_dealloc): Likewise.
(class FFIVec): New class.
(class FFIOpt): Likewise.
(RustHamster::RustHamster): New constructor accepting const
std::string reference.
(struct FormatSpec): Use FFIOpt.
(struct PieceSlice): Remove struct.
(struct RustString): Likewise.
(struct FormatArgsHandle): Likewise.
(collect_pieces): Change function signature.
(clone_pieces): Likewise.
(destroy_pieces): Remove extern "C" function declaration.
(Pieces::~Pieces): Remove function declaration.
(Pieces::operator=): Likewise.
(Pieces::get_pieces): Handle changes to class fields.
(Pieces::Pieces): Remove copy and move constructor declarations,
adjust signature of remaining constructor declaration.
(Pieces::pieces_vector): Remove member variable.
(Pieces::handle): Likewise.
(Pieces::data): Add member variable.
* expand/rust-macro-builtins-asm.cc (expand_inline_asm_strings):
Use references to avoid copying.

libgrust/ChangeLog:

* libformat_parser/src/lib.rs (struct FFIVec): New.
(trait StringLeakExt): Remove.
(struct FFIOpt): New.
(trait IntoFFI): Adjust implementation for Option.
(struct RustHamster): Add lifetime and adjust conversion to and
from &str.
(enum Piece): Adjust definition to handle changes to
RustHamster.
(struct Argument): Likewise.
(struct FormatSpec): Use FFIOpt and RustHamster.
(enum Position): Use RustHamster.
(enum Count): Likewise.
(struct PieceSlice): Replace with...
(typedef PieceVec): ...this.
(struct RustString): Remove.
(struct FormatArgsHandle): Likewise.
(fn collect_pieces): Adjust signature, greatly simplifying
implementation.
(fn clone_pieces): Likewise.
(fn destroy_pieces): Remove.
(trait LayoutExt): New.
(fn rust_ffi_alloc): New.
(fn rust_ffi_dealloc): New.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
7 days agogccrs: fix ICE in convert_tree for tuple destructuring with ref
lishin [Sun, 10 Aug 2025 21:21:59 +0000 (22:21 +0100)] 
gccrs: fix ICE in convert_tree for tuple destructuring with ref

gcc/rust/ChangeLog:

* backend/rust-compile-pattern.cc (CompilePatternLet::visit):
Handle tuple destructuring containing by-ref.

gcc/testsuite/ChangeLog:

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

Signed-off-by: lishin <lishin1008@gmail.com>
7 days agogccrs: Implement rest pattern support for slice patterns
Yap Zhi Heng [Mon, 11 Aug 2025 13:51:11 +0000 (21:51 +0800)] 
gccrs: Implement rest pattern support for slice patterns

This patch adds support for compiling rest patterns present in slice patterns
(e.g. `[1, .., 2]`). 006t.original output from compiling match-slicepattern-slice-2.rs
for first 2 match arms:

...
  if (RUSTTMP.3.len > 1 && *NON_LVALUE_EXPR <RUSTTMP.3.data> == 1)
    {
      {
                struct () RUSTTMP.4;
        {
                    struct () RUSTTMP.5;
          {
           ..
          }
        }
        goto <D.139>;
      }
    }
  if ((RUSTTMP.3.len > 1 && *NON_LVALUE_EXPR <RUSTTMP.3.data> == 0) && *(RUSTTMP.3.data + (sizetype) (RUSTTMP.3.len + 18446744073709551615) * 4) == 0)
    {
      {
                struct () RUSTTMP.6;
        {
                    struct () RUSTTMP.7;
          {
          }
        }
        goto <D.139>;
      }
    }
...

gcc/rust/ChangeLog:

* hir/tree/rust-hir-pattern.h: Add SlicePatternItems base class and
SlicePatternItemsNoRest/SlicePatternItemsHasRest derived classes.
Update SlicePattern to hold patterns using the new classes.
* hir/tree/rust-hir-full-decls.h: Declare new classes.
* hir/tree/rust-hir.cc: Add visits for new classes.
* hir/tree/rust-hir-visitor.h: Add visits for new classes.
* hir/tree/rust-hir-visitor.cc: Implement visits for new classes.
* hir/rust-hir-dump.h: Add visits for new classes.
* hir/rust-hir-dump.cc: Implement Dump::visit for new classes.
* hir/rust-ast-lower-base.h: Declare new lower_slice_pattern_no_rest/has_rest
methods.
* hir/rust-ast-lower-base.cc: Implement lower_slice_pattern_no_rest/has_rest
to lower AST slice pattern items to HIR.
* hir/rust-ast-lower-pattern.cc: Update ASTLoweringPattern::visit for
SlicePattern to use new lowering methods.
* backend/rust-compile-pattern.cc: Update CompilePatternCheckExpr::visit
and CompilePatternBindings::visit for SlicePattern to handle
SlicePatternItemsNoRest/HasRest.
* checks/errors/borrowck/rust-bir-builder-pattern.cc: Update
PatternBindingBuilder::visit for SlicePattern to iterate members correctly.
* checks/errors/borrowck/rust-bir-builder-struct.h: Add visits for new
classes.
* checks/errors/borrowck/rust-function-collector.h: Add visits for new
classes.
* checks/errors/rust-const-checker.h: Add visits for new classes.
* checks/errors/rust-const-checker.cc: Implement empty visits for new classes.
* checks/errors/rust-hir-pattern-analysis.h: Add visits for new classes.
* checks/errors/rust-hir-pattern-analysis.cc: Implement empty visits for new
classes.
* checks/errors/rust-unsafe-checker.h: Add visits for new classes.
* checks/errors/rust-unsafe-checker.cc: Implement empty visits for new
classes.
* typecheck/rust-hir-type-check-pattern.cc: Update TypeCheckPattern::visit
for SlicePattern to handle SlicePatternItemsNoRest/HasRest.

gcc/testsuite/ChangeLog:

* rust/compile/slice_rest_pattern.rs: Removed -fsyntax-only.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
7 days agogccrs: Collect lang items after expansion
Owen Avery [Thu, 10 Jul 2025 22:57:12 +0000 (18:57 -0400)] 
gccrs: Collect lang items after expansion

This allows macros to create lang items.

gcc/rust/ChangeLog:

* rust-session-manager.cc (Session::compile_crate): Collect lang
items after expansion.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
7 days agogccrs: Replace old read-only checker with new implementation.
Ryutaro Okada [Tue, 12 Aug 2025 05:17:09 +0000 (22:17 -0700)] 
gccrs: Replace old read-only checker with new implementation.

gcc/rust/ChangeLog:

* Make-lang.in: Replace old read-only checker with new implementation.
* checks/errors/rust-readonly-check.cc (ReadonlyChecker::ReadonlyChecker):
Replace old read-only checker with new implementation.
* checks/errors/rust-readonly-check.h:
Replace old read-only checker with new implementation.
* rust-session-manager.cc (Session::compile_crate):
Switch to new read-only checker.
* checks/errors/rust-readonly-check2.cc: Removed.
* checks/errors/rust-readonly-check2.h: Removed.

Signed-off-by: Ryutaro Okada <1015ryu88@gmail.com>
7 days agogccrs: Read-only check if the variable is mutable type.
Ryutaro Okada [Tue, 12 Aug 2025 05:01:08 +0000 (22:01 -0700)] 
gccrs: Read-only check if the variable is mutable type.

gcc/rust/ChangeLog:

* checks/errors/rust-readonly-check2.cc (ReadonlyChecker::check_variable):
Read-only check if the variable is mutable type.
(ReadonlyChecker::is_mutable_type): Read-only check if the variable is mutable type.
* checks/errors/rust-readonly-check2.h: Read-only check if the variable is mutable type.

Signed-off-by: Ryutaro Okada <1015ryu88@gmail.com>
7 days agogccrs: Add IdentifierPattern subpattern support for ClosureParamInfer
Yap Zhi Heng [Tue, 12 Aug 2025 14:02:08 +0000 (22:02 +0800)] 
gccrs: Add IdentifierPattern subpattern support for ClosureParamInfer

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-pattern.cc(ClosureParamInfer(IdentifierPattern)):
Resolve subpattern types for IdentifierPattern.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
7 days agogccrs: Implement let statement support for IdentifierPattern's subpatterns
Yap Zhi Heng [Tue, 12 Aug 2025 13:58:18 +0000 (21:58 +0800)] 
gccrs: Implement let statement support for IdentifierPattern's subpatterns

Trimmed GIMPLE code gen for let-identifierpattern-subpattern.rs

...
      RUSTTMP.1.__0 = 0;
      RUSTTMP.1.__1 = 2;
      RUSTTMP.1.__2 = 3;
      bar = RUSTTMP.1.__0;
      RUSTTMP.2 = RUSTTMP.1.__1;
      RUSTTMP.3 = RUSTTMP.1.__2;
      foo.__0 = 0;
      foo.__1 = 2;
      foo.__2 = 3;
      ret = 1;
      RUSTTMP.5 = foo;
      _1 = RUSTTMP.5.__0;
      _2 = _1 == 0;
      _3 = RUSTTMP.5.__1;
      _4 = _3 == 2;
      _5 = _2 & _4;
      _6 = RUSTTMP.5.__2;
      _7 = _6 == 3;
      _8 = _5 & _7;
      if (_8 != 0) goto <D.143>; else goto <D.144>;
      <D.143>:
      {
        {
          ret = bar;
        }
        goto <D.137>;
      }
...

gcc/rust/ChangeLog:

* backend/rust-compile-pattern.cc(CompilePatternLet::visit(IdentifierPattern)):
Add support for subpatterns.
* backend/rust-compile-var-decl.h(CompileVarDecl::visit(IdentifierPattern)):
Implement compilation for subpatterns.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
7 days agogccrs: fix ICE by skipping invalid (non-FNDEF) candidates
lishin [Wed, 13 Aug 2025 18:16:52 +0000 (19:16 +0100)] 
gccrs: fix ICE by skipping invalid (non-FNDEF) candidates

gcc/rust/ChangeLog:

* typecheck/rust-hir-dot-operator.cc (MethodResolver::Select):
Skip asserts by checking candidate type and using early-continue.
(MethodResolver::try_select_predicate_candidates):
Skip invalid candidates.

gcc/testsuite/ChangeLog:

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

Signed-off-by: lishin <lishin1008@gmail.com>
7 days agogccrs: fix ICE for empty enum variant
lishin [Thu, 14 Aug 2025 15:23:50 +0000 (16:23 +0100)] 
gccrs: fix ICE for empty enum variant

gcc/rust/ChangeLog:

* rust-gcc.cc (constructor_expression):
Ensure vec_alloc reserves at least one element.

gcc/testsuite/ChangeLog:

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

Signed-off-by: lishin <lishin1008@gmail.com>
7 days agogccrs: Reject empty cfg_attr
Pierre-Emmanuel Patry [Wed, 13 Aug 2025 15:20:40 +0000 (17:20 +0200)] 
gccrs: Reject empty cfg_attr

gcc/rust/ChangeLog:

* ast/rust-ast.cc (Attribute::check_cfg_predicate): Emit an error with
empty cfg_attr input.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 days agogccrs: Improve handling of non-final path segments
Owen Avery [Mon, 11 Aug 2025 17:44:25 +0000 (13:44 -0400)] 
gccrs: Improve handling of non-final path segments

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.hxx
(ForeverStack::resolve_segments): Remove usage of optional
reference, allow non-final path segments to resolve to types
even outside the type namespace, and allow resolution to
progress past non-final path segments which resolve to modules.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
7 days agogccrs: nr2.0: Fix ChangeLog entry
Owen Avery [Thu, 31 Jul 2025 21:23:52 +0000 (17:23 -0400)] 
gccrs: nr2.0: Fix ChangeLog entry

"options.txt" was supposed to be "options.h".

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
7 days agogccrs: Fix Self macro invocation parsing failure
Pierre-Emmanuel Patry [Tue, 12 Aug 2025 15:40:27 +0000 (17:40 +0200)] 
gccrs: Fix Self macro invocation parsing failure

No check was performed and the value was assumed non null.
Path conversion returned an empty path for "Self" due to a hack in
generics Self injection that prevented any "Self!" macro from beeing
recognized correctly.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_stmt_or_expr): Add null check
on parse_macro_invocation_partial call.
* ast/rust-path.cc (Path::convert_to_simple_path): Do not exclude
capitalized "Self".

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 days agogccrs: expand: Add handling for macro expansion in pattern context
Arthur Cohen [Wed, 13 Aug 2025 09:39:58 +0000 (11:39 +0200)] 
gccrs: expand: Add handling for macro expansion in pattern context

gcc/rust/ChangeLog:

* ast/rust-ast-fragment.cc (Fragment::is_pattern_fragment): New function.
(Fragment::take_pattern_fragment): Likewise.
(Fragment::assert_single_fragment): Likewise.
* ast/rust-ast-fragment.h: Declare them.
* ast/rust-ast.cc (SingleASTNode::SingleASTNode): Add new constructor for pattern
single AST nodes.
(SingleASTNode::operator=): Handle patterns.
(SingleASTNode::accept_vis): Likewise.
(SingleASTNode::is_error): Likewise.
(SingleASTNode::as_string): Likewise.
* ast/rust-ast.h: Add get_pattern_ptr() functions.
* ast/rust-expr.h: Likewise.
* ast/rust-item.h: Likewise.
* ast/rust-pattern.h: Likewise.
* ast/rust-stmt.h: Likewise.
* expand/rust-expand-visitor.cc (derive_item): Use new API enum values.
(expand_item_attribute): Likewise.
(expand_stmt_attribute): Likewise.
(ExpandVisitor::maybe_expand_pattern): New function.
(ExpandVisitor::expand_closure_params): Handle patterns.
(ExpandVisitor::visit): Add new visitors for patterns and missed exprs.
* expand/rust-expand-visitor.h: Declare them.
* expand/rust-macro-expand.cc (transcribe_pattern): New function.
(transcribe_context): Call it.
* expand/rust-macro-expand.h (struct MacroExpander): New Context type.

gcc/testsuite/ChangeLog:

* rust/compile/issue-3726.rs: New test.
* rust/compile/issue-3898.rs: New test.

7 days agogccrs: ast: Cleanup SingleASTNode::NodeType
Arthur Cohen [Tue, 12 Aug 2025 15:04:03 +0000 (17:04 +0200)] 
gccrs: ast: Cleanup SingleASTNode::NodeType

gcc/rust/ChangeLog:

* ast/rust-ast.h: Change NodeType to enum class Kind.
* ast/rust-ast-fragment.cc: Use new names.
* ast/rust-ast-fragment.h: Likewise.
* ast/rust-ast.cc (SingleASTNode::SingleASTNode): Likewise.

7 days agogccrs: Detect failure to match an ident metavariable
Owen Avery [Sun, 10 Aug 2025 15:56:54 +0000 (11:56 -0400)] 
gccrs: Detect failure to match an ident metavariable

Fixes https://github.com/Rust-GCC/gccrs/issues/4054

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h
(Parser::parse_identifier_or_keyword_token): Record error on
failure.

gcc/testsuite/ChangeLog:

* rust/compile/macros/mbe/macro-issue4054.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
7 days agogccrs: Add name resolution processing for discriminant values
Ryutaro Okada [Fri, 8 Aug 2025 05:51:00 +0000 (22:51 -0700)] 
gccrs: Add name resolution processing for discriminant values

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-stmt.h:
Add name resolution processing for discriminant values.
gcc/testsuite/ChangeLog:

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

Signed-off-by: Ryutaro Okada <1015ryu88@gmail.com>
7 days agogccrs: fix error number
Ryutaro Okada [Tue, 11 Mar 2025 10:59:17 +0000 (19:59 +0900)] 
gccrs: fix error number

gcc/rust/ChangeLog:

* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): fix error code

Signed-off-by: Ryutaro Okada <1015ryu88@gmail.com>
7 days agogccrs: CfgStrip AST nodes marked with #[test]
Owen Avery [Tue, 12 Aug 2025 02:06:02 +0000 (22:06 -0400)] 
gccrs: CfgStrip AST nodes marked with #[test]

gcc/rust/ChangeLog:

* expand/rust-cfg-strip.cc: Include "rust-macro-expand.h".
(fails_cfg): Rename to...
(CfgStrip::fails_cfg): ...here and handle test attributes.
(fails_cfg_with_expand): Rename to...
(CfgStrip::fails_cfg_with_expand): ...here and handle test
attributes.
* expand/rust-cfg-strip.h (struct ExpansionCfg): Forward
declare.
(CfgStrip::fails_cfg): New member function.
(CfgStrip::fails_cfg_with_expand): Likewise.
(CfgStrip::CfgStrip): Accept reference to ExpansionCfg.
(CfgStrip::expansion_cfg): New member variable.
* rust-session-manager.cc (Session::expansion): Pass
ExpansionCfg instance to CfgStrip constructor.

gcc/testsuite/ChangeLog:

* rust/compile/cfg-test.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
7 days agogccrs: Add test for multiple wildcard use declaration.
Pierre-Emmanuel Patry [Tue, 12 Aug 2025 11:53:13 +0000 (13:53 +0200)] 
gccrs: Add test for multiple wildcard use declaration.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 days agogccrs: Remove abort on wildcard patterns
Pierre-Emmanuel Patry [Mon, 11 Aug 2025 21:06:12 +0000 (23:06 +0200)] 
gccrs: Remove abort on wildcard patterns

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc (Early::finalize_rebind_import):
Do not abort on wildcard patterns.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 days agogccrs: Emit an error message on unsupported llvm_asm
Pierre-Emmanuel Patry [Mon, 11 Aug 2025 14:52:32 +0000 (16:52 +0200)] 
gccrs: Emit an error message on unsupported llvm_asm

llvm_asm was never meant to be completely supported since it has been
replaced with the asm macro but we still need it to compile some parts
of libcore, previously the compiler was aborting when an unsupported
llvm_asm construct was found.

gcc/rust/ChangeLog:

* ast/rust-expr.h: Add const getters to llvm members.
* hir/rust-ast-lower-expr.cc (check_llvm_asm_support): Check llvm_asm
usage validity.
(ASTLoweringExpr::visit): Emit an error message instead of aborting.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 days agogccrs: Fix infinite loop on inline assembly clobbers
Pierre-Emmanuel Patry [Mon, 11 Aug 2025 14:22:32 +0000 (16:22 +0200)] 
gccrs: Fix infinite loop on inline assembly clobbers

Fix Rust-GCC/gccrs#4046 where the inline llvm_asm macro parser did not
expect a comma.

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-asm.cc (parse_llvm_clobbers): Expect a
comma between clobbers.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 days agogccrs: Refactor inline assembly constructor
Pierre-Emmanuel Patry [Mon, 11 Aug 2025 13:58:53 +0000 (15:58 +0200)] 
gccrs: Refactor inline assembly constructor

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-asm.cc (parse_asm): Simplify expression.
(parse_llvm_asm): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 days agogccrs: Add checks to ExpandVisitor
Owen Avery [Sat, 9 Aug 2025 22:33:58 +0000 (18:33 -0400)] 
gccrs: Add checks to ExpandVisitor

This should help detect issues like
https://github.com/Rust-GCC/gccrs/issues/3444.

gcc/rust/ChangeLog:

* ast/rust-ast.h (Stmt::get_node_id): Make virtual.
(Type::get_node_id): Likewise.
(AssociatedItem::get_node_id): New virtual member function.
* ast/rust-expr.h (TypeCastExpr::get_casted_expr_ptr): New
member function.
(TypeCastExpr::get_type_to_cast_to_ptr): Likewise.
(ClosureExprInner::get_definition_expr_ptr): Likewise.
* ast/rust-item.h (TypeAlias::get_node_id): New member function
to override AssociatedItem::get_node_id.
(ConstantItem::get_node_id): Likewise.
* expand/rust-expand-visitor.cc
(ExpandVisitor::maybe_expand_expr): Adjust
macro_invoc_expect_id.
(ExpandVisitor::maybe_expand_type): Likewise and add an overload
for std::unique_ptr<TypeNoBounds>.
(ExpandVisitor::visit): Check macro_invoc_expect_id and
generally improve visitors so that the testsuite will still
pass.
* expand/rust-expand-visitor.h (ExpandVisitor::ExpandVisitor):
Initialize member variable macro_invoc_expect_id.
(ExpandVisitor::maybe_expand_type): Add an overload for
std::unique_ptr<TypeNoBounds>.
(ExpandVisitor::expand_macro_children): Adjust
macro_invoc_expect_id.
(ExpandVisitor::visit): Add an overload for TypeCastExpr.
(ExpandVisitor::macro_invoc_expect_id): New member variable.

gcc/testsuite/ChangeLog:

* rust/compile/macros/mbe/macro49.rs: Add missing lang items.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
7 days agogccrs: Fix ICE on exclusive_range_pattern lowering
lishin [Fri, 8 Aug 2025 21:35:20 +0000 (22:35 +0100)] 
gccrs: Fix ICE on exclusive_range_pattern lowering

gcc/rust/ChangeLog:

* backend/rust-compile-pattern.cc (CompilePatternCheckExpr::visit):
Check upper compare operator.
* hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::visit):
Handle lowering of exclusive range pattern.
* hir/tree/rust-hir-pattern.h (class RangePattern):
Add support for exclusive ranges in HIR representation.

gcc/testsuite/ChangeLog:

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

Signed-off-by: lishin <lishin1008@gmail.com>
7 days agogccrs: Exclude some inline assembly test
Pierre-Emmanuel Patry [Fri, 8 Aug 2025 16:50:58 +0000 (18:50 +0200)] 
gccrs: Exclude some inline assembly test

Those tests contains inline assembly which is architecture dependent.

gcc/testsuite/ChangeLog:

* rust/execute/inline_asm_inout_ident.rs: Add arch filter on test.
* rust/execute/inline_asm_inout_var.rs: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 days agogccrs: Handle attributes in expression macros
Owen Avery [Sat, 12 Jul 2025 03:35:53 +0000 (23:35 -0400)] 
gccrs: Handle attributes in expression macros

gcc/rust/ChangeLog:

* expand/rust-macro-expand.cc (transcribe_expression): Parse any
outer attributes before parsing an expression.
* parse/rust-parse.h (Parser::parse_outer_attributes): Make
public.

gcc/testsuite/ChangeLog:

* rust/compile/attr-macro.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
7 days agogccrs: Improve vector usages and avoid copies.
Pierre-Emmanuel Patry [Wed, 6 Aug 2025 15:35:03 +0000 (17:35 +0200)] 
gccrs: Improve vector usages and avoid copies.

Several place built an object before copying it in a vector. This commit
favorise in place construction and use readily available vector size to
reserve memory beforehand.

gcc/rust/ChangeLog:

* ast/rust-expr.h (struct TupleClobber): Add constructor.
* backend/rust-compile-context.h (struct fncontext): Likewise.
* typecheck/rust-hir-dot-operator.h: Likewise.
* typecheck/rust-tyty-variance-analysis-private.h (struct Constraint):
Likewise.
* typecheck/rust-unify.h: Likewise.
* ast/rust-ast-builder.cc (Builder::new_lifetime_param): Add memory
reservation and construct in place.
(Builder::new_generic_args): Likewise.
* ast/rust-ast-collector.cc (TokenCollector::newline): Likewise.
(TokenCollector::indentation): Likewise.
(TokenCollector::comment): Likewise.
* ast/rust-desugar-apit.cc: Likewise.
* ast/rust-path.cc (Path::convert_to_simple_path): Likewise.
(TypePath::as_simple_path): Likewise.
* ast/rust-path.h: Likewise.
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Likewise.
(TyTyResolveCompile::create_dyn_obj_record): Likewise.
* checks/errors/rust-hir-pattern-analysis.cc (Matrix::specialize):
Likewise.
(WitnessMatrix::apply_constructor): Likewise.
(check_match_usefulness): Likewise.
* expand/rust-derive-clone.cc (DeriveClone::clone_fn): Likewise.
* expand/rust-macro-builtins-asm.cc (parse_clobber_abi): Likewise.
* expand/rust-macro-expand.cc (MacroExpander::parse_proc_macro_output):
Likewise.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_generic_args):
Likewise.
(ASTLoweringBase::lower_extern_block): Likewise.
* hir/rust-ast-lower-enumitem.h: Likewise.
* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise.
* hir/rust-ast-lower-extern.h: Likewise.
* hir/rust-ast-lower-implitem.cc (ASTLowerImplItem::visit): Likewise.
(ASTLowerTraitItem::visit): Likewise.
* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Likewise.
* hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::visit): Likewise.
* hir/rust-ast-lower.cc (ASTLowering::go): Likewise.
(ASTLoweringBlock::visit): Likewise.
(ASTLoweringIfLetBlock::desugar_iflet): Likewise.
(ASTLoweringExprWithBlock::visit): Likewise.
(ASTLowerPathInExpression::visit): Likewise.
(ASTLowerQualPathInExpression::visit): Likewise.
* hir/tree/rust-hir.cc (PathPattern::convert_to_simple_path): Likewise.
(TypePath::as_simple_path): Likewise.
* metadata/rust-export-metadata.cc (ExportContext::emit_function):
Likewise.
* parse/rust-parse-impl.h (Parser::parse_decl_macro_def): Likewise.
(Parser::parse_lifetime_params): Likewise.
* resolve/rust-ast-resolve-item.cc (ResolveTraitItems::visit):
Likewise.
(ResolveItem::visit): Likewise.
(flatten_list): Likewise.
* resolve/rust-ast-resolve-pattern.cc (PatternDeclaration::visit):
Likewise.
* typecheck/rust-autoderef.cc (AutoderefCycle::try_autoderefed):
Likewise.
* typecheck/rust-coercion.cc (TypeCoercionRules::coerce_unsized):
Likewise.
* typecheck/rust-hir-dot-operator.cc: Likewise.
* typecheck/rust-hir-path-probe.cc: Likewise.
* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait):
Likewise.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
Likewise.
(TypeCheckExpr::resolve_fn_trait_call): Likewise.
* typecheck/rust-hir-type-check-implitem.cc (TypeCheckTopLevelExternItem::visit):
Likewise.
(TypeCheckImplItem::visit): Likewise.
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit):
Likewise.
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
Likewise.
* typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::resolve):
Likewise.
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit):
Likewise.
* typecheck/rust-hir-type-check.cc (TraitItemReference::get_type_from_fn):
Likewise.
* typecheck/rust-typecheck-context.cc (TypeCheckContext::push_return_type):
Likewise.
(TypeCheckContext::insert_associated_impl_mapping): Likewise.
* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::scan): Likewise.
(TypeBoundsProbe::add_trait_bound): Likewise.
(TypeBoundPredicate::operator=): Likewise.
(TypeBoundPredicateItem::get_tyty_for_receiver): Likewise.
(TypeBoundPredicate::get_associated_type_items): Likewise.
* typecheck/rust-tyty-call.cc (TypeCheckMethodCallExpr::go): Likewise.
* typecheck/rust-tyty-subst.cc (SubstitutionRef::clone_substs):
Likewise.
(SubstitutionRef::infer_substitions): Likewise.
(SubstitutionRef::are_mappings_bound): Likewise.
* typecheck/rust-tyty-variance-analysis.cc (GenericTyPerCrateCtx::query_generic_variance):
Likewise.
(GenericTyVisitorCtx::add_constraint): Likewise.
* typecheck/rust-tyty.cc (FnPtr::clone): Likewise.
(DynamicObjectType::get_object_items): Likewise.
* typecheck/rust-unify.cc (UnifyRules::Resolve): Likewise.
(UnifyRules::go): Likewise.
(UnifyRules::expect_tuple): Likewise.
* util/rust-canonical-path.h: Likewise.
* util/rust-token-converter.cc (convert): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 days agogccrs: Add missing direct include
Pierre-Emmanuel Patry [Wed, 6 Aug 2025 08:35:06 +0000 (10:35 +0200)] 
gccrs: Add missing direct include

gcc/rust/ChangeLog:

* util/bi-map.h: Add include directive for required declarations.
* util/fnv-hash.h: Likewise.
* util/rust-dump.h: Likewise.
* util/rust-inline-visitor.h: Likewise.
* util/rust-unwrap-segment.h: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 days agogccrs: Add header guards
Pierre-Emmanuel Patry [Wed, 6 Aug 2025 09:17:21 +0000 (11:17 +0200)] 
gccrs: Add header guards

gcc/rust/ChangeLog:

* util/rust-lang-item.h (RUST_LANG_ITEM_H): Add header guards.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 days agogccrs: Fix friendly class to friendly struct qualification
Pierre-Emmanuel Patry [Wed, 6 Aug 2025 08:18:56 +0000 (10:18 +0200)] 
gccrs: Fix friendly class to friendly struct qualification

gcc/rust/ChangeLog:

* parse/rust-parse.h: Change class to struct for friend qualification.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 days agogccrs: Remove cyclic inclusion and unused headers.
Pierre-Emmanuel Patry [Tue, 5 Aug 2025 16:41:18 +0000 (18:41 +0200)] 
gccrs: Remove cyclic inclusion and unused headers.

gcc/rust/ChangeLog:

* checks/lints/rust-lint-marklive-base.h (RUST_HIR_LIVENESS_BASE):
Remove header includes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 days agogccrs: Prevent copy from vector implementation
Pierre-Emmanuel Patry [Tue, 5 Aug 2025 15:58:26 +0000 (17:58 +0200)] 
gccrs: Prevent copy from vector implementation

gcc/rust/ChangeLog:

* ast/rust-cond-compilation.h: Delete copy constructor for
ConfigurationAll and ConfigurationAny.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 days agogccrs: Fix variadic member flag value in constructor
Pierre-Emmanuel Patry [Tue, 5 Aug 2025 15:09:08 +0000 (17:09 +0200)] 
gccrs: Fix variadic member flag value in constructor

gcc/rust/ChangeLog:

* ast/rust-type.h: Update member instead of parameter

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 days agogccrs: Move vector of unique_ptr
Pierre-Emmanuel Patry [Tue, 5 Aug 2025 13:19:32 +0000 (15:19 +0200)] 
gccrs: Move vector of unique_ptr

gcc/rust/ChangeLog:

* ast/rust-cond-compilation.h: Move vector instead of passing it by
value.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 days agogccrs: Avoid transitive declaration
Pierre-Emmanuel Patry [Tue, 5 Aug 2025 09:49:21 +0000 (11:49 +0200)] 
gccrs: Avoid transitive declaration

gcc/rust/ChangeLog:

* ast/rust-pattern.h: Include header directly.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 days agogccrs: Copy cfg_attrs instead setting it to itself
Pierre-Emmanuel Patry [Tue, 5 Aug 2025 09:45:00 +0000 (11:45 +0200)] 
gccrs: Copy cfg_attrs instead setting it to itself

CfgAttribute copy constructor did not copy cfg_attrs properly.

gcc/rust/ChangeLog:

* ast/rust-cond-compilation.h: Copy cfg_attrs

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 days agogccrs: Add missing header inclusion
Pierre-Emmanuel Patry [Tue, 5 Aug 2025 09:43:25 +0000 (11:43 +0200)] 
gccrs: Add missing header inclusion

Header relied on transitive header inclusion.

gcc/rust/ChangeLog:

* ast/rust-ast-formatting.h (RUST_AST_FORMATTING_H): Include required
headers directly.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 days agogccrs: Improve handling of AttrInputLiteral
Owen Avery [Tue, 5 Aug 2025 20:44:02 +0000 (16:44 -0400)] 
gccrs: Improve handling of AttrInputLiteral

Also adjusts a few error messages to be more in line with rustc (and
more amenable to extract_string_literal usage).

gcc/rust/ChangeLog:

* util/rust-attributes.cc (Attributes::extract_string_literal):
New function definition.
* util/rust-attributes.h (Attributes::extract_string_literal):
New function declaration.
* ast/rust-collect-lang-items.cc (get_lang_item_attr): Use
extract_string_literal.
* backend/rust-compile-base.cc: Include "rust-attributes.h".
(HIRCompileBase::handle_link_section_attribute_on_fndecl):
Use extract_string_literal.
(HIRCompileBase::handle_must_use_attribute_on_fndecl): Likewise.
* hir/rust-ast-lower-base.cc
(ASTLoweringBase::handle_lang_item_attribute): Likewise.
* rust-session-manager.cc (Session::handle_crate_name):
Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
7 days agogccrs: Refactor HIR::PatternItem class and its derivatives
Yap Zhi Heng [Sat, 2 Aug 2025 09:03:53 +0000 (17:03 +0800)] 
gccrs: Refactor HIR::PatternItem class and its derivatives

Renames HIR::TupleItems to PatternItems for better generalization because it will be reused for
SlicePattern in the future. Enum values MULTIPLE/RANGED are renamed to NO_REST/HAS_REST
to reduce misleadingness as it is completely different and separate from the ranged values  `..`
representation. This results in renaming of all related classes and updates to all code that
references them.

gcc/rust/ChangeLog:

* hir/tree/rust-hir-pattern.h:
- Rename TupleItems to PatternItems.
- Rename TuplePatternItemsMultiple/Ranged & TupleStructItemsRange/NoRange to
TuplePatternItemsNoRest/HasRest and TupleStructItemsNoRest/HasRest.
- Update enum values to NO_REST/HAS_REST.
- Rename clone_tuple_items_impl to clone_pattern_items_impl.
* hir/tree/rust-hir-full-decls.h: Renamed the classes accordingly.
* hir/tree/rust-hir-visitor.h: Renamed the classes accordingly.
* hir/tree/rust-hir-visitor.cc: Renamed the classes accordingly.
* hir/rust-hir-dump.h: Renamed the classes accordingly.
* hir/rust-hir-dump.cc: Renamed the classes accordingly.
* hir/tree/rust-hir.cc: Renamed the classes accordingly.
* hir/rust-ast-lower-base.cc: Renamed the classes accordingly.
* hir/rust-ast-lower-pattern.cc: Renamed the classes accordingly.
* backend/rust-compile-pattern.cc: Renamed the classes accordingly.
* backend/rust-compile-var-decl.h: Renamed the classes accordingly.
* checks/errors/borrowck/rust-bir-builder-pattern.cc: Renamed the classes accordingly.
* checks/errors/borrowck/rust-bir-builder-struct.h: Renamed the classes accordingly.
* checks/errors/borrowck/rust-function-collector.h: Renamed the classes accordingly.
* checks/errors/rust-const-checker.cc: Renamed the classes accordingly.
* checks/errors/rust-const-checker.h: Renamed the classes accordingly.
* checks/errors/rust-hir-pattern-analysis.cc: Renamed the classes accordingly.
* checks/errors/rust-hir-pattern-analysis.h: Renamed the classes accordingly.
* checks/errors/rust-unsafe-checker.cc: Renamed the classes accordingly.
* checks/errors/rust-unsafe-checker.h: Renamed the classes accordingly.
* checks/errors/rust-readonly-check2.cc: Renamed the classes accordingly.
* typecheck/rust-hir-type-check-pattern.cc: Update references to renamed classes and enum
values.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
7 days agogccrs: Explicitly use an empty vector for structural eq
Pierre-Emmanuel Patry [Tue, 5 Aug 2025 08:55:33 +0000 (10:55 +0200)] 
gccrs: Explicitly use an empty vector for structural eq

Previous code was technically valid since the moved from vector was
empty but explicitly setting it empty with it's own name will help.

gcc/rust/ChangeLog:

* expand/rust-derive-eq.cc: Use empty vector explicitly.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 days agodwarf: handle repeated decl with different btf_decl_tags [PR122248]
David Faust [Tue, 28 Oct 2025 18:13:25 +0000 (11:13 -0700)] 
dwarf: handle repeated decl with different btf_decl_tags [PR122248]

The check in gen_btf_tag_dies which asserted that if the target DIE
already had an annotation then it must be the same as the one we are
attempting to add was too strict.  It is valid for multiple declarations
of the same object to appear with different decl_tags, in which case the
tags from each are accumulated in DECL_ATTRIBUTES.  The existing
annotation may not be the same as the one being added, since new tags
will be added to the head of the chain.

The proper behavior is to always replace any existing AT_GNU_annotation
to refer to the chain of annotations we have just constructed, whether
the head of that chain is the same or not.

PR debug/122248

gcc/

* dwarf2out.cc (gen_btf_tag_dies): Always replace an existing
AT_GNU_annotation on the target die.

gcc/testsuite/

* gcc.dg/debug/dwarf2/dwarf-btf-decl-tag-4.c: New.
* gcc.dg/debug/dwarf2/dwarf-btf-decl-tag-5.c: New.
* gcc.dg/debug/dwarf2/dwarf-btf-decl-tag-6.c: New.

7 days agobtf: do not prune at typedefs
David Faust [Wed, 29 Oct 2025 22:21:16 +0000 (15:21 -0700)] 
btf: do not prune at typedefs

The existing BTF pruning logic meant that an anonymous struct or
union type hidden behind a typedef, such as in the common construct:

  typedef struct { ... } my_struct_type;

could be pruned if 'my_struct_type' was only ever referenced via pointer
members in other structs/unions types used in the program.

The result of pruning is to skip emitting full type information for
a struct or union type by replacing it with a BTF_KIND_FWD, indicating
that it exists but its definition is omitted.  Any types used only by
pruned types are fully omitted from the generated BTF.

In cases like this where the struct/union type is anonymous, the result
is an anonymous BTF_KIND_FWD, which is useless.  The presence of such a
type record rightly causes complaints from BTF loaders.  Worse, since
the TYPEDEF for 'my_struct_type' itself may _not_ be pruned, its type
information will be incomplete.

Change the BTF pruner so that we never consider pruning at a typedef,
and always either keep or discard both the type and the typedef.

gcc/

* btfout.cc (btf_add_used_type_1): Do not consider creating
fixups at typedefs.

gcc/testsuite/

* gcc.dg/debug/btf/btf-prune-4.c: New.

7 days agoRemove parentheses in dg-scan directive
Eric Botcazou [Thu, 30 Oct 2025 15:59:27 +0000 (16:59 +0100)] 
Remove parentheses in dg-scan directive

gcc/testsuite/
* gcc.dg/cpp/escape-3.i: Remove parentheses in dg-scan directive.

7 days agolto: Stream out partitioned toplevel assembly
Michal Jires [Mon, 25 Aug 2025 16:30:07 +0000 (18:30 +0200)] 
lto: Stream out partitioned toplevel assembly

Toplevel assembly is now streamed as partitioned instead of into the
first partition.

gcc/ChangeLog:

* lto-cgraph.cc (output_symtab): Remove asm_nodes_out.
* lto-streamer-out.cc (lto_output_toplevel_asms): Use
partitioning.
(create_order_remap): Remove asm_nodes_out.
(lto_output): In LGEN add asm_nodes into partition.
* lto-streamer.h (lto_output_toplevel_asms): Add encoder.

gcc/lto/ChangeLog:

* lto.cc (stream_out_partitions): Remove asm_nodes_out.

7 days agolto: Partition toplevel assembly in 1to1
Michal Jires [Mon, 25 Aug 2025 16:23:24 +0000 (18:23 +0200)] 
lto: Partition toplevel assembly in 1to1

1to1 partitioning now also partitions toplevel assembly.
Other partitionings keep the old behavior of putting all
toplevel assembly into single partition.

gcc/ChangeLog:

* lto-cgraph.cc (compute_ltrans_boundary): Add asm_node.

gcc/lto/ChangeLog:

* lto-partition.cc (create_partition_if_empty): New.
(node_into_file_partition): Break out from ...
(lto_1_to_1_map): ... here. Partition toplevel assembly.
(create_asm_partition): New.
(lto_max_map): Use create_asm_partition.
(lto_balanced_map): Likewise.

7 days agolto: Use toplevel_node in lto_symtab_encoder
Michal Jires [Mon, 25 Aug 2025 16:07:29 +0000 (18:07 +0200)] 
lto: Use toplevel_node in lto_symtab_encoder

This patch replaces symtab_node with toplevel_node in lto_symtab_encoder
and modifies all places where lto_symtab_encoder is used to handle
(ignore) asm_node.

gcc/ChangeLog:

* ipa-icf.cc (sem_item_optimizer::write_summary): Use
toplevel_node.
(sem_item_optimizer::read_section): Likewise.
* ipa-modref.cc (modref_write): Likewise.
* ipa-prop.cc (ipa_write_return_summaries): Likewise.
(ipcp_write_transformation_summaries): Likewise.
* ipa-reference.cc (ipa_reference_write_optimization_summary):
Likewise.
* lto-cgraph.cc (lto_symtab_encoder_new): Likewise.
(lto_symtab_encoder_encode): Likewise.
(lto_symtab_encoder_delete_node): Likewise.
(lto_symtab_encoder_in_partition_p): Likewise.
(lto_set_symtab_encoder_in_partition): Likewise.
(output_refs): Likewise.
(compute_ltrans_boundary): Likewise.
(output_symtab): Likewise.
(output_cgraph_opt_summary): Likewise.
* lto-streamer-out.cc (lto_output): Likewise.
(produce_symtab): Likewise.
(produce_symtab_extension): Likewise.
* lto-streamer.h (struct lto_encoder_entry): Likewise.
(struct lto_symtab_encoder_d): Likewise.
(lto_symtab_encoder_encode): Likewise.
(lto_symtab_encoder_delete_node): Likewise.
(lto_symtab_encoder_in_partition_p): Likewise.
(lto_symtab_encoder_lookup): Likewise.
(lsei_next): Likewise.
(lsei_varpool_node): Likewise.

gcc/lto/ChangeLog:

* lto-partition.cc (add_symbol_to_partition): Use toplevel_node.
(undo_partition): Likewise.
(join_partitions): Likewise.
(split_partition_into_nodes): Likewise.
(is_partition_reorder): Likewise.
(lto_balanced_map): Likewise.
(lto_promote_cross_file_statics): Likewise.
* lto.cc (lto_wpa_write_files): Likewise.

7 days agolto: Simplify control variable in loop of balanced partitioning
Michal Jires [Mon, 25 Aug 2025 15:58:03 +0000 (17:58 +0200)] 
lto: Simplify control variable in loop of balanced partitioning

Minor simplification as preparation for next patch.

gcc/lto/ChangeLog:

* lto-partition.cc (lto_balanced_map): Simplify.