Commit graph

208087 commits

Author SHA1 Message Date
John David Anglin
b31a35b8aa Skip various cmp-mem-const tests on lp64 hppa*-*-*
Prior optimization already reduced the constant.

2024-01-16  John David Anglin  <danglin@gcc.gnu.org>

gcc/testsuite/ChangeLog:

	* gcc.dg/cmp-mem-const-3.c: Skip on lp64 hppa*-*-*.
	* gcc.dg/cmp-mem-const-4.c: Likewise.
	* gcc.dg/cmp-mem-const-5.c: Likewise.
	* gcc.dg/cmp-mem-const-6.c: Likewise.
2024-01-16 20:04:11 +00:00
John David Anglin
3867dfc306 xfail all scan-tree-dump-times checks on hppa*64*-*-* in sra-17.c and sra-18.c
2024-01-64  John David Anglin  <danglin@gcc.gnu.org>

gcc/testsuite/ChangeLog:

	PR tree-optimization/91624
	* gcc.dg/tree-ssa/sra-17.c: xfail all scan-tree-dump-times
	checks on hppa*64*-*-*.
	* gcc.dg/tree-ssa/sra-18.c: Likewise.
2024-01-16 19:32:56 +00:00
Wilco Dijkstra
a0d16e1c06 AArch64: Add -mcpu=cobalt-100
Add support for -mcpu=cobalt-100 (Neoverse N2 with a different implementer ID).

gcc/ChangeLog:
	* config/aarch64/aarch64-cores.def (AARCH64_CORE): Add 'cobalt-100' CPU.
	* config/aarch64/aarch64-tune.md: Regenerated.
	* doc/invoke.texi (-mcpu): Add cobalt-100 core.
2024-01-16 18:20:57 +00:00
Owen Avery
e621b174d7 gccrs: Adjust item kind enums for TupleStructItems and TuplePatternItems
gcc/rust/ChangeLog:

	* hir/tree/rust-hir-pattern.h
	(TupleStructItems::ItemType::RANGE): Rename to...
	(TupleStructItems::ItemType::RANGED): ...here.
	(TupleStructItems::ItemType::NO_RANGE): Rename to...
	(TupleStructItems::ItemType::MULTIPLE): ...here.

	(TuplePatternItems::TuplePatternItemType): Rename to...
	(TuplePatternItems::ItemType): ...here.

	: Handle renames.

	* backend/rust-compile-pattern.cc: Likewise.
	* typecheck/rust-hir-type-check-pattern.cc: Likewise.
	* checks/errors/borrowck/rust-bir-builder-pattern.h: Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-01-16 19:13:15 +01:00
Pierre-Emmanuel Patry
4e554b0dde gccrs: Add a new test for float disambiguation
This new regression test highlight the behavior fixed for float
disambiguation with empty floating point.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:15 +01:00
Pierre-Emmanuel Patry
348f028fc2 gccrs: Fix float lexing and tuple index disambiguation
When a float has a floating point but no value after it, a zero was added
this lead to errors when trying to disambiguate a float into a tuple
index.

gcc/rust/ChangeLog:

	* lex/rust-lex.cc (Lexer::parse_decimal_int_or_float): Remove
	additional zero after empty floating point.
	* parse/rust-parse-impl.h (Parser::left_denotation): Handle float with
	empty floating point.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:15 +01:00
Raiki Tamura
4bd9f1159b gccrs: v0-mangle closures
gcc/rust/ChangeLog:

	* backend/rust-compile-expr.cc (CompileExpr::generate_closure_function):
	Fix reference to node.
	* backend/rust-mangle.cc (struct V0Path): Modified to accept closures.
	(v0_crate_path): Modified to accept closures.
	(v0_closure): New function to mangle closures.
	(v0_path): Modified to accept closures
	* util/rust-mapping-common.h (UNKNOWN_NODEID): Change to UINT32_MAX.
	(UNKNOWN_HIRID): Change to UINT32_MAX.

