]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
18 months agogccrs: Unify raw attribute values
Pierre-Emmanuel Patry [Fri, 1 Sep 2023 11:14:09 +0000 (13:14 +0200)] 
gccrs: Unify raw attribute values

Attribute values were used as raw string, this is error prone and
makes renaming harder. Using a constexpr instead will leverage the power
of the compiler and emit an error when an incorrect builtin attribute
value is used.

gcc/rust/ChangeLog:

* ast/rust-ast.cc (Attribute::check_cfg_predicate): Change raw
string to constexpr call.
(Attribute::separate_cfg_attrs): Likewise.
* backend/rust-compile-base.cc (should_mangle_item): Likewise.
(HIRCompileBase::setup_fndecl): Likewise.
(HIRCompileBase::handle_cold_attribute_on_fndecl): Likewise.
* checks/errors/privacy/rust-privacy-reporter.cc (find_proc_macro_attribute):
Likewise.
* checks/errors/rust-unsafe-checker.cc (check_target_attr):
Likewise.
* expand/rust-cfg-strip.cc (fails_cfg): Likewise.
(fails_cfg_with_expand): Likewise.
(expand_cfg_attrs): Likewise.
* expand/rust-macro-builtins.cc: Likewise.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::handle_outer_attributes): Likewise.
(ASTLoweringBase::lower_macro_definition): Likewise.
* hir/rust-hir-dump.cc (Dump::visit): Likewise.
* parse/rust-parse-impl.h (Parser::parse_doc_comment): Likewise.
* parse/rust-parse.cc (extract_module_path): Likewise.
* resolve/rust-early-name-resolver.cc (is_macro_use_module):
Likewise.
(EarlyNameResolver::visit): Likewise.
* resolve/rust-toplevel-name-resolver-2.0.cc (is_macro_export):
Likwise.
* rust-session-manager.cc (Session::injection): Likewise.
* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::parse_repr_options): Likewise.
* util/rust-attributes.cc (is_proc_macro_type): Likewise.
(AttributeChecker::check_attribute): Likewise.
(AttributeChecker::visit): Likewise.
* util/rust-hir-map.cc (Mappings::insert_macro_def): Likewise.
* util/rust-attribute-values.h: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Remove Gcc_backend
Owen Avery [Mon, 4 Sep 2023 18:09:10 +0000 (14:09 -0400)] 
gccrs: Remove Gcc_backend

gcc/rust/ChangeLog:

* rust-backend.h
(Backend::Backend): New.
(Backend::~Backend): Remove.
(class Gcc_backend): Remove.
* rust-gcc.cc
(Gcc_backend::Gcc_backend): Rename to ...
(Backend::Backend): ... here.
(rust_get_backend): Construct Backend instead of Gcc_backend.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Add missing linemap to lexer
Pierre-Emmanuel Patry [Tue, 29 Aug 2023 15:24:03 +0000 (17:24 +0200)] 
gccrs: Add missing linemap to lexer

When some proc macro create tokens and later have some code referring to
those created tokens the code was missing a linemap since the pointer
was null, throwing an ICE.

gcc/rust/ChangeLog:

* expand/rust-proc-macro.cc (tokenstream_from_string): Change
linemap null pointer to the current linemap.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Add proc macro definition insertion
Pierre-Emmanuel Patry [Tue, 29 Aug 2023 14:49:31 +0000 (16:49 +0200)] 
gccrs: Add proc macro definition insertion

Insert proc macro definition from extern crates.

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit):
Add proc macro definition insertion.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Change proc macro mapping definition insertion
Pierre-Emmanuel Patry [Tue, 29 Aug 2023 14:41:55 +0000 (16:41 +0200)] 
gccrs: Change proc macro mapping definition insertion

Since the node id already is contained into the proc macro we may omit
it from the function arguments.

gcc/rust/ChangeLog:

* util/rust-hir-map.cc (Mappings::insert_derive_proc_macro_def):
Change the function body to fetch the node id from the macro
parameter.
(Mappings::insert_bang_proc_macro_def): Likewise.
(Mappings::insert_attribute_proc_macro_def): Likewise.
* util/rust-hir-map.h: Update the function's prototype by
removing the node id from the list of arguments.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Retrieve def for derive & attribute proc macros
Pierre-Emmanuel Patry [Tue, 29 Aug 2023 13:59:58 +0000 (15:59 +0200)] 
gccrs: Retrieve def for derive & attribute proc macros

Add definition retrieval for derive and attribute proc macro types.

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc (Early::visit_attributes):
Add proc macro handle retrieval for attribute and derive proc macros.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Change proc macro definition lookup to optionals
Pierre-Emmanuel Patry [Tue, 29 Aug 2023 13:02:21 +0000 (15:02 +0200)] 
gccrs: Change proc macro definition lookup to optionals

Continue changing the api to use optionals instead of bools and double
pointers.

gcc/rust/ChangeLog:

* util/rust-hir-map.cc (Mappings::lookup_derive_proc_macro_def):
Update function to accomodate new signature.
(Mappings::lookup_bang_proc_macro_def): Likewise.
(Mappings::lookup_attribute_proc_macro_def): Likewise.
* util/rust-hir-map.h: Update function signatures.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Use optional for proc macro invocation lookup
Pierre-Emmanuel Patry [Tue, 29 Aug 2023 12:42:02 +0000 (14:42 +0200)] 
gccrs: Use optional for proc macro invocation lookup

The old interface for those mappings was clunky at best. Now we can use
the optional structure to return a reference to the instance.

gcc/rust/ChangeLog:

* expand/rust-macro-expand.h (struct MacroExpander): Update
lookup function prototypes.
* util/rust-hir-map.cc (Mappings::lookup_derive_proc_macro_invocation):
Update lookup function according to new signature.
(Mappings::lookup_bang_proc_macro_invocation): Likewise.
(Mappings::lookup_attribute_proc_macro_invocation): Likewise.
* util/rust-hir-map.h: Update function prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Remove Backend::write_export_data
Owen Avery [Mon, 4 Sep 2023 18:23:10 +0000 (14:23 -0400)] 
gccrs: Remove Backend::write_export_data

gcc/rust/ChangeLog:

* rust-backend.h
(Backend::write_export_data): Remove.
* rust-gcc.cc
(Backend::write_export_data): Remove.

18 months agogccrs: Move remaining expression-related methods into base class Backend
Owen Avery [Thu, 31 Aug 2023 21:25:55 +0000 (17:25 -0400)] 
gccrs: Move remaining expression-related methods into base class Backend

gcc/rust/ChangeLog:

* rust-backend.h
(Backend::real_part_expression): Make non-virtual.
(Backend::imag_part_expression): Likewise.
(Backend::complex_expression): Likewise.
(Backend::convert_expression): Likewise.
(Backend::struct_field_expression): Likewise.
(Backend::compound_expression): Likewise.
(Backend::conditional_expression): Likewise.
(Backend::negation_expression): Likewise.
(Backend::arithmetic_or_logical_expression): Likewise.
(Backend::arithmetic_or_logical_expression_checked): Likewise.
(Backend::comparison_expression): Likewise.
(Backend::lazy_boolean_expression): Likewise.
(Backend::constructor_expression): Likewise.
(Backend::array_constructor_expression): Likewise.
(Backend::array_initializer): Likewise.
(Backend::array_index_expression): Likewise.
(Backend::call_expression): Likewise.

(Gcc_backend::real_part_expression): Remove.
(Gcc_backend::imag_part_expression): Remove.
(Gcc_backend::complex_expression): Remove.
(Gcc_backend::convert_expression): Remove.
(Gcc_backend::struct_field_expression): Remove.
(Gcc_backend::compound_expression): Remove.
(Gcc_backend::conditional_expression): Remove.
(Gcc_backend::negation_expression): Remove.
(Gcc_backend::arithmetic_or_logical_expression): Remove.
(Gcc_backend::arithmetic_or_logical_expression_checked): Remove.
(Gcc_backend::comparison_expression): Remove.
(Gcc_backend::lazy_boolean_expression): Remove.
(Gcc_backend::constructor_expression): Remove.
(Gcc_backend::array_constructor_expression): Remove.
(Gcc_backend::array_initializer): Remove.
(Gcc_backend::array_index_expression): Remove.
(Gcc_backend::call_expression): Remove.
* rust-gcc.cc
(Gcc_backend::real_part_expression): Rename to ...
(Backend::real_part_expression): ... here.
(Gcc_backend::imag_part_expression): Rename to ...
(Backend::imag_part_expression): ... here.
(Gcc_backend::complex_expression): Rename to ...
(Backend::complex_expression): ... here.
(Gcc_backend::convert_expression): Rename to ...
(Backend::convert_expression): ... here.
(Gcc_backend::struct_field_expression): Rename to ...
(Backend::struct_field_expression): ... here.
(Gcc_backend::compound_expression): Rename to ...
(Backend::compound_expression): ... here.
(Gcc_backend::conditional_expression): Rename to ...
(Backend::conditional_expression): ... here.
(Gcc_backend::negation_expression): Rename to ...
(Backend::negation_expression): ... here.
(Gcc_backend::arithmetic_or_logical_expression): Rename to ...
(Backend::arithmetic_or_logical_expression): ... here.
(Gcc_backend::arithmetic_or_logical_expression_checked): Rename to ...
(Backend::arithmetic_or_logical_expression_checked): ... here.
(Gcc_backend::comparison_expression): Rename to ...
(Backend::comparison_expression): ... here.
(Gcc_backend::lazy_boolean_expression): Rename to ...
(Backend::lazy_boolean_expression): ... here.
(Gcc_backend::constructor_expression): Rename to ...
(Backend::constructor_expression): ... here.
(Gcc_backend::array_constructor_expression): Rename to ...
(Backend::array_constructor_expression): ... here.
(Gcc_backend::array_initializer): Rename to ...
(Backend::array_initializer): ... here.
(Gcc_backend::array_index_expression): Rename to ...
(Backend::array_index_expression): ... here.
(Gcc_backend::call_expression): Rename to ...
(Backend::call_expression): ... here.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Clarify package import procedure
Pierre-Emmanuel Patry [Mon, 4 Sep 2023 10:19:13 +0000 (12:19 +0200)] 
gccrs: Clarify package import procedure

