platform/upstream/gcc.git
16 months agogccrs: ast: Dump never type
Jakub Dupak [Sun, 6 Nov 2022 20:23:12 +0000 (21:23 +0100)]
gccrs: ast: Dump never type

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc (Dump::visit): Add missing never type visitor.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
16 months agogccrs: ast: Dump raw pointer type
Jakub Dupak [Sun, 6 Nov 2022 20:21:34 +0000 (21:21 +0100)]
gccrs: ast: Dump raw pointer type

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc (Dump::visit): Add missing RawPointer visitor.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
16 months agogccrs: ast: Dump array type
Jakub Dupak [Sun, 6 Nov 2022 19:54:40 +0000 (20:54 +0100)]
gccrs: ast: Dump array type

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc (Dump::visit): Add missing array visitor

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
16 months agogccrs: ast: Dump slice type
Jakub Dupak [Sun, 6 Nov 2022 19:49:17 +0000 (20:49 +0100)]
gccrs: ast: Dump slice type

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc (Dump::visit): Add missing slice visitor.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
16 months agogccrs: ast: Dump where clause and recursively needed nodes
Jakub Dupak [Fri, 4 Nov 2022 22:48:12 +0000 (23:48 +0100)]
gccrs: ast: Dump where clause and recursively needed nodes

This is currently needed for lifetimes to use the existing infrastructure.

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc (Dump::visit): Add missing visitors.
* ast/rust-ast-dump.h: Likewise.
* ast/rust-ast.h: Add `get_lifetime_bounds` method.
* ast/rust-item.h: Add missing getter for lifetimes.
* ast/rust-type.h: Likewise.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
16 months agogccrs: ast: add visit overload for references
Jakub Dupak [Fri, 4 Nov 2022 22:30:24 +0000 (23:30 +0100)]
gccrs: ast: add visit overload for references

This is currently needed for lifetimes to use the existing infrastructure.

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc (Dump::visit): Add new reference visitor wrapper.
* ast/rust-ast-dump.h: Declare it.
* ast/rust-item.h: Add mutable visibility getters.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
16 months agogccrs: typecheck: Fix overzealous `delete` call
Arthur Cohen [Wed, 2 Nov 2022 08:52:01 +0000 (09:52 +0100)]
gccrs: typecheck: Fix overzealous `delete` call

gcc/rust/ChangeLog:

* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Fix extra call
to `delete`.

16 months agogccrs: add Location to AST::Visibility
Dave [Thu, 10 Nov 2022 05:17:50 +0000 (23:17 -0600)]
gccrs: add Location to AST::Visibility

gcc/rust/ChangeLog:

* ast/rust-item.h: Add location member.
* hir/rust-ast-lower.cc (translate_visibility): Pass location argument.
* hir/tree/rust-hir-item.h: Fix constructor to accept Location argument.

16 months agogccrs: add lang item "phantom_data"
Raiki Tamura [Wed, 9 Nov 2022 09:49:12 +0000 (18:49 +0900)]
gccrs: add lang item "phantom_data"

gcc/rust/ChangeLog:

* util/rust-lang-item.h: Add handling for `phantom_data` lang item.

gcc/testsuite/ChangeLog:

* rust/compile/torture/phantom_data.rs: New test.

16 months agogccrs: ast: Dump unit struct
Jakub Dupak [Fri, 28 Oct 2022 15:58:39 +0000 (17:58 +0200)]
gccrs: ast: Dump unit struct

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc (Dump::visit): Add handling for unit structures.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
16 months agogccrs: ast: refer correctly to arguments in docs-strings
Jakub Dupak [Fri, 28 Oct 2022 15:27:16 +0000 (17:27 +0200)]
gccrs: ast: refer correctly to arguments in docs-strings

gcc/rust/ChangeLog:

* ast/rust-ast-dump.h: Fix documentation.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
16 months agogccrs: ast: transform helper methods to visits and add methods to simplify repeated...
Jakub Dupak [Thu, 27 Oct 2022 23:37:48 +0000 (01:37 +0200)]
gccrs: ast: transform helper methods to visits and add methods to simplify repeated patterns

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc (Dump::go): Use new API.
(Dump::format_function_param): Refactor.
(Dump::visit_items_joined_by_separator): New function.
(Dump::emit_attrib): Refactor.
(Dump::visit_as_line): New function.
(Dump::visit_items_as_lines): Likewise.
(Dump::visit_items_as_block): Likewise.
(Dump::visit): Use new API.
(Dump::emit_visibility): Likewise.
(Dump::emit_indented_string): Likewise.
(Dump::emit_generic_params): Likewise.
(Dump::format_tuple_field): Likewise.
(Dump::format_struct_field): Likewise.
(Dump::format_function_common): Likewise.
(Dump::visit_function_common): Likewise.
* ast/rust-ast-dump.h: Declare new functions and add documentation.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
16 months agogccrs: ast: visitor pattern -> overload syntax compatibility layer
Jakub Dupak [Thu, 27 Oct 2022 20:27:55 +0000 (22:27 +0200)]
gccrs: ast: visitor pattern -> overload syntax compatibility layer

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc (Dump::visit): Add new visit function for overloading.
* ast/rust-ast-dump.h: Add documentation for layer.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
16 months agogccrs: intrinsics: Implement atomic_load intrinsics
Arthur Cohen [Wed, 26 Oct 2022 15:00:55 +0000 (17:00 +0200)]
gccrs: intrinsics: Implement atomic_load intrinsics

gcc/rust/ChangeLog:

* backend/rust-builtins.cc (BuiltinsContext::setup_atomic_fns): Declare atomic
load intrinsics.
* backend/rust-compile-intrinsic.cc (atomic_load_handler_inner): New handler.
(atomic_load_handler): Likewise.
(unchecked_op_handler): Remove `static` function qualifier.
(build_atomic_builtin_name): Handle load intrinsics.
(atomic_store_handler_inner): New handler.

gcc/testsuite/ChangeLog:

* rust/compile/torture/intrinsics-3.rs:
* rust/execute/torture/atomic_load.rs: New test.

16 months agogccrs: intrinsics: Cleanup error handling around atomic_store_*
Arthur Cohen [Wed, 26 Oct 2022 14:35:12 +0000 (16:35 +0200)]
gccrs: intrinsics: Cleanup error handling around atomic_store_*

gcc/rust/ChangeLog:

* backend/rust-compile-intrinsic.cc (check_for_basic_integer_type): New function.
(build_atomic_builtin_name): Use HIR Type instead of `tree`.
(atomic_store_handler_inner): Cleanup error handling.
(unchecked_op_inner): Likewise.

gcc/testsuite/ChangeLog:

* rust/compile/torture/intrinsics-5.rs: Fix error message.

16 months agogccrs: intrinsics: Use lambdas for wrapping_<op> intrinsics
Arthur Cohen [Wed, 26 Oct 2022 14:06:53 +0000 (16:06 +0200)]
gccrs: intrinsics: Use lambdas for wrapping_<op> intrinsics

gcc/rust/ChangeLog:

* backend/rust-compile-intrinsic.cc (wrapping_op_handler): Refactor to return
an `std::function`.
(wrapping_op_handler_inner): Rename.
(wrapping_add_handler): Remove function.
(wrapping_sub_handler): Likewise.
(wrapping_mul_handler): Likewise.

16 months agogccrs: intrinsics: Add unchecked operation intrinsics
Arthur Cohen [Wed, 26 Oct 2022 13:57:54 +0000 (15:57 +0200)]
gccrs: intrinsics: Add unchecked operation intrinsics

gcc/rust/ChangeLog:

* backend/rust-compile-intrinsic.cc (is_basic_integer_type): New function.
(unchecked_op_inner): New handler.
(unchecked_op_handler): New handler.