gcc/testsuite/ChangeLog:

	* rust/compile/v0-mangle2.rs: New test.

Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
2024-01-16 19:13:14 +01:00
Pierre-Emmanuel Patry
4011a8b5a1 gccrs: Move default visitor templates to header
Move default ast visitor template implementation to headers in order to
match the codebase and avoid link errors.

gcc/rust/ChangeLog:

	* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Move from here...
	* ast/rust-ast-visitor.h: ... to here.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:14 +01:00
Pierre-Emmanuel Patry
32f16cac2d gccrs: Move templated functions to header file
Templated functions shall remain in header files to stay in line with the
rest of the codebase.

gcc/rust/ChangeLog:

	* ast/rust-ast-collector.cc (TokenCollector::visit): Move to header
	file.
	(TokenCollector::visit_items_joined_by_separator): Likewise.
	(TokenCollector::visit_as_line): Likewise.
	(TokenCollector::visit_items_as_lines): Likewise.
	(TokenCollector::visit_items_as_block): Likewise.
	* ast/rust-ast-collector.h: Add implementation.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:14 +01:00
Pierre-Emmanuel Patry
513b0154ab gccrs: Rework function special parameters
Make self param and variadic param Param, introduce Param class and make
function parameters param too.
Self can now be represented as a standard parameter and is thus no longer
required as a separate function attribute.
Prevent self pointers and allow self in standard functions during parsing
so they could be rejected at a later stage.