This part of the code is a bit tricky as it calls multiple functions
with almost the same name and slightly different behaviors. It was even
more with a meaningless variable name.

gcc/rust/ChangeLog:

* rust-session-manager.cc (Session::load_extern_crate): Change
variable name, add temporaries and comments.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: resolver: Refactor macro insertion
Pierre-Emmanuel Patry [Mon, 28 Aug 2023 09:39:44 +0000 (11:39 +0200)] 
gccrs: resolver: Refactor macro insertion

Add a templated function to insert any of the three kind of proc macro
into the resolver context.

gcc/rust/ChangeLog:

* expand/rust-proc-macro.h: Change get_trait_name to get_name in
order to be coherent with the others proc macro type name
convention.
* resolve/rust-toplevel-name-resolver-2.0.cc (insert_macros):
Add a templated funtion that inserts a proc macro into the
context and emit an error on failure.
(TopLevel::visit): Change from manual insertion to a function
call.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: resolver: Refactor assertion
Pierre-Emmanuel Patry [Mon, 28 Aug 2023 08:54:12 +0000 (10:54 +0200)] 
gccrs: resolver: Refactor assertion

Change the condition with rust_unreachable to an assertion. This will
keep the code clean and concise.
Some styling issues appeared during review, this commit make the code
more readable.

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit):
Change to assertion.
* util/rust-hir-map.cc (Mappings::lookup_derive_proc_macros):
Add empty line.
(Mappings::lookup_bang_proc_macros): Likewise.
(Mappings::lookup_attribute_proc_macros): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Move extern crate resolving
Pierre-Emmanuel Patry [Wed, 2 Aug 2023 14:57:09 +0000 (16:57 +0200)] 
gccrs: Move extern crate resolving

Move extern crate resolving under the extern crate declaration instead
of doing it under the crate's root as extern crates are not resolved by
the top level resolver.

gcc/rust/ChangeLog:

* metadata/rust-extern-crate.cc (ExternCrate::ExternCrate):
Update definition to allow Extern crate with no content (pure
proc macros).
(ExternCrate::ok): Panic on no content.
(ExternCrate::load): Likewise.
* metadata/rust-extern-crate.h: Update prototypes.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::go):
Remove macro resolution.
(TopLevel::visit): Likewise.
* resolve/rust-toplevel-name-resolver-2.0.h: Add visit prototype
for extern crate.
* rust-session-manager.cc (Session::load_extern_crate): Adapt
content depending on the loaded crate's content.
* util/rust-hir-map.cc (Mappings::lookup_derive_proc_macros):
Change return type to optional because it is way more
convenient.
(Mappings::lookup_bang_proc_macros): Likewise.
(Mappings::lookup_attribute_proc_macros): Likewise.
* util/rust-hir-map.h: Update function prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Supress error with proc macro crates
Pierre-Emmanuel Patry [Tue, 1 Aug 2023 16:32:46 +0000 (18:32 +0200)] 
gccrs: Supress error with proc macro crates

This error was emitted when a valid proc macro crate was loaded. Proc
macros do not contain any import data for now.

gcc/rust/ChangeLog:

* metadata/rust-imports.cc (Import::try_package_in_directory):
Remove error when some macro are found even if no import data is
available.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Move proc macro definition to mappings
Pierre-Emmanuel Patry [Tue, 1 Aug 2023 15:42:45 +0000 (17:42 +0200)] 
gccrs: Move proc macro definition to mappings

This commit moves the procedural macros loaded definition from outside
the AST to the mappings. This means most getters/setters around the
mappings had to be changed. This commit also introduces the top level
visit of those mappings instead of visiting the Crate ast members.

gcc/rust/ChangeLog:

* ast/rust-ast.h (class BangProcMacro): Move class from here to
rust-proc-macro.h. Also remove related functions.
(class AttributeProcMacro): Likewise.
(class CustomDeriveProcMacro): Likewise.
(struct Crate): Remove proc macro vector members.
* expand/rust-macro-expand.h (struct MacroExpander): Change the
type to the newly created classes.
* expand/rust-proc-macro.cc (BangProcMacro::BangProcMacro): Add
constructor implementation.
(AttributeProcMacro::AttributeProcMacro): Likewise.
(CustomDeriveProcMacro::CustomDeriveProcMacro): Likewise.
* expand/rust-proc-macro.h (class BangProcMacro): Move class to
here.
(class AttributeProcMacro): Likewise.
(class CustomDeriveProcMacro): Likewise.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::go):
Change top level visitor to check mappings instead
* rust-session-manager.cc (Session::load_extern_crate):
Add back macro collection to mappings.
* util/rust-hir-map.cc (Mappings::insert_derive_proc_macros):
Update getter signature with new types.
(Mappings::insert_bang_proc_macros): Likewise.
(Mappings::insert_attribute_proc_macros): Likewise.
(Mappings::lookup_derive_proc_macros): Likewise.
(Mappings::lookup_bang_proc_macros): Likewise.
(Mappings::lookup_attribute_proc_macros): Likewise.
(Mappings::insert_derive_proc_macro_def): Likewise.
(Mappings::insert_bang_proc_macro_def): Likewise.
(Mappings::insert_attribute_proc_macro_def): Likewise.
(Mappings::lookup_derive_proc_macro_def): Likewise.
(Mappings::lookup_bang_proc_macro_def): Likewise.
(Mappings::lookup_attribute_proc_macro_def): Likewise.
(Mappings::insert_derive_proc_macro_invocation): Likewise.
(Mappings::lookup_derive_proc_macro_invocation): Likewise.
(Mappings::insert_bang_proc_macro_invocation): Likewise.
(Mappings::lookup_bang_proc_macro_invocation): Likewise.
(Mappings::insert_attribute_proc_macro_invocation): Likewise.
(Mappings::lookup_attribute_proc_macro_invocation): Likewise.
* util/rust-hir-map.h: Update function prototypes as well as map
types.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Add proc macro top level discovery
Pierre-Emmanuel Patry [Tue, 1 Aug 2023 10:45:11 +0000 (12:45 +0200)] 
gccrs: Add proc macro top level discovery

Add mechanism to discover proc macros in loaded extern crates. In the
top level resolver.

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::go):
Visit crate's newly stored proc macros.
* rust-session-manager.cc (Session::load_extern_crate):
Store proc macros in the parsed crate instead of a local
variable to achieve mappings.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Change early resolver visit_attributes arguments
Pierre-Emmanuel Patry [Tue, 1 Aug 2023 10:43:27 +0000 (12:43 +0200)] 
gccrs: Change early resolver visit_attributes arguments

We do not need to copy the whole vector we can simply take a reference
instead.

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc (Early::visit_attributes):
Change argument to reference.
* resolve/rust-early-name-resolver-2.0.h: Update function
prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Add getters for different types of proc macros
Pierre-Emmanuel Patry [Tue, 1 Aug 2023 09:20:00 +0000 (11:20 +0200)] 
gccrs: Add getters for different types of proc macros

Add some getters on the ast crate in order to be able to retrieve a
reference to a crate's proc macros.

gcc/rust/ChangeLog:

* ast/rust-ast.h: Add getters.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Add proc macros abstractions to crate structure
Pierre-Emmanuel Patry [Mon, 31 Jul 2023 16:31:51 +0000 (18:31 +0200)] 
gccrs: Add proc macros abstractions to crate structure

Add multiple setters for a crate object in order to add macro
abstractions previously introduced.

gcc/rust/ChangeLog:

* ast/rust-ast.h (struct Crate): Add proc macro members.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Add proc macro ast representation
Pierre-Emmanuel Patry [Mon, 31 Jul 2023 16:26:40 +0000 (18:26 +0200)] 
gccrs: Add proc macro ast representation

When resolving proc macros it is convenient to store every macro
directly in the extern crate. These class in the ast module provide a
better abstraction over the raw ProcMacro::{CustomDerive, Bang,
Attribute} structures provided by the proc_macro library.

gcc/rust/ChangeLog:

* ast/rust-ast.h (class BangProcMacro): Add new proc macro
abstraction.
(class AttributeProcMacro): Likewise.
(class CustomDeriveProcMacro): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Visit function and structure attributes
Pierre-Emmanuel Patry [Mon, 31 Jul 2023 13:29:36 +0000 (15:29 +0200)] 
gccrs: Visit function and structure attributes

Add a simple attribute visit function and override StructStruct &
Function visit functions.

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc (Early::visit_attributes):
Add function to handle attributes.
(Early::visit): Override visitor functions.
* resolve/rust-early-name-resolver-2.0.h: Add prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Parse unparsed derive tokenstreams
Pierre-Emmanuel Patry [Mon, 31 Jul 2023 13:10:41 +0000 (15:10 +0200)] 
gccrs: Parse unparsed derive tokenstreams