gcc/testsuite/ChangeLog:

* rust/compile/torture/intrinsics-6.rs: New test.
* rust/compile/torture/intrinsics-7.rs: New test.

16 months agogccrs: intrinsics: Add early implementation for atomic_store_{seqcst, relaxed, release}
Arthur Cohen [Tue, 25 Oct 2022 09:24:10 +0000 (11:24 +0200)]
gccrs: intrinsics: Add early implementation for atomic_store_{seqcst, relaxed, release}

gcc/rust/ChangeLog:

* backend/rust-builtins.cc (BuiltinsContext::setup_atomic_fns): New function.
(BuiltinsContext::setup): Call `setup_atomic_fns`.
* backend/rust-builtins.h: Declare `setup_atomic_fns`.
* backend/rust-compile-intrinsic.cc (atomic_store_handler_inner): New function.
(atomic_store_handler): New handler.
(make_unsigned_long_tree): Add helper around making unsigned long trees.
(prefetch_data_handler): Use `make_unsigned_long_tree`.
(build_atomic_builtin_name): New function.

gcc/testsuite/ChangeLog:

* rust/compile/torture/intrinsics-4.rs: New test.
* rust/compile/torture/intrinsics-5.rs: New test.
* rust/execute/torture/atomic_store.rs: New test.

16 months agogccrs: constexpr: Add `rust_sorry_at` in places relying on init values
Arthur Cohen [Mon, 24 Oct 2022 11:20:41 +0000 (13:20 +0200)]
gccrs: constexpr: Add `rust_sorry_at` in places relying on init values

gcc/rust/ChangeLog:

* backend/rust-constexpr.cc (build_anon_member_initialization): Workaround uninitialized
values.
(build_data_member_initialization): Likewise.

16 months agogccrs: intrinsics: Add `sorry_handler` intrinsic handler
Arthur Cohen [Tue, 25 Oct 2022 08:48:43 +0000 (10:48 +0200)]
gccrs: intrinsics: Add `sorry_handler` intrinsic handler

gcc/rust/ChangeLog:

* backend/rust-compile-intrinsic.cc (sorry_handler): New intrinsic handler.

gcc/testsuite/ChangeLog:

* rust/compile/torture/intrinsics-3.rs: New test.

16 months agogccrs: builtins: Rename all bang macro handlers
Arthur Cohen [Mon, 24 Oct 2022 15:28:11 +0000 (17:28 +0200)]
gccrs: builtins: Rename all bang macro handlers

gcc/rust/ChangeLog:

* expand/rust-macro-builtins.cc (MacroBuiltin::assert): Rename to...
(MacroBuiltin::assert_handler): ..this.
(MacroBuiltin::file): Rename to...
(MacroBuiltin::file_handler): ..this.
(MacroBuiltin::column): Rename to...
(MacroBuiltin::column_handler): ..this.
(MacroBuiltin::include_bytes): Rename to...
(MacroBuiltin::include_bytes_handler): ..this.
(MacroBuiltin::include_str): Rename to...
(MacroBuiltin::include_str_handler): ..this.
(MacroBuiltin::compile_error): Rename to...
(MacroBuiltin::compile_error_handler): ..this.
(MacroBuiltin::concat): Rename to...
(MacroBuiltin::concat_handler): ..this.
(MacroBuiltin::env): Rename to...
(MacroBuiltin::env_handler): ..this.
(MacroBuiltin::cfg): Rename to...
(MacroBuiltin::cfg_handler): ..this.
(MacroBuiltin::include): Rename to...
(MacroBuiltin::include_handler): ..this.
(MacroBuiltin::line): Rename to...
(MacroBuiltin::line_handler): ..this.
* expand/rust-macro-builtins.h: Rename all handlers.
* util/rust-hir-map.cc (Mappings::insert_macro_def): Use new handler
names.

16 months agogccrs: rust: Allow gccrs to build on x86_64-apple-darwin with clang/libc++
Simon Cook [Tue, 12 Apr 2022 14:45:56 +0000 (16:45 +0200)]
gccrs: rust: Allow gccrs to build on x86_64-apple-darwin with clang/libc++

gcc/rust/ChangeLog:

* util/rust-inline-visitor.h: Remove some offending system includes.

16 months agogccrs: Implement the inline visitor
YizhePKU [Tue, 13 Apr 2021 07:28:36 +0000 (07:28 +0000)]
gccrs: Implement the inline visitor

gcc/rust/ChangeLog:

* util/rust-inline-visitor.h: New file.

16 months agogccrs: Support Closure calls as generic trait bounds
Philip Herron [Thu, 20 Oct 2022 17:31:02 +0000 (18:31 +0100)]
gccrs: Support Closure calls as generic trait bounds

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): Refactor checking of closures.
(CompileExpr::generate_possible_fn_trait_call): New function.
* backend/rust-compile-expr.h: Declare `generate_possible_fn_trait_call`.

gcc/testsuite/ChangeLog:

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

16 months agogccrs: Add missing type resolution for function type segments
Philip Herron [Thu, 20 Oct 2022 17:05:43 +0000 (18:05 +0100)]
gccrs: Add missing type resolution for function type segments

gcc/rust/ChangeLog:

* typecheck/rust-tyty-bounds.cc (TypeCheckBase::get_predicate_from_bound): Add missing
implementation.

16 months agogccrs: Add missing hir lowering to function type-path segments
Philip Herron [Thu, 20 Oct 2022 16:59:27 +0000 (17:59 +0100)]
gccrs: Add missing hir lowering to function type-path segments

gcc/rust/ChangeLog:

* Make-lang.in: Compile rust-ast-lower-type.cc.
* ast/rust-path.h: Add `get_locus` method to `TypePathFunction`.
* hir/rust-ast-lower-base.cc (ASTLowerTypePath::visit): Move implementation to
rust-ast-lower-type.cc.
(ASTLowerQualifiedPathInType::visit): Likewise.
(ASTLoweringType::visit): Likewise.
* hir/rust-ast-lower-type.h: Move implementations to source file.
* hir/tree/rust-hir-path.h: Likewise.
* hir/rust-ast-lower-type.cc: New file.

16 months agogccrs: Add missing name resolution to Function type-path segments
Philip Herron [Thu, 20 Oct 2022 16:59:03 +0000 (17:59 +0100)]
gccrs: Add missing name resolution to Function type-path segments

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-type.cc (ResolveRelativeTypePath::go): Add missing handling of
function case.

16 months agogccrs: Closure support at CallExpr
Philip Herron [Wed, 19 Oct 2022 17:02:36 +0000 (18:02 +0100)]
gccrs: Closure support at CallExpr

gcc/rust/ChangeLog:

* backend/rust-compile-context.h: Add new functions: `insert_closure_decl` and
`lookup_closure_decl`.
* backend/rust-compile-expr.cc (CompileExpr::visit): Start compiling Closures properly.
(CompileExpr::generate_closure_function): New function.
(CompileExpr::generate_closure_fntype): Likewise.
* backend/rust-compile-expr.h: Declare `generate_closure_function` and
`generate_closure_fntype`.
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Visit closure types properly.
* backend/rust-mangle.cc (legacy_mangle_name): Add support for closures.
* backend/rust-tree.h (RS_CLOSURE_FLAG): Add new tree macro.
(RS_CLOSURE_TYPE_P): And checking for it on tree nodes.
* typecheck/rust-tyty.cc (ClosureType::is_equal): Add implementation.

gcc/testsuite/ChangeLog:

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

16 months agogccrs: Initial Type resolution for closures
Philip Herron [Tue, 18 Oct 2022 12:21:40 +0000 (13:21 +0100)]
gccrs: Initial Type resolution for closures