gcc/rust/ChangeLog:

	* ast/rust-ast-collector.cc (TokenCollector::visit): Add visitor for
	VariadicParam and remove Self parameter visitor from Function visit.
	* expand/rust-cfg-strip.cc (CfgStrip::maybe_strip_self_param): Remove
	function.
	(CfgStrip::maybe_strip_trait_method_decl): Remove self parameter visit.
	(CfgStrip::maybe_strip_function_params): Handle new function
	parameters.
	(CfgStrip::visit): Handle VariadicParam, SelfParam and FunctionParam.
	* expand/rust-expand-visitor.cc (ExpandVisitor::expand_self_param):
	Remove function.
	(ExpandVisitor::expand_trait_method_decl): Do not visit self parameter.
	(ExpandVisitor::visit): Add visit for VariadicParam, FunctionParam and
	SelfParam.
	(ExpandVisitor::expand_function_params): Visit parameters instead.
	* expand/rust-expand-visitor.h: Update function prototypes.
	* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Update visit
	with new parameters.
	(ResolveTraitItems::visit): Likewise.
	* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
	Update visit functions with the new visitor functions for VariadicParam
	SelfParam and FunctionParam.
	* resolve/rust-early-name-resolver.h: Update function prototypes.
	* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Update visitor
	according to the new function parameter structures.
	* ast/rust-ast-visitor.h: Update prototypes and add visitor virtual
	functions for SelfParam, FunctionParam and VariadicParam.
	* ast/rust-ast.cc (Function::Function): Move constructor in
	implementation instead of header.
	(Function::operator=): Likewise.
	(Function::as_string): Update function with pointer dereference.
	(VariadicParam::as_string): Likewise.
	(TraitFunctionDecl::as_string): Likewise.
	(TraitMethodDecl::as_string): Likewise.
	(FunctionParam::accept_vis): Add function for visitor.
	(SelfParam::accept_vis): Likewise.
	(VariadicParam::accept_vis): Likewise.
	(TraitItemFunc::TraitItemFunc): Move constructor to implementation
	file.
	(TraitItemFunc::operator=): Likewise.
	(TraitItemMethod::TraitItemMethod): Likewise.
	(TraitItemMethod::operator=): Likewise.
	* ast/rust-item.h (class Function): Remove self optional member.
	(class TraitMethodDecl): Likewise.
	(class TraitFunctionDecl): Likewise.
	(class Param): Add abstract parameter class.
	(class SelfParam): Inherit from Param and remove parameter common
	members.
	(class FunctionParam): Likewise.
	(class VariadicParam): Likewise.
	(struct Visibility): Move structure declaration.
	(class VisItem):  Likewise.
	* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add
	a self parameter check during AST validation.
	* checks/errors/rust-ast-validation.h: Add function prototype.
	* expand/rust-derive-clone.cc (DeriveClone::clone_fn): Update function
	constructor.
	* hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_self): Rework
	function for the new parameters.
	(ASTLoweringBase::visit): Add visit functions for VariadicParam,
	FunctionParam and SelfParam.
	* hir/rust-ast-lower-base.h: Update function prototypes.
	* parse/rust-parse-impl.h (Parser::parse_function): Update function
	according to new function representation.
	(Parser::parse_function_param): Return vector of abstract param instead
	of FunctionParam.
	(Parser::parse_method): Update according to new representation.
	(Parser::parse_trait_item): Likewise.
	(Parser::parse_self_param): Error out with
	self pointers and prevent the lexer from eating regular function
	parameters. Update return type.
	* parse/rust-parse.h: Update function return types.
	* ast/rust-ast-collector.h: Add VariadicParam visit prototype.
	* ast/rust-ast.h (struct Visibility): Move struct declaration.
	(class VisItem): Likewise.
	* ast/rust-expr.h: Update included files.
	* checks/errors/rust-feature-gate.h: Add visitor functions for
	SelfParam, FunctionParam and VariadicParam.
	* expand/rust-cfg-strip.h: Update function prototypes.
	* expand/rust-derive.h: Likewise.
	* hir/rust-ast-lower-implitem.h: Handle special arguments.
	* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Likewise.
	* metadata/rust-export-metadata.cc (ExportContext::emit_function):
	Likewise.
	* resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Add visitor
	functions.
	* resolve/rust-ast-resolve-base.h: Update prototypes.
	* resolve/rust-ast-resolve-stmt.h: Handle new parameter kind.
	* resolve/rust-default-resolver.cc (DefaultResolver::visit): Likewise.
	* resolve/rust-default-resolver.h: Update prototype.
	* util/rust-attributes.cc (AttributeChecker::visit): Add visitor
	functions for SelfParam and VariadicParam.
	* util/rust-attributes.h: Add visit prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:14 +01:00
Pierre-Emmanuel Patry
bbb2472501 gccrs: Add new test for invalid variadics
Highlight invalid variadic filtering through the ast validation checker.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:14 +01:00
Pierre-Emmanuel Patry
e92ae55fea gccrs: Add multiple check on variadics position
Variadics are forbidden alone as well as non final position, this should
be checked during ast validation.

gcc/rust/ChangeLog:

	* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add
	check for additional named argument as well as variadic argument's
	position.
	* checks/errors/rust-ast-validation.h: Add visit function prototype for
	external functions.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:14 +01:00
Pierre-Emmanuel Patry
c1d722aa6f gccrs: Add trait context to ContextualASTVisitor
Some construct are forbidden in trait context (eg. pub, async...) and
we'll need to reject those. To do so we need to identify a trait context.

gcc/rust/ChangeLog:

	* ast/rust-ast-visitor.cc (ContextualASTVisitor::visit): Push the new
	trait context when visiting a trait.
	* ast/rust-ast-visitor.h: Add visit function prototype and TRAIT
	context.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:14 +01:00
Pierre-Emmanuel Patry
119e0be8b6 gccrs: Add regression test for invalid label name
An error message should be emitted when the rust code contains invalid
label name. Add a new test for this behavior.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:14 +01:00
Pierre-Emmanuel Patry
66fc33f665 gccrs: Change error location for LoopLabel
Loop label error reporting during ast validation was done at loop label
level. It lead to some innacurate error reporting in break loop labels
due to the way the label is built.