Derive attributes should be parsed before attempting to retrieve any
traits. This will convert the tokenstream to a list of path if this
hasn't been done previously.

gcc/rust/ChangeLog:

* ast/rust-ast.cc (Attribute::get_traits_to_derive): Convert
tokenstream to path list.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Ease some constraints on derive definition
Pierre-Emmanuel Patry [Mon, 31 Jul 2023 11:08:06 +0000 (13:08 +0200)] 
gccrs: Ease some constraints on derive definition

Member function is_derive was overly constrained, the attribute changes
when we parse it's meta items and it no longer contains a tokenstream
while staying a derive.

gcc/rust/ChangeLog:

* ast/rust-ast.cc (Attribute::is_derive): Remove tokenstream
condition.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Change trait getter to return references
Pierre-Emmanuel Patry [Mon, 31 Jul 2023 10:31:58 +0000 (12:31 +0200)] 
gccrs: Change trait getter to return references

Having copy and any other constructor stuff might lead to a breakage in
the future where the node id differs due to a newly constructed
SimplePath node. This change will allow us to assert the NodeId is from
the ast and not any copy made in between.

gcc/rust/ChangeLog:

* ast/rust-ast.cc (Attribute::get_traits_to_derive): Change
return type to a vector of references.
* ast/rust-ast.h: Update constructor.
* expand/rust-expand-visitor.cc (ExpandVisitor::expand_inner_stmts):
Update function call.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Set traits getter as member function
Pierre-Emmanuel Patry [Fri, 28 Jul 2023 15:55:55 +0000 (17:55 +0200)] 
gccrs: Set traits getter as member function

This function will be used outside of the expand visitor, making it
easily accessible is therefore mandatory.

gcc/rust/ChangeLog:

* ast/rust-ast.cc (Attribute::get_traits_to_derive): Add
function as member function.
* ast/rust-ast.h: Add prototype.
* expand/rust-expand-visitor.cc (get_traits_to_derive): Remove
function.
(ExpandVisitor::expand_inner_stmts): Update function call.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Make is_builtin a member function
Pierre-Emmanuel Patry [Fri, 28 Jul 2023 15:26:50 +0000 (17:26 +0200)] 
gccrs: Make is_builtin a member function

This function will be used in the multiple other places, therefore we
should make it easily usable from there.

gcc/rust/ChangeLog:

* ast/rust-ast.cc (Attribute::is_derive): Add member function.
* ast/rust-ast.h: Likewise.
* expand/rust-expand-visitor.cc (is_derive): Remove old
function.
(ExpandVisitor::expand_inner_stmts): Update function call.
(ExpandVisitor::visit_inner_using_attrs): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Fix match-expression code-gen
Philip Herron [Mon, 4 Sep 2023 14:28:46 +0000 (15:28 +0100)] 
gccrs: Fix match-expression code-gen

We were massing the match scruitinee expression as a way to access the
result of the expression. This is wrong and needs to be stored in a
temporary otherwise it will cause the code to be regnerated for each time
it is used. This is not an issue in the case where the expression is only
used once.

Fixes #1895

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): use a temp for the value

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: Move block-related methods into base class Backend
Owen Avery [Thu, 31 Aug 2023 19:58:22 +0000 (15:58 -0400)] 
gccrs: Move block-related methods into base class Backend

gcc/rust/ChangeLog:

* rust-backend.h
(Backend::block): Make non-virtual.
(Backend::block_add_statements): Likewise.

(Gcc_backend::block): Remove.
(Gcc_backend::block_add_statements): Remove.
* rust-gcc.cc
(Gcc_backend::block): Rename to ...
(Backend::block): ... here.
(Gcc_backend::block_add_statements): Rename to ...
(Backend::block_add_statements): ... here.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: libproc_macro: Split c++ and rust
Pierre-Emmanuel Patry [Mon, 28 Aug 2023 15:20:28 +0000 (17:20 +0200)] 
gccrs: libproc_macro: Split c++ and rust

Move the rust interface to the libproc_macro directory.

libgrust/ChangeLog:

* libproc_macro_internal/rust/bridge.rs: Moved to...
* libproc_macro/bridge.rs: ...here.
* libproc_macro_internal/rust/bridge/ffistring.rs: Moved to...
* libproc_macro/bridge/ffistring.rs: ...here.
* libproc_macro_internal/rust/bridge/group.rs: Moved to...
* libproc_macro/bridge/group.rs: ...here.
* libproc_macro_internal/rust/bridge/ident.rs: Moved to...
* libproc_macro/bridge/ident.rs: ...here.
* libproc_macro_internal/rust/bridge/literal.rs: Moved to...
* libproc_macro/bridge/literal.rs: ...here.
* libproc_macro_internal/rust/bridge/punct.rs: Moved to...
* libproc_macro/bridge/punct.rs: ...here.
* libproc_macro_internal/rust/bridge/span.rs: Moved to...
* libproc_macro/bridge/span.rs: ...here.
* libproc_macro_internal/rust/bridge/token_stream.rs: Moved to...
* libproc_macro/bridge/token_stream.rs: ...here.
* libproc_macro_internal/rust/group.rs: Moved to...
* libproc_macro/group.rs: ...here.
* libproc_macro_internal/rust/ident.rs: Moved to...
* libproc_macro/ident.rs: ...here.
* libproc_macro_internal/rust/lib.rs: Moved to...
* libproc_macro/lib.rs: ...here.
* libproc_macro_internal/rust/literal.rs: Moved to...
* libproc_macro/literal.rs: ...here.
* libproc_macro_internal/rust/punct.rs: Moved to...
* libproc_macro/punct.rs: ...here.
* libproc_macro_internal/rust/span.rs: Moved to...
* libproc_macro/span.rs: ...here.
* libproc_macro_internal/rust/token_stream.rs: Moved to...
* libproc_macro/token_stream.rs: ...here.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Rename libproc_macro to libproc_macro_internal
Pierre-Emmanuel Patry [Mon, 28 Aug 2023 15:08:40 +0000 (17:08 +0200)] 
gccrs: Rename libproc_macro to libproc_macro_internal

The name was a bit misleading since libproc_macro is a rust library that
should we should be able to link against some rust code. This cpp
library was the layer below the libproc_macro library, the "real" gcc
libproc_macro act as a translation layer for the internal library.

gcc/rust/ChangeLog:

* expand/rust-macro-expand.h: Change include directive with the
new name.
* expand/rust-proc-macro.h (RUST_PROC_MACRO_H): Likewise.
* util/rust-hir-map.h: Likewise.
* util/rust-token-converter.h: Likewise.
* util/rust-token-converter.cc: Remove useless include
directive.
* Make-lang.in: Rename library.

libgrust/ChangeLog:

* Makefile.am: Change library name.
* Makefile.in: Likewise.
* configure.ac: Likewise.
* configure: Regenerate.
* libproc_macro/Makefile.am: Moved to...
* libproc_macro_internal/Makefile.am: ...here.
* libproc_macro/Makefile.in: Moved to...
* libproc_macro_internal/Makefile.in: ...here.
* libproc_macro/bridge.h: Moved to...
* libproc_macro_internal/bridge.h: ...here.
* libproc_macro/ffistring.cc: Moved to...
* libproc_macro_internal/ffistring.cc: ...here.
* libproc_macro/ffistring.h: Moved to...
* libproc_macro_internal/ffistring.h: ...here.
* libproc_macro/group.cc: Moved to...
* libproc_macro_internal/group.cc: ...here.
* libproc_macro/group.h: Moved to...
* libproc_macro_internal/group.h: ...here.
* libproc_macro/ident.cc: Moved to...
* libproc_macro_internal/ident.cc: ...here.
* libproc_macro/ident.h: Moved to...
* libproc_macro_internal/ident.h: ...here.
* libproc_macro/literal.cc: Moved to...
* libproc_macro_internal/literal.cc: ...here.
* libproc_macro/literal.h: Moved to...
* libproc_macro_internal/literal.h: ...here.
* libproc_macro/proc_macro.cc: Moved to...
* libproc_macro_internal/proc_macro.cc: ...here.
* libproc_macro/proc_macro.h: Moved to...
* libproc_macro_internal/proc_macro.h: ...here.
* libproc_macro/punct.cc: Moved to...
* libproc_macro_internal/punct.cc: ...here.
* libproc_macro/punct.h: Moved to...
* libproc_macro_internal/punct.h: ...here.
* libproc_macro/registration.h: Moved to...
* libproc_macro_internal/registration.h: ...here.
* libproc_macro/rust/bridge.rs: Moved to...
* libproc_macro_internal/rust/bridge.rs: ...here.
* libproc_macro/rust/bridge/ffistring.rs: Moved to...
* libproc_macro_internal/rust/bridge/ffistring.rs: ...here.
* libproc_macro/rust/bridge/group.rs: Moved to...
* libproc_macro_internal/rust/bridge/group.rs: ...here.
* libproc_macro/rust/bridge/ident.rs: Moved to...
* libproc_macro_internal/rust/bridge/ident.rs: ...here.
* libproc_macro/rust/bridge/literal.rs: Moved to...
* libproc_macro_internal/rust/bridge/literal.rs: ...here.
* libproc_macro/rust/bridge/punct.rs: Moved to...
* libproc_macro_internal/rust/bridge/punct.rs: ...here.
* libproc_macro/rust/bridge/span.rs: Moved to...
* libproc_macro_internal/rust/bridge/span.rs: ...here.
* libproc_macro/rust/bridge/token_stream.rs: Moved to...
* libproc_macro_internal/rust/bridge/token_stream.rs: ...here.
* libproc_macro/rust/group.rs: Moved to...
* libproc_macro_internal/rust/group.rs: ...here.
* libproc_macro/rust/ident.rs: Moved to...
* libproc_macro_internal/rust/ident.rs: ...here.
* libproc_macro/rust/lib.rs: Moved to...
* libproc_macro_internal/rust/lib.rs: ...here.
* libproc_macro/rust/literal.rs: Moved to...
* libproc_macro_internal/rust/literal.rs: ...here.
* libproc_macro/rust/punct.rs: Moved to...
* libproc_macro_internal/rust/punct.rs: ...here.
* libproc_macro/rust/span.rs: Moved to...
* libproc_macro_internal/rust/span.rs: ...here.
* libproc_macro/rust/token_stream.rs: Moved to...
* libproc_macro_internal/rust/token_stream.rs: ...here.
* libproc_macro/span.cc: Moved to...
* libproc_macro_internal/span.cc: ...here.
* libproc_macro/span.h: Moved to...
* libproc_macro_internal/span.h: ...here.
* libproc_macro/tokenstream.cc: Moved to...
* libproc_macro_internal/tokenstream.cc: ...here.
* libproc_macro/tokenstream.h: Moved to...
* libproc_macro_internal/tokenstream.h: ...here.
* libproc_macro/tokentree.cc: Moved to...
* libproc_macro_internal/tokentree.cc: ...here.
* libproc_macro/tokentree.h: Moved to...
* libproc_macro_internal/tokentree.h: ...here.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Move statement-related methods into base class Backend
Owen Avery [Thu, 31 Aug 2023 18:53:50 +0000 (14:53 -0400)] 
gccrs: Move statement-related methods into base class Backend