gcc/rust/ChangeLog:

* hir/tree/rust-hir-expr.h: Add `get_params` method.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Typecheck closure nodes.
(TypeCheckExpr::resolve_fn_trait_call): New function.
* typecheck/rust-hir-type-check-expr.h: Declare `resolve_fn_trait_call` and
`resolve_possible_fn_trait_call_method_name`.
* typecheck/rust-hir-type-check.h: Declare `get_context_type`.
* typecheck/rust-tyctx.cc (TypeCheckContextItem::get_context_type): New function.
* typecheck/rust-tyty-cmp.h: Visit closures properly.
* typecheck/rust-tyty-rules.h: Likewise.
* typecheck/rust-tyty.cc (BaseType::bounds_compatible): Add commented out assertin.
(ClosureType::as_string): Implement it.
(ClosureType::clone): Fix closure cloning.
(ClosureType::setup_fn_once_output): New function.
* typecheck/rust-tyty.h: Improve `ClosureType` class and declare `setup_fn_once_output`.

16 months agogccrs: Add closures to lints and error checking
Philip Herron [Wed, 19 Oct 2022 17:30:36 +0000 (18:30 +0100)]
gccrs: Add closures to lints and error checking

gcc/rust/ChangeLog:

* checks/errors/rust-const-checker.cc (ConstChecker::visit): Visit closures properly.
* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise.
* checks/lints/rust-lint-marklive.h: Likewise.

16 months agogccrs: Refactor method call type checking
Philip Herron [Wed, 19 Oct 2022 09:59:18 +0000 (10:59 +0100)]
gccrs: Refactor method call type checking

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Simplify method
call type checking  by removing visitor and instead using one static cast. Use the
new interface.
* typecheck/rust-tyty-call.cc (TypeCheckMethodCallExpr::visit): Likewise.
(TypeCheckMethodCallExpr::go): Likewise.
(TypeCheckMethodCallExpr::check): Likewise.
* typecheck/rust-tyty-call.h (class TypeCheckMethodCallExpr): Likewise.
(class Argument): Likewise.

16 months agogccrs: Add name resolution for closures
Philip Herron [Mon, 17 Oct 2022 16:51:15 +0000 (17:51 +0100)]
gccrs: Add name resolution for closures

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Visit closure properly when
name resolving.
(ResolveExpr::resolve_closure_param): Implement closure name resolving.
* resolve/rust-ast-resolve-expr.h: Declare visitors for closure types.

16 months agogccrs: Formatting cleanup in HIR lowering pattern
Philip Herron [Mon, 17 Oct 2022 16:27:01 +0000 (17:27 +0100)]
gccrs: Formatting cleanup in HIR lowering pattern

gcc/rust/ChangeLog:

* hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::ASTLoweringPattern):
Improve formatting.
(ASTLoweringPattern::translate): Likewise.
* hir/rust-ast-lower-pattern.h: Likewise.
* resolve/rust-ast-resolve-expr.h: Likewise.

16 months agogccrs: Refactor expression hir lowering into cc file
Philip Herron [Mon, 17 Oct 2022 15:51:05 +0000 (16:51 +0100)]
gccrs: Refactor expression hir lowering into cc file

gcc/rust/ChangeLog:

* Make-lang.in: Add new object file for expression lowering.
* ast/rust-expr.h: Move implementation of expr lowering to source file.
* backend/rust-compile-block.h: Likewise.
* backend/rust-compile-expr.cc (CompileExpr::visit): Likewise.
* backend/rust-compile-expr.h: Likewise.
* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): Likewise.
* checks/errors/privacy/rust-privacy-reporter.h: Likewise.
* checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise.
* checks/errors/rust-const-checker.h: Likewise.
* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise.
* checks/errors/rust-unsafe-checker.h: Likewise.
* hir/rust-ast-lower-base.h: Likewise.
* hir/rust-ast-lower-expr.h (RUST_AST_LOWER_EXPR): Likewise.
* hir/rust-ast-lower.cc (ASTLoweringBase::lower_closure_param): Likewise.
* hir/rust-hir-dump.cc (Dump::visit): Likewise.
* hir/rust-hir-dump.h: Likewise.
* hir/tree/rust-hir-expr.h (class ClosureExpr): Likewise.
(class ClosureExprInner): Likewise.
(class ClosureExprInnerTyped): Likewise.
* hir/tree/rust-hir-full-decls.h (class ClosureExprInner): Likewise.
(class ClosureExprInnerTyped): Likewise.
* hir/tree/rust-hir-full-test.cc (ClosureExprInnerTyped::as_string): Likewise.
(ClosureExprInner::as_string): Likewise.
(ClosureExprInner::accept_vis): Likewise.
(ClosureExpr::accept_vis): Likewise.
(ClosureExprInnerTyped::accept_vis): Likewise.
* hir/tree/rust-hir-visitor.h: Likewise.
* hir/tree/rust-hir.h (class Expr): Likewise.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise.
* typecheck/rust-hir-type-check-expr.h: Likewise.
* hir/rust-ast-lower-expr.cc: New file.

16 months agogccrs: Add missing fn_once_output langitem
Philip Herron [Mon, 17 Oct 2022 15:50:34 +0000 (16:50 +0100)]
gccrs: Add missing fn_once_output langitem

gcc/rust/ChangeLog:

* util/rust-lang-item.h: Add handling for `fn_once_output`.

16 months agogccrs: ast: Improve Fragment API
Arthur Cohen [Wed, 19 Oct 2022 12:53:43 +0000 (14:53 +0200)]
gccrs: ast: Improve Fragment API

gcc/rust/ChangeLog:

* ast/rust-ast-fragment.cc (Fragment::Fragment): Add better APIs.
(Fragment::complete): New function.
(Fragment::unexpanded): New function.
* ast/rust-ast-fragment.h: Declare new APIs and add documentation.
* expand/rust-attribute-visitor.h: Use new Fragment API.
* expand/rust-macro-builtins.cc (MacroBuiltin::file): Likewise.
(MacroBuiltin::column): Likewise.
(MacroBuiltin::include_bytes): Likewise.
(MacroBuiltin::include_str): Likewise.
(MacroBuiltin::concat): Likewise.
(MacroBuiltin::env): Likewise.
(MacroBuiltin::cfg): Likewise.
(MacroBuiltin::include): Likewise.
(MacroBuiltin::line): Likewise.
* expand/rust-macro-expand.cc (parse_many): Likewise.
(transcribe_expression): Likewise.
(transcribe_type): Likewise.
* expand/rust-macro-expand.h (struct MacroExpander): Likewise.

16 months agogccrs: rust: Replace uses of ASTFragment -> Fragment
Arthur Cohen [Wed, 19 Oct 2022 12:05:54 +0000 (14:05 +0200)]
gccrs: rust: Replace uses of ASTFragment -> Fragment

gcc/rust/ChangeLog:

* ast/rust-ast.h (class ASTFragment): Remove old ASTFragment class.
* ast/rust-macro.h (class MacroRulesDefinition): Use new Fragment API.
* expand/rust-attribute-visitor.h: Likewise.
* expand/rust-macro-builtins.cc (macro_end_token): Likewise.
(MacroBuiltin::assert): Likewise.
(MacroBuiltin::file): Likewise.
(MacroBuiltin::column): Likewise.
(MacroBuiltin::include_bytes): Likewise.
(MacroBuiltin::include_str): Likewise.
(MacroBuiltin::compile_error): Likewise.
(MacroBuiltin::concat): Likewise.
(MacroBuiltin::env): Likewise.
(MacroBuiltin::cfg): Likewise.
(MacroBuiltin::include): Likewise.
(MacroBuiltin::line): Likewise.
* expand/rust-macro-builtins.h: Likewise.
* expand/rust-macro-expand.cc (MacroExpander::expand_decl_macro): Likewise.
(MacroExpander::expand_invoc): Likewise.
(MacroExpander::match_repetition): Likewise.
(parse_many): Likewise.
(transcribe_many_items): Likewise.
(transcribe_many_ext): Likewise.
(transcribe_many_trait_items): Likewise.
(transcribe_many_impl_items): Likewise.
(transcribe_many_trait_impl_items): Likewise.
(transcribe_expression): Likewise.
(transcribe_type): Likewise.
(transcribe_on_delimiter): Likewise.
(tokens_to_str): Likewise.
* expand/rust-macro-expand.h (struct MacroExpander): Likewise.
* util/rust-hir-map.cc (Mappings::insert_macro_def): Likewise.

16 months agogccrs: ast: Refactor ASTFragment -> Fragment class
Arthur Cohen [Wed, 19 Oct 2022 11:54:04 +0000 (13:54 +0200)]
gccrs: ast: Refactor ASTFragment -> Fragment class

gcc/rust/ChangeLog:

* Make-lang.in: Add `rust-ast-fragment.o` object file.
* ast/rust-ast-fragment.cc: New file.
* ast/rust-ast-fragment.h: New file.

16 months agogccrs: Add check for recursive trait cycles
Philip Herron [Mon, 17 Oct 2022 10:35:26 +0000 (11:35 +0100)]
gccrs: Add check for recursive trait cycles

gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): Check if a
trait query is currently in progress.
* typecheck/rust-hir-type-check.h (class TraitQueryGuard): Add helpers around
checking for trait queries and inserting them.

gcc/testsuite/ChangeLog:

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

16 months agogccrs: dump: Dump macro rules definition
Arthur Cohen [Tue, 27 Sep 2022 14:24:59 +0000 (16:24 +0200)]
gccrs: dump: Dump macro rules definition

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc (Dump::visit): Add missing visitors for macro definition dumping.
(get_delimiters): New function.
* ast/rust-ast-dump.h: Declare `get_delimiters` and add documentation.
* ast/rust-macro.h: Add `get_token_tree` method.

16 months agogccrs: ast: Module: unloaded module and inner attributes
Jakub Dupak [Sat, 15 Oct 2022 19:30:40 +0000 (21:30 +0200)]
gccrs: ast: Module: unloaded module and inner attributes

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc (Dump::visit): Properly handle unloaded modules.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
16 months agogccrs: dump: Fix module dumping
Arthur Cohen [Fri, 14 Oct 2022 14:55:47 +0000 (16:55 +0200)]
gccrs: dump: Fix module dumping

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc (Dump::visit): Fix formatting when dumping modules.

16 months agogccrs: dump: Dump items within modules
Arthur Cohen [Tue, 27 Sep 2022 13:52:57 +0000 (15:52 +0200)]
gccrs: dump: Dump items within modules

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc (Dump::visit): Dump items in modules properly.

16 months agogccrs: dump: Emit visibility when dumping items
Arthur Cohen [Tue, 27 Sep 2022 13:50:39 +0000 (15:50 +0200)]
gccrs: dump: Emit visibility when dumping items

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc: Emit visibility when dumping items.

16 months agogccrs: Support outer attribute handling on trait items just like normal items
Philip Herron [Fri, 14 Oct 2022 15:06:33 +0000 (16:06 +0100)]
gccrs: Support outer attribute handling on trait items just like normal items

gcc/rust/ChangeLog:

* hir/rust-ast-lower-base.h (class ItemWrapper): New class.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::handle_outer_attributes): Use
`ItemWrapper` class.
(ASTLoweringBase::handle_doc_item_attribute): Likewise.
(ASTLoweringBase::handle_lang_item_attribute): Likewise.
* hir/rust-ast-lower-implitem.h: Check outer attributes on items.
* hir/tree/rust-hir-item.h: Add `get_trait_locus` methods.
* hir/tree/rust-hir.h: Likewise.
* util/rust-hir-map.h: Add defId mappings and associated functions.
* util/rust-hir-map.cc (Mappings::insert_defid_mapping): Implement insertion to said
mappings.
(Mappings::lookup_trait_item_defid): And looking up said mappings.

16 months agogccrs: ast: dump TypeAlias
Jakub Dupak [Fri, 14 Oct 2022 10:38:19 +0000 (12:38 +0200)]
gccrs: ast: dump TypeAlias

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc (Dump::visit): Add code for dumping type aliases.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
16 months agogccrs: Refactor TraitResolver to not require a visitor
Philip Herron [Fri, 14 Oct 2022 13:00:16 +0000 (14:00 +0100)]
gccrs: Refactor TraitResolver to not require a visitor

gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-resolve.cc (TraitResolver::TraitResolver): Do not nullptr init
`resolved_trait_reference` anymore.
(TraitResolver::resolve_path): Simplify function and rename to...
(TraitResolver::resolve_path_to_trait): ...this.
(TraitResolver::lookup_path): Use new interface.
* typecheck/rust-hir-trait-resolve.h (class TraitResolver): Do not inherit `HIRFullVisitor`
class anymore.

16 months agogccrs: ast: dump: RangeExprs
David Faust [Thu, 13 Oct 2022 17:23:44 +0000 (10:23 -0700)]
gccrs: ast: dump: RangeExprs

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc (Dump::visit): Add dump for RangeExprs.

16 months agogccrs: ast: dump: various simple Exprs
David Faust [Thu, 13 Oct 2022 17:15:05 +0000 (10:15 -0700)]
gccrs: ast: dump: various simple Exprs

Adds dump for:
- BorrowExpr
- DereferenceExpr
- ErrorPropagationExpr
- NegationExpr
- TypeCastExpr
- GroupedExpr

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc (Dump::visit): Add dump for, BorrowExpr, DereferenceExpr,
ErrorPropagationExpr, NegationExpr, TypeCastExpr and GroupedExpr.

16 months agogccrs: ast: dump: ArrayExpr
David Faust [Thu, 13 Oct 2022 17:14:38 +0000 (10:14 -0700)]
gccrs: ast: dump: ArrayExpr

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc (Dump::visit): Add dump code for ArrayExpr.

16 months agogccrs: ast: dump: ComparisonExpr and LazyBooleanExpr
David Faust [Thu, 13 Oct 2022 16:28:33 +0000 (09:28 -0700)]
gccrs: ast: dump: ComparisonExpr and LazyBooleanExpr

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc (Dump::visit): Add dumps for ComparisonExpr and
LazyBooleanExpr.

16 months agogccrs: ast: dump: minor fixups to IfExpr formatting
David Faust [Thu, 13 Oct 2022 16:27:35 +0000 (09:27 -0700)]
gccrs: ast: dump: minor fixups to IfExpr formatting

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc (Dump::visit): Fix IfExpr formatting.

16 months agogccrs: ast: dump: fix extra newline in block without tail
David Faust [Thu, 13 Oct 2022 16:25:57 +0000 (09:25 -0700)]
gccrs: ast: dump: fix extra newline in block without tail

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc (Dump::visit): Fix block formatting.

16 months agogccrs: Method resolution must support multiple candidates
Philip Herron [Thu, 13 Oct 2022 09:10:37 +0000 (10:10 +0100)]
gccrs: Method resolution must support multiple candidates

This patch fixes bad method resolution in our operator_overload_9 case.
When we have a &mut reference to something and we deref we must resolve to
the mutable reference impl block. The interface we are using to resolve
methods is the can_eq interface which allows for permissive mutability
which means allowing for mutable reference being unified with an immutable
one. This meant we actual match against both the immutable and mutable
version leading to multiple candidate error.