gcc/rust/ChangeLog:

	* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Change
	reported error location to the lifetime location.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:14 +01:00
Pierre-Emmanuel Patry
93ca83c5ef gccrs: Add validation pass for label name
Prevent from using reserved keyword in label name.

gcc/rust/ChangeLog:

	* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Check if there is
	a label before visit.
	* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Emit an
	error when a label has a forbidden name.
	* checks/errors/rust-ast-validation.h: Add function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:13 +01:00
Pierre-Emmanuel Patry
ea59190d54 gccrs: Use a loop label in break expression
Break expression were using a raw lifetime value instead of a loop label
this behavior would have lead to some errors in ast validation.

gcc/rust/ChangeLog:

	* ast/rust-expr.h (class BreakExpr): Change Lifetime to LoopLabel.
	* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Lower lifetime
	inside the label instead.
	* resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Resolve the
	inner lifetime.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:13 +01:00
Pierre-Emmanuel Patry
b52651427b gccrs: Use keyword const values instead of raw values
Change the keyword values from a raw string value to their matching const
value in utils.

gcc/rust/ChangeLog:

	* lex/rust-lex.cc (Lexer::parse_raw_identifier): Use const value.
	* parse/rust-parse-impl.h (Parser::parse_simple_path_segment):
	Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:13 +01:00
Pierre-Emmanuel Patry
e50b0969b8 gccrs: Change keyword set to a map
Some part of the code requires the token id behind a given keyword, a map
keep the "set" aspect whilst providing this additional feature.

gcc/rust/ChangeLog:

	* lex/rust-lex.cc (RS_TOKEN): Remove local map.
	(RS_TOKEN_KEYWORD): Likewise.
	(Lexer::classify_keyword): Change call to utils.
	* util/rust-keyword-values.cc (get_keywords): Add init function.
	(RS_TOKEN_KEYWORD): Call to X macro.
	* util/rust-keyword-values.h: Change from set to a map.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:13 +01:00
Pierre-Emmanuel Patry
8f41baaa83 gccrs: Replace local keyword set with the utils
We don't require that local set anymore.

gcc/rust/ChangeLog:

	* checks/errors/rust-ast-validation.cc (RS_TOKEN): Remove locale set.
	(RS_TOKEN_KEYWORD): Likewise.
	(ASTValidation::visit): Change keyword set call to the one from utils.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:13 +01:00
Pierre-Emmanuel Patry
0344e23236 gccrs: Add new keyword utility class
Much like attributes values, keywords are known beforehand and never
change. Instead of relying on handcrafted string we could centralize
everything in one place. We may require to check whether a word is a
keyword, which can now be done easily thanks to the keyword set.

gcc/rust/ChangeLog:

	* Make-lang.in: Add rust-keyword-values.cc to the list.
	* util/rust-keyword-values.cc: New file.
	* util/rust-keyword-values.h: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:13 +01:00
Pierre-Emmanuel Patry
65de922f9b gccrs: Add licence text and change header guard name
This file was missing a licence text and it's header guard was not
matching the file name.

gcc/rust/ChangeLog:

	* util/rust-attribute-values.h (RUST_ATTRIBUTES_VALUE_H): Remove old
	header guard.
	(RUST_ATTRIBUTE_VALUES_H): Add new one.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:13 +01:00
Pierre-Emmanuel Patry
ff82ac5541 gccrs: Add regression test for lifetime name validation
Lifetime name are restricted and cannot be keyword, this commit add a
test failing the ast validation pass due to some keyword name.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:13 +01:00
Pierre-Emmanuel Patry
ea4cd6453d gccrs: Add lifetime name validation pass
Add lifetime name check in ast validation visitor.