gcc/rust/ChangeLog:

* rust-backend.h
(Backend::init_statement): Make non-virtual.
(Backend::assignment_statement): Likewise.
(Backend::return_statement): Likewise.
(Backend::if_statement): Likewise.
(Backend::loop_expression): Likewise.
(Backend::exit_expression): Likewise.
(Backend::compound_statement): Likewise.
(Backend::statement_list): Likewise.
(Backend::exception_handler_statement): Likewise.

(Gcc_backend::init_statement): Remove.
(Gcc_backend::assignment_statement): Remove.
(Gcc_backend::return_statement): Remove.
(Gcc_backend::if_statement): Remove.
(Gcc_backend::compound_statement): Remove.
(Gcc_backend::statement_list): Remove.
(Gcc_backend::exception_handler_statement): Remove.
(Gcc_backend::loop_expression): Remove.
(Gcc_backend::exit_expression): Remove.
* rust-gcc.cc
(Gcc_backend::init_statement): Rename to ...
(Backend::init_statement): ... here.
(Gcc_backend::assignment_statement): Rename to ...
(Backend::assignment_statement): ... here.
(Gcc_backend::return_statement): Rename to ...
(Backend::return_statement): ... here.
(Gcc_backend::exception_handler_statement): Rename to ...
(Backend::exception_handler_statement): ... here.
(Gcc_backend::if_statement): Rename to ...
(Backend::if_statement): ... here.
(Gcc_backend::loop_expression): Rename to ...
(Backend::loop_expression): ... here.
(Gcc_backend::exit_expression): Rename to ...
(Backend::exit_expression): ... here.
(Gcc_backend::compound_statement): Rename to ...
(Backend::compound_statement): ... here.
(Gcc_backend::statement_list): Rename to ...
(Backend::statement_list): ... here.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Move function-related methods into base class Backend
Owen Avery [Thu, 31 Aug 2023 18:39:27 +0000 (14:39 -0400)] 
gccrs: Move function-related methods into base class Backend

gcc/rust/ChangeLog:

* rust-backend.h
(Backend::function): Make non-virtual.
(Backend::function_defer_statement): Likewise.
(Backend::function_set_parameters): Likewise.
(Backend::write_global_definitions): Likewise.
(Backend::write_export_data): Likewise.

(Gcc_backend::function): Remove.
(Gcc_backend::function_defer_statement): Remove.
(Gcc_backend::function_set_parameters): Remove.
(Gcc_backend::write_global_definitions): Remove.
(Gcc_backend::write_export_data): Remove.
* rust-gcc.cc
(Gcc_backend::function): Rename to ...
(Backend::function): ... here.
(Gcc_backend::function_defer_statement):
Fix a qualified lookup of Backend::label and rename to ...
(Backend::function_defer_statement): ... here.
(Gcc_backend::function_set_parameters) Rename to ...
(Backend::function_set_parameters): ... here.
(Gcc_backend::write_global_definitions): Rename to ...
(Backend::write_global_definitions): ... here.
(Gcc_backend::write_export_data): Rename to ...
(Backend::write_export_data): ... here.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: gccrs:[E0592] methods or associated functions with same name already defined
Muhammad Mahad [Thu, 17 Aug 2023 05:42:52 +0000 (10:42 +0500)] 
gccrs: gccrs:[E0592] methods or associated functions with same name already defined

gcc/rust/ChangeLog:

* typecheck/rust-hir-inherent-impl-overlap.h:
Added rich location and errorcode.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
likewise.

gcc/testsuite/ChangeLog:

* rust/compile/generics7.rs: Added Errorcode hint.
* rust/compile/generics8.rs: Updated dejagnu comment.
* rust/compile/issue-925.rs: Added Errorcode hint.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: [E0532] Pattern arm did not match expected kind
Muhammad Mahad [Sat, 2 Sep 2023 10:18:20 +0000 (15:18 +0500)] 
gccrs: [E0532] Pattern arm did not match expected kind

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
Added error code.

gcc/testsuite/ChangeLog:

* rust/compile/issue-2029.rs:
Updated for dejagnu testcase.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: Move some simple expression-related methods into base class Backend
Owen Avery [Thu, 31 Aug 2023 20:23:53 +0000 (16:23 -0400)] 
gccrs: Move some simple expression-related methods into base class Backend

gcc/rust/ChangeLog:

* rust-backend.h
(Backend::zero_expression): Make non-virtual.
(Backend::var_expression): Likewise.
(Backend::integer_constant_expression): Likewise.
(Backend::float_constant_expression): Likewise.
(Backend::complex_constant_expression): Likewise.
(Backend::string_constant_expression): Likewise.
(Backend::char_constant_literal): Likewise.
(Backend::wchar_constant_literal): Likewise.
(Backend::boolean_constant_expression): Likewise.

(Gcc_backend::zero_expression): Remove.
(Gcc_backend::var_expression): Remove.
(Gcc_backend::integer_constant_expression): Remove.
(Gcc_backend::float_constant_expression): Remove.
(Gcc_backend::complex_constant_expression): Remove.
(Gcc_backend::string_constant_expression): Remove.
(Gcc_backend::wchar_constant_expression): Remove.
(Gcc_backend::char_constant_expression): Remove.
(Gcc_backend::boolean_constant_expression): Remove.
* rust-gcc.cc
(Gcc_backend::zero_expression): Rename to ...
(Backend::zero_expression): ... here.
(Gcc_backend::var_expression): Rename to ...
(Backend::var_expression): ... here.
(Gcc_backend::integer_constant_expression): Rename to ...
(Backend::integer_constant_expression): ... here.
(Gcc_backend::float_constant_expression): Rename to ...
(Backend::float_constant_expression): ... here.
(Gcc_backend::complex_constant_expression): Rename to ...
(Backend::complex_constant_expression): ... here.
(Gcc_backend::string_constant_expression): Rename to ...
(Backend::string_constant_expression): ... here.
(Gcc_backend::wchar_constant_expression): Rename to ...
(Backend::wchar_constant_expression): ... here.
(Gcc_backend::char_constant_expression): Rename to ...
(Backend::char_constant_expression): ... here.
(Gcc_backend::boolean_constant_expression): Rename to ...
(Backend::boolean_constant_expression): ... here.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Move variable-related methods into base class Backend
Owen Avery [Thu, 31 Aug 2023 15:39:51 +0000 (11:39 -0400)] 
gccrs: Move variable-related methods into base class Backend

gcc/rust/ChangeLog:

* rust-backend.h
(Backend::global_variable): Make non-virtual.
(Backend::global_variable_set_init): Likewise.
(Backend::local_variable): Likewise.
(Backend::parameter_variable): Likewise.
(Backend::static_chain_variable): Likewise.
(Backend::temporary_variable): Likewise.

(Gcc_backend::global_variable): Remove.
(Gcc_backend::global_variable_set_init): Remove.
(Gcc_backend::local_variable): Remove.
(Gcc_backend::parameter_variable): Remove.
(Gcc_backend::static_chain_variable): Remove.
(Gcc_backend::temporary_variable): Remove.

(Gcc_backend::non_zero_size_type): Move to ...
(Backend::non_zero_size_type): ... here.
(Gcc_backend::convert_tree): Move to ...
(Backend::convert_tree): ... here.