The fix here adds a method resolution flag to the can_eq interface so that
we enforce mutability equality. The other hack is that we do not allow
can_eq of ParamTypes to generic Slices. I think there is some subtle thing
going on for that case. The Rustc method resolver actually filters the
impl blocks for reference types based looking up the relevant lang items
we need to do this as well but is a much larger refactor to our method
resolver which should be done seperately.

Fixes #1588

gcc/rust/ChangeLog:

* typecheck/rust-autoderef.cc: Add support for multiple resolution candidates.
* typecheck/rust-hir-dot-operator.cc (MethodResolver::MethodResolver): Edit
`try_result` field and change constructor.
(MethodResolver::Probe): Return set of candidates instead of singular candidate.
(MethodResolver::select): Add better implementation to account for multiple
candidates.
* typecheck/rust-hir-dot-operator.h (struct MethodCandidate): Overload comparison
operator in order to store them in `std::set`.
* typecheck/rust-hir-inherent-impl-overlap.h: Do not fail assertion on missing type.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Adapt code to use
multiple candidates.
* typecheck/rust-tyty.cc (set_cmp_autoderef_mode): Add code to handle automatic
derefs properly.
(reset_cmp_autoderef_mode): Add helper function to reset said mode.
* typecheck/rust-tyty.h (set_cmp_autoderef_mode): Declare function.
(reset_cmp_autoderef_mode): Likewise.
* typecheck/rust-tyty-cmp.h: Add handling of `autoderef_cmp_flag`

gcc/testsuite/ChangeLog:

* rust/compile/generics7.rs: Fix test with missing assertion.
* rust/execute/torture/operator_overload_9.rs: Fix test assertion.

16 months agogccrs: Add ABI mappings for rust-call to map to ABI::RUST
Philip Herron [Wed, 12 Oct 2022 11:26:24 +0000 (12:26 +0100)]
gccrs: Add ABI mappings for rust-call to map to ABI::RUST

gcc/rust/ChangeLog:

* util/rust-abi.cc (get_abi_from_string): Add missing "rust-call"
possibility for ABI variant.

16 months agogccrs: Add mappings for fn_once lang item
Philip Herron [Wed, 12 Oct 2022 11:25:52 +0000 (12:25 +0100)]
gccrs: Add mappings for fn_once lang item

gcc/rust/ChangeLog:

* util/rust-lang-item.h: Add `fn_once` lang item.

16 months agogccrs: Support type resolution on super traits on dyn objects
Philip Herron [Thu, 6 Oct 2022 13:46:17 +0000 (14:46 +0100)]
gccrs: Support type resolution on super traits on dyn objects

When checking if specified bounds satisfy other bounds we must lookup the
super traits. To finish the support for super traits we need to redo the
computation of method addresses to support super traits.

Addresses #914

gcc/rust/ChangeLog:

* backend/rust-compile.cc: Add note about missing support for super
traits.
* typecheck/rust-tyty.cc (BaseType::satisfies_bound): New function.
(BaseType::bounds_compatible): New function.
(DynamicObjectType::get_object_items): New function.
* typecheck/rust-hir-trait-ref.h: Use new API to perform type resolution
on dyn objects.

16 months agogccrs: early-name-resolver: Add simple macro name resolution
Arthur Cohen [Tue, 11 Oct 2022 09:12:50 +0000 (11:12 +0200)]
gccrs: early-name-resolver: Add simple macro name resolution

This name resolver performs the same macro name resolution as what was
previously done by the AttrVisitor visitor and macro expander.

It also resolves macro expressions in builtin-macros properly, as well
as expanded AST nodes when necessary.

gcc/rust/ChangeLog:

* Make-lang.in: Compile early name resolver.
* expand/rust-attribute-visitor.cc (AttrVisitor::visit): Move macro
name resolution.
* expand/rust-macro-builtins.cc (try_expand_macro_expression): Run ENR
when recursively expanding macros.
* expand/rust-macro-expand.cc (MacroExpander::expand_invoc): No longer
perform name resolution in `expand_invoc`.
* expand/rust-macro-expand.h (struct MacroExpander): Keep ENR within
MacroExpander.
* rust-session-manager.cc (Session::expansion): Run ENR.
* resolve/rust-early-name-resolver.cc: New file.
* resolve/rust-early-name-resolver.h: New file.

16 months agogccrs: ast: Add accept_vis() method to `GenericArg`
Arthur Cohen [Tue, 11 Oct 2022 13:54:07 +0000 (15:54 +0200)]
gccrs: ast: Add accept_vis() method to `GenericArg`

gcc/rust/ChangeLog:

* ast/rust-path.h: Add `accept_vis` method to `GenericArg` class.

16 months agogccrs: rust-ast-resolve-item: Add note about resolving glob uses
Arthur Cohen [Tue, 11 Oct 2022 09:39:15 +0000 (11:39 +0200)]
gccrs: rust-ast-resolve-item: Add note about resolving glob uses

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Add note for
glob import resolving.

16 months agogccrs: mappings: Add MacroInvocation -> MacroRulesDef mappings
Arthur Cohen [Tue, 11 Oct 2022 09:38:55 +0000 (11:38 +0200)]
gccrs: mappings: Add MacroInvocation -> MacroRulesDef mappings

gcc/rust/ChangeLog:

* util/rust-hir-map.h: Add new mappings.
* util/rust-hir-map.cc (Mappings::insert_macro_invocation): Add insertion
function into mappings.
(Mappings::lookup_macro_invocation): Add lookup function for mappings.

16 months agogccrs: fix ICE on missing closing paren
Marc Poulhiès [Fri, 7 Oct 2022 16:48:36 +0000 (18:48 +0200)]
gccrs: fix ICE on missing closing paren

Fix crash (segfault) on a missing closing parenthesis when parsing the
expressions in a block. The returned `expr` was missing a check before being
used.

Add corresponding test.

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_stmt_or_expr_without_block):
Check if `expr` is valid after parsing it.

gcc/testsuite/ChangeLog:

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

16 months agogccrs: intrinsics: Add data prefetching intrinsics
Arthur Cohen [Wed, 5 Oct 2022 15:49:44 +0000 (17:49 +0200)]
gccrs: intrinsics: Add data prefetching intrinsics

gcc/rust/ChangeLog:

* backend/rust-builtins.cc (BuiltinsContext::setup): Declare prefetch
intrinsics.
* backend/rust-compile-intrinsic.cc (enum class Prefetch): Add kinds of
prefetch intrinsics.
(prefetch_data_handler): New function.
(prefetch_read_data): Likewise.
(prefetch_write_data): Likewise.

gcc/testsuite/ChangeLog:

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

16 months agogccrs: ast: dump structs, enums and unions
David Faust [Thu, 6 Oct 2022 18:32:17 +0000 (11:32 -0700)]
gccrs: ast: dump structs, enums and unions

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc (Dump::visit): Fill empty functions for
structs, enums and unions.

16 months agogccrs: ast: dump: add format_{tuple,struct}_field helpers
David Faust [Thu, 6 Oct 2022 20:43:06 +0000 (13:43 -0700)]
gccrs: ast: dump: add format_{tuple,struct}_field helpers

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc (Dump::format_tuple_field): New.
(Dump::format_struct_field): New.
* ast/rust-ast-dump.h (format_tuple_field): New.
(format_struct_field): New.

16 months agogccrs: ast: dump: add emit_generic_params helper
David Faust [Thu, 6 Oct 2022 18:32:02 +0000 (11:32 -0700)]
gccrs: ast: dump: add emit_generic_params helper

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc (Dump::visit): move generic params dump ...
(Dump::emit_generic_params): ... here.
* ast/rust-ast-dump.h (emit_generic_params): New.