gcc/rust/ChangeLog:

	* checks/errors/rust-ast-validation.cc (RS_TOKEN): Add keyword set.
	(RS_TOKEN_KEYWORD): Likewise.
	(ASTValidation::visit): Add validation on lifetime visit.
	* checks/errors/rust-ast-validation.h: Add function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:12 +01:00
Owen Avery
6b8365a990 gccrs: Replace AST::Method with existing AST::Function
gcc/rust/ChangeLog:

	* ast/rust-item.h
	(class Method): Remove.
	(Function::self_param): New.
	(Function::has_self_param): New.
	(Function::Function): Initialize self_param.
	(Function::operator=): Likewise.
	(Function::get_self_param): New.
	* ast/rust-ast.cc
	(Method::as_string): Remove.
	(Method::accept_vis): Remove.

	* ast/rust-ast-collector.cc
	(TokenCollector::visit):
	Remove AST::Method visitor, handle self_param in AST::Function visitor.
	* ast/rust-ast-collector.h
	(TokenCollector::visit): Remove AST::Method visitor.
	* ast/rust-ast-full-decls.h (class Method): Remove.

	* ast/rust-ast-visitor.h
	(ASTVisitor::visit): Remove AST::Method visitor.
	(DefaultASTVisitor::visit): Likewise.
	* ast/rust-ast-visitor.cc
	(DefaultASTVisitor::visit):
	Remove AST::Method visitor, handle self_param in AST::Function visitor.

	* checks/errors/rust-feature-gate.cc
	(FeatureGate::visit): Remove AST::Method visitor.
	* checks/errors/rust-feature-gate.h
	(FeatureGate::visit): Likewise..

	* expand/rust-cfg-strip.cc
	(CfgStrip::visit):
	Remove AST::Method visitor, handle self_param in AST::Function visitor.
	* expand/rust-cfg-strip.h
	(CfgStrip::visit): Remove AST::Method visitor.

	* expand/rust-derive-clone.cc
	(DeriveClone::clone_fn): Return AST::Function instead of AST::Method.
	* expand/rust-derive.h (DeriveVisitor::visit): Remove AST::Method visitor.

	* expand/rust-expand-visitor.cc
	(ExpandVisitor::visit):
	Remove AST::Method visitor, handle self_param in AST::Function visitor.
	* expand/rust-expand-visitor.h:
	(ExpandVisitor::visit): Remove AST::Method visitor.

	* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise.
	* hir/rust-ast-lower-base.h (ASTLoweringBase::visit): Likewise.

	* hir/rust-ast-lower-implitem.h
	(ASTLowerImplItem::visit):
	Remove AST::Method visitor, handle self_param in AST::Function visitor.

	* parse/rust-parse-impl.h: Include optional.h.
	(Parser::parse_function): Adjust AST::Function construction.
	(Parser::parse_inherent_impl_function_or_method):
	Construct AST::Function instead of AST::Method,
	adjust AST::Function construction.
	(Parser::parse_trait_impl_function_or_method): Likewise.
	(Parser::parse_method):
	Return std::unique_ptr<AST::Function> instead of AST::Method.

	* parse/rust-parse.h
	(Parser::parse_method): Likewise.

	* resolve/rust-ast-resolve-base.cc
	(ResolverBase::visit): Remove AST::Method visitor.
	* resolve/rust-ast-resolve-base.h
	(ResolverBase::visit): Likewise.

	* resolve/rust-ast-resolve-implitem.h
	(ResolveToplevelImplItem::visit): Likewise.

	* resolve/rust-ast-resolve-item.cc
	(ResolveItem::visit): Remove AST::Method visitor,
	handle self_param in AST::Function visitor.
	* resolve/rust-ast-resolve-item.h
	(ResolveItem::visit): Remove AST::Method visitor.

	* resolve/rust-default-resolver.cc
	(DefaultResolver::visit): Remove AST::Method visitor.
	* resolve/rust-default-resolver.h
	(DefaultResolver::visit): Likewise.

	* resolve/rust-early-name-resolver.cc
	(EarlyNameResolver::visit): Remove AST::Method visitor,
	handle self_param in AST::Function visitor.
	* resolve/rust-early-name-resolver.h
	(EarlyNameResolver::visit): Remove AST::Method visitor.

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

	* util/rust-attributes.cc
	(AttributeChecker::visit): Likewise.
	* util/rust-attributes.h
	(AttributeChecker::visit): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-01-16 19:13:12 +01:00