* rust-gcc.cc
(Gcc_backend::non_zero_size_type): Rename to ...
(Backend::non_zero_size_type): ... here.
(Gcc_backend::convert_tree): Rename to ...
(Backend::convert_tree): ... here.
(Gcc_backend::global_variable): Rename to ...
(Backend::global_variable): ... here.
(Gcc_backend::global_variable_set_init): Rename to ...
(Backend::global_variable_set_init): ... here.
(Gcc_backend::local_variable): Rename to ...
(Backend::local_variable): ... here.
(Gcc_backend::parameter_variable): Rename to ...
(Backend::parameter_variable): ... here.
(Gcc_backend::static_chain_variable): Rename to ...
(Backend::static_chain_variable): ... here.
(Gcc_backend::temporary_variable): Rename to ...
(Backend::temporary_variable): ... here.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: [E0603] Use of private item outside scope
Muhammad Mahad [Sun, 3 Sep 2023 06:13:53 +0000 (11:13 +0500)] 
gccrs: [E0603] Use of private item outside scope

gcc/rust/ChangeLog:

* checks/errors/privacy/rust-privacy-reporter.cc
(PrivacyReporter::check_for_privacy_violation):
Added errorcode & richlocation.

gcc/testsuite/ChangeLog:

* rust/compile/privacy1.rs: Added errorcode.
* rust/compile/privacy3.rs: likewise.
* rust/compile/privacy4.rs: likewise.
* rust/compile/privacy5.rs: likewise.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: Move debug-related functions into base class Backend
Owen Avery [Thu, 31 Aug 2023 15:25:47 +0000 (11:25 -0400)] 
gccrs: Move debug-related functions into base class Backend

gcc/rust/ChangeLog:

* rust-backend.h
(Backend::debug): Make non-virtual.
(Backend::get_identifier_node): Likewise.

(Gcc_backend::debug): Remove.
(Gcc_backend::get_identifier_node): Remove.
* rust-gcc.cc
(Gcc_backend::debug): Rename to ...
(Backend::debug): ... here.
(Gcc_backend::get_identifier_node): Rename to ...
(Backend::get_identifier_node): ... here.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Improve type checking for if expressions
Owen Avery [Sat, 2 Sep 2023 02:07:30 +0000 (22:07 -0400)] 
gccrs: Improve type checking for if expressions

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc
(TypeCheckExpr::visit): Expect if conditions to have type bool.

gcc/testsuite/ChangeLog:

* rust/compile/type-if.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Move label-related functions into base class Backend
Owen Avery [Thu, 31 Aug 2023 15:32:11 +0000 (11:32 -0400)] 
gccrs: Move label-related functions into base class Backend

gcc/rust/ChangeLog:

* rust-backend.h
(Backend::label): Make non-virtual.
(Backend::label_definition_statement): Likewise.
(Backend::goto_statement): Likewise.
(Backend::label_address): Likewise.

(Gcc_backend::label): Remove.
(Gcc_backend::label_definition_statement): Remove.
(Gcc_backend::goto_statement): Remove.
(Gcc_backend::label_address): Remove.
* rust-gcc.cc
(Gcc_backend::label): Rename to ...
(Backend::label): ... here.
(Gcc_backend::label_definition_statement): Rename to ...
(Backend::label_definition_statement): ... here.
(Gcc_backend::goto_statement): Rename to ...
(Backend::goto_statement): ... here.
(Gcc_backend::label_address): Rename to ...
(Backend::label_address): ... here.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Fix ODR violations
Owen Avery [Sat, 2 Sep 2023 00:46:20 +0000 (20:46 -0400)] 
gccrs: Fix ODR violations

gcc/rust/ChangeLog:

* backend/rust-constexpr.cc
(struct constexpr_fundef): Rename to ...
(struct rust_constexpr_fundef): ... here.
(struct constexpr_call): Rename to ...
(struct rust_constexpr_call): ... here.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Add check for no_mangle attribute
Raiki Tamura [Fri, 18 Aug 2023 04:00:47 +0000 (13:00 +0900)] 
gccrs: Add check for no_mangle attribute

gcc/rust/ChangeLog:

* lex/rust-input-source.h: Move constants from here...
* util/rust-codepoint.h (struct Codepoint): ... to here
* util/rust-attributes.cc (check_no_mangle_function): New function.
(AttributeChecker::visit): Use it.
* util/rust-unicode.cc (is_ascii_only): New function.
* util/rust-unicode.h (is_ascii_only): Likewise.
* backend/rust-mangle.cc (legacy_mangle_name): Use it.
* util/rust-punycode.cc (extract_basic_string): Likewise.
* lex/rust-lex.cc (Lexer::parse_byte_char): Likewise.

Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
18 months agogccrs: [E0658] top level or-patterns are not allowed let binding
Muhammad Mahad [Fri, 18 Aug 2023 12:06:02 +0000 (17:06 +0500)] 
gccrs: [E0658] top level or-patterns are not allowed let binding

gcc/rust/ChangeLog:

* hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::visit):
Added richlocation & error code.

gcc/testsuite/ChangeLog:

* rust/compile/let_alt.rs: Updated comment.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: Fix invalid call to vector::front in TypeBoundPredicate constructors
Owen Avery [Thu, 24 Aug 2023 02:49:30 +0000 (22:49 -0400)] 
gccrs: Fix invalid call to vector::front in TypeBoundPredicate constructors

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc
(TypeCheckExpr::resolve_fn_trait_call): Add TODO comment.
* typecheck/rust-tyty-bounds.cc
(TypeBoundPredicate::TypeBoundPredicate):
Add assertions, new error constructor.
(TypeBoundPredicate::error): Use new error constructor.
* typecheck/rust-tyty.h
(struct TypeBoundPredicate::mark_is_error): New.
(TypeBoundPredicate::TypeBoundPredicate):
Add new error constructor.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Move type-related functions into base class Backend
Owen Avery [Thu, 31 Aug 2023 15:15:43 +0000 (11:15 -0400)] 
gccrs: Move type-related functions into base class Backend

gcc/rust/ChangeLog:

* rust-backend.h:
(Backend::wchar_type): Make non-virtual.
(Backend::get_pointer_size): Likewise.
(Backend::raw_str_type): Likewise.
(Backend::integer_type): Likewise.
(Backend::float_type): Likewise.
(Backend::complex_type): Likewise.
(Backend::pointer_type): Likewise.
(Backend::reference_type): Likewise.
(Backend::immutable_type): Likewise.
(Backend::function_type): Likewise.
(Backend::function_type_varadic): Likewise.
(Backend::function_ptr_type): Likewise.
(Backend::struct_type): Likewise.
(Backend::union_type): Likewise.
(Backend::array_type): Likewise.
(Backend::named_type): Likewise.
(Backend::type_size): Likewise.
(Backend::type_alignment): Likewise.
(Backend::type_field_alignment): Likewise.
(Backend::type_field_offset): Likewise.

(Gcc_backend::wchar_type): Remove.
(Gcc_backend::get_pointer_size): Remove.
(Gcc_backend::raw_str_type): Remove.
(Gcc_backend::integer_type): Remove.
(Gcc_backend::float_type): Remove.
(Gcc_backend::complex_type): Remove.
(Gcc_backend::pointer_type): Remove.
(Gcc_backend::reference_type): Remove.
(Gcc_backend::immutable_type): Remove.
(Gcc_backend::function_type): Remove.
(Gcc_backend::function_type_varadic): Remove.
(Gcc_backend::function_ptr_type): Remove.
(Gcc_backend::struct_type): Remove.
(Gcc_backend::union_type): Remove.
(Gcc_backend::array_type): Remove.
(Gcc_backend::named_type): Remove.
(Gcc_backend::type_size): Remove.
(Gcc_backend::type_alignment): Remove.
(Gcc_backend::type_field_alignment): Remove.
(Gcc_backend::type_field_offset): Remove.

(Gcc_backend::fill_in_fields): Move to ...
(Backend::fill_in_fields): ... here.
(Gcc_backend::fill_in_array): Move to ...
(Backend::fill_in_array): ... here.

* rust-gcc.cc
(Gcc_backend::wchar_type): Rename to ...
(Backend::wchar_type): ... here.
(Gcc_backend::get_pointer_size): Rename to ...
(Backend::get_pointer_size): ... here.
(Gcc_backend::raw_str_type): Rename to ...
(Backend::raw_str_type): ... here.
(Gcc_backend::integer_type): Rename to ...
(Backend::integer_type): ... here.
(Gcc_backend::float_type): Rename to ...
(Backend::float_type): ... here.
(Gcc_backend::complex_type): Rename to ...
(Backend::complex_type): ... here.
(Gcc_backend::pointer_type): Rename to ...
(Backend::pointer_type): ... here.
(Gcc_backend::reference_type): Rename to ...
(Backend::reference_type): ... here.
(Gcc_backend::immutable_type): Rename to ...
(Backend::immutable_type): ... here.
(Gcc_backend::function_type): Rename to ...
(Backend::function_type): ... here.
(Gcc_backend::function_type_varadic): Rename to ...
(Backend::function_type_varadic): ... here.
(Gcc_backend::function_ptr_type): Rename to ...
(Backend::function_ptr_type): ... here.
(Gcc_backend::struct_type): Rename to ...
(Backend::struct_type): ... here.
(Gcc_backend::union_type): Rename to ...
(Backend::union_type): ... here.
(Gcc_backend::fill_in_fields): Rename to ...
(Backend::fill_in_fields): ... here.
(Gcc_backend::array_type): Rename to ...
(Backend::array_type): ... here.
(Gcc_backend::fill_in_array): Rename to ...
(Backend::fill_in_array): ... here.
(Gcc_backend::named_type): Rename to ...
(Backend::named_type): ... here.
(Gcc_backend::type_size): Rename to ...
(Backend::type_size): ... here.
(Gcc_backend::type_alignment): Rename to ...
(Backend::type_alignment): ... here.
(Gcc_backend::type_field_alignment): Rename to ...
(Backend::type_field_alignment): ... here.
(Gcc_backend::type_field_offset): Rename to ...
(Backend::type_field_offset): ... here.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: fix bug in the iterator testcase
Philip Herron [Thu, 31 Aug 2023 10:50:31 +0000 (11:50 +0100)] 
gccrs: fix bug in the iterator testcase