16 months agogccrs: Support looking up super traits for trait items
Philip Herron [Wed, 5 Oct 2022 16:24:42 +0000 (17:24 +0100)]
gccrs: Support looking up super traits for trait items

When supporting calls to super traits we need to allow lookups based on
the super traits as specified on the TraitReferences.

Fixes #1555

gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-ref.h (lookup_trait_item): Add lookup
in super_trait.

gcc/testsuite/ChangeLog:

* rust/compile/torture/issue-1555.rs: New test.

16 months agogccrs: Ensure uniqueness on Path probe's
Philip Herron [Wed, 5 Oct 2022 16:24:26 +0000 (17:24 +0100)]
gccrs: Ensure uniqueness on Path probe's

When we lookup names in paths such as Foo::bar, foo is a type we resolve
and then we lookup 'bar' based on what type Foo is which includes probing
relevant bounds of this type. We currently return a vector of possible
candidates and this patch changes it so that we return a set of unique
items based on DefId.

Addresses #1555

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc
(CompileExpr::resolve_method_address): Use auto and minor change
in candidate init.
* typecheck/rust-hir-type-check-path.cc
(TypeCheckExpr::resolve_segments): Likewise.
* typecheck/rust-hir-type-check-type.cc: Likewise.
* backend/rust-compile-resolve-path.cc
(HIRCompileBase::query_compile): Likewise. Removecall to
set_ty_ref.
* typecheck/rust-hir-path-probe.h (struct PathProbeCandidate): Add
locus initializer in ctor, implement get_defid.
(class PathProbeType::Probe): return a set instead of vector.
Adjust class impl.
(class ReportMultipleCandidateError): Do not inherit from
HIRImplVisitor anymore and remove corresponding impl. Adjust for
change in Probe. Simplify Report handling.
(class PathProbeImplTrait::Probe): Adjust return type.

16 months agogccrs: Track DefId on ADT variants
Philip Herron [Wed, 5 Oct 2022 16:22:43 +0000 (17:22 +0100)]
gccrs: Track DefId on ADT variants

We must track the DefID on variants for algebraic data types as this will
allow us to enforce unique'ness on path queries relating to this.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-enumitem.cc
(TypeCheckEnumItem::visit): Adjust VariantDef ctor calls with
DefID.
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit):
Likewise.
* typecheck/rust-tyty.h (VariantDef): Add defid parameter to ctor.

16 months agogccrs: builtins: Move implementation into source file
Arthur Cohen [Thu, 6 Oct 2022 08:19:11 +0000 (10:19 +0200)]
gccrs: builtins: Move implementation into source file

gcc/rust/ChangeLog:

* Make-lang.in: Add `rust-builtins.o` as target
* backend/rust-builtins.h: Refactor to new file.
* backend/rust-builtins.cc: New file.

16 months agogccrs: ast: dump If expressions
David Faust [Wed, 5 Oct 2022 17:11:38 +0000 (10:11 -0700)]
gccrs: ast: dump If expressions

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc (Dump::visit): Implement visitor for If
expressions.

16 months agogccrs: ast: dump assignment and compound assignment expr
David Faust [Wed, 5 Oct 2022 17:10:18 +0000 (10:10 -0700)]
gccrs: ast: dump assignment and compound assignment expr

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc (Dump::visit): Dump assignment and compound
assignment expressions.

16 months agogccrs: testing: try loop in const function
Faisal Abbas [Mon, 3 Oct 2022 18:32:30 +0000 (19:32 +0100)]
gccrs: testing: try loop in const function

Signed-off-by: Faisal Abbas <90.abbasfaisal@gmail.com>
gcc/testsuite/ChangeLog:

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

Signed-off-by: Faisal Abbas <faisal.abbas@elastica.co>
16 months agogccrs: Add catch for recusive type queries
Philip Herron [Fri, 30 Sep 2022 12:41:09 +0000 (13:41 +0100)]
gccrs: Add catch for recusive type queries

When we have a type query where by generic substitution occurs we can hit
the case where we need to Probe the bounds of the substited item to
determine whether the the bounds are compatible this can cause us to
end up querying the same type recursively.

Fixes #1550

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::query_type):
Check for recursive queries.
* typecheck/rust-hir-type-check.h: New functions: `query_completed`,
`query_in_progress`, `insert_query`.
* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::scan): Use `query_type` API.

16 months agogccrs: dump: Emit visibility when dumping items
Arthur Cohen [Tue, 27 Sep 2022 13:50:39 +0000 (15:50 +0200)]
gccrs: dump: Emit visibility when dumping items

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc (Dump::emit_visibility): New function.
(Dump::visit): Call into `emit_visibility`.
(Dump::format_function_common): Likewise.
* ast/rust-ast-dump.h: Declare `emit_visibility`.

16 months agogccrs: visibility: Rename get_public_vis_type -> get_vis_type
Arthur Cohen [Tue, 27 Sep 2022 13:49:59 +0000 (15:49 +0200)]
gccrs: visibility: Rename get_public_vis_type -> get_vis_type

gcc/rust/ChangeLog:

* ast/rust-item.h: Rename get_public_vis_type.
* hir/rust-ast-lower.cc (translate_visibility): Use new name.

16 months agogccrs: Fix missing dead code analysis ICE on local enum definition
Philip Herron [Tue, 27 Sep 2022 08:50:06 +0000 (09:50 +0100)]
gccrs: Fix missing dead code analysis ICE on local enum definition

When resolving local enum's within a Block the name resolution info is
not at the top of the stack so this patch introduces a new mappings class
for miscellaneous name resolutions which can be used during path analaysis.

Fixes #1272

gcc/rust/ChangeLog:

* resolve/rust-name-resolver.h: Add miscellenaous item mappings.
* resolve/rust-name-resolver.cc (Resolver::insert_resolved_misc): Use
new mappings.
(Resolver::lookup_resolved_misc): Likewise.
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_segments):
Adapt function to insert into miscelleanous mappings.
* checks/lints/rust-lint-marklive.cc (MarkLive::find_ref_node_id):
Allow lookup in miscelleanous mappings in mark-live phase.

gcc/testsuite/ChangeLog:

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

16 months agotree-optimization/108868 - new testcase
Richard Biener [Tue, 21 Feb 2023 09:32:10 +0000 (10:32 +0100)]
tree-optimization/108868 - new testcase

New testcase for the fixed bug.

PR tree-optimization/108868
* gcc.dg/pr108868.c: New testcase.

16 months agotree-optimization/108855 - new testcase
Richard Biener [Tue, 21 Feb 2023 09:31:29 +0000 (10:31 +0100)]
tree-optimization/108855 - new testcase

New testcase for the fixed bug.

PR tree-optimization/108855
* gcc.dg/pr108855.c: New testcase.

16 months agoRevert "tree-optimization/108691 - indirect calls to setjmp"
Richard Biener [Tue, 21 Feb 2023 09:26:30 +0000 (10:26 +0100)]
Revert "tree-optimization/108691 - indirect calls to setjmp"

This reverts commit 6436add49ed9ecf74f1f01b4fe18961df4f3e83d.

16 months agoxtensa: Enforce return address saving when -Og is specified
Takayuki 'January June' Suwa [Sat, 18 Feb 2023 04:54:10 +0000 (13:54 +0900)]
xtensa: Enforce return address saving when -Og is specified

Leaf function often omits saving its return address to the stack slot,
and this feature often makes debugging very confusing, especially for
stack dump analysis.

gcc/ChangeLog:

* config/xtensa/xtensa.cc (xtensa_call_save_reg): Change to return
true if register A0 (return address register) when -Og is specified.