Pierre-Emmanuel Patry
0df14bb1f3 gccrs: Add named variadic argument test
Variadic arguments may have a name or a pattern. This commit provides two
new tests in order to ensure their correct behavior.

gcc/testsuite/ChangeLog:

	* rust/compile/pattern_variadic.rs: New test.
	* rust/execute/torture/named_variadic.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:12 +01:00
Pierre-Emmanuel Patry
8e3740a25e gccrs: Add a new regression test for named variadics
This test ensure that extern C named variadics are parsed correctly.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:12 +01:00
Pierre-Emmanuel Patry
88e327fa07 gccrs: Parse named variadic parameters
Add ability to parse named variadic parameters in extern c functions.

gcc/rust/ChangeLog:

	* parse/rust-parse-impl.h (Parser::parse_named_function_param): Add
	new parsing ability.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:12 +01:00
Pierre-Emmanuel Patry
39308ab20e gccrs: Add a new regression test
This new test highlight the behavior of the new parser and it's ability
to parse variadic rust functions.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:12 +01:00
Pierre-Emmanuel Patry
2272cfb53e gccrs: Fix multiple issues with variadic representation
The new variadic representation has introduced multiple issues and ICE
into the codebase. Some early passes in the compiler depend on the
parameters all having a type and being an actual parameter.

gcc/rust/ChangeLog:

	* ast/rust-ast.cc (ExternalFunctionItem::as_string): Adapt as_string
	function to the new ast representation.
	(NamedFunctionParam::as_string): Likewise.
	* ast/rust-item.h: Add a function to test whether a FunctionParam has
	a name pattern.
	* expand/rust-cfg-strip.cc (CfgStrip::visit): Adapt cfg strip visitor
	for the new variadic arguments.
	* hir/rust-ast-lower-extern.h: Adapt lowering to the new variadic
	function representation.
	* metadata/rust-export-metadata.cc (ExportContext::emit_function):
	Change call to constructor.
	* parse/rust-parse-impl.h (Parser::parse_named_function_param): Change
	NamedFunctionParam parsing to accomodate new variadic representation.
	(Parser::parse_external_item): Change external item parsing to use the
	new NamedFunctionParam variadics.
	* parse/rust-parse.h: Add new parsing function prototypes.
	* ast/rust-ast-collector.cc (TokenCollector::visit): Rework token
	collection to take into account variadic parameters.
	* ast/rust-ast-visitor.cc: Likewise.
	* expand/rust-expand-visitor.cc (ExpandVisitor::visit): Change function
	bound to avoid getting the type of a variadic parameter.
	* resolve/rust-ast-resolve-item.cc (ResolveExternItem::visit):
	Likewise.
	* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
	Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:12 +01:00
Pierre-Emmanuel Patry
df4e37c7dc gccrs: Allow variadic NamedFunctionParam
This was made to align NamedFunctionParam with FunctionParam.

gcc/rust/ChangeLog:

	* ast/rust-item.h (class NamedFunctionParam): Add variadic boolean and
	another constructor.
	* hir/rust-ast-lower-extern.h: Avoid last parameter when variadic.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:12 +01:00
Pierre-Emmanuel Patry
41f480d16d gccrs: Add a function to check if a function is variadic
This function provides an easy way to check for a function's varidicity.

gcc/rust/ChangeLog:

	* ast/rust-item.h: Add a getter to check if a given function is
	variadic.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:12 +01:00