gcc/testsuite/ChangeLog:

* rust/compile/iterators1.rs: this should be casting to the $ty

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: Fix move_val_init
Philip Herron [Thu, 31 Aug 2023 10:33:27 +0000 (11:33 +0100)] 
gccrs: Fix move_val_init

The intrinsic move_val_init was being optimized away even at -O0 because
the function looked "pure" but this adds in the attributes to enforce that
this function has side-effects to override that bad assumption by the
middle-end.

Addresses #1895

gcc/rust/ChangeLog:

* backend/rust-compile-intrinsic.cc (move_val_init_handler): mark as side-effects

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: Mark uninit-intrinsic as side-effects
Philip Herron [Thu, 31 Aug 2023 10:33:12 +0000 (11:33 +0100)] 
gccrs: Mark uninit-intrinsic as side-effects

Ensure the uninit intrinsic does not get optimized away

Addresses #1895

gcc/rust/ChangeLog:

* backend/rust-compile-intrinsic.cc (uninit_handler): Update fndecl attributes

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: Fix overflow intrinsic use before init
Philip Herron [Thu, 31 Aug 2023 10:32:18 +0000 (11:32 +0100)] 
gccrs: Fix overflow intrinsic use before init

The overflow intrinsic returns a tuple of (value, boolean) where it value
is the operator result and boolean if it overflowed or not. The intrinsic
here did not initilize the resulting tuple and therefore was creating a use
before init error resulting in garbage results

Addresses #1895

gcc/rust/ChangeLog:

* backend/rust-compile-intrinsic.cc (op_with_overflow_inner): fix use before init

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: Fix bad uninit intrinsic
Philip Herron [Mon, 28 Aug 2023 13:20:04 +0000 (14:20 +0100)] 
gccrs: Fix bad uninit intrinsic

We were using the DECL_RESULT but this just contains the TREE_TYPE of the
retval. It was also missing taking the address of the destination for the
memset call. This changes the code to create a temp variable for the return
value and asserts the destination size is the same as the size of the
template param.

Fixes #2583

gcc/rust/ChangeLog:

* backend/rust-compile-intrinsic.cc (enter_intrinsic_block): take the locals vector
(uninit_handler): make a temp variable and use the address of it

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: Collect error instance instead of lambda functions
Pierre-Emmanuel Patry [Wed, 30 Aug 2023 15:13:36 +0000 (17:13 +0200)] 
gccrs: Collect error instance instead of lambda functions

Use error object instead of lambda for error collection.

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc (Early::visit):
Collect error instead of lambda.
* resolve/rust-early-name-resolver-2.0.h (std::function<void):
Remove type alias.
* rust-diagnostics.h: Change collection type.
* rust-session-manager.cc (Session::expansion): Change
collection container.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Add regression test for nested macros
Pierre-Emmanuel Patry [Wed, 30 Aug 2023 15:11:24 +0000 (17:11 +0200)] 
gccrs: Add regression test for nested macros

Add a new test to avoid regression on newly added changes about macros
expanding to new macro definitions.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Resolve nested macro definition
Pierre-Emmanuel Patry [Tue, 8 Aug 2023 10:16:44 +0000 (12:16 +0200)] 
gccrs: Resolve nested macro definition

We need to collect the early resolver's macros error to emit them at a
later stage after further expansion in order to retrieve macros defined
by other macro invocations.
Register some mappings for macro invocations and macro definitions.

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc (Early::visit):
Collect error instead of emitting it. Also add invocation
registration.
* resolve/rust-early-name-resolver-2.0.h (std::function<void):
Add type definition for collection.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit):
Register macro rule definition in mappings.
* rust-session-manager.cc (Session::expansion): Add macro
resolve error collection.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Handle gengtype annotations in backend/rust-tree.{cc,h}
Owen Avery [Fri, 18 Aug 2023 21:01:34 +0000 (17:01 -0400)] 
gccrs: Handle gengtype annotations in backend/rust-tree.{cc,h}

gcc/rust/ChangeLog:

* config-lang.in:
Add "backend/rust-tree.h" and "backend/rust-tree.h" to gtfiles.
* backend/rust-tree.cc: Include new header generated by gengtype.

* backend/rust-tree.h
(struct language_function): Add TODO.
* rust-lang.cc:
Include "rust-tree.h".
(struct lang_type): Remove duplicate definition.
(struct lang_decl): Likewise.
(struct lang_identifier): Likewise.
(struct language_function): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: [E0769] Use of tuple struct/variant in struct variant
Muhammad Mahad [Wed, 16 Aug 2023 10:30:45 +0000 (15:30 +0500)] 
gccrs: [E0769] Use of tuple struct/variant in struct variant

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
Added error code and rich location.

gcc/testsuite/ChangeLog:

* rust/compile/match4.rs:
Updated new error commment.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: Add missing gengtype related structs
Owen Avery [Fri, 18 Aug 2023 21:53:53 +0000 (17:53 -0400)] 
gccrs: Add missing gengtype related structs

gcc/rust/ChangeLog:

* backend/rust-tree.h
(struct rust_cp_class_binding): Fork from gcc/cp/name_lookup.h.
(struct rust_cp_binding_level): Likewise.
(struct named_label_entry): Remove declaration...
(struct rust_named_label_entry): ... and fork definition from gcc/cp/decl.cc.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: diagnostics: Added non-const `rich_location *` function
Muhammad Mahad [Sun, 20 Aug 2023 12:32:29 +0000 (17:32 +0500)] 
gccrs: diagnostics: Added non-const `rich_location *` function

Currently, gccrs using the const `rich_location &`, and
then using the cast to convert it to the functions which
was used to emit the errors, having the overloaded is
good, similiar to other frontends.

gcc/rust/ChangeLog:

* rust-diagnostics.cc (rust_be_error_at): Added overload function.
(rust_error_at): non-const `rich_location *` function.
* rust-diagnostics.h (rust_error_at): Implementation of overloaded
function.
(rust_be_error_at): likewise.
* rust_error_codes.def: Added GNU license.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: [E0271] Type mismatch between associated type trait.
Muhammad Mahad [Tue, 15 Aug 2023 17:24:10 +0000 (22:24 +0500)] 
gccrs: [E0271] Type mismatch between associated type trait.

Added rich location and error code.

gcc/rust/ChangeLog:

* typecheck/rust-tyty.cc (BaseType::satisfies_bound):
Added errorcode and user-friendly error message.

gcc/testsuite/ChangeLog:

* rust/compile/issue-1725-2.rs:
Updated dejagnu message.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: Fork c++ resorting methods
Owen Avery [Fri, 18 Aug 2023 20:39:47 +0000 (16:39 -0400)] 
gccrs: Fork c++ resorting methods

gcc/rust/ChangeLog:

* backend/rust-tree.cc
(resort_data): Fork from c++ frontend.
(resort_member_name_cmp): Likewise.
(resort_type_member_vec): Likewise.
* backend/rust-tree.h
(resort_type_member_vec): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Rename some structs to avoid ODR issues
Owen Avery [Fri, 18 Aug 2023 20:37:46 +0000 (16:37 -0400)] 
gccrs: Rename some structs to avoid ODR issues

gcc/rust/ChangeLog:

* backend/rust-tree.cc
(struct conv_type_hasher): Rename to ...
(struct rust_conv_type_hasher): ... here.
(struct cplus_array_hasher): Rename to ...
(struct rust_cplus_array_hasher): ... here.
(struct source_location_table_entry_hash): Rename to ...
(struct rust_source_location_table_entry_hash): ... here.
* backend/rust-tree.h
(struct named_decl_hash): Rename to ...
(struct rust_named_decl_hash): ... here.
(struct cxx_saved_binding): Rename to ...
(struct rust_cxx_saved_binding): ... here.
(struct named_label_hash): Rename to ...
(struct rust_named_label_hash): ... here.
(struct tree_pair_s): Rename to ...
(struct rust_tree_pair_s): ... here.
(struct tree_pair_p): Rename to ...
(struct rust_tree_pair_p): ... here.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Namespace related tweaks
Owen Avery [Sat, 19 Aug 2023 17:13:21 +0000 (13:13 -0400)] 
gccrs: Namespace related tweaks

gcc/rust/ChangeLog:

* backend/rust-tree.cc
(Rust::gt_pch_nx): Move external function declaration ...
(gt_pch_nx): ... out of Rust namespace.
* backend/rust-tree.h
(OVL_FIRST): Qualify function name.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Fix compilation of types which hold onto dangling infer vars
Philip Herron [Mon, 21 Aug 2023 11:35:26 +0000 (12:35 +0100)] 
gccrs: Fix compilation of types which hold onto dangling infer vars

There is a case where some generic types are holding onto inference
variable pointers directly. So this gives the backend a chance to do one
final lookup to resolve the type.

This now allows us to compile a full test case for iterators but there is
still one miscompilation in here which results in a segv on O2 and bad
result on -O0.

Addresses #1895

gcc/rust/ChangeLog:

* backend/rust-compile-type.cc (TyTyResolveCompile::visit): do a final lookup

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: Invalid order of generic parameters
Muhammad Mahad [Thu, 17 Aug 2023 10:49:15 +0000 (15:49 +0500)] 
gccrs: Invalid order of generic parameters