16 months agoDaily bump.
GCC Administrator [Tue, 21 Feb 2023 00:18:20 +0000 (00:18 +0000)]
Daily bump.

16 months agoi386: Introduce general_x64constmem_operand predicate
Uros Bizjak [Mon, 20 Feb 2023 22:17:20 +0000 (23:17 +0100)]
i386: Introduce general_x64constmem_operand predicate

Instructions that use high-part QImode registers can not be encoded
with REX prefix.  To avoid REX prefix, operand constraints allow
only legacy QImode registers, immediates and constant memory operands.
The patch introduces matching predicate, so invalid operands are not
combined into instruction RTX only to be later fixed up by reload pass.

2023-02-20  Uroš Bizjak  <ubizjak@gmail.com>

gcc/ChangeLog:

* config/i386/predicates.md
(general_x64constmem_operand): New predicate.
* config/i386/i386.md (*cmpqi_ext<mode>_1):
Use nonimm_x64constmem_operand.
(*cmpqi_ext<mode>_3): Use general_x64constmem_operand.
(*addqi_ext<mode>_1): Ditto.
(*testqi_ext<mode>_1): Ditto.
(*andqi_ext<mode>_1): Ditto.
(*andqi_ext<mode>_1_cc): Ditto.
(*<any_or:code>qi_ext<mode>_1): Ditto.
(*xorqi_ext<mode>_1_cc): Ditto.

17 months agopowerpc: Another umaddditi4 fix [PR108862]
Jakub Jelinek [Mon, 20 Feb 2023 21:07:57 +0000 (22:07 +0100)]
powerpc: Another umaddditi4 fix [PR108862]

The following testcase is miscompiled on powerpc64le-linux with
-O2 -mcpu=power9.  The problem is that gen_umaddditi4 is called with
the same TImode register for both op0 and op3, and maddlddi4
overwrites the low half of op0 before the low half of op3 is read,
so when they are the same register it reads the result of maddlddi4.

The following patch fixes that by swapping maddlddi4 and
umadddi4_highpart{,_le} during expansion, as the latter writes into
a temporary pseudo and so can't change anything maddlddi4 depends on.

2023-02-20  Jakub Jelinek  <jakub2redhat.com>

PR target/108862
* config/rs6000/rs6000.md (umaddditi4): Swap gen_maddlddi4 with
gen_umadddi4_highpart{,_le}.

* gcc.dg/pr108862.c: New test.
* gcc.target/powerpc/pr108862.c: New test.

17 months agolibstdc++: Update baseline symbols for m68k-linux
Andreas Schwab [Sat, 11 Feb 2023 10:30:45 +0000 (11:30 +0100)]
libstdc++: Update baseline symbols for m68k-linux

libstdc++-v3/:
* config/abi/post/m68k-linux-gnu/baseline_symbols.txt: Update.

17 months agoc++: ICE with -fno-elide-constructors and trivial fn [PR101073]
Marek Polacek [Thu, 9 Feb 2023 00:13:18 +0000 (19:13 -0500)]
c++: ICE with -fno-elide-constructors and trivial fn [PR101073]

In constexpr-nsdmi3.C, with -fno-elide-constructors, we don't elide
the Y::Y(const Y&) call used to initialize o.c.  So store_init_value
-> cxx_constant_init must constexpr-evaluate the call to Y::Y(const Y&)
in cxx_eval_call_expression.  It's a trivial function, so we do the
"Shortcut trivial constructor/op=" code and rather than evaluating
the function, we just create an assignment

  o.c = *(const struct Y &) (const struct Y *) &(&<PLACEHOLDER_EXPR struct X>)->b

which is a MODIFY_EXPR, so the preeval code in cxx_eval_store_expression
clears .ctor and .object, therefore we can't replace the PLACEHOLDER_EXPR
whereupon we crash at

      /* A placeholder without a referent.  We can get here when
         checking whether NSDMIs are noexcept, or in massage_init_elt;
         just say it's non-constant for now.  */
      gcc_assert (ctx->quiet);

The PLACEHOLDER_EXPR can also be on the LHS as in constexpr-nsdmi10.C.
I don't think we can do much here, but I noticed that the whole
trivial_fn_p (fun) block is only entered when -fno-elide-constructors.
This is true since GCC 9; it wasn't easy to bisect what changes made it
so, but r240845 is probably one of them.  -fno-elide-constructors is an
option for experiments only so it's not clear to me why we'd still want
to shortcut trivial constructor/op=.  I propose to remove the code and
add a checking assert to make sure we're not getting a trivial_fn_p
unless -fno-elide-constructors.

PR c++/101073

gcc/cp/ChangeLog:

* constexpr.cc (cxx_eval_call_expression): Replace shortcutting trivial
constructor/op= with a checking assert.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/constexpr-nsdmi3.C: New test.
* g++.dg/cpp1y/constexpr-nsdmi10.C: New test.

17 months agolibstdc++: Fix uses of non-reserved names in simd header
Matthias Kretz [Thu, 16 Feb 2023 15:29:54 +0000 (16:29 +0100)]
libstdc++: Fix uses of non-reserved names in simd header

Signed-off-by: Matthias Kretz <m.kretz@gsi.de>
libstdc++-v3/ChangeLog:

* include/experimental/bits/simd.h (__extract_part, split):
Use reserved name for template parameter.

17 months agolibstdc++: Update baseline symbols for riscv64-linux
Andreas Schwab [Sat, 11 Feb 2023 10:28:01 +0000 (11:28 +0100)]
libstdc++: Update baseline symbols for riscv64-linux

libstdc++-v3/
* config/abi/post/riscv64-linux-gnu/baseline_symbols.txt: Update.

17 months agoRISC-V: prefetch.* only take base register with zero-offset for the address
Kito Cheng [Mon, 20 Feb 2023 13:47:01 +0000 (21:47 +0800)]
RISC-V: prefetch.* only take base register with zero-offset for the address

Catched by running gcc.c-torture/execute/builtin-prefetch-2.c with
-march=rv64gc_zicbop.

gcc/ChangeLog:

* config/riscv/riscv.md (prefetch): Use r instead of p for the
address operand.
(riscv_prefetchi_<mode>): Ditto.

17 months agoc++: ICE with redundant capture [PR108829]
Marek Polacek [Thu, 16 Feb 2023 22:41:24 +0000 (17:41 -0500)]
c++: ICE with redundant capture [PR108829]

Here we crash in is_capture_proxy:

  /* Location wrappers should be stripped or otherwise handled by the
     caller before using this predicate.  */
  gcc_checking_assert (!location_wrapper_p (decl));

We only crash with the redundant capture:

  int abyPage = [=, abyPage] { ... }

because prune_lambda_captures is only called when there was a default
capture, and with [=] only abyPage won't be in LAMBDA_EXPR_CAPTURE_LIST.

The problem is that LAMBDA_CAPTURE_EXPLICIT_P wasn't propagated
correctly and so var_to_maybe_prune proceeded where it shouldn't.

Co-Authored by: Patrick Palka <ppalka@redhat.com>

PR c++/108829

gcc/cp/ChangeLog:

* pt.cc (prepend_one_capture): Set LAMBDA_CAPTURE_EXPLICIT_P.
(tsubst_lambda_expr): Pass LAMBDA_CAPTURE_EXPLICIT_P to
prepend_one_capture.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/lambda/lambda-108829-2.C: New test.
* g++.dg/cpp0x/lambda/lambda-108829.C: New test.

17 months agotree-optimization/108816 - vect versioning check split confusion
Richard Biener [Mon, 20 Feb 2023 09:59:15 +0000 (10:59 +0100)]
tree-optimization/108816 - vect versioning check split confusion

