aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/rust-gcc.cc
AgeCommit message (Collapse)AuthorFilesLines
2025-04-16gccrs: Fix ICE when checking shift's which are behind array refsPhilip Herron1-0/+1
I copied a bad form of this check from the c front-end this updates it to ensure the rhs is an INTEGER_CST and the lhs needs checked in the first place. Fixes Rust-GCC#3664 gcc/rust/ChangeLog: * rust-gcc.cc (arithmetic_or_logical_expression): Ensure this is an integer gcc/testsuite/ChangeLog: * rust/compile/issue-3664.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-04-10rust: Add comment inside block [PR119342]Andrew Pinski1-0/+2
Inside a BLOCK node, all of the variables of the scope/block are chained together and that connects them to the block. This just adds a comment to that effect as reading the code it is not so obvious why they need to be chained together. gcc/rust/ChangeLog: PR rust/119342 * rust-gcc.cc (block): Add comment on why chaining the variables of the scope toether. Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2025-04-10rust: use range for inside rust-gcc.cc [PR119341]Andrew Pinski1-36/+21
There are some places inside rust-gcc.cc which are candidates to use range for instead of iterators directly. This changes the locations I saw and makes the code slightly more readable. gcc/rust/ChangeLog: PR rust/119341 * rust-gcc.cc (function_type): Use range fors. (function_type_variadic): Likewise. (fill_in_fields): Likewise. (statement_list): Likewise. (block): Likewise. (block_add_statements): Likewise. (function_set_parameters): Likewise. (write_global_definitions): Likewise. Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2025-04-10rust: Use error_operand_p in rust-gcc.ccAndrew Pinski1-101/+88
Just a simple cleanupof the code to use error_operand_p instead of directly comparing against error_mark_node. This also moves some cdoe around when dealing with error_operand_p just to be faster and/or slightly tighten up the code slightly. gcc/rust/ChangeLog: * rust-gcc.cc (Bvariable::get_tree): Use error_operand_p. (pointer_type): Likewise. (reference_type): Likewise. (immutable_type): Likewise. (function_type): Likewise. (function_type_variadic): Likewise. Cleanup the check for receiver.type first. (function_ptr_type): Use error_operand_p. (fill_in_fields): Likewise. (fill_in_array): Likewise. (named_type): Likewise. (type_size): Likewise. (type_alignment): Likewise. (type_field_alignment): Likewise. (type_field_offset): Likewise. (zero_expression): Likewise. (float_constant_expression): Likewise. (convert_expression): Likewise. (struct_field_expression): Likewise. (compound_expression): Likewise. (conditional_expression): Likewise. (negation_expression): Likewise. (arithmetic_or_logical_expression): Likewise. (arithmetic_or_logical_expression_checked): Likewise. (comparison_expression): Likewise. (lazy_boolean_expression): Likewise. (constructor_expression): Likewise. (array_constructor_expression): Likewise. (array_index_expression): Likewise. (call_expression): Likewise. (init_statement): Likewise. (assignment_statement): Likewise. (return_statement): Likewise. (exception_handler_statement): Likewise. (if_statement): Likewise. (compound_statement): Likewise. Tighten up the code, removing t variable. (statement_list): Use error_operand_p. (block): Likewise. (block_add_statements): Likewise. (convert_tree): Likewise. (global_variable): Likewise. (global_variable_set_init): Likewise. (local_variable): Likewise. (parameter_variable): Likewise. (static_chain_variable): Likewise. (temporary_variable): Likewise. (function): Likewise. Tighten up the code. (function_defer_statement): Use error_operand_p. (function_set_parameters): Use error_operand_p. (write_global_definitions): Use error_operand_p. Tighten up the code around the loop. Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2025-04-10rust: Use FLOAT_TYPE_P instead of manual checkingAndrew Pinski1-4/+4
This moves is_floating_point over to using FLOAT_TYPE_P instead of manually checking. Note before it would return true for all COMPLEX_TYPE but complex types' inner type could be integral. Also fixes up the comment to be in more of the GNU style. Bootstrapped and tested on x86_64-linux-gnu. gcc/rust/ChangeLog: * rust-gcc.cc (is_floating_point): Use FLOAT_TYPE_P instead of manually checking the type. Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2025-04-01gccrs: Fix ICE when doing shift checks on const declPhilip Herron1-0/+6
Const decls are just delcarations wrapping the value into the DECL_INITIAL and the shift checks we have assume no decls are involved and its just flat values. This patch simply unwraps the constant values if they exist. Fixes Rust-GCC#3665 gcc/rust/ChangeLog: * rust-gcc.cc (arithmetic_or_logical_expression): unwrap const decls gcc/testsuite/ChangeLog: * rust/compile/issue-3665.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-01-10gccrs: cleanup our enum type layout to be closer to rustcPhilip Herron1-1/+1
This changes our enum type layout so for example: enum Foo { A, B, C(char), D { x: i32, y: i32 }, } Used to get layed out like this in gccrs: union { struct A { int RUST$ENUM$DISR; }; struct B { int RUST$ENUM$DISR; }; struct C { int RUST$ENUM$DISR; char __0; }; struct D { int RUST$ENUM$DISR; i64 x; i64 y; }; } This has some issues notably with the constexpr because this is just a giant union it means its not simple to constify what enum variant we are looking at because the discriminant is a mess. This now gets layed out as: struct { int RUST$ENUM$DISR; union { struct A { }; struct B { }; struct C { char __0; }; struct D { i64 x; i64 y; }; } payload; } This layout is much cleaner and allows for our constexpr to work properly. gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::visit): new layout * backend/rust-compile-pattern.cc (CompilePatternCheckExpr::visit): likewise (CompilePatternBindings::visit): likewise * backend/rust-compile-resolve-path.cc: likewise * backend/rust-compile-type.cc (TyTyResolveCompile::visit): implement new layout * rust-gcc.cc (constructor_expression): get rid of useless assert Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-12-13gccrs: fix bad not expression in rustPhilip Herron1-1/+1
Fixes Rust-GCC#3229 gcc/rust/ChangeLog: * rust-gcc.cc (operator_to_tree_code): ! expressions are BIT_NOT_EXPR Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-12-02gccrs: add checks for division by zero and left shift overflowPhilip Herron1-0/+11
These are ported from the c-family code c-warn.cc and c/c-typchk.cc Fixes Rust-GCC#2394 gcc/rust/ChangeLog: * backend/rust-constexpr.cc (eval_store_expression): check for null (eval_call_expression): remove bad warning * rust-gcc.cc (arithmetic_or_logical_expression): add warnings gcc/testsuite/ChangeLog: * rust/compile/issue-2394.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-11-27gccrs: ensure packed and aligned is applied properlyPhilip Herron1-6/+9
We cannot apply aligned or packed after layout_type is called you need to set this up first then call it. Fixes Rust-GCC#3260 gcc/rust/ChangeLog: * backend/rust-compile-type.cc (TyTyResolveCompile::visit): call lauout type directly * rust-backend.h (struct_type): add optional layout parameter (union_type): likewise (fill_in_fields): likewise * rust-gcc.cc (struct_type): likewise (union_type): likewise (fill_in_fields): only layout if we required Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-05-06Remove unnecessary SIDE_EFFECTS/READONLY macrosMael Cravero1-17/+0
Closes #2357 gcc/rust/ChangeLog: * rust-gcc.cc: remove unnecessary TREE_SIDE_EFFECTS and TREE_READONLY macros used in arithmetic overflow checks. Signed-off-by: Mael Cravero <mael.cravero@embecosm.com>
2024-02-16Update copyright years.Sahil Yeole1-1/+1
Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com>
2023-12-18gccrs: refactor builtins initialization and attributesArthur Cohen1-4/+4
This commit performs builtin initialization in a more "GCC-y" way, similarly to what the D frontend is doing. This way, we no longer have to worry about invalid attributes or types when initializing them by hand. Also add attributes support through LANG_HOOKS_COMMON_ATTRIBUTE_TABLE lang hook. Most of these changes are based on D frontend. gcc/rust/ChangeLog: * Make-lang.in (GRS_OBJS): Add rust-attribs.o. * backend/rust-builtins.cc (builtin_const, builtin_noreturn) (builtin_novops): Remove. (BuiltinsContext::lookup_simple_builtin): Adjust. (BuiltinsContext::setup_overflow_fns): Remove. (BuiltinsContext::define_function_type): Set builtin type to errormark so the builtin is considered unavailable. (BuiltinsContext::setup_math_fns): Remove. (BuiltinsContext::setup_atomic_fns): Remove. (build_c_type_nodes): Refactor based on D frontend. (BuiltinsContext::define_builtin_types): Likewise. (DEF_PRIMITIVE_TYPE): New. (DEF_FUNCTION_TYPE_0): New. (DEF_FUNCTION_TYPE_1): New. (DEF_FUNCTION_TYPE_2): New. (DEF_FUNCTION_TYPE_3): New. (DEF_FUNCTION_TYPE_4): New. (DEF_FUNCTION_TYPE_5): New. (DEF_FUNCTION_TYPE_6): New. (DEF_FUNCTION_TYPE_7): New. (DEF_FUNCTION_TYPE_8): New. (DEF_FUNCTION_TYPE_9): New. (DEF_FUNCTION_TYPE_10): New. (DEF_FUNCTION_TYPE_11): New. (DEF_FUNCTION_TYPE_VAR_0): New. (DEF_FUNCTION_TYPE_VAR_1): New. (DEF_FUNCTION_TYPE_VAR_2): New. (DEF_FUNCTION_TYPE_VAR_3): New. (DEF_FUNCTION_TYPE_VAR_4): New. (DEF_FUNCTION_TYPE_VAR_5): New. (DEF_FUNCTION_TYPE_VAR_6): New. (DEF_FUNCTION_TYPE_VAR_7): New. (DEF_FUNCTION_TYPE_VAR_11): New. (DEF_POINTER_TYPE): New. (BuiltinsContext::setup): Adjust. (BuiltinsContext::define_builtin_attributes): New. (DEF_ATTR_NULL_TREE): New. (DEF_ATTR_INT): New. (DEF_ATTR_STRING): New. (DEF_ATTR_IDENT): New. (DEF_ATTR_TREE_LIST): New. (handle_flags): Remove. (BuiltinsContext::define_builtins): New. (DEF_BUILTIN): New. (BuiltinsContext::define_builtin): Remove. (BuiltinsContext::register_rust_mappings): New. Add all missing builtins. (BuiltinsContext::lookup_gcc_builtin): Adjust. * backend/rust-builtins.h (DEF_PRIMITIVE_TYPE): New. (DEF_FUNCTION_TYPE_0): New. (DEF_FUNCTION_TYPE_1): New. (DEF_FUNCTION_TYPE_2): New. (DEF_FUNCTION_TYPE_3): New. (DEF_FUNCTION_TYPE_4): New. (DEF_FUNCTION_TYPE_5): New. (DEF_FUNCTION_TYPE_6): New. (DEF_FUNCTION_TYPE_7): New. (DEF_FUNCTION_TYPE_8): New. (DEF_FUNCTION_TYPE_9): New. (DEF_FUNCTION_TYPE_10): New. (DEF_FUNCTION_TYPE_11): New. (DEF_FUNCTION_TYPE_VAR_0): New. (DEF_FUNCTION_TYPE_VAR_1): New. (DEF_FUNCTION_TYPE_VAR_2): New. (DEF_FUNCTION_TYPE_VAR_3): New. (DEF_FUNCTION_TYPE_VAR_4): New. (DEF_FUNCTION_TYPE_VAR_5): New. (DEF_FUNCTION_TYPE_VAR_6): New. (DEF_FUNCTION_TYPE_VAR_7): New. (DEF_FUNCTION_TYPE_VAR_11): New. (DEF_POINTER_TYPE): New. (DEF_ATTR_NULL_TREE): New. (DEF_ATTR_INT): New. (DEF_ATTR_STRING): New. (DEF_ATTR_IDENT): New. (DEF_ATTR_TREE_LIST): New. * backend/rust-compile-intrinsic.cc (Intrinsics::compile): Add comment. (op_with_overflow_inner): Adjust. (copy_handler_inner): Adjust. (prefetch_data_handler): Adjust. (build_atomic_builtin_name): Adjust. (atomic_load_handler_inner): Adjust. (uninit_handler): Adjust. (move_val_init_handler): Adjust. (expect_handler_inner): Adjust. * rust-gcc.cc (fetch_overflow_builtins): Adjust. * rust-lang.cc (rust_localize_identifier): Adjust. (LANG_HOOKS_COMMON_ATTRIBUTE_TABLE): New. * rust-attribs.cc: New file. gcc/testsuite/ChangeLog: * rust/compile/torture/intrinsics-4.rs: Adjust. * rust/compile/torture/intrinsics-math.rs: Adjust. * rust/execute/torture/atomic_load.rs: Adjust. * rust/execute/torture/atomic_store.rs: Adjust. * rust/compile/torture/intrinsics-1.rs: Removed. * rust/compile/torture/builtin_abort.rs: New test. * rust/execute/torture/builtin_abort.rs: New test. Signed-off-by: Marc Poulhiès <dkm@kataplop.net> Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2023-09-17gccrs: Minor typo fixMarc Poulhiès1-4/+4
Fix varadic -> variadic gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::visit): Fix typo in varIadic. * backend/rust-compile-type.cc (TyTyResolveCompile::visit): Likewise. * rust-backend.h (function_type_varadic): Rename into ... (function_type_variadic): ... this. * rust-gcc.cc (function_type_varadic): Rename into ... (function_type_variadic): ... this. * typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Likewise. * typecheck/rust-tyty.h (is_varadic): Renamed into ... (is_variadic): ... this. Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
2023-09-14Memoize Backend::wchar_typeOwen Avery1-2/+8
gcc/rust/ChangeLog: * rust-gcc.cc (Backend::wchar_type): Store static wchar tree. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2023-09-14Remove unused complex number supportOwen Avery1-90/+0
gcc/rust/ChangeLog: * rust-backend.h (complex_type): Remove. (complex_constant_expression): Remove. (real_part_expression): Remove. (imag_part_expression): Remove. (complex_expression): Remove. * rust-gcc.cc (complex_type): Remove. (complex_constant_expression): Remove. (real_part_expression): Remove. (imag_part_expression): Remove. (complex_expression): Remove. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2023-09-13Use namespace definition to simplify function declarationsOwen Avery1-126/+119
gcc/rust/ChangeLog: * rust-gcc.cc (namespace Backend): Use namespace definition instead of qualified names. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2023-09-12Shorten `make_unsigned_long_tree` code and remove ↵Guillaume Gomez1-13/+0
`Backend::integer_constant_expression` gcc/rust/ChangeLog: * backend/rust-compile-intrinsic.cc: Simplify `make_unsigned_long_tree` * rust-backend.h: Remove `integer_constant_expression` * rust-gcc.cc: Remove `integer_constant_expression`
2023-09-07Convert class Backend into namespaceOwen Avery1-9/+2
gcc/rust/ChangeLog: * rust-backend.h (class Backend): Convert to ... (namespace Backend): ... namespace. * rust-gcc.cc (Backend::Backend): Rename to ... (Backend::init): ... here. (rust_get_backend): Remove. * rust-session-manager.cc (rust_get_backend): Remove. (Session::init): Use Backend::init instead of rust_get_backend. (Session::compile_crate): Initialize Context without pointer to Backend. * rust-session-manager.h (Session::backend): Remove. * backend/rust-compile-context.cc (Context::Context): Remove pointer to Backend. * backend/rust-compile-context.h (class Context): Remove pointer to Backend, update function calls. * backend/rust-compile-base.cc: Update function calls. * backend/rust-compile-block.cc: Likewise. * backend/rust-compile-expr.cc: Likewise. * backend/rust-compile-extern.h: Likewise. * backend/rust-compile-fnparam.cc: Likewise. * backend/rust-compile-intrinsic.cc: Likewise. * backend/rust-compile-item.cc: Likewise. * backend/rust-compile-pattern.cc: Likewise. * backend/rust-compile-resolve-path.cc: Likewise. * backend/rust-compile-type.cc: Likewise. * backend/rust-compile-var-decl.h: Likewise. * backend/rust-compile.cc: Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2023-09-07Remove Gcc_backendOwen Avery1-2/+2
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>
2023-09-06Remove Backend::write_export_dataOwen Avery1-6/+0
gcc/rust/ChangeLog: * rust-backend.h (Backend::write_export_data): Remove. * rust-gcc.cc (Backend::write_export_data): Remove.
2023-09-06Move remaining expression-related methods into base class BackendOwen Avery1-33/+33
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>
2023-09-04Move block-related methods into base class BackendOwen Avery1-5/+5
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>
2023-09-04Move statement-related methods into base class BackendOwen Avery1-12/+11
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>
2023-09-04Move function-related methods into base class BackendOwen Avery1-10/+10
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>
2023-09-03Move some simple expression-related methods into base class BackendOwen Avery1-9/+9
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>
2023-09-03Move variable-related methods into base class BackendOwen Avery1-17/+16
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>
2023-09-02Move debug-related functions into base class BackendOwen Avery1-3/+3
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>
2023-09-02Move label-related functions into base class BackendOwen Avery1-5/+4
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>
2023-09-01Move type-related functions into base class BackendOwen Avery1-32/+30
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>
2023-08-10Remove unneeded references to "this" in backend methodsOwen Avery1-38/+33
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>
2023-08-09Move Backend::error_variable to Bvariable::error_variableOwen Avery1-5/+11
gcc/rust/ChangeLog: * rust-backend.h (Backend::error_variable): Remove. (Gcc_backend::error_variable): Move to ... * rust-gcc.cc (Bvariable::error_variable): ... here ... * rust-gcc.h (Bvariable::error_variable): ... and declare here. (Gcc_backend::global_variable): Update error_variable call. (Gcc_backend::local_variable): Likewise. (Gcc_backend::parameter_variable): Likewise. (Gcc_backend::static_chain_variable): Likewise. (Gcc_backend::temporary_variable): Likewise. * backend/rust-compile-extern.h (CompileExternItem::visit): Likewise. * backend/rust-compile-fnparam.cc (CompileFnParam::CompileFnParam): Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2023-08-09Remove Backend::bool_type and Backend::char_typeOwen Avery1-1/+1
gcc/rust/ChangeLog: * backend/rust-compile-type.cc (TyTyResolveCompile::visit): Inline Backend::bool_type call. * rust-backend.h (Backend::bool_type): Remove. (Backend::char_type): Remove. (Gcc_backend::bool_type): Remove. (Gcc_backend::char_type): Remove. * rust-gcc.cc (Gcc_backend::char_constant_expression): Inline Backend::char_type call. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2023-07-29Move Gcc_backend declaration to header fileOwen Avery1-214/+0
gcc/rust/ChangeLog: * rust-backend.h: Include "rust-gcc.h". (class Gcc_backend): Move to ... * rust-gcc.cc (class Gcc_backend): ... here. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2023-07-29Remove Location typedefOwen Avery1-5/+6
gcc/rust/ChangeLog: * rust-location.h (typedef Location): Remove. * expand/rust-proc-macro.cc (register_callback): Replace Location constructor with UNDEF_LOCATION. * ast/rust-ast-collector.h: Replace Location with location_t. * checks/errors/privacy/rust-privacy-reporter.cc: Likewise. * checks/errors/privacy/rust-privacy-reporter.h: Likewise. * checks/errors/privacy/rust-pub-restricted-visitor.cc: Likewise. * checks/errors/privacy/rust-pub-restricted-visitor.h: Likewise. * checks/errors/rust-feature-gate.cc: Likewise. * checks/errors/rust-feature-gate.h: Likewise. * metadata/rust-imports.h: Likewise. * resolve/rust-ast-resolve-path.h: Likewise. * resolve/rust-name-resolver.h: Likewise. * rust-backend.h: Likewise. * rust-diagnostics.h: Likewise. * rust-gcc.cc: Likewise. * rust-linemap.h: Likewise. * util/rust-attributes.cc: Likewise. * util/rust-hir-map.cc: Likewise. * util/rust-hir-map.h: Likewise. * util/rust-token-converter.cc: Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2023-07-27Replace Location with location_t in unnamed function parametersOwen Avery1-39/+41
gcc/rust/ChangeLog: * backend/rust-compile-base.h: Replace Location with location_t. * metadata/rust-imports.h: Likewise. * resolve/rust-name-resolver.cc: Likewise. * resolve/rust-name-resolver.h: Likewise. * rust-backend.h: Likewise. * rust-gcc.cc: Likewise. * rust-gcc.h: Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2023-07-21Continue to replace usages of Location with location_tOwen Avery1-35/+38
gcc/rust/ChangeLog: * backend/rust-compile-base.cc: Replace Location with location_t. * backend/rust-compile-base.h: Likewise. * backend/rust-compile-expr.cc: Likewise. * lex/rust-token.h: Likewise. * metadata/rust-import-archive.cc: Likewise. * metadata/rust-imports.cc: Likewise. * metadata/rust-imports.h: Likewise. * rust-backend.h: Likewise. * rust-diagnostics.cc: Likewise. * rust-diagnostics.h: Likewise. * rust-gcc.cc: Likewise. * rust-linemap.cc: Likewise. * util/rust-token-converter.cc: Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2023-07-17Replace some usages of Location with location_tOwen Avery1-4/+4
gcc/rust/ChangeLog: * ast/rust-ast-collector.cc: Replace Location with location_t. * ast/rust-ast.cc: Likewise. * ast/rust-ast.h: Likewise. * ast/rust-expr.h: Likewise. * ast/rust-item.h: Likewise. * ast/rust-macro.h: Likewise. * ast/rust-path.cc: Likewise. * ast/rust-path.h: Likewise. * ast/rust-pattern.h: Likewise. * ast/rust-stmt.h: Likewise. * ast/rust-type.h: Likewise. * backend/rust-compile-base.cc: Likewise. * backend/rust-compile-base.h: Likewise. * backend/rust-compile-block.cc: Likewise. * backend/rust-compile-expr.cc: Likewise. * backend/rust-compile-expr.h: Likewise. * backend/rust-compile-fnparam.cc: Likewise. * backend/rust-compile-fnparam.h: Likewise. * backend/rust-compile-intrinsic.cc: Likewise. * backend/rust-compile-pattern.cc: Likewise. * backend/rust-compile-resolve-path.h: Likewise. * backend/rust-compile.cc: Likewise. * checks/errors/rust-const-checker.cc: Likewise. * checks/errors/rust-const-checker.h: Likewise. * checks/errors/rust-unsafe-checker.cc: Likewise. * checks/errors/rust-unsafe-checker.h: Likewise. * expand/rust-macro-builtins.cc: Likewise. * expand/rust-macro-expand.h: Likewise. * hir/rust-ast-lower-base.h: Likewise. * hir/rust-ast-lower-implitem.h: Likewise. * hir/rust-ast-lower-item.cc: Likewise. * hir/tree/rust-hir-expr.h: Likewise. * hir/tree/rust-hir-item.h: Likewise. * hir/tree/rust-hir-path.h: Likewise. * hir/tree/rust-hir-pattern.h: Likewise. * hir/tree/rust-hir-stmt.h: Likewise. * hir/tree/rust-hir-type.h: Likewise. * hir/tree/rust-hir.cc: Likewise. * hir/tree/rust-hir.h: Likewise. * lex/rust-token.h: Likewise. * metadata/rust-extern-crate.cc: Likewise. * metadata/rust-extern-crate.h: Likewise. * parse/rust-parse-impl.h: Likewise. * parse/rust-parse.h: Likewise. * resolve/rust-ast-resolve-expr.cc: Likewise. * resolve/rust-ast-resolve-implitem.h: Likewise. * resolve/rust-ast-resolve-pattern.h: Likewise. * resolve/rust-ast-resolve-stmt.h: Likewise. * resolve/rust-ast-resolve-toplevel.h: Likewise. * resolve/rust-ast-resolve-type.h: Likewise. * resolve/rust-name-resolver.cc: Likewise. * resolve/rust-name-resolver.h: Likewise. * rust-diagnostics.cc: Likewise. * rust-diagnostics.h: Likewise. * rust-gcc.cc: Likewise. * rust-session-manager.cc: Likewise. * rust-session-manager.h: Likewise. * typecheck/rust-casts.cc: Likewise. * typecheck/rust-casts.h: Likewise. * typecheck/rust-coercion.cc: Likewise. * typecheck/rust-coercion.h: Likewise. * typecheck/rust-hir-path-probe.cc: Likewise. * typecheck/rust-hir-path-probe.h: Likewise. * typecheck/rust-hir-trait-reference.cc: Likewise. * typecheck/rust-hir-trait-reference.h: Likewise. * typecheck/rust-hir-trait-resolve.cc: Likewise. * typecheck/rust-hir-type-check-base.cc: Likewise. * typecheck/rust-hir-type-check-base.h: Likewise. * typecheck/rust-hir-type-check-item.cc: Likewise. * typecheck/rust-hir-type-check-item.h: Likewise. * typecheck/rust-hir-type-check-path.cc: Likewise. * typecheck/rust-hir-type-check-pattern.cc: Likewise. * typecheck/rust-hir-type-check-pattern.h: Likewise. * typecheck/rust-hir-type-check-type.cc: Likewise. * typecheck/rust-hir-type-check-type.h: Likewise. * typecheck/rust-hir-type-check.cc: Likewise. * typecheck/rust-hir-type-check.h: Likewise. * typecheck/rust-substitution-mapper.cc: Likewise. * typecheck/rust-substitution-mapper.h: Likewise. * typecheck/rust-type-util.cc: Likewise. * typecheck/rust-typecheck-context.cc: Likewise. * typecheck/rust-tyty-bounds.cc: Likewise. * typecheck/rust-tyty-call.h: Likewise. * typecheck/rust-tyty-subst.cc: Likewise. * typecheck/rust-tyty-subst.h: Likewise. * typecheck/rust-tyty-util.cc: Likewise. * typecheck/rust-tyty-util.h: Likewise. * typecheck/rust-tyty.cc: Likewise. * typecheck/rust-tyty.h: Likewise. * typecheck/rust-unify.cc: Likewise. * typecheck/rust-unify.h: Likewise. * util/rust-hir-map.cc: Likewise. * util/rust-hir-map.h: Likewise. * util/rust-identifier.h: Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2023-07-17Move some Gcc_backend method definitions out of class declarationOwen Avery1-12/+30
gcc/rust/ChangeLog: * rust-gcc.cc (Gcc_backend::debug): Move out of class declaration. (Gcc_backend::get_identifier_node): Likewise. (Gcc_backend::wchar_type): Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2023-07-14rust-unreachable: Add specific behavior for rust_unreachableArthur Cohen1-8/+8
As discussed during the community call, rust_unreachable() should always trigger an internal compiler error and should not offer the behavior of __builtin_unreachable when asserts are disabled, unlike gcc_unreachable(). gcc/rust/ChangeLog: * rust-system.h (rust_unreachable): Change definition to fancy_abort * ast/rust-ast-collector.cc (TokenCollector::visit): Use rust_unreachable instead of gcc_unreachable. (get_delimiters): Likewise. * ast/rust-ast-dump.h: Likewise. * ast/rust-ast-formatting.cc (get_string_in_delims): Likewise. (get_mode_dump_desc): Likewise. * ast/rust-ast.cc (Visibility::as_string): Likewise. (UseTreeGlob::as_string): Likewise. * ast/rust-ast.h: Likewise. * ast/rust-macro.h: Likewise. * ast/rust-path.h: Likewise. * backend/rust-compile-expr.cc (sort_tuple_patterns): Likewise. (CompileExpr::visit): Likewise. (CompileExpr::generate_closure_fntype): Likewise. * backend/rust-compile-intrinsic.cc (op_with_overflow_inner): Likewise. * backend/rust-compile-pattern.cc (CompilePatternBindings::visit): Likewise. (CompilePatternLet::visit): Likewise. * backend/rust-constexpr.cc (base_field_constructor_elt): Likewise. (eval_array_reference): Likewise. (label_matches): Likewise. (eval_store_expression): Likewise. (eval_call_expression): Likewise. (build_data_member_initialization): Likewise. (array_index_cmp): Likewise. (get_array_or_vector_nelts): Likewise. (eval_bit_field_ref): Likewise. (eval_loop_expr): Likewise. (potential_constant_expression_1): Likewise. * backend/rust-mangle.cc (v0_simple_type_prefix): Likewise. (v0_type_prefix): Likewise. (v0_mangle_item): Likewise. (Mangler::mangle_item): Likewise. * backend/rust-tree.cc (convert_to_void): Likewise. (type_memfn_quals): Likewise. (rs_tree_equal): Likewise. (fold_offsetof): Likewise. (fold_builtin_source_location): Likewise. (lvalue_error): Likewise. * backend/rust-tree.h (struct named_decl_hash): Likewise. (struct named_label_hash): Likewise. * checks/errors/privacy/rust-visibility-resolver.cc (VisibilityResolver::resolve_visibility): Likewise. (VisibilityResolver::visit): Likewise. * checks/errors/rust-const-checker.cc (ConstChecker::ctx_to_str): Likewise. * checks/errors/rust-feature.cc (Feature::create): Likewise. * expand/rust-expand-visitor.cc (get_traits_to_derive): Likewise. (derive_item): Likewise. (expand_item_attribute): Likewise. (expand_stmt_attribute): Likewise. * expand/rust-macro-expand.cc (MacroExpander::match_matcher): Likewise. (MacroExpander::match_repetition): Likewise. (transcribe_context): Likewise. (MacroExpander::import_proc_macros): Likewise. (MacroExpander::parse_proc_macro_output): Likewise. * expand/rust-macro-expand.h: Likewise. * expand/rust-macro-invoc-lexer.h: Likewise. * expand/rust-macro-substitute-ctx.cc (SubstituteCtx::substitute_token): Likewise. * expand/rust-proc-macro-invoc-lexer.h: Likewise. * expand/rust-proc-macro.cc (load_macros): Likewise. * hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_generic_args): Likewise. (ASTLoweringBase::lower_literal): Likewise. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise. * hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::visit): Likewise. * hir/rust-ast-lower-type.cc (ASTLoweringType::visit): Likewise. * hir/rust-hir-dump.cc (Dump::visit): Likewise. * hir/tree/rust-hir.cc (get_string_in_delims): Likewise. (Visibility::as_string): Likewise. (UseTreeGlob::as_string): Likewise. (CompoundAssignmentExpr::as_string): Likewise. (ArithmeticOrLogicalExpr::as_string): Likewise. * lex/rust-lex.cc (Lexer::parse_byte_string): Likewise. (Lexer::parse_string): Likewise. * lex/rust-token.cc (RS_TOKEN): Likewise. * parse/rust-parse-impl.h (Parser::parse_simple_path_segment): Likewise. (Parser::parse_path_ident_segment): Likewise. (Parser::parse_attr_input): Likewise. (Parser::parse_inherent_impl_item): Likewise. (Parser::parse_trait_impl_item): Likewise. (Parser::parse_type_path_segment): Likewise. (Parser::parse_reference_type): Likewise. (get_lbp_for_comparison_expr): Likewise. * parse/rust-parse.cc (peculiar_fragment_match_compatible): Likewise. * resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path): Likewise. * resolve/rust-ast-resolve-pattern.cc (PatternDeclaration::visit): Likewise. * resolve/rust-ast-resolve-type.cc (ResolveRelativeTypePath::go): Likewise. (ResolveTypeToCanonicalPath::visit): Likewise. (ResolveGenericArgs::resolve_disambiguated_generic): Likewise. * rust-gcc.cc (operator_to_tree_code): Likewise. (fetch_overflow_builtins): Likewise. (Gcc_backend::non_zero_size_type): Likewise. (Gcc_backend::convert_tree): Likewise. * rust-lang.cc (grs_langhook_type_for_mode): Likewise. (grs_langhook_global_bindings_p): Likewise. (grs_langhook_pushdecl): Likewise. (grs_langhook_getdecls): Likewise. (convert): Likewise. * typecheck/rust-autoderef.h: Likewise. * typecheck/rust-hir-path-probe.cc: Likewise. * typecheck/rust-hir-trait-reference.cc (TraitItemReference::get_tyty): Likewise. * typecheck/rust-hir-type-check-base.cc (TypeCheckBase::resolve_literal): Likewise. * typecheck/rust-hir-type-check-expr.cc: Likewise. * typecheck/rust-hir-type-check-expr.h: Likewise. * typecheck/rust-hir-type-check-implitem.cc (TypeCheckImplItem::visit): Likewise. * typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): Likewise. * typecheck/rust-hir-type-check-stmt.h: Likewise. * typecheck/rust-hir-type-check.cc (TraitItemReference::get_type_from_fn): Likewise. * typecheck/rust-substitution-mapper.h: Likewise. * typecheck/rust-typecheck-context.cc (TypeCheckContextItem::get_context_type): Likewise. * typecheck/rust-tyty-call.h: Likewise. * typecheck/rust-tyty.cc (TypeKindFormat::to_string): Likewise. (BaseType::monomorphized_clone): Likewise. (VariantDef::variant_type_string): Likewise. (ClosureType::handle_substitions): Likewise. (IntType::as_string): Likewise. (UintType::as_string): Likewise. (FloatType::as_string): Likewise. * typecheck/rust-unify.cc (UnifyRules::expect_projection): Likewise. * util/rust-token-converter.cc (convert): Likewise. (from_literal): Likewise. (from_group): Likewise. (from_tokentree): Likewise.
2023-07-06Change class Location into typedefOwen Avery1-99/+75
gcc/rust/ChangeLog: * backend/rust-compile-base.cc (HIRCompileBase::address_expression): Remove gcc_location method call. (HIRCompileBase::indirect_expression): Likewise. (HIRCompileBase::compile_constant_item): Likewise. (HIRCompileBase::named_constant_expression): Likewise. * backend/rust-compile-expr.cc (CompileExpr::visit): Remove gcc_location method call, use UNKNOWN_LOCATION to initialize. (CompileExpr::get_fn_addr_from_dyn): Remove gcc_location method call. (CompileExpr::type_cast_expression): Likewise. * backend/rust-compile-intrinsic.cc (transmute_handler): Replace "Location ().gcc_location ()" with UNKNOWN_LOCATION. (copy_nonoverlapping_handler): Likewise. (prefetch_data_handler): Likewise. (atomic_store_handler_inner): Likewise. (atomic_load_handler_inner): Likewise. * resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Remove gcc_location method call. * rust-diagnostics.cc (rust_be_error_at): Likewise. (rust_be_warning_at): Likewise. (rust_be_fatal_error): Likewise. (rust_be_inform): Likewise. * rust-diagnostics.h (rust_sorry_at): Likewise. * rust-gcc.cc (Bvariable::get_tree): Likewise. (Gcc_backend::fill_in_fields): Likewise. (Gcc_backend::named_type): Likewise. (Gcc_backend::real_part_expression): Likewise. (Gcc_backend::imag_part_expression): Likewise. (Gcc_backend::complex_expression): Likewise. (Gcc_backend::convert_expression): Likewise. (Gcc_backend::struct_field_expression): Likewise. (Gcc_backend::compound_expression): Likewise. (Gcc_backend::conditional_expression): Likewise. (Gcc_backend::negation_expression): Likewise. (Gcc_backend::arithmetic_or_logical_expression): Likewise. (Gcc_backend::arithmetic_or_logical_expression_checked): Likewise. (Gcc_backend::comparison_expression): Likewise. (Gcc_backend::lazy_boolean_expression): Likewise. (Gcc_backend::constructor_expression): Likewise. (Gcc_backend::array_constructor_expression): Likewise. (Gcc_backend::array_initializer): Likewise. (Gcc_backend::array_index_expression): Likewise. (Gcc_backend::call_expression): Likewise. (Gcc_backend::assignment_statement): Likewise. (Gcc_backend::return_statement): Likewise. (Gcc_backend::exception_handler_statement): Likewise. (Gcc_backend::if_statement): Likewise. (Gcc_backend::loop_expression): Likewise. (Gcc_backend::exit_expression): Likewise. (Gcc_backend::block): Likewise. (Gcc_backend::convert_tree): Likewise. (Gcc_backend::global_variable): Likewise. (Gcc_backend::local_variable): Likewise. (Gcc_backend::parameter_variable): Likewise. (Gcc_backend::static_chain_variable): Likewise. (Gcc_backend::temporary_variable): Likewise. (Gcc_backend::label): Likewise. (Gcc_backend::goto_statement): Likewise. (Gcc_backend::label_address): Likewise. (Gcc_backend::function): Likewise. * rust-linemap.cc (Gcc_linemap::to_string): Likewise. (Gcc_linemap::location_file): Likewise. (Gcc_linemap::location_line): Likewise. (Gcc_linemap::location_column): Likewise. (Gcc_linemap::is_predeclared): Likewise. (Gcc_linemap::is_unknown): Likewise. (RichLocation::RichLocation): Likewise. (RichLocation::add_range): Likewise. (RichLocation::add_fixit_insert_before): Likewise. (RichLocation::add_fixit_insert_after): Likewise. * rust-location.h (class Location): Replace with typedef. (operator<): Remove. (operator==): Remove. (operator+): Remove. (operator-): Remove. * typecheck/rust-hir-trait-resolve.cc (AssociatedImplTrait::setup_associated_types): Initialize Location with UNKNOWN_LOCATION. * typecheck/rust-hir-type-check-stmt.cc (TypeCheckStmt::visit): Likewise. * util/rust-token-converter.cc (convert): Remove gcc_location method call. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2023-05-08gccrs: Redo how we handle unit types for the final timePhilip Herron1-108/+8
We had a very inconsistant way for dealing with unit-types in gccrs we tried to optimize the case for a function returning unit type to be clever and not emit any return value for unit types. Then for other cases we would use an empty constructor for an empty tuple and in others use a zero percsion integer. This was all just confusing and made the IR less conformant to Rust. In this patch I change all of this to use an empty tuple type for all cases so we pass around {} which maps over to Rust and gets optimized away in the middle end anyway. In the patch we also remove old gccgo code which optimizes away zero size types to void_type_node which is why my original attempt at doing this two years ago failed. Fixes #2188 gcc/rust/ChangeLog: * backend/rust-compile-base.cc (HIRCompileBase::compile_function_body): use unit_expression (HIRCompileBase::unit_expression): new helper * backend/rust-compile-base.h: update prototype * backend/rust-compile-block.cc (CompileBlock::visit): use unit_expression * backend/rust-compile-expr.cc (CompileExpr::visit): likewise (CompileExpr::generate_closure_function): likewise * backend/rust-compile-implitem.cc (CompileTraitItem::visit): cleanup * backend/rust-compile-item.cc (CompileItem::visit): likewise * backend/rust-compile-pattern.cc (CompilePatternLet::visit): likewise * backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve): likewise * backend/rust-compile-type.cc (TyTyResolveCompile::get_unit_type): new helper (TyTyResolveCompile::visit): use new unit_type helper * backend/rust-compile-type.h: likewise * rust-backend.h: simplify the return_expression * rust-gcc.cc (Gcc_backend::function_type): likewise (Gcc_backend::return_statement): likewise * backend/rust-constexpr.cc (eval_constant_expression): remove bad assertion gcc/testsuite/ChangeLog: * rust/compile/issue-2188.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2023-02-12Merge commit '83ffe9cde7fe0b4deb0d1b54175fd9b19c38179c' into HEADThomas Schwinge1-1/+1
Conflicts: gcc/rust/rust-gcc-diagnostics.cc gcc/rust/typecheck/rust-hir-trait-ref.h gcc/rust/typecheck/rust-hir-type-check-toplevel.cc gcc/rust/typecheck/rust-hir-type-check-toplevel.h gcc/rust/typecheck/rust-tyctx.cc gcc/rust/typecheck/rust-tyty-rules.h Upstream GCC commit r13-5197-g83ffe9cde7fe0b4deb0d1b54175fd9b19c38179c "Update copyright years" did updated those files that don't exist in GCC/Rust master branch anymore.
2023-01-16Update copyright years.Jakub Jelinek1-1/+1
2022-12-13gccrs: Add base for HIR to GCC GENERIC loweringPhilip Herron1-0/+2718
This pass walks the HIR crate and turns them into GCC `tree`s. We do not have any Rust specific tree's. We are slowly removing the backend abstraction which was ported over from gccgo in favour of using `tree`s directly. gcc/rust/ * backend/rust-builtins.h: New. * backend/rust-compile-base.cc: New. * backend/rust-compile-base.h: New. * backend/rust-mangle.cc: New. * backend/rust-mangle.h: New. * backend/rust-tree.cc: New. * backend/rust-tree.h: New. * rust-backend.h: New. * rust-gcc.cc: New. Co-authored-by: David Faust <david.faust@oracle.com>
2022-12-09var_expression: document that the memory of the val argument isn't freedArthur Cohen1-0/+1
2022-12-09Merge #1683bors[bot]1-1/+1
1683: backend: Replace double_int_to_tree -> wide_int_to_tree r=CohenArthur a=CohenArthur Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-12-06backend: Don't fold convert_to expressionsArthur Cohen1-4/+4
2022-12-06backend: Replace double_int_to_tree -> wide_int_to_treeArthur Cohen1-1/+1
2022-12-04Revert "builtins: Cleanup initialization of builtins"Philip Herron1-4/+4
This reverts commit fc59d137491ce393797dfec1d8cd5251a41b5f67.