Pierre-Emmanuel Patry
6ac7d47338 gccrs: Parse variadic functions
Variadic functions were not parsed because it is an unstable feature.
While it is still unstable, it is required in order to parse libcore.

gcc/rust/ChangeLog:

	* parse/rust-parse-impl.h (Parser::parse_function_param): Parse
	variadic functions.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:11 +01:00
Pierre-Emmanuel Patry
f1cca5671f gccrs: Change FunctionParam to represent variadic params
Variadic were represented at the function level while retaining most
informations of a given parameter.

gcc/rust/ChangeLog:

	* ast/rust-item.h (class FunctionParam): Add some informations to
	function parameters in order to be able to store variadic argument as
	a function parameter.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:11 +01:00
Pierre-Emmanuel Patry
59bd1fc1a4 gccrs: Add a new test for const without body
This new regression test highlight the fixed behavior for 2709.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:11 +01:00
Pierre-Emmanuel Patry
222f27d3ac gccrs: Make use of the Contextual visitor in validation
Use the new contextual ast visitor to reduce the amount of code in the
ast validation visitor.

gcc/rust/ChangeLog:

	* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Adapt
	the call to the new visit functions.
	(ASTValidation::check): Launch the parent class visitor root function.
	* checks/errors/rust-ast-validation.h (class ASTValidation): Inherit
	from the contextual visitor.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:11 +01:00
Pierre-Emmanuel Patry
ddcd4c9675 gccrs: Add a new visitor that gathers context information
This visitor is intended to be used by other visitors that require
context at some point for a given item.

gcc/rust/ChangeLog:

	* ast/rust-ast-visitor.cc (ContextualASTVisitor::visit): Add multiple
	context saving calls.
	* ast/rust-ast-visitor.h (class DefaultASTVisitor): Make visit
	functions virtual.
	(class ContextualASTVisitor): Add a stack like container for the
	current context chain.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:11 +01:00
Pierre-Emmanuel Patry
5a9c2732d5 gccrs: Add a default AST visitor
This will allow us to derive other visitors from it and overload only a
few selected visit methods.

gcc/rust/ChangeLog:

	* Make-lang.in: Add the new visitor object file.
	* ast/rust-ast-visitor.h (class DefaultASTVisitor): Create the default
	visitor class.
	* ast/rust-ast.h: Add a new reference getter for visitor pattern.
	* ast/rust-ast-visitor.cc: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:11 +01:00
Pierre-Emmanuel Patry
7065e2dbfe gccrs: Add some reference getter
Visitor pattern requires a getter to children using a mutable reference.

gcc/rust/ChangeLog:

	* ast/rust-ast.h: Add some missing mutable reference getters.
	* ast/rust-expr.h: Likewise.
	* ast/rust-item.h: Likewise.
	* ast/rust-path.h: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:11 +01:00
Pierre-Emmanuel Patry
863174590a gccrs: Small fix to the ast collector visitor
The parameter type was used instead of the default value.

gcc/rust/ChangeLog:

	* ast/rust-ast-collector.cc (TokenCollector::visit): Check for presence
	of a type and use the default value instead of the type.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:11 +01:00
Pierre-Emmanuel Patry
cb9ecb5596 gccrs: Emit an error on associated const without values
Associated const with no value that are not in trait impl are prohibited.

gcc/rust/ChangeLog:

	* checks/errors/rust-ast-validation.cc (ASTValidation::check): Launch
	check over the whole given crate.
	(ASTValidation::visit): Implement visitor for some members of the ast.
	* checks/errors/rust-ast-validation.h: Update some prototype according
	to implemented visitor functions. Also add a context tracker.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:11 +01:00
Pierre-Emmanuel Patry
3fa7df6885 gccrs: Add call to ast validation checker
Add call to ast validation check, also add appropriate step to this pass
and the feature gating.

gcc/rust/ChangeLog:

	* rust-session-manager.cc (Session::compile_crate): Add call to ast
	validation.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:10 +01:00