Added more userfriendly message.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_generic_params):
Added more user friendly message.

gcc/testsuite/ChangeLog:

* rust/compile/generics13.rs:
for dejagnu,

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: Improve byte vector to string conversion
Owen Avery [Wed, 2 Aug 2023 20:45:42 +0000 (16:45 -0400)] 
gccrs: Improve byte vector to string conversion

gcc/rust/ChangeLog:

* expand/rust-macro-builtins.cc
(MacroBuiltin::include_str_handler): Use vector::data.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: [E0573] Something other than type was used
Muhammad Mahad [Fri, 18 Aug 2023 11:28:34 +0000 (16:28 +0500)] 
gccrs: [E0573] Something other than type was used

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-type.cc:
Added last variant name, errorcode & rich location. for enum candidates.

gcc/testsuite/ChangeLog:

* rust/compile/issue-2479.rs: Updated comment.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: Remove stmt_tree and dependency on cp_token_cache
Owen Avery [Fri, 18 Aug 2023 21:02:16 +0000 (17:02 -0400)] 
gccrs: Remove stmt_tree and dependency on cp_token_cache

gcc/rust/ChangeLog:

* backend/rust-tree.h
(struct stmt_tree_s): Remove.
(typedef stmt_tree): Remove.
(c_language_function::x_stmt_tree): Remove.
(saved_scope::x_stmt_tree): Remove.
(lang_decl_fn::pending_inline_p): Remove.
(lang_decl_fn::spare): Adjust size.
(lang_decl_fn::pending_inline_info): Remove.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Handle gengtype annotations in rust-constexpr.cc
Owen Avery [Sat, 12 Aug 2023 15:37:10 +0000 (11:37 -0400)] 
gccrs: Handle gengtype annotations in rust-constexpr.cc

gcc/rust/ChangeLog:

* backend/rust-constexpr.cc:
Include gt-rust-rust-constexpr.h.
(struct constexpr_call_hasher): Rename to ...
(struct rust_constexpr_call_hasher): ... here.
(struct constexpr_fundef_hasher): Rename to ...
(struct rust_constexpr_fundef_hasher): ... here.
* config-lang.in: Add rust-constexpr.cc to gtfiles.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Add punycode encoding to v0 mangling
Raiki Tamura [Mon, 7 Aug 2023 17:08:38 +0000 (02:08 +0900)] 
gccrs: Add punycode encoding to v0 mangling

gcc/rust/ChangeLog:

* backend/rust-mangle.cc (v0_add_identifier): Added punycode encoding
(v0_mangle_item): Likewise.
* lex/rust-lex.cc (assert_source_content): Change type
(test_buffer_input_source): Change type
(test_file_input_source): Change type
* resolve/rust-ast-resolve-toplevel.h: fix typo
* rust-session-manager.cc (Session::load_extern_crate): fix typo
* util/rust-canonical-path.h: fix typo
* util/rust-hir-map.cc (NodeMapping::get_error): fix typo
(Mappings::Mappings): fix typo
* util/rust-mapping-common.h (UNKNOWN_CREATENUM): fix typo
(UNKNOWN_CRATENUM): Change 0 to UINT32_MAX

Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
18 months agogccrs: [E0391] Detected type dependency cycle
Muhammad Mahad [Tue, 15 Aug 2023 16:29:03 +0000 (21:29 +0500)] 
gccrs: [E0391] Detected type dependency cycle

This errorcode & message emits when cycle
detected when computing the super predicates
of `x` which requires computing the super
predicates of `y`, which again requires
computing the super predicates of `x`,
completing the cycle.

gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait):
Updated errorcode & more userfriendly message.

gcc/testsuite/ChangeLog:

* rust/compile/issue-1589.rs: Updated comment for dejagnu.
* rust/compile/trait-cycle.rs: New relevant test.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: Non-allowed default type paramters
Muhammad Mahad [Mon, 14 Aug 2023 12:09:25 +0000 (17:09 +0500)] 
gccrs: Non-allowed default type paramters

gcc/rust/ChangeLog:

* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit):
Added more helpful error message.

gcc/testsuite/ChangeLog:

* rust/compile/generics10.rs: for dejagnu.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: [E0034] found more than one items for method
Muhammad Mahad [Tue, 15 Aug 2023 15:19:36 +0000 (20:19 +0500)] 
gccrs: [E0034] found more than one items for method

Multiple items found with same prototype.
Fixes: https://github.com/Rust-GCC/gccrs/issues/2366
gcc/rust/ChangeLog:

* typecheck/rust-hir-path-probe.h:
Fixes issue & added rich location message.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
Added rich location and error code.

gcc/testsuite/ChangeLog:

* rust/compile/generics6.rs: Updated dejagnu comment.
* rust/compile/generics7.rs: likewise.
* rust/compile/issue-925.rs: likewise.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: Add a regression test for decimal lexing
Pierre-Emmanuel Patry [Thu, 3 Aug 2023 13:52:51 +0000 (15:52 +0200)] 
gccrs: Add a regression test for decimal lexing

Issue #2514 fixed by the previous commit highlight a behavior we want to
avoid in the future, hence this regression test.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: fix lexer exponent output on tuple indices
Pierre-Emmanuel Patry [Thu, 3 Aug 2023 13:28:40 +0000 (15:28 +0200)] 
gccrs: fix lexer exponent output on tuple indices

The lexer did output a literal for values such as 42.e wich are invalid
in rust.

gcc/rust/ChangeLog:

* lex/rust-lex.cc (Lexer::parse_decimal_int_or_float): Only
accept digits after a dot instead of accepting any float
member.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: [E0164] Neither tuple struct nor tuple variant used as a pattern
Muhammad Mahad [Wed, 16 Aug 2023 12:40:09 +0000 (17:40 +0500)] 
gccrs: [E0164] Neither tuple struct nor tuple variant used as a pattern

Checking if pattern has items, before returing solves ICE.
Added error code and rich location.
Also, fixes https://github.com/Rust-GCC/gccrs/issues/2430

gcc/rust/ChangeLog:

* ast/rust-pattern.h: No need of assertion, we are handling it.
* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
Added check which emits error instead of using assertion.
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
Added rich location and error code.

gcc/testsuite/ChangeLog:

* rust/compile/match5.rs:
Updated comment for dejagnu.
* rust/compile/pattern-struct.rs: New test for ICE.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: [E0535] Unknown argument given to inline attribute
Muhammad Mahad [Tue, 15 Aug 2023 14:07:52 +0000 (19:07 +0500)] 
gccrs: [E0535] Unknown argument given to inline attribute

The inline attribute only supports two arguments:
 - always
 - never
All other arguments given to the inline attribute will
return error.

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc (HIRCompileBase::handle_inline_attribute_on_fndecl):
Added rich_location & error code.

gcc/testsuite/ChangeLog:

* rust/compile/inline_2.rs: Added new message.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: [E0380] Use of auto trait with method or associated item
Muhammad Mahad [Thu, 17 Aug 2023 05:25:33 +0000 (10:25 +0500)] 
gccrs: [E0380] Use of auto trait with method or associated item

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_trait):
added errorcode & updated error message.

gcc/testsuite/ChangeLog:

* rust/compile/auto_trait_invalid.rs:
Updated comment.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: [E0753] Use of inner doc comment in invalid context
Muhammad Mahad [Thu, 17 Aug 2023 05:13:00 +0000 (10:13 +0500)] 
gccrs: [E0753] Use of inner doc comment in invalid context

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_outer_attribute):
Added errorcode & updated error function.

gcc/testsuite/ChangeLog:

* rust/compile/bad_inner_doc.rs:
Updated comment to pass testcase.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: Support for rich-loc & errorcode in parser error
Muhammad Mahad [Thu, 10 Aug 2023 17:10:09 +0000 (22:10 +0500)] 
gccrs: Support for rich-loc & errorcode in parser error

Added method of binding ErrorCode & rich location to
parser and expansion errors.
Fixes https://github.com/Rust-GCC/gccrs/issues/2385

gcc/rust/ChangeLog:

* rust-diagnostics.cc (va_constructor):
Added constructor for all possible cases.
(Error::Error): Updated error struct
for all possible cases.
* rust-diagnostics.h (struct Error):
Updated error struct to support error
code & rich location support.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: [E0534] inline attribute was malformed
Muhammad Mahad [Tue, 15 Aug 2023 13:52:10 +0000 (18:52 +0500)] 
gccrs: [E0534] inline attribute was malformed

Inline attribute takes one argument, but
more than one argument was found.

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc (HIRCompileBase::handle_inline_attribute_on_fndecl):
Added rich_location & error code.

gcc/testsuite/ChangeLog:

* rust/compile/inline_2.rs: Added new case.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: diagnostics: Fix mismatch between new[] and free
Arthur Cohen [Thu, 3 Aug 2023 14:40:07 +0000 (16:40 +0200)] 
gccrs: diagnostics: Fix mismatch between new[] and free

We cannot use `free` on a pointer allocated through `new[]`, and this
causes an ASAN failure. This fixes it by using `xcalloc` instead of
`new[]` when creating description buffers for our error codes.

gcc/rust/ChangeLog:

* rust-diagnostics.cc: Switch from new[] to xcalloc

18 months agogccrs: Type annotation for make-unicode-data.py
Raiki Tamura [Sun, 6 Aug 2023 09:49:20 +0000 (18:49 +0900)] 
gccrs: Type annotation for make-unicode-data.py