The split of the versioning condition assumes the definition is
in the condition block which is ensured by the versioning code.
But that only works when we actually have to insert any statements
for the versioning condition.  The following adjusts the guard
accordingly and asserts this condition.

PR tree-optimization/108816
* tree-vect-loop-manip.cc (vect_loop_versioning): Adjust
versioning condition split prerequesite, assert required
invariant.

* gcc.dg/torture/pr108816.c: New testcase.

17 months agorust: Fix rust-tree.cc compilation on SPARC
Rainer Orth [Mon, 20 Feb 2023 10:40:24 +0000 (11:40 +0100)]
rust: Fix rust-tree.cc compilation on SPARC

This patch

commit 27a89f84c458ae938bc3eb92ad0d594c06fc3b42
Author: Thomas Schwinge <thomas@codesourcery.com>
Date:   Fri Feb 17 23:36:20 2023 +0100

    '#include "tm_p.h"' in 'gcc/rust/backend/rust-tree.cc'

broke rust bootstrap on SPARC:

In file included from ./tm_p.h:4,
                 from /vol/gcc/src/hg/master/local/gcc/rust/backend/rust-tree.cc:38:
/vol/gcc/src/hg/master/local/gcc/config/sparc/sparc-protos.h:46:47: error: use of enum 'memmodel' without previous declaration
   46 | extern void sparc_emit_membar_for_model (enum memmodel, int, int);
      |                                               ^~~~~~~~

Fixed by including memmodel.h.  Tested on sparc-sun-solaris2.11 and
i386-pc-solaris2.11.

2023-02-20  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

gcc/rust:
* backend/rust-tree.cc: Include memmodel.h.

17 months agotree-optimization/108825 - checking ICE with unroll-and-jam
Richard Biener [Mon, 20 Feb 2023 08:54:37 +0000 (09:54 +0100)]
tree-optimization/108825 - checking ICE with unroll-and-jam

The issue is that unroll-and-jam applies RPO VN on the transformed body but
that leaves the IL in "indetermined" state (it returns a TODO to make it
valid again).  But unroll-and-jam then continues to transform another loop and
in using the tree_unroll_loop helper runs into tree_transform_and_unroll_loop
performing IL checking on the whole function.

While the real fix is to elide all such checking I'm only making the
loop-local LC SSA verifier not perform function-wide SSA verification
at this point.

PR tree-optimization/108825
* tree-ssa-loop-manip.cc (verify_loop_closed_ssa): For
loop-local verfication only verify there's no pending SSA
update.

* gcc.dg/torture/pr108825.c: New testcase.

17 months agotree-optimization/108819 - niter analysis ICE with unexpected constant
Richard Biener [Fri, 17 Feb 2023 13:21:39 +0000 (14:21 +0100)]
tree-optimization/108819 - niter analysis ICE with unexpected constant

The following makes sure we do not ICE on unfolded stmts like
_1 = 1 & 1.

PR tree-optimization/108819
* tree-ssa-loop-niter.cc (number_of_iterations_cltz): Check
we have an SSA name as iv_2 as expected.

17 months agoDaily bump.
GCC Administrator [Mon, 20 Feb 2023 00:16:30 +0000 (00:16 +0000)]
Daily bump.

17 months agolibgm2/libm2iso/RTco.cc (re-implementation) Bugfix for [PR108835]
Gaius Mulley [Sun, 19 Feb 2023 22:08:31 +0000 (22:08 +0000)]
libgm2/libm2iso/RTco.cc (re-implementation) Bugfix for [PR108835]

This is a re-implementation of RTco.cc which fixes the race hazzard
seen occasionally when running testtransfer and coroutines from the
modula2 testsuite.

libgm2/ChangeLog:

PR testsuite/108835
* libm2iso/RTco.cc: Re-implementation using a single lock
mutex and inlined wait/signal implementation within
transfer.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
17 months agoDaily bump.
GCC Administrator [Sun, 19 Feb 2023 00:16:39 +0000 (00:16 +0000)]
Daily bump.

17 months agoc++: static_assert (false) in template [DR2518]
Jason Merrill [Sat, 11 Feb 2023 00:16:45 +0000 (16:16 -0800)]
c++: static_assert (false) in template [DR2518]

For a long time, people have expected to be able to write
static_assert (false) in a template and only have it diagnosed if the
template is instantiated, but we (and other implementations) gave an error
about the uninstantiated template because the standard says that if no valid
instantiation of the template is possible, the program is ill-formed, no
diagnostic required, and we try to diagnose IFNDR things when feasible.

At the meeting last week we were looking at CWG2518, which wanted to specify
that an implementation must not accept a program containing a failing #error
or static_assert.  We also looked at P2593, which proposed allowing
static_assert in an uninstantiated template.  We ended up combining these
two in order to avoid requiring implementations to reject programs with
static_assert (false) in uninstantiated templates.

The committee accepted this as a DR, so I'm making the change to all
standard modes.  This behavior was also conformant previously, since no
diagnostic was required in this case.

We continue to diagnose non-constant or otherwise ill-formed conditions, so
no changes to existing tests were needed.

DR 2518
PR c++/52809
PR c++/53638
PR c++/87389
PR c++/89741
PR c++/92099
PR c++/104041
PR c++/104691

gcc/cp/ChangeLog:

* semantics.cc (finish_static_assert): Don't diagnose in
template context.

gcc/testsuite/ChangeLog:

* g++.dg/DRs/dr2518.C: New test.

17 months agoreassoc: Fold some statements [PR108819]
Jakub Jelinek [Sat, 18 Feb 2023 11:40:49 +0000 (12:40 +0100)]
reassoc: Fold some statements [PR108819]

This spot in update_ops can replace one or both of the assign operands with
constants, creating 1 & 1 and similar expressions which can confuse later
passes until they are folded.  Rather than folding both constants by hand
and also handling swapping of operands for commutative ops if the first one
is constant and second one is not, the following patch just uses
fold_stmt_inplace to do that.  I think we shouldn't fold more than the
single statement because that could screw up the rest of the pass, we'd have
to mark all those with uids, visited and the like.

2023-02-18  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/108819
* tree-ssa-reassoc.cc (update_ops): Fold new stmt in place.

* gcc.dg/pr108819.c: New test.

17 months agoi386: Fix up replacement of registers in certain peephole2s [PR108832]
Jakub Jelinek [Sat, 18 Feb 2023 11:40:04 +0000 (12:40 +0100)]
i386: Fix up replacement of registers in certain peephole2s [PR108832]

As mentioned in the PR, replace_rtx has 2 modes, one that only replaces
x == from with to, the other which i386.md uses which also replaces
REGNO (x) == REGNO (from) with to if both are REGs, but assert they have
the same mode.  This is reasonable behavior if one replaces from with
some other expression, say constant etc., but ICEs whenever the register
appears in a different mode, which happens e.g. on the following testcase,
where from/to has DImode but inside of the operands we have SImode of
the from register.  replace_rtx also does some limited simplifications
(though far less than simplify_replace_fn_rtx), which is needed if
from a REG is replaced say with CONST_INT, but the peephole2s that use
this only replace one REG with another one.

The following patch introduces a new backend function for this, avoids doing
any simplifications and just replaces the REGs, for safety on a copy of
the expression if any changes will be needed.

2023-02-18  Jakub Jelinek  <jakub@redhat.com>

PR target/108832
* config/i386/i386-protos.h (ix86_replace_reg_with_reg): Declare.
* config/i386/i386-expand.cc (ix86_replace_reg_with_reg): New
function.
* config/i386/i386.md: Replace replace_rtx calls in all peephole2s
with ix86_replace_reg_with_reg.

* gcc.target/i386/pr108832.c: New test.