Pierre-Emmanuel Patry
cdf2cd9af4 gccrs: Add two new steps to compile process
Add the ast validation and feature gating steps to the compile pipeline.

gcc/rust/ChangeLog:

	* lang.opt: Add the new compile options and update the enum values.
	* rust-session-manager.h (struct CompileOptions): Add the new steps to
	the enumeration.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:10 +01:00
Pierre-Emmanuel Patry
f24d408342 gccrs: Add ast validation checker
Add a new visitor to validate a given ast after the expansion pass.

gcc/rust/ChangeLog:

	* Make-lang.in: Add the new object file the list.
	* checks/errors/rust-ast-validation.cc: New file.
	* checks/errors/rust-ast-validation.h: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:10 +01:00
Pierre-Emmanuel Patry
d430d0bac3 gccrs: Add more checks for expr value in early visitors
Early passes visitors may encounter constant item without a value, this
is expected as the pass rejecting a constant without an expression is
done later during the ast validation.

gcc/rust/ChangeLog:

	* expand/rust-cfg-strip.cc (CfgStrip::visit): Add expr value check.
	* expand/rust-expand-visitor.cc (ExpandVisitor::visit): Likewise.
	* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
	Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:13:10 +01:00
Pierre-Emmanuel Patry
55bfecc95a gccrs: Move SingleASTNode implementation out of header
Those functions implementation put additional constraints on the headers
which makes the codebase harder to work with.

gcc/rust/ChangeLog:

	* ast/rust-ast.h: Move implementation from here...
	* ast/rust-ast.cc (SingleASTNode::SingleASTNode): ...to here.
	(SingleASTNode::operator=): ...and here...
	(SingleASTNode::accept_vis): ...and here...
	(SingleASTNode::is_error): ...and here...
	(SingleASTNode::as_string): ...also here.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:09:36 +01:00
Pierre-Emmanuel Patry
74ef5529c8 gccrs: Add missing override specifier
Some function lacked the override specifier, this made the compiler emit
several warning.

gcc/rust/ChangeLog:

	* ast/rust-ast.h: Add override specifier.
	* ast/rust-item.h: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:09:36 +01:00
Pierre-Emmanuel Patry
f522eefcfd gccrs: Add regression test for float literal tuple indices
Add a new regression test in order to highlight the fix for #2659.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:09:36 +01:00
Pierre-Emmanuel Patry
311121156e gccrs: Fix token lexed as a float literal
The lexer cannot distinguish the difference between a float literal and a
tuple index in some cases. This means we should fix this while parsing
depending on the context.

gcc/rust/ChangeLog:

	* expand/rust-macro-invoc-lexer.cc (MacroInvocLexer::split_current_token):
	Add implementation for multiple token split.
	* expand/rust-macro-invoc-lexer.h: Add function prototype.
	* expand/rust-proc-macro-invoc-lexer.cc (ProcMacroInvocLexer::split_current_token):
	Add implementation for 2+ token split for procedural macros.
	* expand/rust-proc-macro-invoc-lexer.h: Add function prototype.
	* lex/rust-lex.cc (Lexer::split_current_token): Add function to split a
	token in multiple other tokens.
	* lex/rust-lex.h: Add function prototype for split_current_token.
	* parse/rust-parse-impl.h (Parser::left_denotation): Handle float tuple
	index identified as a float literal.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:09:35 +01:00
Jakub Dupak
80bdb1a85a gccrs: HIR: remove obsole double borrow member
gcc/rust/ChangeLog:

	* hir/rust-hir-dump.cc (Dump::visit): Remove obsolete member.
	* hir/tree/rust-hir-expr.h (class BorrowExpr): Remove obsolete member.
	* hir/tree/rust-hir.cc (BorrowExpr::as_string): Remove obsolete member.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-01-16 19:09:35 +01:00