CohenArthur [Thu, 24 Apr 2025 16:41:11 +0000 (18:41 +0200)]
derive(PartialEq): Fix raw strings in test
gcc/testsuite/ChangeLog:
* rust/execute/torture/derive-partialeq2.rs: Add missing terminating nul char.
Co-authored-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Arthur Cohen [Wed, 16 Apr 2025 15:38:27 +0000 (17:38 +0200)]
derive(PartialEq): Allow deriving enum structs
gcc/rust/ChangeLog:
* expand/rust-derive-partial-eq.cc (DerivePartialEq::match_enum_tuple): Remove debug call.
(DerivePartialEq::match_enum_struct): Add proper implementation.
(DerivePartialEq::visit_enum): Call it.
gcc/testsuite/ChangeLog:
* rust/execute/torture/derive-partialeq2.rs: New test.
Arthur Cohen [Wed, 16 Apr 2025 15:37:31 +0000 (17:37 +0200)]
ast: builder: Allow building struct ident patterns
gcc/rust/ChangeLog:
* ast/rust-ast-builder.cc (Builder::struct_pattern_ident_pattern): New.
* ast/rust-ast-builder.h: New declaration.
Arthur Cohen [Wed, 16 Apr 2025 15:39:28 +0000 (17:39 +0200)]
backend: Remove checks on StructFieldIdentPattern
gcc/rust/ChangeLog:
* backend/rust-compile-pattern.cc (CompilePatternCheckExpr::visit): Remove old invalid
checks.
Arthur Cohen [Wed, 16 Apr 2025 14:32:35 +0000 (16:32 +0200)]
backend: Compile struct rebinding patterns
Allow matching on a struct instance and rebinding its fields to new names:
match X {
Foo {
field0: new_name0,
field1: new_name1,
} => {
do_something(new_name0, new_name1);
},
}
This will enable us to finish derives for PartialEq and PartialOrd but
isn't a complete implementation of these patterns yet.
gcc/rust/ChangeLog:
* backend/rust-compile-pattern.cc (CompilePatternBindings::make_struct_access):
New function.
(CompilePatternBindings::visit): Properly implement patterns mentioned above
and call make_struct_accesss.
* backend/rust-compile-pattern.h: New declaration.
gcc/testsuite/ChangeLog:
* rust/execute/torture/struct_pattern1.rs: New test.
Arthur Cohen [Wed, 16 Apr 2025 14:03:26 +0000 (16:03 +0200)]
backend: Refactor struct pattern compilation
gcc/rust/ChangeLog:
* backend/rust-compile-pattern.h: Split struct pattern compilation into three functions.
* backend/rust-compile-pattern.cc: Implement them.
Arthur Cohen [Mon, 28 Apr 2025 19:45:13 +0000 (21:45 +0200)]
nr2.0: late: Correctly initialize funny_error member
gcc/rust/ChangeLog:
* resolve/rust-late-name-resolver-2.0.cc (Late::Late): False initialize the
funny_error field.
Owen Avery [Thu, 17 Apr 2025 02:53:18 +0000 (22:53 -0400)]
Fix narrowing conversion warnings
Fixes PR#119641
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-bir-place.h
(IndexVec::size_type): Add.
(IndexVec::MAX_INDEX): Add.
(IndexVec::size): Change the return type to the type of the
internal value used by the index type.
(PlaceDB::lookup_or_add_variable): Use the return value from the
PlaceDB::add_place call.
* checks/errors/borrowck/rust-bir.h
(struct BasicBlockId): Move this definition before the
definition of the struct Function.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Pierre-Emmanuel Patry [Mon, 28 Apr 2025 11:05:49 +0000 (13:05 +0200)]
Visit visibility in UseDeclaration
Default visitor should visit all it's children.
gcc/rust/ChangeLog:
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Visit visibility.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Owen Avery [Sat, 11 Jan 2025 05:15:05 +0000 (00:15 -0500)]
Some assorted tweaks and bug fixes
gcc/rust/ChangeLog:
* ast/rust-ast-visitor.cc
(DefaultASTVisitor::visit): Visit the loop labels of
WhileLetLoopExpr instances before visiting their scrutinee
expressions.
* resolve/rust-early-name-resolver-2.0.cc
(Early::resolve_glob_import): Pass the glob import's path
directly to NameResolutionContext::resolve_path.
* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Remove unnecessary call to
Identifier::as_string.
(flatten_glob): Improve handling of cases where a glob use tree
has no path.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Pierre-Emmanuel Patry [Fri, 25 Apr 2025 14:02:12 +0000 (16:02 +0200)]
Completely duplicate path node
Both nodes had the same id, this led to a resolution conflict.
gcc/rust/ChangeLog:
* expand/rust-derive-clone.cc (DeriveClone::clone_enum_struct): Clone
path to avoid using the same nodeid.
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: Remove now passing test from exclusion
list.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Sat, 19 Apr 2025 12:14:25 +0000 (14:14 +0200)]
Use specialized param visit function for params
This commit introduce a new public function to visit function parameters
in the default visitor. It allows visitors derived from DefaultVisitor
to override only a small part of the default visitor.
gcc/rust/ChangeLog:
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit_function_params):
Add specialized function to visit function parameters.
(DefaultASTVisitor::visit): Remove parameter visit and call specialized
function instead.
* ast/rust-ast-visitor.h: Add function prototye.
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Remove
function.
(Late::visit_function_params): Override specialized visit function.
* resolve/rust-late-name-resolver-2.0.h: Add overriden function
prototype.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Sun, 6 Apr 2025 17:54:06 +0000 (19:54 +0200)]
Remove passing test from exclusion list
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: Remove passing test from exclusion list.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Sun, 6 Apr 2025 16:49:11 +0000 (18:49 +0200)]
Use stacked context for nested bindings.
Binding context may be stacked when a new binding group is introduced
within a const expression.
gcc/rust/ChangeLog:
* resolve/rust-name-resolution-context.h: Use BindingLayer instead.
* resolve/rust-name-resolution-context.cc (BindingLayer::BindingLayer):
Add new constructor for binding layer.
(BindingLayer::bind_test): Add a function to test a binding constraint.
(BindingLayer::push): Push a new binding group.
(BindingLayer::and_binded): Add function to test and-binding
constraint.
(BindingLayer::or_binded): Add function to test or-binding constraints.
(BindingLayer::insert_ident): Insert a new identifier in the current
binding group.
(BindingLayer::merge): Merge current binding group with it's parent.
(BindingLayer::get_source): Get the source of the current binding
group.
* resolve/rust-late-name-resolver-2.0.cc: Use stacked context for
binding group.
* util/rust-stacked-contexts.h: Add mutable peek function.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Sun, 6 Apr 2025 16:17:41 +0000 (18:17 +0200)]
Add pattern bindings
gcc/rust/ChangeLog:
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add binding
creation in visitor.
* resolve/rust-late-name-resolver-2.0.h: Add function prototypes.
* resolve/rust-name-resolution-context.h: Add binding context.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Sun, 6 Apr 2025 15:09:42 +0000 (17:09 +0200)]
Add binding context class
We need to differentiate bindings types, so the same binding cannot be
reused multiple time in a product binding.
gcc/rust/ChangeLog:
* resolve/rust-name-resolution-context.h (struct Binding): Add Binding
struct to differentiate Or and Product bindings in patterns.
(enum class): Add Binding kind.
(class BindingContext): Add binding context with Binding stack.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Sat, 5 Apr 2025 23:44:18 +0000 (01:44 +0200)]
Add hash function for Identifiers
gcc/rust/ChangeLog:
* ast/rust-ast.h: Add hash function.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Sat, 5 Apr 2025 23:43:20 +0000 (01:43 +0200)]
Add equality operator for identifiers
gcc/rust/ChangeLog:
* ast/rust-ast.h: Add equality operator.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Fri, 4 Apr 2025 13:35:15 +0000 (15:35 +0200)]
Add fn_once and Sized lang items to the test
gcc/testsuite/ChangeLog:
* rust/compile/multiple_bindings1.rs: Add missing lang items.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Thu, 24 Apr 2025 12:28:59 +0000 (14:28 +0200)]
Change expected error output to match nr2
Name resolution 2.0 message describes the context around the unresolved
items and should therefore be kept.
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: Remove test from exclusion list.
* rust/compile/use_1.rs: Change expected output and remove test from
nr1.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 23 Apr 2025 12:41:24 +0000 (14:41 +0200)]
Update generics9 expected error message
gcc/testsuite/ChangeLog:
* rust/compile/generics9.rs: Change expected error message.
* rust/compile/nr2/exclude: Remove test from exclusion list.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 23 Apr 2025 12:40:22 +0000 (14:40 +0200)]
Prevent forward declaration in type parameters
gcc/rust/ChangeLog:
* resolve/rust-default-resolver.cc (DefaultResolver::visit): Add visit
function for TypeParam.
* resolve/rust-default-resolver.h: Add function prototype.
* resolve/rust-forever-stack.h: Add function to check for forward
declaration ban.
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Check forward
declarations.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Mon, 7 Apr 2025 13:59:15 +0000 (15:59 +0200)]
Remove error state for GenericArg
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Remove error kind
and change function call.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Change call name.
* ast/rust-path.cc (ConstGenericParam::as_string): Likewise.
* ast/rust-path.h: Remove error kind.
* hir/rust-ast-lower-type.cc (ASTLowerGenericParam::visit): Change call
name.
* parse/rust-parse-impl.h (Parser::parse_generic_param): Use optional
on parsing failure.
(Parser::parse_generic_arg): Likewise.
(Parser::parse_path_generic_args): Likewise.
* parse/rust-parse.h: Likewise.
* resolve/rust-ast-resolve-type.h: Change call name.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 23 Apr 2025 15:24:04 +0000 (17:24 +0200)]
Change error message to match expected test output
gcc/rust/ChangeLog:
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Change error
message.
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: Remove passing test from exclusion list.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Owen Avery [Thu, 17 Apr 2025 17:51:43 +0000 (13:51 -0400)]
nr2.0: Improve error handling
gcc/rust/ChangeLog:
* resolve/rust-early-name-resolver-2.0.cc
(Early::build_import_mapping): Avoid outputting an "unresolved
import" error if other errors are outputted during resolution.
* resolve/rust-early-name-resolver-2.0.h
(Early::resolve_path_in_all_ns): Collect path resolution errors
while avoiding duplicate errors for resolutions in each
namespace.
* resolve/rust-forever-stack.h
(ForeverStack::resolve_path): Add parameter for collecting
errors.
(ForeverStack::find_starting_point): Likewise.
(ForeverStack::resolve_segments): Likewise.
* resolve/rust-forever-stack.hxx
(check_leading_kw_at_start): Likewise.
(ForeverStack::find_starting_point): Likewise.
(ForeverStack::resolve_segments): Likewise.
(ForeverStack::resolve_path): Likewise.
* resolve/rust-name-resolution-context.h
(NameResolutionContext::resolve_path): Add optional parameter
for collecting errors.
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: Remove entry.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Owen Avery [Sun, 6 Apr 2025 22:48:58 +0000 (18:48 -0400)]
nr2.0: Fix derive-debug1.rs
gcc/testsuite/ChangeLog:
* rust/compile/derive-debug1.rs: Adjust a path.
* rust/compile/nr2/exclude: Remove derive-debug1.rs.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Thomas Schwinge [Sat, 19 Apr 2025 13:49:34 +0000 (15:49 +0200)]
Disable parallel testing for 'rust/compile/nr2/compile.exp' [PR119508]
..., using the standard idiom. This '*.exp' file doesn't adhere to the
parallel testing protocol as defined in 'gcc/testsuite/lib/gcc-defs.exp'.
This also restores proper behavior for '*.exp' files executing after (!) this
one, which erroneously caused hundreds or even thousands of individual test
cases get duplicated vs. skipped, randomly, depending on the '-jN' level.
PR testsuite/119508
gcc/testsuite/
* rust/compile/nr2/compile.exp: Disable parallel testing.
(cherry picked from commit
79d2c3089f480738613b7d338d86d8be710f8158)
Philip Herron [Thu, 17 Apr 2025 15:19:35 +0000 (16:19 +0100)]
gccrs: prealloc the initilizer vector
There are two cases when initilizing an array, this is the
const context which means we need to build the array ctor,
which means using lots of memory, its super inefficient
because we are using a big wrapper over the GCC internals here
but preallocating the vectors here causes a:
terminate called after throwing an instance of 'std::bad_alloc'
So this is a handy error condition to rely on for this senario.
Fixes Rust-GCC#3713
Fixes Rust-GCC#3727
gcc/rust/ChangeLog:
* backend/rust-compile-expr.cc (CompileExpr::array_copied_expr): prealloc the vector
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Thu, 17 Apr 2025 14:53:58 +0000 (15:53 +0100)]
gccrs: Fix ICE with empty generic arguments
We have an assertion when accessing generic args if there are any which
is really useful so this adds the missing guards for the case where
they are specified but empty.
Fixes Rust-GCC#3649
gcc/rust/ChangeLog:
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): add guard
* expand/rust-expand-visitor.cc (ExpandVisitor::visit): add guard
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: nr2 is missing error for this
* rust/compile/issue-3649.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Owen Avery [Thu, 17 Apr 2025 20:51:21 +0000 (16:51 -0400)]
Adjust segment start position errors
gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-path.cc
(ResolvePath::resolve_path): Adjust error messages.
* resolve/rust-ast-resolve-type.cc
(ResolveRelativeTypePath::go): Likewise.
* resolve/rust-forever-stack.hxx
(check_leading_kw_at_start): Likewise.
gcc/testsuite/ChangeLog:
* rust/compile/issue-3568.rs: Adjust expected errors.
* rust/compile/name_resolution9.rs: Likewise.
* rust/compile/self-path2.rs: Likewise.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Philip Herron [Thu, 17 Apr 2025 12:50:55 +0000 (13:50 +0100)]
gccrs: Fix ICE when handling case of unknown field in HIR::FieldAccess
We were wrongly adding the assertion that this must not be an enum but
this is a pointless assertion we only care that there are variant in the
ADT and if the field exists in the first variant.
Fixes Rust-GCC#3581
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): fix bad assertion
gcc/testsuite/ChangeLog:
* rust/compile/nonexistent-field.rs: fix bad error message
* rust/compile/issue-3581-1.rs: New test.
* rust/compile/issue-3581-2.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Fri, 18 Apr 2025 10:37:55 +0000 (11:37 +0100)]
gccrs: Add test case to show ice is fixed
Fixes Rust-GCC#3652
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: nr2 does not error on the T it should require Self::T
* rust/compile/issue-3652.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Owen Avery [Thu, 17 Apr 2025 23:23:12 +0000 (19:23 -0400)]
nr2.0: Remove unnecessary copy of Node
gcc/rust/ChangeLog:
* resolve/rust-forever-stack.hxx
(ForeverStack::resolve_path): Pass instance of Node to lambda by
reference instead of by value.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Philip Herron [Thu, 17 Apr 2025 13:38:04 +0000 (14:38 +0100)]
gccrs: Fix ICE in struct expressions
The error handling here was done long ago when we didnt know how to do
any error handling very well. This removed bad fatal_errors and adds in
some nice rich_location error diagnostics instead.
Fixes Rust-GCC#3628
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-struct-field.h: keep reference to parent expression
* typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::TypeCheckStructExpr):
update ctor
(TypeCheckStructExpr::resolve): remove bad rust_fatal_errors
(TypeCheckStructExpr::visit): cleanup errors
gcc/testsuite/ChangeLog:
* rust/compile/macros/mbe/macro-issue2983_2984.rs: cleanup error diagnotics
* rust/compile/struct_init1.rs: likewise
* rust/compile/issue-3628.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Owen Avery [Thu, 17 Apr 2025 18:02:45 +0000 (14:02 -0400)]
nr2.0: Handle StructPatternFieldIdent
gcc/rust/ChangeLog:
* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Handle StructPatternFieldIdent.
* resolve/rust-late-name-resolver-2.0.h
(Late::visit): Likewise.
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: Remove entry.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Philip Herron [Thu, 17 Apr 2025 15:29:05 +0000 (16:29 +0100)]
gccrs: Add test case to show ICE is fixed
Fixes Rust-GCC#3662
gcc/testsuite/ChangeLog:
* rust/compile/issue-3662.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Thu, 17 Apr 2025 15:04:55 +0000 (16:04 +0100)]
gccrs: Add test case to show issue is fixed
This was already fixed in:
bb01719f0e1 but we require fn_once lang item
to be defined as we are working on libcore support still.
Fixes Rust-GCC#3711
gcc/testsuite/ChangeLog:
* rust/compile/issue-3711.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Pierre-Emmanuel Patry [Thu, 17 Apr 2025 16:28:52 +0000 (18:28 +0200)]
Add gimple test for black box intrinsic
gcc/testsuite/ChangeLog:
* rust/compile/black_box.rs: New test.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Thu, 17 Apr 2025 15:53:15 +0000 (17:53 +0200)]
Add execute test for black_box intrinsic
gcc/testsuite/ChangeLog:
* rust/execute/black_box.rs: New test.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Thu, 17 Apr 2025 12:27:11 +0000 (14:27 +0200)]
Add LlvmInlineAsm node dump
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Dump llvm inline
asm tokens.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Tue, 15 Apr 2025 09:38:29 +0000 (11:38 +0200)]
Parse and lower llvm asm node
Add a new HIR LlvmInlineAsm HIR node as well as some structures to
represent it's options and operands. Lower AST::LlvmInlineAsm node to it
and then create a tree from that node.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Remove unreachable
code.
* ast/rust-expr.h (struct LlvmOperand): Add LlvmOperand struct to
represent input and outputs.
(class LlvmInlineAsm): Add input, output and clobber operands.
(struct TupleTemplateStr): Add locus getter.
* backend/rust-compile-block.h: Add visit for LlvmInlineAsm.
* backend/rust-compile-expr.cc (CompileExpr::visit): Add llvm inline
asm stmt compilation.
* backend/rust-compile-expr.h: Add function prototype.
* backend/rust-compile-asm.h (class CompileLlvmAsm): Add llvm asm hir
not to gimple.
* backend/rust-compile-asm.cc (CompileLlvmAsm::CompileLlvmAsm): Add
constructor.
(CompileLlvmAsm::construct_operands): Add function to construct operand
tree.
(CompileLlvmAsm::construct_clobbers): Add function to construct clobber
tree.
(CompileLlvmAsm::tree_codegen_asm): Generate the whole tree for a given
llvm inline assembly node.
* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit):
Add visit function.
* checks/errors/borrowck/rust-bir-builder-expr-stmt.h: Add function
prototype.
* checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: Add visit
function.
* checks/errors/borrowck/rust-bir-builder-struct.h: Likewise.
* checks/errors/borrowck/rust-function-collector.h: Likewise.
* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit):
Likewise.
* checks/errors/privacy/rust-privacy-reporter.h: Add visit function
prototype.
* checks/errors/rust-const-checker.cc (ConstChecker::visit): Add visit
function.
* checks/errors/rust-const-checker.h: Add visit function prototype.
* checks/errors/rust-hir-pattern-analysis.cc (PatternChecker::visit):
Add visit function.
* checks/errors/rust-hir-pattern-analysis.h: Add visit function
prototype.
* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Add
visit function.
* checks/errors/rust-unsafe-checker.h: Add function prototype.
* expand/rust-macro-builtins-asm.cc (parse_llvm_templates): Parse
templates.
(parse_llvm_arguments): Add function to parse non template tokens.
(parse_llvm_operands): Add function to parse operands, either input or
output.
(parse_llvm_outputs): Add function to parse and collect llvm asm
outputs.
(parse_llvm_inputs): Likewise with inputs.
(parse_llvm_clobbers): Add function to parse llvm asm clobbers.
(parse_llvm_options): Add function to parse llvm asm options.
(parse_llvm_asm): Add function to parse llvm asm.
* expand/rust-macro-builtins-asm.h (class LlvmAsmContext): Add context
for llvm asm parser.
(parse_llvm_outputs): Add function prototype.
(parse_llvm_inputs): Likewise.
(parse_llvm_clobbers): Likewise.
(parse_llvm_options): Likewise.
* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Lower AST llvm
asm node to HIR.
* hir/rust-ast-lower-expr.h: Add function prototype.
* hir/rust-hir-dump.cc (Dump::visit): Add visit function.
* hir/rust-hir-dump.h: Add function prototype.
* hir/tree/rust-hir-expr-abstract.h: Add HIR llvm asm node kind.
* hir/tree/rust-hir-expr.h (struct LlvmOperand): Add LlvmOperand type
to represent input and outputs.
(class LlvmInlineAsm): Add LlvmInlineAsm hir node.
* hir/tree/rust-hir-full-decls.h (class LlvmInlineAsm): Add
LlvmInlineAsm hir node forward declaration.
* hir/tree/rust-hir-visitor.h: Add visit functions for LlvmInlineAsm
hir node.
* hir/tree/rust-hir.cc (LlvmInlineAsm::accept_vis): Add hir node
visitor related functions.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
Type check input and output operands.
* typecheck/rust-hir-type-check-expr.h: Add function prototype.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Visit input and
output operand expressions.
* resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Resolve input
and output expressions.
* resolve/rust-ast-resolve-expr.h: Add function prototypes.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Thu, 10 Apr 2025 11:05:15 +0000 (13:05 +0200)]
Add llvmInlineAsm node
InlineAsm node does not support memory clobbers.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Make visitor
unreachable.
* ast/rust-ast-collector.h: Add visit for LlvmInlineAsmNode.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Add visit
function for the default ast visitor.
* ast/rust-ast-visitor.h: Add function prototype.
* ast/rust-ast.cc (LlvmInlineAsm::accept_vis): Add accept_vis to
LlvmInlineAsm node.
* ast/rust-ast.h: Add LlvmInlineAsm node kind.
* ast/rust-expr.h (class LlvmInlineAsm): Add LlvmInlineAsm node.
* expand/rust-derive.h: Add visit function for LlvmInlineAsm node.
* expand/rust-macro-builtins-asm.cc (MacroBuiltin::llvm_asm_handler):
Add handler for llvm inline assembly nodes.
(parse_llvm_asm): Add function to parse llvm assembly nodes.
* expand/rust-macro-builtins-asm.h (parse_llvm_asm): Add function
prototypes.
* expand/rust-macro-builtins.cc (inline_llvm_asm_maker): Add macro
transcriber.
* expand/rust-macro-builtins.h: Add transcriber function prototype.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Add visit
function for LlvmInlineAsm node.
* hir/rust-ast-lower-base.h: Add visit function prototype.
* resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Add visit
function for LlvmInlineAsm node.
* resolve/rust-ast-resolve-base.h: Add visit function prototype.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 9 Apr 2025 15:41:24 +0000 (17:41 +0200)]
Emit error with old asm syntax in new asm blocks
gcc/rust/ChangeLog:
* expand/rust-macro-builtins-asm.cc (parse_asm_arg): Emit error
message.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Philip Herron [Wed, 16 Apr 2025 19:38:17 +0000 (20:38 +0100)]
gccrs: Add check for placeholder (infer) type in return position
It is not allowed to have a declared inference variable in the return
position of a function as this may never get infered you need good points
of truth.
Ideally if we get a student for GSoC 25 we will get the Default Hir Visitor
so that we can grab the HIR::InferredType locus instead of using the ref
location lookups.
Fixes Rust-GCC#402
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): add diagnostic
* typecheck/rust-tyty.cc (BaseType::contains_infer): new helper to grab first infer var
* typecheck/rust-tyty.h: prototype
gcc/testsuite/ChangeLog:
* rust/compile/issue-402.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Wed, 16 Apr 2025 16:13:04 +0000 (17:13 +0100)]
gccrs: Fix ICE when checking shift's which are behind array refs
I copied a bad form of this check from the c front-end this updates it
to ensure the rhs is an INTEGER_CST and the lhs needs checked in the first
place.
Fixes Rust-GCC#3664
gcc/rust/ChangeLog:
* rust-gcc.cc (arithmetic_or_logical_expression): Ensure this is an integer
gcc/testsuite/ChangeLog:
* rust/compile/issue-3664.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Wed, 16 Apr 2025 16:00:28 +0000 (17:00 +0100)]
gccrs: Fix crash in hir dump as labels are optional
gcc/rust/ChangeLog:
* hir/rust-hir-dump.cc (Dump::visit): add guard for optional label
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Yap Zhi Heng [Fri, 4 Apr 2025 11:37:03 +0000 (19:37 +0800)]
gccrs: Update comments in repr parsing code
gcc/rust/ChangeLog:
* typecheck/rust-tyty.h: Remove extra redundant comment.
* typecheck/rust-hir-type-check-base.cc: Update comment on repr
handling.
Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
Zhi Heng [Thu, 3 Apr 2025 15:02:59 +0000 (23:02 +0800)]
gccrs: Implement integer representation for enums
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-base.cc: Set enum representing
type properly if repr is an integer type.
* typecheck/rust-hir-type-check-item.cc: Update comments.
Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
Zhi Heng [Thu, 3 Apr 2025 12:23:46 +0000 (20:23 +0800)]
gccrs: Implement typecheck for zero-variant enums
gcc/rust/ChangeLog:
* typecheck/rust-tyty.h: Add new `ReprKind` enum to
`ReprOptions`.
* typecheck/rust-hir-type-check-base.cc: Handle setting of
`repr_kind`.
* typecheck/rust-hir-type-check-item.cc: New check for
zero-variant enums.
Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
Philip Herron [Fri, 4 Apr 2025 15:35:13 +0000 (16:35 +0100)]
gccrs: Fix segv in unsafe chcker
Trait constants were missing type resolution step, this adds that
as if it was a normal constant. The unsafe checker was missing a
null check.
Fixes Rust-GCC#3612
gcc/rust/ChangeLog:
* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): add null check
* hir/tree/rust-hir-item.h: add has_type helper
* typecheck/rust-hir-trait-resolve.cc (TraitItemReference::resolve_item):
add missing type checking
gcc/testsuite/ChangeLog:
* rust/compile/issue-3612.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Arthur Cohen [Tue, 8 Apr 2025 15:04:09 +0000 (17:04 +0200)]
lang-items: Add ManuallyDrop<T>
gcc/rust/ChangeLog:
* util/rust-lang-item.h: Add new manually_drop lang item.
* util/rust-lang-item.cc: Likewise.
Arthur Cohen [Wed, 9 Apr 2025 13:17:38 +0000 (15:17 +0200)]
attributes: Handle external tool annotations like rustfmt::
gcc/rust/ChangeLog:
* util/rust-attribute-values.h: Add RUSTFMT value.
* util/rust-attributes.cc: Define the attribute.
* util/rust-attributes.h (enum CompilerPass): Add EXTERNAL variant.
* expand/rust-macro-builtins.cc: Fix formatting.
Arthur Cohen [Wed, 9 Apr 2025 12:48:55 +0000 (14:48 +0200)]
nr2.0: Only insert derive macros if they exist
This causes an assertion failure when compiling core with nr2.0, but should
probably be improved. I'm not sure how this code enables built-in derive
macros to be resolved so this is a temporary fix.
gcc/rust/ChangeLog:
* resolve/rust-early-name-resolver-2.0.cc (Early::visit_attributes): Remove assertion.
Arthur Cohen [Fri, 4 Apr 2025 12:20:04 +0000 (14:20 +0200)]
attributes: Add missing attributes used in `core`
gcc/rust/ChangeLog:
* util/rust-attribute-values.h: Add missing attributes.
* util/rust-attributes.cc: Likewise.
* util/rust-attributes.h (enum CompilerPass): Mention adding something for const
functions.
beamandala [Thu, 20 Mar 2025 22:34:48 +0000 (17:34 -0500)]
Add `#[track_caller]` as known attribute
gcc/rust/ChangeLog:
* expand/rust-macro-builtins.cc (MacroBuiltin::builtin_transcribers):
Add entry for track_caller.
* util/rust-attribute-values.h: add `TRACK_CALLER` attribute.
* util/rust-attributes.cc: add `track_caller` attribute definition.
gcc/testsuite/ChangeLog:
* rust/compile/track_caller.rs: New test.
Signed-off-by: Bhavesh Mandalapu <mandalapubhavesh@gmail.com>
Arthur Cohen [Mon, 14 Apr 2025 08:58:25 +0000 (10:58 +0200)]
ci: Update warnings for new location in install.texi
ChangeLog:
* .github/glibcxx_ubuntu64b_log_expected_warnings: Change line number
for warning from 2230 to 2236.
* .github/log_expected_warnings: Likewise.
Arthur Cohen [Tue, 1 Apr 2025 11:00:56 +0000 (13:00 +0200)]
install.texi: Mention Rust requirement for building gccrs
Addresses PR#117869
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117869
gcc/ChangeLog:
* doc/install.texi: Add requirements for building gccrs.
Owen Avery [Sat, 5 Apr 2025 21:20:44 +0000 (17:20 -0400)]
Fix const checking of enum discriminants
gcc/rust/ChangeLog:
* checks/errors/rust-const-checker.cc
(ConstChecker::visit): Visit the enum items of enums.
* resolve/rust-ast-resolve-item.cc
(ResolveItem::visit): Resolve enum discriminants during nr1.0.
gcc/testsuite/ChangeLog:
* rust/compile/enum_discriminant2.rs: New test.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Arthur Cohen [Wed, 9 Apr 2025 12:42:08 +0000 (14:42 +0200)]
format_args: Allow extraneous commas, improve safety
gcc/rust/ChangeLog:
* expand/rust-macro-builtins-format-args.cc (format_args_parse_arguments): Improve safety,
allow extra commas after end of argument list.
gcc/testsuite/ChangeLog:
* rust/compile/format_args_extra_comma.rs: New test.
Arthur Cohen [Tue, 8 Apr 2025 14:20:18 +0000 (16:20 +0200)]
expansion: Desugar doc comments into attributes before expansion
gcc/rust/ChangeLog:
* expand/rust-macro-expand.cc (MacroExpander::expand_decl_macro): Call into
TokenTreeDesugar.
* expand/rust-token-tree-desugar.cc: New file.
* expand/rust-token-tree-desugar.h: New file.
* Make-lang.in: Compile them.
gcc/testsuite/ChangeLog:
* rust/compile/macros/mbe/macro-issue3709-1.rs: New test.
* rust/compile/macros/mbe/macro-issue3709-2.rs: New test.
Arthur Cohen [Tue, 8 Apr 2025 12:41:16 +0000 (14:41 +0200)]
expansion: Only add fragments if the matcher succeeded
gcc/rust/ChangeLog:
* expand/rust-macro-expand.cc (MacroExpander::match_n_matches): Do not
insert fragments and substack fragments if the matcher failed.
gcc/testsuite/ChangeLog:
* rust/compile/macros/mbe/macro-issue3708.rs: New test.
Arthur Cohen [Fri, 4 Apr 2025 12:21:00 +0000 (14:21 +0200)]
session: Desugar question mark operator after expansion instead.
gcc/rust/ChangeLog:
* rust-session-manager.cc (Session::compile_crate): Call the visitor later in the pipeline.
Arthur Cohen [Wed, 9 Apr 2025 12:44:11 +0000 (14:44 +0200)]
ast: Add get_locus() to DelimTokenTree
gcc/rust/ChangeLog:
* ast/rust-ast.h (DelimTokenTree::get_locus): New function.
Arthur Cohen [Wed, 9 Apr 2025 12:44:56 +0000 (14:44 +0200)]
ast: Support outer attributes for AST::RangeExpr
gcc/rust/ChangeLog:
* ast/rust-expr.h (class RangeExpr): Add empty outer attributes and allow getting them
and setting them.
Arthur Cohen [Fri, 4 Apr 2025 12:18:33 +0000 (14:18 +0200)]
nr2.0: Do not resolve modules this run if they are unloaded
Instead, mark the visitor as dirty and wait for the next round of the fixed point to take care of
them. This avoids issues with module items being loaded while not being stripped yet.
gcc/rust/ChangeLog:
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Return if module
is unloaded.
Arthur Cohen [Thu, 3 Apr 2025 14:22:10 +0000 (16:22 +0200)]
typecheck: Properly select methods when dealing with specialization
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-expr.cc (is_default_fn): New.
(emit_ambiguous_resolution_error): New.
(handle_multiple_candidates): Properly handle multiple candidates in
the case of specialization.
(TypeCheckExpr::visit): Call `handle_multiple_candidates`.
gcc/testsuite/ChangeLog:
* rust/execute/torture/min_specialization2.rs: New test.
* rust/execute/torture/min_specialization3.rs: New test.
Andrew Pinski [Thu, 20 Mar 2025 00:30:02 +0000 (17:30 -0700)]
rust: Add comment inside block [PR119342]
Inside a BLOCK node, all of the variables of the scope/block
are chained together and that connects them to the block.
This just adds a comment to that effect as reading the code
it is not so obvious why they need to be chained together.
gcc/rust/ChangeLog:
PR rust/119342
* rust-gcc.cc (block): Add comment on why chaining
the variables of the scope toether.
Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
Andrew Pinski [Thu, 20 Mar 2025 00:30:01 +0000 (17:30 -0700)]
rust: use range for inside rust-gcc.cc [PR119341]
There are some places inside rust-gcc.cc which are candidates
to use range for instead of iterators directly. This changes
the locations I saw and makes the code slightly more readable.
gcc/rust/ChangeLog:
PR rust/119341
* rust-gcc.cc (function_type): Use range fors.
(function_type_variadic): Likewise.
(fill_in_fields): Likewise.
(statement_list): Likewise.
(block): Likewise.
(block_add_statements): Likewise.
(function_set_parameters): Likewise.
(write_global_definitions): Likewise.
Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
Andrew Pinski [Thu, 20 Mar 2025 00:30:00 +0000 (17:30 -0700)]
rust: Use error_operand_p in rust-gcc.cc
Just a simple cleanupof the code to use error_operand_p
instead of directly comparing against error_mark_node.
This also moves some cdoe around when dealing with error_operand_p
just to be faster and/or slightly tighten up the code slightly.
gcc/rust/ChangeLog:
* rust-gcc.cc (Bvariable::get_tree): Use error_operand_p.
(pointer_type): Likewise.
(reference_type): Likewise.
(immutable_type): Likewise.
(function_type): Likewise.
(function_type_variadic): Likewise.
Cleanup the check for receiver.type first.
(function_ptr_type): Use error_operand_p.
(fill_in_fields): Likewise.
(fill_in_array): Likewise.
(named_type): Likewise.
(type_size): Likewise.
(type_alignment): Likewise.
(type_field_alignment): Likewise.
(type_field_offset): Likewise.
(zero_expression): Likewise.
(float_constant_expression): Likewise.
(convert_expression): Likewise.
(struct_field_expression): Likewise.
(compound_expression): Likewise.
(conditional_expression): Likewise.
(negation_expression): Likewise.
(arithmetic_or_logical_expression): Likewise.
(arithmetic_or_logical_expression_checked): Likewise.
(comparison_expression): Likewise.
(lazy_boolean_expression): Likewise.
(constructor_expression): Likewise.
(array_constructor_expression): Likewise.
(array_index_expression): Likewise.
(call_expression): Likewise.
(init_statement): Likewise.
(assignment_statement): Likewise.
(return_statement): Likewise.
(exception_handler_statement): Likewise.
(if_statement): Likewise.
(compound_statement): Likewise.
Tighten up the code, removing t variable.
(statement_list): Use error_operand_p.
(block): Likewise.
(block_add_statements): Likewise.
(convert_tree): Likewise.
(global_variable): Likewise.
(global_variable_set_init): Likewise.
(local_variable): Likewise.
(parameter_variable): Likewise.
(static_chain_variable): Likewise.
(temporary_variable): Likewise.
(function): Likewise. Tighten up the code.
(function_defer_statement): Use error_operand_p.
(function_set_parameters): Use error_operand_p.
(write_global_definitions): Use error_operand_p.
Tighten up the code around the loop.
Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
Andrew Pinski [Thu, 20 Mar 2025 00:29:59 +0000 (17:29 -0700)]
rust: Use FLOAT_TYPE_P instead of manual checking
This moves is_floating_point over to using FLOAT_TYPE_P instead
of manually checking. Note before it would return true for all
COMPLEX_TYPE but complex types' inner type could be integral.
Also fixes up the comment to be in more of the GNU style.
Bootstrapped and tested on x86_64-linux-gnu.
gcc/rust/ChangeLog:
* rust-gcc.cc (is_floating_point): Use FLOAT_TYPE_P
instead of manually checking the type.
Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
Owen Avery [Mon, 24 Mar 2025 01:40:47 +0000 (21:40 -0400)]
nr2.0: Adjust test macro6.rs
gcc/testsuite/ChangeLog:
* rust/compile/macros/mbe/macro6.rs: Remove call of undefined
function.
* rust/compile/nr2/exclude: Remove macros/mbe/macro6.rs.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Owen Avery [Mon, 24 Mar 2025 22:27:41 +0000 (18:27 -0400)]
nr2.0: Adjust test issue-2812.rs
gcc/testsuite/ChangeLog:
* rust/compile/issue-2812.rs: Avoid multiple definition error.
* rust/compile/nr2/exclude: Remove issue-2812.rs.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Matty Kuhn [Sat, 5 Apr 2025 00:09:41 +0000 (18:09 -0600)]
gccrs: fix ICE segfault with empty feature gate
This patch fixes an issue where an empty feature gate would segfault,
instead of reporting a syntax error to the user.
gcc/rust/ChangeLog:
* ast/rust-ast.h: (AST::Attribute): add empty_input function
* checks/errors/rust-feature-gate.cc: (FeatureGate::visit): check for empty feature gate
gcc/testsuite/ChangeLog:
* rust/compile/feature.rs: add an invalid empty feature to produce an error
Signed-off-by: Matty Kuhn <matty.kuhn.1@gmail.com>
Pierre-Emmanuel Patry [Thu, 3 Apr 2025 13:43:40 +0000 (15:43 +0200)]
Rename label getter to unchecked
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Update label
getter call.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise.
* ast/rust-ast.cc (BreakExpr::as_string): Likewise.
* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise.
* resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Likewise.
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Likewise.
* ast/rust-expr.h: Add optional getter and rename label getter to
get_label_unchecked.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Thu, 3 Apr 2025 12:40:15 +0000 (14:40 +0200)]
Rename label getter in ContinueExpr
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit):
Call unchecked getter.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit):
Likewise.
* ast/rust-ast.cc (ContinueExpr::as_string): Likewise.
* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise.
* resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Likewise.
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Likewise.
* ast/rust-expr.h: Add new getter for the optional and rename getter
to get_label_unchecked.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Thu, 3 Apr 2025 11:16:33 +0000 (13:16 +0200)]
Change optional to expected for parse_loop_label
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::parse_loop_label): Change function
return type to expected.
(Parser::parse_labelled_loop_expr): Adapt call location to new return
type.
* parse/rust-parse.h (enum class): Update function prototype.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 2 Apr 2025 16:20:54 +0000 (18:20 +0200)]
Adapt testcase to name resolution 2.0
Name resolution 2.0 behavior matches more closely rustc's behavior
and trying to prevent undeclared label error emission would break some
other test.
gcc/testsuite/ChangeLog:
* rust/compile/invalid_label_name.rs: Adapt test to nr2.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 2 Apr 2025 15:41:54 +0000 (17:41 +0200)]
Resolve labels within break or continue expressions
gcc/rust/ChangeLog:
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add call
to label resolution if there is one label.
(Late::resolve_label): Look for labels and emit an error message on
failure.
* resolve/rust-late-name-resolver-2.0.h: Add function prototypes.
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: Remove test.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 2 Apr 2025 15:38:28 +0000 (17:38 +0200)]
Fix unresolved label error message
gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit):
Change error message to match rustc.
gcc/testsuite/ChangeLog:
* rust/compile/undeclared_label.rs: Change test
expected string.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Tue, 1 Apr 2025 17:55:28 +0000 (19:55 +0200)]
Migrate error state to optionals
gcc/rust/ChangeLog:
* ast/rust-ast-builder.cc (Builder::self_ref_param): Remove error state
and use optional.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Check label
before visiting.
* ast/rust-ast.cc (ContinueExpr::as_string): Retrieve label value.
(Lifetime::as_string): Retrieve lifetime value.
(ReferenceType::as_string): Likewise.
(SelfParam::as_string): Likewise.
* ast/rust-ast.h: Remove lifetime and LifetimeParam error state.
* ast/rust-desugar-for-loops.cc (DesugarForLoops::DesugarCtx::make_break_arm):
Use optional instead of error state.
* ast/rust-expr.h (class ContinueExpr): Make label optional.
* ast/rust-item.h (class SelfParam): Make lifetime optional.
* ast/rust-type.h (class ReferenceType): Likewise.
* backend/rust-compile-base.cc: Use optional for self param instead
of error state.
* backend/rust-compile-base.h: Update function prototype.
* expand/rust-derive-clone.cc (DeriveClone::clone_fn): Use optional.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_self): Lower
lifetime only if it exists.
* hir/rust-ast-lower-block.h: Lower loop label only if it exists.
* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise.
* hir/rust-ast-lower-implitem.cc (ASTLowerImplItem::visit): Remove
references to error state.
(ASTLowerTraitItem::visit): Lower self param only if it exists.
* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Use nullopt
for default value instead of SelfParam error state.
* hir/rust-ast-lower.cc (ASTLoweringExprWithBlock::visit): Lower label
only if it exists.
* hir/rust-hir-dump.cc (Dump::do_traitfunctiondecl): Print self only if
it exists.
(Dump::visit): Liewise.
* hir/tree/rust-hir-bound.h: Remove error state.
* hir/tree/rust-hir-expr.cc (ContinueExpr::ContinueExpr): Use optional
in constructor for loop label.
(BreakExpr::BreakExpr): Likewise.
* hir/tree/rust-hir-expr.h (class ContinueExpr): Remove error state
implementation.
(class BreakExpr): Likewise.
* hir/tree/rust-hir-generic-param.h: Likewise.
* hir/tree/rust-hir-item.cc (SelfParam::SelfParam): Make lifetime
optional.
(Function::Function): Make self param optional.
* hir/tree/rust-hir-item.h (class Function): Likewise.
* hir/tree/rust-hir-type.cc (ReferenceType::ReferenceType): Make
lifetime optional.
* hir/tree/rust-hir-type.h (class ReferenceType): Likewise.
* hir/tree/rust-hir.cc (ContinueExpr::as_string): Use new getter.
(BreakExpr::as_string): Likewise.
(Lifetime::as_string): Likewise.
(ReferenceType::as_string): Likewise.
(TraitFunctionDecl::as_string): Likewise.
(SelfParam::as_string): Remove error state checking.
* parse/rust-parse-impl.h (Parser::parse_generic_param): Adapt to
optional.
(Parser::parse_lifetime_params): Likewise.
(Parser::parse_lifetime_params_objs): Likewise.
(Parser::parse_lifetime_param): Likewise.
(Parser::parse_lifetime_where_clause_item): Likewise.
(Parser::parse_type_param_bound): Likewise.
(Parser::parse_lifetime_bounds): Likewise.
(Parser::parse_path_generic_args): Likewise.
(Parser::parse_self_param): Likewise.
(Parser::parse_break_expr): Likewise.
(Parser::parse_continue_expr): Likewise.
(Parser::parse_reference_type_inner): Likewise.
* parse/rust-parse.h (class ParseLifetimeParamError): Add new class for
lifetime param parsing errors.
(class ParseLifetimeError): Add new class for lifetime parsing errors.
(enum ParseSelfError): Add new class for self param parsing errors.
* typecheck/rust-hir-type-check-implitem.cc (TypeCheckImplItem::visit):
Use unchecked getter in checked context. And make anonymous region.
* typecheck/rust-hir-type-check.cc (TraitItemReference::get_type_from_fn):
Likewise.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Tue, 1 Apr 2025 14:10:38 +0000 (16:10 +0200)]
Update ast visitor with proper check for looplabel
The visitor was visiting loop label even when they did not exist.
gcc/rust/ChangeLog:
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Add
check for loop label before visiting it.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Tue, 1 Apr 2025 14:08:37 +0000 (16:08 +0200)]
Remove unused error constructor and getter
These constructor for eroneous state are not in use anymore since we
replaced this error state with an optional in the parent nodes.
gcc/rust/ChangeLog:
* ast/rust-expr.h: Remove error getter and constructor.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Tue, 1 Apr 2025 13:57:47 +0000 (15:57 +0200)]
Make loop label truly optional
A loop label error state was in use to represent missing loop label but
this may be easily forgotten and the optional nature of the label was
misrepresented.
gcc/rust/ChangeLog:
* ast/rust-ast-builder.cc (Builder::block): Call with a nullopt instead
of an error loop label.
(WhileLetLoopExpr::as_string): Use getter function and adapt to
newtype.
* ast/rust-ast.cc (WhileLoopExpr::as_string): Likewise.
(LoopExpr::as_string): Likewise.
(BreakExpr::as_string): Likewise.
(ForLoopExpr::as_string): Likewise.
* ast/rust-expr.h (class BlockExpr): Make loop label optional.
(class BreakExpr): Likewise.
* expand/rust-derive-clone.cc (DeriveClone::clone_fn): Use nullopt.
* expand/rust-derive-debug.cc (DeriveDebug::stub_debug_fn): Likewise.
* expand/rust-derive-default.cc (DeriveDefault::default_fn): Likewise.
* expand/rust-derive-eq.cc: Likewise.
* parse/rust-parse-impl.h (Parser::parse_block_expr): Use optional
for arguments.
(Parser::parse_loop_expr): Likewise.
(Parser::parse_while_loop_expr): Likewise.
(Parser::parse_while_let_loop_expr): Likewise.
(Parser::parse_for_loop_expr): Likewise.
(Parser::parse_labelled_loop_expr): Likewise.
(Parser::parse_loop_label): Return an optional.
* parse/rust-parse.h: Update function prototype and use nullopt for
default values.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Tue, 1 Apr 2025 10:02:31 +0000 (12:02 +0200)]
Visit loop label before predicate expression
If the label is referenced within the while predicate expression it has
to be resolved before the latter.
gcc/rust/ChangeLog:
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Change default
visit order.
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: Remove test from exclusion list.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Mon, 31 Mar 2025 15:01:18 +0000 (17:01 +0200)]
Add check for label
gcc/rust/ChangeLog:
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Visit loop label
only if it exists.
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: Remove passing test.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Mon, 31 Mar 2025 15:00:11 +0000 (17:00 +0200)]
Resolve labels
gcc/rust/ChangeLog:
* hir/rust-ast-lower.cc (ASTLoweringBlock::visit): Lower label only if
it exists.
* hir/tree/rust-hir-expr.cc (BlockExpr::BlockExpr): Make loop label
optional.
(BaseLoopExpr::BaseLoopExpr): Likewise.
(LoopExpr::LoopExpr): Likewise.
(WhileLoopExpr::WhileLoopExpr): Likewise.
* hir/tree/rust-hir-expr.h: Use optional for lifetime and labels.
* hir/tree/rust-hir.cc (WhileLoopExpr::as_string): Use getter.
(WhileLetLoopExpr::as_string): Likewise.
(LoopExpr::as_string): Likewise.
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Resolve labels.
* resolve/rust-late-name-resolver-2.0.h: Add visit function prototype
for loop labels.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Thu, 3 Apr 2025 15:27:46 +0000 (17:27 +0200)]
Revert part of
44ffe1193269
This commit got rid of msvc specific code and remove the else clause,
this triggered warning with tl::expected::value function.
gcc/rust/ChangeLog:
* util/expected.h: Use gcc_unreachable within gcc context.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Sri Ganesh Thota [Tue, 25 Mar 2025 13:00:58 +0000 (18:30 +0530)]
gccrs: refactoring rust_error_at "redefined multiple times"
gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-base.h (redefined_error): created a function for
rust_error_at for redefined at multiple times.
* resolve/rust-ast-resolve-implitem.h: changed rust_error_at to redefined_error.
* resolve/rust-ast-resolve-stmt.cc (ResolveStmt::visit): changed rust_error_at to
redefined_error.
* resolve/rust-ast-resolve-stmt.h: changed rust_error_at to redefined_error.
* resolve/rust-ast-resolve-toplevel.h: changed rust_error_at to redefined_error.
Signed-off-by: Sri Ganesh Thota <sriganeshthota12345@gmail.com>
Owen Avery [Sun, 30 Mar 2025 23:08:45 +0000 (19:08 -0400)]
nr2.0: Improve test script
gcc/testsuite/ChangeLog:
* rust/compile/nr2/compile.exp: Avoid absolute paths in output,
adjust phrasing of output, and avoid false XPASS output when
tests are run in parallel.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Owen Avery [Tue, 1 Apr 2025 21:50:32 +0000 (17:50 -0400)]
nr2.0: Remove duplicate self visit
gcc/rust/ChangeLog:
* ast/rust-ast-visitor.cc
(DefaultASTVisitor::visit): Remove explicit visitation of a
function's self parameter, as if it exists it'll be visited as
one of the function parameters.
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: Remove entry.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Philip Herron [Thu, 3 Apr 2025 15:32:36 +0000 (16:32 +0100)]
gccrs: Fix ICE for reserved lifetime name
This is a reserved name so this changes the assertion to a diagnostic.
Fixes Rust-GCC#3647
gcc/rust/ChangeLog:
* typecheck/rust-typecheck-context.cc (TypeCheckContext::lookup_lifetime): emit error
gcc/testsuite/ChangeLog:
* rust/compile/issue-3647.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Arthur Cohen [Tue, 1 Apr 2025 15:45:28 +0000 (17:45 +0200)]
hir: Add default qualifier to function, lower it properly
gcc/rust/ChangeLog:
* ast/rust-ast.cc (Function::Function): Rename is_default -> has_default.
(Function::operator=): Likewise.
* ast/rust-item.h (class Function): Add `is_default` method.
* hir/rust-ast-lower-implitem.cc (ASTLowerImplItem::visit): Lower default qualifier.
* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Likewise.
* hir/tree/rust-hir-item.cc (Function::Function): Add `is_default` member.
(Function::operator=): Likewise.
* hir/tree/rust-hir-item.h (enum class Defaultness): New enum.
(class Function): Use it.
gcc/testsuite/ChangeLog:
* rust/compile/min_specialization1.rs: New test.
Arthur Cohen [Tue, 1 Apr 2025 15:45:00 +0000 (17:45 +0200)]
feature: Add min_specialization feature
gcc/rust/ChangeLog:
* checks/errors/rust-feature.cc (Feature::create): Handle `#![feature(min_specialization)]`.
* checks/errors/rust-feature.h: Likewise.
Philip Herron [Wed, 2 Apr 2025 20:02:44 +0000 (21:02 +0100)]
gccrs: Fix ICE when hitting invalid types for generics
We need to check upfront if the type is valid or not. Then
error with a decent message.
Fixes Rust-GCC#3643
Fixes Rust-GCC#3646
Fixes Rust-GCC#3654
Fixes Rust-GCC#3663
Fixes Rust-GCC#3671
gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-type.cc (ResolveRelativeTypePath::go): fix error msg
* typecheck/rust-substitution-mapper.cc (SubstMapper::Resolve): add validation
(SubstMapper::valid_type): new check
(SubstMapper::visit): check if can resolve
* typecheck/rust-substitution-mapper.h: new prototype
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: nr2 is missing type path error
* rust/compile/issue-3643.rs: New test.
* rust/compile/issue-3646.rs: New test.
* rust/compile/issue-3654.rs: New test.
* rust/compile/issue-3663.rs: New test.
* rust/compile/issue-3671.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Thu, 3 Apr 2025 14:39:58 +0000 (15:39 +0100)]
gccrs: Fix ICE on raw reference
This patch adds support for raw references which enforce the pointer
type away from a reference type.
Fixes Rust-GCC#3667
gcc/rust/ChangeLog:
* backend/rust-compile-base.cc (HIRCompileBase::address_expression): allow optional type
* backend/rust-compile-base.h: update prototype
* backend/rust-compile-expr.cc (CompileExpr::visit): update borrow expr
* backend/rust-compile-extern.h: remove unused debug
* backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): update usage
* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): lower raw ref
* hir/tree/rust-hir-expr.cc (BorrowExpr::BorrowExpr): add flag for raw ref
* hir/tree/rust-hir-expr.h (class BorrowExpr): add new raw ref field
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): add handle for raw ref
gcc/testsuite/ChangeLog:
* rust/compile/issue-3667.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Thu, 3 Apr 2025 14:37:40 +0000 (15:37 +0100)]
gccrs: Fix ICE on invalid match arms
We hit assertions on empty enum or unknown variant, this catches the error
and emits a new diagnostic.
Fixes Rust-GCC#3656
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): emit error
gcc/testsuite/ChangeLog:
* rust/compile/issue-3656.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Wed, 2 Apr 2025 17:21:46 +0000 (18:21 +0100)]
gccrs: Fix recusive type query and nullptr on type path
This was a small fix to sort out the segfault to check for nullptr on the
TypePath cases for query type. But when this happened opened up a few bugs
that were hidden under the carpet namely: compile/issue-2905-{1,2}.rs which
has a recursive type query which needs to ne handled but now and error
message is being output for the type path. This happens because we start
resolving a generic struct:
struct Wierd<T>(A<(T,)>);
So the child field A is also generic and the generic argument of the tuple
of T needs to be applied to this generic field. This causes a chunk of
code to do bounds checking to ensure the bounds are ok, this is also
something that probably might change as generic types will have the bounds
secified anyway but thats besides the case right now. So once this bounds
checking occurs we endup looking at the impl block for Wierd<i32> which is
also grand but we still havent finished resolving the parent type of Wierd
which is recusive. But the query type system needs to check for that.
The other issue was: compile/issue-3022.rs which is a resolution issue:
impl<T: Foo<U>, U> Foo<U> for Bar<T, U>
The bound of Foo<T> is added to T before U is resolved but this was hidden
before the new error message was added. So now we have a generic
arguements handler being used correctly all over the code base apart from
1 last case for Traits but we will deal with that later. This handles the
case by setting up the type parameters upfront then sorting out their
bounds.
Fixes Rust-GCC#3625
gcc/rust/ChangeLog:
* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): new argument
* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::TypeCheckBase): new helper
* typecheck/rust-hir-type-check-base.h: new helper prototype
* typecheck/rust-hir-type-check-implitem.cc (TypeCheckTopLevelExternItem::visit):
remove comment out code
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_root_path): check for null
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path): likewise
(TypeResolveGenericParam::Resolve): new args
(TypeResolveGenericParam::ApplyAnyTraitBounds): new helper
(TypeResolveGenericParam::apply_trait_bounds): new field
(TypeResolveGenericParam::visit): update
* typecheck/rust-hir-type-check-type.h: new args
* typecheck/rust-hir-type-check.cc (TraitItemReference::get_type_from_fn): reuse helper
* typecheck/rust-type-util.cc (query_type): check for recursive query
* typecheck/rust-tyty-subst.cc (SubstitutionParamMapping::SubstitutionParamMapping):
remove const
(SubstitutionParamMapping::get_generic_param): likewise
* typecheck/rust-tyty-subst.h: likewise
* typecheck/rust-tyty-variance-analysis.cc (GenericTyVisitorCtx::process_type): likewise
gcc/testsuite/ChangeLog:
* rust/compile/issue-3625.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Wed, 2 Apr 2025 15:16:47 +0000 (16:16 +0100)]
gccrs: Fix ICE when there are 2 functions named main
We need to setup the main_identifier_node for MAIN_DECL_P checks in the
middle-end. But it is valid to have a main function/method on impl blocks.
So we need to flag if this is a "root" item or not, which is one that is
jsut an HIR::Function on part of the Crate::items as oppposed to a
HIR::Function which is part of an HIR::ImplBlock as part of the HIR::Crate.
Some small cleanups have been added here too.
Fixes Rust-GCC#3648
gcc/rust/ChangeLog:
* backend/rust-compile-base.cc: new flag is_root_item
* backend/rust-compile-base.h: update prototype
* backend/rust-compile-implitem.cc (CompileTraitItem::visit): update call
* backend/rust-compile-implitem.h: remove old debug internal error
* backend/rust-compile-item.cc (CompileItem::visit): update call
* backend/rust-compile-item.h: remove old debug
* backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): update calls
* backend/rust-compile.cc: likewise
* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_path_to_trait):
remove assertion and error
gcc/testsuite/ChangeLog:
* rust/compile/issue-3648.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Mon, 31 Mar 2025 16:33:59 +0000 (17:33 +0100)]
gccrs: Fix ICE when resolving lifetimes without name
We dont need to assert here the lifetime code already supports this case.
Fixes Rust-GCC#3657
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-base.cc: remove assertion
gcc/testsuite/ChangeLog:
* rust/compile/issue-3657.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Mon, 31 Mar 2025 16:58:24 +0000 (17:58 +0100)]
gccrs: Fix ICE when doing shift checks on const decl
Const decls are just delcarations wrapping the value into the DECL_INITIAL
and the shift checks we have assume no decls are involved and its just flat
values. This patch simply unwraps the constant values if they exist.
Fixes Rust-GCC#3665
gcc/rust/ChangeLog:
* rust-gcc.cc (arithmetic_or_logical_expression): unwrap const decls
gcc/testsuite/ChangeLog:
* rust/compile/issue-3665.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
This page took 0.0989640000000001 seconds and 5 git commands to generate.