gcc/rust/ChangeLog:

* util/make-rust-unicode.py: Add type annotation

Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
18 months agogccrs: improve name mangling hash
Philip Herron [Sat, 12 Aug 2023 17:18:51 +0000 (18:18 +0100)] 
gccrs: improve name mangling hash

We can endup with duplicate symbol names for different intrinsics with our
current hash setup. This adds in the mappings and extra info to improve
hash uniqueness.

Addresses #1895

gcc/rust/ChangeLog:

* backend/rust-compile-intrinsic.cc (check_for_cached_intrinsic):
simplify this cached intrinsic check
* backend/rust-mangle.cc (legacy_mangle_item): use new interface
* typecheck/rust-tyty.h: new managle helper

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: simplify matching possible candidates
Philip Herron [Sat, 12 Aug 2023 17:23:06 +0000 (18:23 +0100)] 
gccrs: simplify matching possible candidates

We do extra checking after the fact here to ensure its a valid candidate
and in the case there is only one candidate lets just go for it.

Addresses #1895

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc (HIRCompileBase::resolve_method_address):
use the single candidate

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: Cleanup HIR dump
Marc Poulhiès [Thu, 10 Aug 2023 21:06:32 +0000 (23:06 +0200)] 
gccrs: Cleanup HIR dump

visit_field() correctly handles empty unique_ptr<> and displays "none".

gcc/rust/ChangeLog:

* hir/rust-hir-dump.cc (Dump::visit): Remove useless if/else
already handled by visit_field.

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
18 months agogccrs: Add missing CHECKING_P guard to rust-punycode.cc
Owen Avery [Sat, 12 Aug 2023 02:39:57 +0000 (22:39 -0400)] 
gccrs: Add missing CHECKING_P guard to rust-punycode.cc

gcc/rust/ChangeLog:

* util/rust-punycode.cc: Add CHECKING_P guard.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Fix legacy mangling to use Unicode escape
Raiki Tamura [Sat, 12 Aug 2023 07:16:53 +0000 (16:16 +0900)] 
gccrs: Fix legacy mangling to use Unicode escape

gcc/rust/ChangeLog:

* backend/rust-mangle.cc (legacy_mangle_name): Use Unicode escape

Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
18 months agogccrs: remove horrible hack in solving complex generics on impl blocks
Philip Herron [Sat, 12 Aug 2023 16:06:37 +0000 (17:06 +0100)] 
gccrs: remove horrible hack in solving complex generics on impl blocks

We hit an assertion with range based iterators here. This code was used
to solve complex generics such as:

  struct Foo<X,Y>(X,Y);
  impl<T> Foo<T, i32> {
    fn test<Y>(self, a: Y) { }
  }

The impl item will have the signiture of:

  fn test<T,Y> (Foo<T, i32> self, a:Y)

So in the case where we have:

  let a = Foo(123f32, 456);
  a.test<bool>(true);

We need to solve the generic argument T from the impl block by infering the
arguments there and applying them so that when we apply the generic
argument bool we dont end up in the case of missing number of generics.

Addresses #1895

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): remove hack

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: Use MacroInvocLexerBase in ProcMacroInvocLexer
Owen Avery [Fri, 30 Jun 2023 01:37:33 +0000 (21:37 -0400)] 
gccrs: Use MacroInvocLexerBase in ProcMacroInvocLexer

gcc/rust/ChangeLog:

* expand/rust-proc-macro-invoc-lexer.cc
(ProcMacroInvocLexer::skip_token): Remove.
* expand/rust-proc-macro-invoc-lexer.h:
Include "rust-macro-invoc-lexer.h".
(class ProcMacroInvocLexer):
Extend MacroInvocLexerBase.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: clean up Codepoint and InputSource
Raiki Tamura [Sun, 6 Aug 2023 10:17:17 +0000 (19:17 +0900)] 
gccrs: clean up Codepoint and InputSource

gcc/rust/ChangeLog:

* lex/rust-codepoint.h: Moved to...
* util/rust-codepoint.h: ...here.
* lex/rust-input-source.h: Add missing license
* util/rust-unicode.cc: Add missing license
* util/rust-punycode.cc (extract_basic_string): Remove constant

Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
18 months agogccrs: macro-expand: Keep optional references to last_{def, invoc}
Arthur Cohen [Thu, 3 Aug 2023 15:24:14 +0000 (17:24 +0200)] 
gccrs: macro-expand: Keep optional references to last_{def, invoc}

This avoids a use-after-free when reaching the recursion limit.

gcc/rust/ChangeLog:

* expand/rust-macro-expand.h: Keep optional references for last_def
and last_invoc.
* expand/rust-macro-expand.cc (MacroExpander::expand_invoc): Store
optional references.
* rust-session-manager.cc (Session::expansion): Use tl::optional's APIs
for better checking.

18 months agogccrs: Adjust HIR dump for IfExpr and IfExprConseqElse
Marc Poulhiès [Thu, 10 Aug 2023 20:45:38 +0000 (22:45 +0200)] 
gccrs: Adjust HIR dump for IfExpr and IfExprConseqElse

Adjust the HIR dump for IfExpr and IfExprConseqElse
to use visit_field() and factor common part.

gcc/rust/ChangeLog:

* hir/rust-hir-dump.h (do_ifexpr): New.
* hir/rust-hir-dump.cc (Dump::do_ifexpr): New.
(Dump::visit): Use do_ifexpr and visit_field

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
18 months agogccrs: [E0054/E0604/E0620/E0606] TypeCasting ErrorCodes
Muhammad Mahad [Sat, 5 Aug 2023 12:28:45 +0000 (17:28 +0500)] 
gccrs: [E0054/E0604/E0620/E0606] TypeCasting ErrorCodes

Added errorcodes according to different conditions
and updated error message according to type casting
type.

gcc/rust/ChangeLog:

* typecheck/rust-casts.cc (TypeCastRules::emit_cast_error):
Refactored ErrorCodes & error messages.

gcc/testsuite/ChangeLog:

* rust/compile/bad_as_bool_char.rs:
Updated comment to pass test case.
* rust/compile/cast1.rs: likewise.
* rust/compile/cast4.rs: likewise.
* rust/compile/cast5.rs: likewise.
* rust/compile/all-cast.rs: New test for all error codes.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: [E0541] Use of unknown meta item
Muhammad Mahad [Sat, 5 Aug 2023 08:18:16 +0000 (13:18 +0500)] 
gccrs: [E0541] Use of unknown meta item

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc:
Added ErrorCode.

gcc/testsuite/ChangeLog:

* rust/compile/attr_deprecated_2.rs:
Updated comment to pass the testcase.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: [E0703] Use of Invalid ABI
Muhammad Mahad [Thu, 3 Aug 2023 15:46:50 +0000 (20:46 +0500)] 
gccrs: [E0703] Use of Invalid ABI

Added error code support for invalid ABI.

gcc/rust/ChangeLog:

* hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_qualifiers):
called error function.
(ASTLoweringBase::lower_extern_block): likewise.

gcc/testsuite/ChangeLog:

* rust/compile/abi-options1.rs: updated comment for testcase.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: Basic formatting/comment fixes
Owen Avery [Wed, 9 Aug 2023 16:55:37 +0000 (12:55 -0400)] 
gccrs: Basic formatting/comment fixes

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc: Adjust formatting.
* checks/errors/rust-feature-gate.cc: Add trailing newline.
* rust-diagnostics.h: Remove old comment.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Remove unneeded references to "this" in backend methods
Owen Avery [Tue, 1 Aug 2023 19:59:14 +0000 (15:59 -0400)] 
gccrs: Remove unneeded references to "this" in backend methods

gcc/rust/ChangeLog:

* rust-gcc.cc
(Gcc_backend::struct_type): Remove references to "this".
(Gcc_backend::union_type): Likewise.
(Gcc_backend::array_type): Likewise.
(Gcc_backend::wchar_constant_expression): Likewise.
(Gcc_backend::convert_expression): Likewise.
(Gcc_backend::constructor_expression): Likewise.
(Gcc_backend::array_initializer): Likewise.
(Gcc_backend::assignment_statement): Likewise.
(Gcc_backend::global_variable): Likewise.
(Gcc_backend::temporary_variable): Likewise.
(Gcc_backend::function_defer_statement): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Add function `Rust::encode_punycode`
Raiki Tamura [Sun, 30 Jul 2023 10:54:36 +0000 (19:54 +0900)] 
gccrs: Add function `Rust::encode_punycode`

gcc/rust/ChangeLog:

* Make-lang.in: Add rust-punycode.o.
* rust-lang.cc (run_rust_tests): Add selftest.
* util/rust-punycode.cc: New file.
* util/rust-punycode.h: New file.

Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
18 months agogccrs: [E0308] array misamatch types
Muhammad Mahad [Sat, 5 Aug 2023 07:55:36 +0000 (12:55 +0500)] 
gccrs: [E0308] array misamatch types

gcc/rust/ChangeLog:

* backend/rust-compile.cc (HIRCompileBase::verify_array_capacities):
Added ErrorCode.

gcc/testsuite/ChangeLog:

* rust/compile/arrays2.rs: changed comment to pass
testcase.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: [E0282] type annotations needed
Muhammad Mahad [Sat, 5 Aug 2023 06:27:19 +0000 (11:27 +0500)] 
gccrs: [E0282] type annotations needed

type must be known at compile time.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check.cc (TypeResolution::Resolve):
added errorcode.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>