]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
4 months agogccrs: nr1.0: Resolve lang item paths properly.
Arthur Cohen [Wed, 4 Dec 2024 14:14:45 +0000 (15:14 +0100)] 
gccrs: nr1.0: Resolve lang item paths properly.

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Adapt resolver
to lang item paths.
* resolve/rust-ast-resolve-type.h: Likewise.

4 months agogccrs: hir: Start adapting visitors to accept multiple kinds of Paths
Arthur Cohen [Wed, 6 Nov 2024 15:32:35 +0000 (16:32 +0100)] 
gccrs: hir: Start adapting visitors to accept multiple kinds of Paths

gcc/rust/ChangeLog:

* ast/rust-item.h: Add new method to specifically get a type-path.
* ast/rust-path.cc (LangItemPath::as_string): Implement properly.
* hir/rust-ast-lower-type.cc (ASTLowerTypePath::translate): Adapt
visitor to use the new LangItemPath.
* hir/rust-ast-lower-type.h: Likewise.
* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Likewise.
* resolve/rust-ast-resolve-type.h: Likewise.

4 months agogccrs: derive(Copy): Use new LangItemPath
Arthur Cohen [Wed, 4 Dec 2024 14:10:10 +0000 (15:10 +0100)] 
gccrs: derive(Copy): Use new LangItemPath

gcc/rust/ChangeLog:

* expand/rust-derive-copy.cc: Use new LangItemPath for derive(Copy).

4 months agogccrs: ast: Add LangItemPath class
Arthur Cohen [Wed, 4 Dec 2024 14:09:58 +0000 (15:09 +0100)] 
gccrs: ast: Add LangItemPath class

This commit adds a new kind of Path, changes the base Path class and turns TypePath
into a child of the base Path class.

gcc/rust/ChangeLog:

* ast/rust-path.h (class LangItemPath): New.
(class TypePath): Adapt to accomodate LangItemPath.
* ast/rust-ast.cc (TraitImpl::as_string): Use new checks for lang items.
(QualifiedPathType::as_string): Likewise.
(FormatArgs::set_outer_attrs): Likewise.
* ast/rust-item.h (class TraitImpl): Likewise.

4 months agogccrs: Fix ForeverStack::find_starting_point output parameter
Owen Avery [Mon, 11 Nov 2024 21:04:58 +0000 (16:04 -0500)] 
gccrs: Fix ForeverStack::find_starting_point output parameter

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.h
(ForeverStack::find_starting_point): Use type
'std::reference_wrapper<Node> &' instead of 'Node &' for
parameter starting_point.
* resolve/rust-forever-stack.hxx
(ForeverStack::find_starting_point): Likewise.
(ForeverStack::resolve_path): Handle change to
ForeverStack::find_starting_point.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: type-check: Remove unused capture in nr2.0
Arthur Cohen [Fri, 29 Nov 2024 11:03:59 +0000 (12:03 +0100)] 
gccrs: type-check: Remove unused capture in nr2.0

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path):
Remove unused capture in lambda.

4 months agogccrs: attributes: Add class for sharing methods on attributes.
Arthur Cohen [Wed, 4 Dec 2024 13:53:11 +0000 (13:53 +0000)] 
gccrs: attributes: Add class for sharing methods on attributes.

gcc/rust/ChangeLog:

* util/rust-attributes.h (class Attributes): New.
* util/rust-attributes.cc: Implement Attributes::is_known().
* ast/rust-collect-lang-items.cc (is_known_attribute): Remove.
(get_lang_item_attr): Call Attributes::is_known() instead.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::handle_outer_attributes): Likewise.
(ASTLoweringBase::is_known_attribute): Remove.

4 months agogccrs: lang-items: Add lang-items AST collector
Arthur Cohen [Mon, 25 Nov 2024 13:30:39 +0000 (14:30 +0100)] 
gccrs: lang-items: Add lang-items AST collector

gcc/rust/ChangeLog:

* Make-lang.in: Add new object file.
* rust-session-manager.cc (Session::compile_crate): Call CollectLangItems.
* ast/rust-collect-lang-items.cc: New file.
* ast/rust-collect-lang-items.h: New file.

4 months agogccrs: lang-items: Store NodeId mappings for lang items
Arthur Cohen [Mon, 25 Nov 2024 14:05:32 +0000 (15:05 +0100)] 
gccrs: lang-items: Store NodeId mappings for lang items

gcc/rust/ChangeLog:

* util/rust-hir-map.h: Keep a NodeId mappings for lang items.
* util/rust-hir-map.cc (Mappings::insert_lang_item_node): New function.
(Mappings::lookup_lang_item_node): Likewise.

4 months agogccrs: fix crash in hir dump
Philip Herron [Mon, 2 Dec 2024 17:38:55 +0000 (17:38 +0000)] 
gccrs: fix crash in hir dump

gcc/rust/ChangeLog:

* hir/rust-hir-dump.cc (Dump::visit): add missing check for no return value

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: add test case to show issue is fixed
Philip Herron [Mon, 2 Dec 2024 17:02:25 +0000 (17:02 +0000)] 
gccrs: add test case to show issue is fixed

Fixes Rust-GCC#266

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/issue-266.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: add checks for division by zero and left shift overflow
Philip Herron [Mon, 2 Dec 2024 13:54:29 +0000 (13:54 +0000)] 
gccrs: add checks for division by zero and left shift overflow

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>
4 months agogccrs: constant evaluation like these are coercion sites
Philip Herron [Mon, 2 Dec 2024 16:17:54 +0000 (16:17 +0000)] 
gccrs: constant evaluation like these are coercion sites

The code here was wrongly assuming the decl type from the folding of the
expression would be the type of the constant decl. This is not the case for
unsized coercions for slices, where the expression here is a reference to
an array then we require the coercion to fix the result up to the expected
type.

Fixes Rust-GCC#1525

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc: apply coercion site to result
* backend/rust-compile-base.h: update prototype
* backend/rust-compile-implitem.cc (CompileTraitItem::visit): send in coercion info
* backend/rust-compile-item.cc (CompileItem::visit): likewise

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: Remove bad assertion in name resolution
Philip Herron [Mon, 2 Dec 2024 14:10:11 +0000 (14:10 +0000)] 
gccrs: Remove bad assertion in name resolution

This was a handy debug assertion but only works for valid rust code. This
needs to handle the case where the type is not resolved which is a valid
case.

Fixes Rust-GCC#2423

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): remove assertions

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 can't handle this
* rust/compile/issue-2423.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: ast: Use StackedContexts class in ContextualASTVisitor
Arthur Cohen [Tue, 26 Nov 2024 16:39:04 +0000 (16:39 +0000)] 
gccrs: ast: Use StackedContexts class in ContextualASTVisitor

gcc/rust/ChangeLog:

* ast/rust-ast-visitor.h: Replace context with StackedContexts.
* ast/rust-ast-visitor.cc (ContextualASTVisitor::visit): Use new APIs.
* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Likewise.

4 months agogccrs: stacked-contexts: Add peek() method
Arthur Cohen [Tue, 26 Nov 2024 16:34:37 +0000 (16:34 +0000)] 
gccrs: stacked-contexts: Add peek() method

gcc/rust/ChangeLog:

* util/rust-stacked-contexts.h: Add new method to see what context we are currently in.

4 months agogccrs: hir: Remove duplicate function in TraitItemFunc
Arthur Cohen [Fri, 29 Nov 2024 10:05:29 +0000 (11:05 +0100)] 
gccrs: hir: Remove duplicate function in TraitItemFunc

Both TraitItemFunc::has_definition() and TraitItemFunc::has_block_defined()
were exactly the same implementation, so remove one.

gcc/rust/ChangeLog:

* hir/tree/rust-hir-item.h: Remove TraitItemFunc::has_block_defined()
* backend/rust-compile-implitem.cc (CompileTraitItem::visit):
Call TraitItemFunc::has_definition() instead.
* checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise.
* checks/errors/rust-hir-pattern-analysis.cc (PatternChecker::visit): Likewise.
* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise.
* typecheck/rust-hir-trait-resolve.cc (ResolveTraitItemToRef::visit): Likewise.

4 months agogccrs: mappings: Move lang_item definitions to .cc
Arthur Cohen [Mon, 25 Nov 2024 11:37:12 +0000 (12:37 +0100)] 
gccrs: mappings: Move lang_item definitions to .cc

gcc/rust/ChangeLog:

* util/rust-hir-map.h: Move definitions from header...
* util/rust-hir-map.cc: ...to source file.

4 months agogccrs: lang-items: Move comment about arithmetic lang items
Arthur Cohen [Mon, 25 Nov 2024 11:21:05 +0000 (12:21 +0100)] 
gccrs: lang-items: Move comment about arithmetic lang items

gcc/rust/ChangeLog:

* util/rust-lang-item.h: Fix comment location to align with other comments.

4 months agogccrs: ensure packed and aligned is applied properly
Philip Herron [Tue, 26 Nov 2024 18:05:25 +0000 (18:05 +0000)] 
gccrs: ensure packed and aligned is applied properly

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>
4 months agogccrs: allow casts from numeric types to floats
Philip Herron [Tue, 26 Nov 2024 15:33:35 +0000 (15:33 +0000)] 
gccrs: allow casts from numeric types to floats

Fixes Rust-GCC#3261

gcc/rust/ChangeLog:

* typecheck/rust-casts.cc (TypeCastRules::cast_rules): allow casts to float

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: improve handling of Self Type paths
Philip Herron [Mon, 25 Nov 2024 21:37:19 +0000 (21:37 +0000)] 
gccrs: improve handling of Self Type paths

TypePaths have special handling for Self where we can look at the current ctx
for more acurate TypeAlias information if required. We cant do this for Impl
contexts but not for Traits as we might as well fall back to the TypePathProbe.

The other issue was the dyn type comming in because Foo::foo and Foo is a trait
reference we represent this as a dyn type as the root resolved path but then find
the associated impl block for this but we cannot do this when we have resolved to
a Dyn because this is just a representation that we know we are talking about a
trait not because we are actually working with a real Dyn type.

Fixes Rust-GCC#2907

gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): track trait
* typecheck/rust-hir-type-check-implitem.cc: trait block
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_segments): dont when dyn
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): look at Self contenxt
(TypeCheckType::resolve_root_path): track if Self
(TypeCheckType::resolve_associated_type): look at current context for associated types
* typecheck/rust-hir-type-check-type.h: change prototype
* typecheck/rust-hir-type-check.h (class TypeCheckBlockContextItem):
new context system to track current state
* typecheck/rust-typecheck-context.cc (TypeCheckContext::have_block_context): likewise
(TypeCheckContext::peek_block_context): likewise
(TypeCheckContext::push_block_context): likewise
(TypeCheckContext::pop_block_context): likewise
(TypeCheckBlockContextItem::Item::Item): likewise
(TypeCheckBlockContextItem::TypeCheckBlockContextItem): likewise
(TypeCheckBlockContextItem::is_impl_block): likewise
(TypeCheckBlockContextItem::is_trait_block): likewise
(TypeCheckBlockContextItem::get_impl_block): likewise
(TypeCheckBlockContextItem::get_trait): likewise

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/issue-2907.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: fix crash in hir dump with missing guards
Philip Herron [Mon, 25 Nov 2024 20:16:42 +0000 (20:16 +0000)] 
gccrs: fix crash in hir dump with missing guards

gcc/rust/ChangeLog:

* hir/rust-hir-dump.cc (Dump::visit): add missing null checks

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: Prepend crate name to functions with nr2
Pierre-Emmanuel Patry [Mon, 25 Nov 2024 13:24:21 +0000 (14:24 +0100)] 
gccrs: Prepend crate name to functions with nr2

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc: Prepend crate name to function's ir
name.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove passing tests from exclude list.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Prevent execution of some nr1.0 functions with nr2.0
Owen Avery [Thu, 21 Nov 2024 20:28:46 +0000 (15:28 -0500)] 
gccrs: Prevent execution of some nr1.0 functions with nr2.0

gcc/rust/ChangeLog:

* resolve/rust-name-resolver.cc: Include options.txt.
(Resolver::insert_resolved_name): Assert that name resolution
2.0 is disabled.
(Resolver::lookup_resolved_name): Likewise.
(Resolver::insert_resolved_type): Likewise.
(Resolver::lookup_resolved_type): Likewise.
(Resolver::insert_resolved_label): Likewise.
(Resolver::lookup_resolved_label): Likewise.
(Resolver::insert_resolved_macro): Likewise.
(Resolver::lookup_resolved_macro): Likewise.
(Resolver::insert_resolved_misc): Likewise.
(Resolver::lookup_resolved_misc): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: empty match expressions should resolve to !
Philip Herron [Thu, 21 Nov 2024 17:36:34 +0000 (17:36 +0000)] 
gccrs: empty match expressions should resolve to !

This is a special case in Rust and the ! type can unify with pretty much
anything its almost a inference variable and a unit-type for special cases.

Fixes Rust-GCC/gccrs#3231
Fixes Rust-GCC/gccrs#2567

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (check_match_scrutinee): check for empty match
(CompileExpr::visit): fix assertion
* checks/errors/rust-hir-pattern-analysis.cc (check_match_usefulness): check for empty
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): resolve to !

gcc/testsuite/ChangeLog:

* rust/compile/exhaustiveness1.rs: remove bad check
* rust/compile/issue-2567-1.rs: New test.
* rust/compile/issue-2567-2.rs: New test.
* rust/compile/issue-2567-3.rs: New test.
* rust/compile/issue-3231.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: fix crashes in hir dump since move to references
Philip Herron [Thu, 21 Nov 2024 17:27:31 +0000 (17:27 +0000)] 
gccrs: fix crashes in hir dump since move to references

gcc/rust/ChangeLog:

* hir/rust-hir-dump.cc (Dump::visit): add guards

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: Clean up some system includes
Pierre-Emmanuel Patry [Fri, 22 Nov 2024 11:20:09 +0000 (12:20 +0100)] 
gccrs: Clean up some system includes

System includes shall use rust-system header instead.

gcc/rust/ChangeLog:

* ast/rust-stmt.h: Remove stdlib include and use rust-system instead.
* backend/rust-compile-expr.cc: Likewise.
* backend/rust-mangle-legacy.cc: Likewise.
* backend/rust-mangle-v0.cc: Likewise.
* hir/rust-hir-dump.cc: Likewise.
* typecheck/rust-hir-type-check-type.cc: Likewise.
* typecheck/rust-tyty.cc: Likewise.
* typecheck/rust-tyty.h: Likewise.
* util/rust-common.h: Likewise.
* util/rust-token-converter.cc: Likewise.
* util/rust-token-converter.h: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Use nr2.0 in typechecker
Owen Avery [Tue, 19 Nov 2024 20:10:09 +0000 (15:10 -0500)] 
gccrs: Use nr2.0 in typechecker

I probably missed a few spots, but this should cover most of the type
checker.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc: Add includes.
(TypeCheckExpr::visit): Use name resolver 2.0.
(TypeCheckExpr::resolve_operator_overload): Likewise.
(TypeCheckExpr::resolve_fn_trait_call): Likewise.
* typecheck/rust-hir-type-check-path.cc
(TypeCheckExpr::visit): Likewise.
(TypeCheckExpr::resolve_segments): Likewise.
* typecheck/rust-hir-type-check-type.cc
(TypeCheckType::resolve_segments): Likewise.
(ResolveWhereClauseItem::visit): Likewise.
(TypeCheckType::visit): Avoid usage of
Resolver::get_unit_type_node_id when handling TupleType, use
name resolver 2.0 when handling QualifiedPathInType.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Handle type path segments during late resolution 2.0
Owen Avery [Tue, 19 Nov 2024 21:09:01 +0000 (16:09 -0500)] 
gccrs: Handle type path segments during late resolution 2.0

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Call DefaultResolver::visit when visiting
TypePath.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Use nr2.0 in PrivacyReporter
Owen Avery [Tue, 19 Nov 2024 18:57:34 +0000 (13:57 -0500)] 
gccrs: Use nr2.0 in PrivacyReporter

gcc/rust/ChangeLog:

* checks/errors/privacy/rust-privacy-reporter.cc
(PrivacyReporter::check_for_privacy_violation): Use name
resolver 2.0.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Use a reference wrapper to please GCC 4.8
Pierre-Emmanuel Patry [Wed, 20 Nov 2024 12:35:22 +0000 (13:35 +0100)] 
gccrs: Use a reference wrapper to please GCC 4.8

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): Change call.
(CompileExpr::resolve_operator_overload): Update function arguments.
* backend/rust-compile-expr.h: Change the function's prototype to use
a reference wrapper instead of a reference within the optional.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Use default constructor for default arguments
Pierre-Emmanuel Patry [Wed, 20 Nov 2024 12:19:15 +0000 (13:19 +0100)] 
gccrs: Use default constructor for default arguments

GCC 4.8 complains about the initializer list.

gcc/rust/ChangeLog:

* typecheck/rust-tyty.h: Change initializer list to default constructor
call.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add optional template arguments to please GCC4.8
Pierre-Emmanuel Patry [Wed, 20 Nov 2024 00:44:28 +0000 (01:44 +0100)] 
gccrs: Add optional template arguments to please GCC4.8

Clang on macos as well as GCC 4.8 complains when those templates are
missing.

gcc/rust/ChangeLog:

* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Add template
to tl::optional.
* hir/rust-ast-lower-type.cc (ASTLowerGenericParam::visit): Likewise.
* typecheck/rust-hir-type-check-type.cc (TypeResolveGenericParam::visit):
Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Fix FnParam pattern location ternary logic
Pierre-Emmanuel Patry [Wed, 20 Nov 2024 00:28:04 +0000 (01:28 +0100)] 
gccrs: Fix FnParam pattern location ternary logic

Condition was inverted, we should retrieve the locus only if we have a
pattern.

gcc/rust/ChangeLog:

* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Do not
get a reference if the pattern does not exist.
(TypeCheckMethodCallExpr::check): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Refactor optional initializers
Pierre-Emmanuel Patry [Tue, 19 Nov 2024 16:24:59 +0000 (17:24 +0100)] 
gccrs: Refactor optional initializers

Refactor some optional initializer in the lowering stage to make them
more readable.

gcc/rust/ChangeLog:

* hir/rust-ast-lower-stmt.cc (ASTLoweringStmt::visit): Change the
ternary expression with a more readable if.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: FnParam cloning now keeps projections
Pierre-Emmanuel Patry [Tue, 19 Nov 2024 14:37:56 +0000 (15:37 +0100)] 
gccrs: FnParam cloning now keeps projections

FnParam type where monomorphized during cloning.

gcc/rust/ChangeLog:

* typecheck/rust-tyty.h: Reverse monomorphization during cloning and
make a new function to explicitly monomorphize.
* typecheck/rust-tyty.cc: Use monomorphization when required.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Fix Generic type retrieval
Pierre-Emmanuel Patry [Fri, 8 Nov 2024 11:01:15 +0000 (12:01 +0100)] 
gccrs: Fix Generic type retrieval

gcc/rust/ChangeLog:

* hir/rust-ast-lower-type.cc (ASTLowerGenericParam::visit): Forward
an optional to the constructor.
* hir/tree/rust-hir-item.cc (TypeParam::TypeParam): Use an optional
in the constructor.
(TypeParam::operator=): Ensure the TypeParam has a type properly.
(TypeParam::get_type_mappings): Likewise.
* hir/tree/rust-hir-item.h: Wrap the type smart pointer into an
optional.
* hir/tree/rust-hir.cc (TypeParam::as_string): Unwrap optional type
correctly.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Fixes some tests appearing with a moved variant
Pierre-Emmanuel Patry [Mon, 28 Oct 2024 17:08:52 +0000 (18:08 +0100)] 
gccrs: Fixes some tests appearing with a moved variant

A variant being moved lead to a null being created and a segfault later
down the line.

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): Call getter
instead of size function.
* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit):
Only check privacy if the type is present.
* hir/rust-ast-lower-stmt.cc (ASTLoweringStmt::visit): Use an optional.
* hir/tree/rust-hir-generic-param.h: Assert type before getting it.
* hir/tree/rust-hir-item.h: Assert pointers before dereference, fix
has_type condition.
* hir/tree/rust-hir-path.h: Add more assertions.
* hir/tree/rust-hir-stmt.cc: Change constructor with optionals.
* hir/tree/rust-hir-stmt.h: Use optionals over smart pointers to
emphasize these fields might be missing.
* hir/tree/rust-hir.cc (LetStmt::as_string): Use getters.
* typecheck/rust-hir-type-check-expr.cc: Clone structures to prevent
parent's fields from being nulled by the move operation.
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): Use
optionals.
* typecheck/rust-tyty.cc: Likewise.
* typecheck/rust-tyty.h: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Refactor hir to avoid raw pointers and unneeded fwd
Pierre-Emmanuel Patry [Tue, 15 Oct 2024 13:22:56 +0000 (15:22 +0200)] 
gccrs: Refactor hir to avoid raw pointers and unneeded fwd

Refactor the hir tree files to remove raw pointer usage and most forward
declarations. Move implementation out of headers and split headers into
smaller and more manageable units.

gcc/rust/ChangeLog:

* Make-lang.in: Add new files.
* hir/tree/rust-hir-item.h: Move Item definition and remove
implementations to their corresponding cc file.
* hir/tree/rust-hir-expr.h: Move implementation to the corresponding
cc file.
* 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-visitor.h: Likewise.
* hir/tree/rust-hir.h: Likewise.
* hir/tree/rust-hir.cc (Crate::Crate): Add implementations from Crate
and remove ConstGenericParam implementations to move them to their
own file.
* hir/tree/rust-hir-attrs.h: New file.
* hir/tree/rust-hir-bound-abstract.h: New file.
* hir/tree/rust-hir-bound.h: New file.
* hir/tree/rust-hir-expr-abstract.h: New file.
* hir/tree/rust-hir-expr.cc: New file.
* hir/tree/rust-hir-generic-param.cc: New file.
* hir/tree/rust-hir-generic-param.h: New file.
* hir/tree/rust-hir-item.cc: New file.
* hir/tree/rust-hir-literal.h: New file.
* hir/tree/rust-hir-node.h: New file.
* hir/tree/rust-hir-path.cc: New file.
* hir/tree/rust-hir-pattern-abstract.h: New file.
* hir/tree/rust-hir-simple-path.h: New file.
* hir/tree/rust-hir-stmt.cc: New file.
* hir/tree/rust-hir-trait-bound.h: New file.
* hir/tree/rust-hir-type-abstract.cc: New file.
* hir/tree/rust-hir-type-abstract.h: New file.
* hir/tree/rust-hir-type-no-bounds.h: New file.
* hir/tree/rust-hir-type.cc: New file.
* hir/tree/rust-hir-visibility.h: New file.
* hir/tree/rust-hir-visitable.h: New file.
* checks/lints/rust-lint-marklive.h: Use References.
* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Reformat
vectors.
* hir/rust-hir-dump.cc (Dump::visit): Use reference.
* typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::resolve):
Use references.
* typecheck/rust-tyty-bounds.cc: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Refactor HIR with optionals, references & newtypes
Pierre-Emmanuel Patry [Fri, 8 Mar 2024 13:42:10 +0000 (14:42 +0100)] 
gccrs: Refactor HIR with optionals, references & newtypes

The HIR made heavy use of pair and other unamed types which can be
difficult to read.

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc: Use FnParam getter.
* backend/rust-compile-expr.cc (CompileExpr::visit): Likewise.
* backend/rust-compile-intrinsic.cc: Likewise.
* backend/rust-compile-type.cc: Likewise.
* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit):
Only visit childrens if not missing.
* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Use
a reference instead of a raw pointer.
* hir/tree/rust-hir-expr.h: Add presence function for return
expression.
* hir/tree/rust-hir-item.h: Remove take_param_name.
* hir/tree/rust-hir.h: Make mapping getter const.
* typecheck/rust-hir-dot-operator.cc (MethodResolver::Select): Use
getter.
* typecheck/rust-hir-type-check-expr.cc: Likewise.
* typecheck/rust-hir-type-check-implitem.cc: Use FnParam vector instead
of std::pair of Pattern and BaseType.
* typecheck/rust-hir-type-check-item.cc: Likewise.
* typecheck/rust-hir-type-check.cc: Likewise.
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Use getters.
(TypeCheckMethodCallExpr::check): Likewise.
* typecheck/rust-tyty-cmp.h: Likewise.
* typecheck/rust-tyty.cc: Use FnParam.
* typecheck/rust-tyty.h (class FnParam): Add FnParam to handle function
parameters instead of handling std::pairs.
* typecheck/rust-unify.cc (UnifyRules::expect_fndef): Use getters.
(UnifyRules::expect_fnptr): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Refactor HIR to reduce the amount of raw pointers
Pierre-Emmanuel Patry [Tue, 27 Feb 2024 12:43:37 +0000 (13:43 +0100)] 
gccrs: Refactor HIR to reduce the amount of raw pointers

Attempt to use references and smart pointers whenever possible.

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc (HIRCompileBase::compile_function_body):
Remove usage of get function to retrieve a raw pointer.
* backend/rust-compile-base.h:
Change API usage from raw pointer to a reference.
* backend/rust-compile-block.cc (CompileBlock::compile): Likewise.
(CompileBlock::visit): Likewise.
(CompileConditionalBlocks::visit): Likewise.
* backend/rust-compile-block.h: Likewise.
* backend/rust-compile-expr.cc (CompileExpr::Compile): Likewise.
(CompileExpr::visit): Likewise.
(check_match_scrutinee): Likewise.
(CompileExpr::array_value_expr): Likewise.
(CompileExpr::array_copied_expr): Likewise.
(CompileExpr::generate_closure_function): Likewise.
(CompileExpr::generate_possible_fn_trait_call): Likewise.
* backend/rust-compile-expr.h: Likewise.
* backend/rust-compile-fnparam.cc (CompileFnParam::compile): Likewise.
(CompileFnParam::visit): Likewise.
* backend/rust-compile-fnparam.h: Likewise.
* backend/rust-compile-implitem.cc (CompileTraitItem::visit): Likewise.
* backend/rust-compile-intrinsic.cc (compile_fn_params): Likewise.
* backend/rust-compile-item.cc (CompileItem::visit): Likewise.
* backend/rust-compile-pattern.cc (CompilePatternCheckExpr::visit):
Likewise.
(compile_range_pattern_bound): Likewise.
(CompilePatternBindings::visit): Likewise.
(CompilePatternLet::visit): Likewise.
* backend/rust-compile-pattern.h: Likewise.
* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve):
Likewise.
(HIRCompileBase::query_compile): Likewise.
* backend/rust-compile-stmt.cc (CompileStmt::visit): Likewise.
* backend/rust-compile-struct-field-expr.cc (CompileStructExprField::Compile):
Likewise.
(CompileStructExprField::visit): Likewise.
* backend/rust-compile-struct-field-expr.h: Likewise.
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Likewise.
* backend/rust-compile-var-decl.h: Likewise.
* backend/rust-compile.cc: Likewise.
* backend/rust-mangle-v0.cc (v0_inherent_or_trait_impl_path): Likewise.
* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit):
Likewise.
* checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: Likewise.
* checks/errors/borrowck/rust-bir-builder-pattern.h: Likewise.
* checks/errors/borrowck/rust-bir-builder-struct.h: Likewise.
* checks/errors/borrowck/rust-bir-builder.h: Likewise.
* checks/errors/borrowck/rust-function-collector.h: Likewise.
* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::check_type_privacy):
Likewise.
(PrivacyReporter::visit): Likewise.
* checks/errors/privacy/rust-privacy-reporter.h: Likewise.
* checks/errors/privacy/rust-reachability.cc (ReachabilityVisitor::visit):
Likewise.
* checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise.
* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit):
Likewise.
* checks/lints/rust-lint-marklive.cc (MarkLive::visit): Likewise.
* checks/lints/rust-lint-marklive.h: Likewise.
* hir/rust-hir-dump.cc (Dump::visit): 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.h: Likewise.
* typecheck/rust-autoderef.cc: Likewise.
* typecheck/rust-hir-dot-operator.cc (MethodResolver::select):
Likewise.
* typecheck/rust-hir-inherent-impl-overlap.h: Likewise.
* typecheck/rust-hir-path-probe.cc (PathProbeType::process_impl_item_candidate):
Likewise.
(PathProbeImplTrait::process_trait_impl_items_for_candidates): Likewise.
* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait):
Likewise.
(TraitItemReference::resolve_item): Likewise.
* typecheck/rust-hir-type-check-base.cc: Likewise.
* typecheck/rust-hir-type-check-base.h: Likewise.
* typecheck/rust-hir-type-check-enumitem.cc (TypeCheckEnumItem::Resolve):
Likewise.
(TypeCheckEnumItem::visit): Likewise.
* typecheck/rust-hir-type-check-enumitem.h: Likewise.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::Resolve):
Likewise.
(TypeCheckExpr::visit): Likewise.
(TypeCheckExpr::resolve_fn_trait_call): Likewise.
* typecheck/rust-hir-type-check-expr.h: Likewise.
* typecheck/rust-hir-type-check-implitem.cc (TypeCheckTopLevelExternItem::Resolve):
Likewise.
(TypeCheckTopLevelExternItem::visit): Likewise.
(TypeCheckImplItem::visit): Likewise.
(TypeCheckImplItemWithTrait::visit): Likewise.
* typecheck/rust-hir-type-check-implitem.h: Likewise.
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): Likewise.
(TypeCheckItem::resolve_impl_item): Likewise.
(TypeCheckItem::resolve_impl_block_substitutions): Likewise.
(TypeCheckItem::resolve_impl_block_self): Likewise.
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::visit): Likewise.
(TypeCheckExpr::resolve_segments): Likewise.
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::Resolve):
Likewise.
(TypeCheckPattern::visit): Likewise.
(ClosureParamInfer::Resolve): Likewise.
(ClosureParamInfer::visit): Likewise.
* typecheck/rust-hir-type-check-pattern.h: Likewise.
* typecheck/rust-hir-type-check-stmt.cc (TypeCheckStmt::Resolve):
Likewise.
(TypeCheckStmt::visit): Likewise.
* typecheck/rust-hir-type-check-stmt.h: Likewise.
* typecheck/rust-hir-type-check-struct-field.h: Likewise.
* typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::TypeCheckStructExpr):
Likewise.
(TypeCheckStructExpr::Resolve): Likewise.
(TypeCheckStructExpr::resolve): Likewise.
(TypeCheckStructExpr::visit): Likewise.
* typecheck/rust-hir-type-check-type.cc (TypeCheckResolveGenericArguments::resolve):
Likewise.
(TypeCheckType::Resolve): Likewise.
(TypeCheckType::visit): Likewise.
(TypeCheckType::resolve_root_path): Likewise.
(TypeResolveGenericParam::Resolve): Likewise.
(TypeResolveGenericParam::visit): Likewise.
(ResolveWhereClauseItem::visit): Likewise.
* typecheck/rust-hir-type-check-type.h: Likewise.
* typecheck/rust-hir-type-check.cc (TraitItemReference::get_type_from_fn):
Likewise.
* typecheck/rust-hir-type-check.h: Likewise.
* typecheck/rust-type-util.cc (query_type): Likewise.
* typecheck/rust-typecheck-context.cc (TypeCheckContextItem::TypeCheckContextItem):
Likewise.
* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::scan): Likewise.
(TypeCheckBase::get_predicate_from_bound): Likewise.
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Likewise.
(TypeCheckMethodCallExpr::go): Likewise.
(TypeCheckMethodCallExpr::check): Likewise.
* typecheck/rust-tyty-subst.cc: Likewise.
* typecheck/rust-tyty.cc (BaseType::monomorphized_clone): Likewise.
(VariantDef::VariantDef): Remove copy constructor.
(VariantDef::operator=): Change to move operator.
(VariantDef::get_discriminant): Replace return type to a reference
instead of a reference to a unique pointer.
(VariantDef::clone): Change to references.
(VariantDef::monomorphized_clone): Likewise.
(FnType::as_string): Likewise.
(FnType::clone): Likewise.
* typecheck/rust-tyty.h: Likewise.
* util/rust-hir-map.cc (Mappings::insert_hir_impl_block): Likewise.
* backend/rust-compile-asm.cc: Use a reference instead of the raw
pointer value.
* checks/errors/borrowck/rust-bir-builder-pattern.cc: Use references.
* checks/errors/rust-hir-pattern-analysis.cc: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Improve handling of static items in toplevel 2.0
Owen Avery [Mon, 11 Nov 2024 21:19:44 +0000 (16:19 -0500)] 
gccrs: Improve handling of static items in toplevel 2.0

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Use DefaultResolver::visit and avoid a call
to Identifier::as_string while handling instances of StaticItem.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Push ribs by kind rather than by value
Owen Avery [Mon, 11 Nov 2024 21:37:38 +0000 (16:37 -0500)] 
gccrs: Push ribs by kind rather than by value

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.h
(ForeverStack::push): Accept argument of type Rib::Kind rather
than Rib.
* resolve/rust-forever-stack.hxx
(ForeverStack::push): Likewise.
* resolve/rust-name-resolution-context.cc
(NameResolutionContext::scoped): Likewise.
* resolve/rust-name-resolution-context.h
(NameResolutionContext::scoped): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Fix bad handling for recursive type query
Philip Herron [Tue, 12 Nov 2024 12:16:40 +0000 (12:16 +0000)] 
gccrs: Fix bad handling for recursive type query

When resolving a type like this which is generic it causes the argument
substitution to go through bounds checking which is expected. But this
can call a type bounds probe which again calls a type query which will be
on the Impl Type on an impl block which can result in a recursive type
query which does eventually get caught and errors correctly. But this then
triggers some old error diagnositcs which are not valid error codes but old
error messages we used to catch simple errors very early on which do not
apply for this senario.

Fixes Rust-GCC#2905

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::resolve_impl_block_substitutions):
dont check for unconstrained when the self is not resolved
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path):
remove bad debug error diagnostic
* typecheck/rust-tyty-subst.cc: likewise

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/issue-2905-1.rs: New test.
* rust/compile/issue-2905-2.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: asm: Fix clang warnings
Arthur Cohen [Wed, 6 Nov 2024 14:19:55 +0000 (15:19 +0100)] 
gccrs: asm: Fix clang warnings

Fixes a couple of warnings thrown by clang, with mismatched class/struct
usages and unused members.

gcc/rust/ChangeLog:

* ast/rust-expr.h: Remove invalid usage of `struct`.
* backend/rust-compile-asm.h: Remove unused `translated` member.
* backend/rust-compile-asm.cc (CompileAsm::CompileAsm): Remove usage
of `translated` member.
* checks/errors/rust-unsafe-checker.h: Mark visitor as `override`.
* hir/tree/rust-hir-expr.h (struct AnonConst): Remove unused `locus`
member.

4 months agogccrs: typecheck: Remove unused parameter in TyTyCheckCallExpr
Arthur Cohen [Wed, 6 Nov 2024 14:19:10 +0000 (15:19 +0100)] 
gccrs: typecheck: Remove unused parameter in TyTyCheckCallExpr

gcc/rust/ChangeLog:

* typecheck/rust-tyty-call.h: Remove unused context member.

4 months agogccrs: hir: Mark AttrVec::get_outer_attrs as override
Arthur Cohen [Wed, 6 Nov 2024 14:15:02 +0000 (15:15 +0100)] 
gccrs: hir: Mark AttrVec::get_outer_attrs as override

gcc/rust/ChangeLog:

* hir/tree/rust-hir.h: Add override qualifier to overriden method.

4 months agogccrs: add test case to show issue is fixed
Philip Herron [Wed, 6 Nov 2024 11:08:27 +0000 (11:08 +0000)] 
gccrs: add test case to show issue is fixed

The original test case 1773 has been moved to a new issue 3242 which
is still open and test-case is skipped. The original issue in 1773 is
fixed so this will close out that issue

Fixes Rust-Gcc#1773

gcc/testsuite/ChangeLog:

* rust/compile/issue-1773.rs: new test case
* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/issue-3242.rs: old test ranamed to match issue.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: Improve handling of implicit Self parameter in AST
Owen Avery [Mon, 4 Nov 2024 20:05:03 +0000 (15:05 -0500)] 
gccrs: Improve handling of implicit Self parameter in AST

gcc/rust/ChangeLog:

* ast/rust-item.h
(Trait::self_param): Add.
(Trait::Trait): Initialize self_param.
(Trait::operator=): Copy self_param.
(Trait::insert_implicit_self): Remove.
(Trait::get_implicit_self): Add.
* hir/rust-ast-lower-item.cc
(ASTLoweringItem::visit): Make sure implicit self is still
lowered to HIR.
* resolve/rust-ast-resolve-item.cc
(ResolveItem::visit): Adjust handling of implicit self.
* resolve/rust-early-name-resolver.cc
(EarlyNameResolver::visit): Add commit to Trait visitor
mentioning that implicit self is not visited.
* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Remove call to Trait::insert_implicit_self.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.
* rust/link/generic_function_0.rs: No longer expect failure.
* rust/link/trait_import_0.rs: Likewise.
* rust/link/trait_import_1.rs
(trait Sized): Add.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: fix typechecking of Fn trait calls using ADT types
Philip Herron [Tue, 5 Nov 2024 17:41:44 +0000 (17:41 +0000)] 
gccrs: fix typechecking of Fn trait calls using ADT types

Fixes RustGcc#2953

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): fix the ty_id

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 cant handle these
* rust/compile/issue-2953-1.rs: New test.
* rust/compile/issue-2953-2.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: fix ICE for placeholder which is not setup
Philip Herron [Tue, 5 Nov 2024 17:35:37 +0000 (17:35 +0000)] 
gccrs: fix ICE for placeholder which is not setup

We can have a case where the placeholder is not configred and the
can_resolve check is not detecting this case which can lead to ICE.

gcc/rust/ChangeLog:

* typecheck/rust-tyty.cc (PlaceholderType::can_resolve): check for empty mappings

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: Reorganize the CPU feature detection
Antoni Boucher [Fri, 11 Oct 2024 21:05:22 +0000 (17:05 -0400)] 
gccrs: Reorganize the CPU feature detection

Move the code from i386-rust.cc to i386-rust-and-jit.inc so that it can
be reused by libgccjit.

gcc/ChangeLog:

* config/i386/i386-rust-and-jit.inc: New file.
* config/i386/i386-rust.cc: Move code to i386-rust-and-jit.inc.

4 months agogccrs: Use name resolver 2.0 for module descendance checks
Owen Avery [Sun, 27 Oct 2024 00:52:31 +0000 (20:52 -0400)] 
gccrs: Use name resolver 2.0 for module descendance checks

gcc/rust/ChangeLog:

* checks/errors/privacy/rust-privacy-reporter.cc:
Include rust-immutable-name-resolution-context.h.
(is_child_module): Use ForeverStack::is_module_descendant if name
resolution 2.0 is enabled.
* resolve/rust-forever-stack.h
(ForeverStack::is_module_descendant): Add.
(ForeverStack::dfs_node): Add.
* resolve/rust-forever-stack.hxx
(ForeverStack::dfs_rib): Use ForeverStack::dfs_node.
(ForeverStack::dfs_node): Add.
(ForeverStack::is_module_descendant): Add.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Use name resolver 2.0 in VisibilityResolver
Owen Avery [Tue, 5 Nov 2024 02:52:14 +0000 (21:52 -0500)] 
gccrs: Use name resolver 2.0 in VisibilityResolver

gcc/rust/ChangeLog:

* checks/errors/privacy/rust-visibility-resolver.cc:
Add includes.
(VisibilityResolver::resolve_module_path): Use name resolver 2.0
(when enabled) to lookup path resolutions.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: fix bad type inference on local patterns
Philip Herron [Mon, 4 Nov 2024 14:43:25 +0000 (14:43 +0000)] 
gccrs: fix bad type inference on local patterns

We do not need to inject inference variables on generic patterns
with generic blocks. This will just cause unconstrained inference
variables as they may not unify against something.

Fixes Rust-GCC#2323

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_root_path): dont infer here

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/issue-2323.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: Improve handling of struct expressions in nr2.0
Owen Avery [Sun, 27 Oct 2024 02:19:21 +0000 (22:19 -0400)] 
gccrs: Improve handling of struct expressions in nr2.0

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Handle StructExprStruct and use
ForeverStack::resolve_path instead of ForeverStack::get to
resolve struct expression paths.
* resolve/rust-late-name-resolver-2.0.h
(Late::visit): Handle StructExprStruct.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Remove usage of Resolver::get_builtin_types
Owen Avery [Fri, 1 Nov 2024 16:58:44 +0000 (12:58 -0400)] 
gccrs: Remove usage of Resolver::get_builtin_types

gcc/rust/ChangeLog:

* backend/rust-compile-context.cc
(Context::setup_builtins): Use TypeCheckContext::get_builtins
instead of Resolver::get_builtin_types,
TypeCheckContext::lookup_type_by_node_id, and
TypeCheckContext::lookup_type.
* typecheck/rust-hir-type-check.h
(TypeCheckContext::get_builtins): Add.
* typecheck/rust-typecheck-context.cc
(TypeCheckContext::get_builtins): Add.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: fix bad type inferencing on path's
Philip Herron [Fri, 1 Nov 2024 16:18:28 +0000 (16:18 +0000)] 
gccrs: fix bad type inferencing on path's

This catch to inject inference variables into generic paths was a
catch all 'hack' that we needed before we handled generics correctly
as we do now.

Fixes #3009

gcc/rust/ChangeLog:

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

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/issue-3009.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: Make TyTy::TupleType::get_unit_type cache its return value
Owen Avery [Mon, 28 Oct 2024 23:02:23 +0000 (19:02 -0400)] 
gccrs: Make TyTy::TupleType::get_unit_type cache its return value

This removes a usage of Resolver::get_unit_type_node_id in
rust-hir-type-check-expr.cc (the HIR::TupleExpr overload of
TypeCheckExpr::visit).

gcc/rust/ChangeLog:

* typecheck/rust-tyty.cc
(TupleType::get_unit_type): Remove parameter, cache return
value.
* typecheck/rust-tyty.h
(TupleType::get_unit_type): Remove parameter.
* resolve/rust-late-name-resolver-2.0.cc
(Late::setup_builtin_types): Adjust calls to get_unit_type.
* resolve/rust-name-resolver.cc
(Resolver::generate_builtins): Likewise.
* typecheck/rust-hir-type-check-expr.cc
(TypeCheckExpr::visit): Likewise.
* typecheck/rust-hir-type-check-implitem.cc
(TypeCheckTopLevelExternItem::visit): Likewise.
(TypeCheckImplItem::visit): Likewise.
* typecheck/rust-hir-type-check-item.cc
(TypeCheckItem::visit): Likewise.
* typecheck/rust-hir-type-check-stmt.cc
(TypeCheckStmt::visit): Likewise.
* typecheck/rust-hir-type-check-type.cc
(TypeCheckType::visit): Likewise.
* typecheck/rust-hir-type-check.cc
(TraitItemReference::get_type_from_fn): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: add test case to show method resolution is working
Philip Herron [Fri, 1 Nov 2024 14:07:54 +0000 (14:07 +0000)] 
gccrs: add test case to show method resolution is working

The issue here was that the impl block for Cell<T> defines that T must have
the bound of Copy implemented. But simultaneously if you do an deref
you get direct access to the unsafe cell which also defines a get method
so these are two valid ways of accessing the method in question but
when Copy is implementet the simplest case is prefered so it does resolve
to Cell<T>::get.

Fixes #3033

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr can't handle this
* rust/compile/issue-3033.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: Resolve SelfParam in name resolution 2.0
Owen Avery [Fri, 4 Oct 2024 16:56:16 +0000 (12:56 -0400)] 
gccrs: Resolve SelfParam in name resolution 2.0

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Handle SelfParam.
* resolve/rust-late-name-resolver-2.0.h
(Late::visit): Likewise.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Use name resolution 2.0 in TraitResolver
Owen Avery [Sat, 26 Oct 2024 23:43:11 +0000 (19:43 -0400)] 
gccrs: Use name resolution 2.0 in TraitResolver

gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-resolve.cc: Add includes.
(TraitResolver::resolve_path_to_trait):
Use name resolution 2.0 resolver when enabled.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agorust: Desugar IfLet* into MatchExpr
Marc Poulhiès [Wed, 12 Jun 2024 19:58:26 +0000 (21:58 +0200)] 
rust: Desugar IfLet* into MatchExpr

Replace the "regular" AST->HIR lowering for IfLet* with a desugaring
into a MatchExpr.

Desugar a simple if let:

   if let Some(y) = some_value {
     bar();
   }

into:

   match some_value {
     Some(y) => {bar();},
     _ => ()
   }

Same applies for IfLetExprConseqElse (if let with an else block).

Desugar:

   if let Some(y) = some_value {
     bar();
   } else {
     baz();
   }

into:

   match some_value {
     Some(y) => {bar();},
     _ => {baz();}
   }

Fixes https://github.com/Rust-GCC/gccrs/issues/1177

gcc/rust/ChangeLog:

* backend/rust-compile-block.h: Adjust after removal of
HIR::IfLetExpr and HIR::IfLetExprConseqElse.
* backend/rust-compile-expr.h: Likewise.
* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
(ExprStmtBuilder::visit): Likewise.
* checks/errors/borrowck/rust-bir-builder-expr-stmt.h: Likewise.
* checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h:
Likewise.
* checks/errors/borrowck/rust-bir-builder-struct.h: Likewise.
* checks/errors/borrowck/rust-function-collector.h: Likewise.
* checks/errors/privacy/rust-privacy-reporter.cc
(PrivacyReporter::visit): Likewise.
* checks/errors/privacy/rust-privacy-reporter.h: 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-block.h (ASTLoweringIfLetBlock::translate):
Change return type.
* hir/rust-ast-lower.cc (ASTLoweringIfLetBlock::desugar_iflet):
New.
(ASTLoweringIfLetBlock::visit(AST::IfLetExpr &)): Adjust and use
desugar_iflet.
* hir/rust-ast-lower.h: Add comment.
* hir/rust-hir-dump.cc (Dump::do_ifletexpr): Remove.
(Dump::visit(IfLetExpr&)): Remove.
(Dump::visit(IfLetExprConseqElse&)): Remove.
* hir/rust-hir-dump.h (Dump::do_ifletexpr): Remove.
(Dump::visit(IfLetExpr&)): Remove.
(Dump::visit(IfLetExprConseqElse&)): Remove.
* hir/tree/rust-hir-expr.h (class IfLetExpr): Remove.
(class IfLetExprConseqElse): Remove.
* hir/tree/rust-hir-full-decls.h (class IfLetExpr): Remove.
(class IfLetExprConseqElse): Remove.
* hir/tree/rust-hir-visitor.h: Adjust after removal of
HIR::IfLetExpr and HIR::IfLetExprConseqElse.
* hir/tree/rust-hir.cc (IfLetExpr::as_string): Remove.
(IfLetExprConseqElse::as_string): Remove.
(IfLetExpr::accept_vis): Remove.
(IfLetExprConseqElse::accept_vis): Remove.
* hir/tree/rust-hir.h: Adjust after removal of HIR::IfLetExpr and
HIR::IfLetExprConseqElse.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
Likewise.
* typecheck/rust-hir-type-check-expr.h: Likewise.
* checks/errors/rust-hir-pattern-analysis.cc
(PatternChecker::visit (IfLetExpr &)): Remove.
(PatternChecker::visit (IfLetExprConseqElse &)): Remove.
* checks/errors/rust-hir-pattern-analysis.h (visit(IfLetExpr &)): Remove.
(visit(IfLetExprConseqElse &)): Remove.

gcc/testsuite/ChangeLog:

* rust/compile/if_let_expr.rs: Adjust.
* rust/compile/if_let_expr_simple.rs: New test.
* rust/compile/iflet.rs: New test.
* rust/execute/torture/iflet.rs: New test.
* rust/compile/nr2/exclude: Add iflet.rs and if_let_expr_simple.rs

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
4 months agogccrs: Fix name resolution 2.0 definition lookups in unsafe checker
Owen Avery [Wed, 9 Oct 2024 04:16:27 +0000 (00:16 -0400)] 
gccrs: Fix name resolution 2.0 definition lookups in unsafe checker

gcc/rust/ChangeLog:

* checks/errors/rust-unsafe-checker.cc: Add includes.
(UnsafeChecker::visit): Use 2.0 version of resolver when name
resolution 2.0 is enabled.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Improve path handling while testing name resolution 2.0
Owen Avery [Thu, 17 Oct 2024 00:18:48 +0000 (20:18 -0400)] 
gccrs: Improve path handling while testing name resolution 2.0

gcc/testsuite/ChangeLog:

* rust/compile/nr2/compile.exp: Handle paths using "file join"
and "file split".
* rust/compile/nr2/exclude: Remove debug-diagnostics-on.rs.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Use name resolver 2.0 in CompileTraitItem
Owen Avery [Sat, 26 Oct 2024 23:53:42 +0000 (19:53 -0400)] 
gccrs: Use name resolver 2.0 in CompileTraitItem

gcc/rust/ChangeLog:

* backend/rust-compile-implitem.cc
(CompileTraitItem::visit): Use name resolver 2.0 (when enabled)
to obtain canonical paths for instances of TraitItemConst and
TraitItemFunc.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Use name resolution 2.0 in TraitItemReference
Owen Avery [Sun, 27 Oct 2024 19:55:48 +0000 (15:55 -0400)] 
gccrs: Use name resolution 2.0 in TraitItemReference

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check.cc: Add includes.
(TraitItemReference::get_type_from_fn): Use
ForeverStack::to_canonical_path when name resolution 2.0 is
enabled.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Rename some PathIdentSegment functions
Owen Avery [Sat, 26 Oct 2024 19:05:43 +0000 (15:05 -0400)] 
gccrs: Rename some PathIdentSegment functions

This makes PathIdentSegment more similar to other classes used to
represent path segments.

gcc/rust/ChangeLog:

* ast/rust-path.h
(PathIdentSegment::is_super_segment): Rename to...
(PathIdentSegment::is_super_path_seg): ...here.
(PathIdentSegment::is_crate_segment): Rename to...
(PathIdentSegment::is_crate_path_seg): ...here.
(PathIdentSegment::is_lower_self): Rename to...
(PathIdentSegment::is_lower_self_seg): ...here.
(PathIdentSegment::is_big_self): Rename to...
(PathIdentSegment::is_big_self_seg): ...here.

(PathExprSegment::is_super_path_seg): Handle renames.
(PathExprSegment::is_crate_path_seg): Likewise.
(PathExprSegment::is_lower_self_seg): Likewise.
(TypePathSegment::is_crate_path_seg): Likewise.
(TypePathSegment::is_super_path_seg): Likewise.
(TypePathSegment::is_big_self_seg): Likewise.
(TypePathSegment::is_lower_self_seg): Likewise.
* ast/rust-ast-collector.cc
(TokenCollector::visit): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Add a newline to the end of nr2/exclude
Owen Avery [Thu, 24 Oct 2024 18:20:29 +0000 (14:20 -0400)] 
gccrs: Add a newline to the end of nr2/exclude

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Add trailing newline along with
comment.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Fix variable shadowing in late resolution 2.0
Owen Avery [Sun, 27 Oct 2024 17:32:09 +0000 (13:32 -0400)] 
gccrs: Fix variable shadowing in late resolution 2.0

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Visit the initialization expressions of let
statements before visiting their patterns.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Insert trait names during toplevel resolution 2.0
Owen Avery [Wed, 16 Oct 2024 04:40:01 +0000 (00:40 -0400)] 
gccrs: Insert trait names during toplevel resolution 2.0

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Insert trait names into the type namespace.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Fix bad recursive operator overload call
Philip Herron [Fri, 11 Oct 2024 16:53:50 +0000 (17:53 +0100)] 
gccrs: Fix bad recursive operator overload call

When we are typechecking the impl block for DerefMut for &mut T
the implementation follows the usual operator overload check
but this ended up just resolving directly to the Trait definition
which ends up being recursive which we usually handle. The issue
we had is that a dereference call can be for either the DEREF
or DEREF_MUT lang item here it was looking for a recurisve call
to the DEREF lang item but we were in the DEREF_MUT lang item
so this case was not accounted for.

Fixes #3032

gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-reference.h: new get locus helper
* typecheck/rust-hir-trait-resolve.cc (AssociatedImplTrait::get_locus): implemention
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::resolve_operator_overload):
fix overload

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/issue-3032-1.rs: New test.
* rust/compile/issue-3032-2.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agoicf: Punt for musttail call flag differences in ICF [PR119376]
Jakub Jelinek [Fri, 21 Mar 2025 11:18:35 +0000 (12:18 +0100)] 
icf: Punt for musttail call flag differences in ICF [PR119376]

The following testcase shows we were ignoring musttail flags on calls
when deciding if two functions are the same.
That can result in problems in both directions, either we silently
lose musttail attribute because there is a similar function without it
earlier and then we e.g. don't diagnose if it can't be tail called
or don't try harder to do a tail call, or we get it even in functions
which didn't have it before.

The following patch for now just punts if it differs.  Perhaps we could
just merge it and get musttail flag if any of the merged functions had
one in such position, but it feels to me that it is now too late in GCC 15
cycle to play with this.

2025-03-21  Jakub Jelinek  <jakub@redhat.com>

PR ipa/119376
* ipa-icf-gimple.cc (func_checker::compare_gimple_call): Return false
for gimple_call_must_tail_p mismatches.

* c-c++-common/musttail27.c: New test.

4 months agofnsplit: Set musttail call during function splitting if there are musttail calls...
Jakub Jelinek [Fri, 21 Mar 2025 11:17:45 +0000 (12:17 +0100)] 
fnsplit: Set musttail call during function splitting if there are musttail calls [PR119376]

The just posted inliner patch can regress musttail calls if we perform
function splitting and then inline the outlined body back into the original
(or inline both the small function and outlined large body into something
else).
If there are any musttail calls, I think we need to call the outlined
body using a musttail call, so that the inliner will preserve musttail
attributes in the body.

2025-03-21  Jakub Jelinek  <jakub@redhat.com>

PR ipa/119376
* ipa-split.cc (split_function): Call gimple_call_set_must_tail
on the call to outlined partition if has_musttail and
!add_tsan_func_exit.

* g++.dg/opt/musttail1.C: New test.

4 months agoinliner: Silently drop musttail flag on calls during inlining unless the inlined...
Jakub Jelinek [Fri, 21 Mar 2025 11:17:01 +0000 (12:17 +0100)] 
inliner: Silently drop musttail flag on calls during inlining unless the inlined routine was musttail called [PR119376]

As discussed in the PR, some packages fail to build because they use
musttail attribute on calls in functions which we inline, and if they
are inlined into a middle of the function, that results in an error
because we have a musttail call in the middle of a function and so it
can't be tail called there.

Now, guess the primary intent of the musttail attribute is ensuring
we don't get an extra stack frame in the backtrace.  Inlining itself
removes one extra stack frame from the backtrace as well (sure, not
counting virtual backtraces in gdb), so I think erroring out on that
is unnecessary.

Except when we are inlining a musttail call which has musttail calls
in it, in that case we are being asked to remove 2 stack frames from
the backtrace, inlining removes one, so we need to keep musttail
on the calls so that another stack frame is removed through a tail call.

The following patch implements that, keeping previous behavior when
id->call_stmt is NULL (i.e. when versioning/cloning etc.).

2025-03-21  Jakub Jelinek  <jakub@redhat.com>

PR ipa/119376
* tree-inline.cc (remap_gimple_stmt): Silently clear
gimple_call_must_tail_p on inlined call stmts if id->call_stmt
is a call without that flag set.

* c-c++-common/musttail26.c: New test.

4 months agolibstdc++: Fix localized %c formatting for non-UTC times [PR117214]
Jonathan Wakely [Wed, 19 Mar 2025 22:05:28 +0000 (22:05 +0000)] 
libstdc++: Fix localized %c formatting for non-UTC times [PR117214]

The previous commit fixed most cases of %c formatting, but it
incorrectly prints times using the system's local time zone. This only
matters if the locale's %c format includes %Z, but some do.

To print a correct value for %Z we can set tm.tm_zone to either "UTC" or
the abbreviation passed to the formatter in the local-time-format-t
structure.

For local times with no info and for systems that don't support tm_zone
(which is new in POSIX.1-2024) we just set tm_isdst = -1 so that no zone
name is printed.

In theory, a locale's %c format could use %z which should print a +hhmm
offset from UTC. I'm unsure how to control that though. The new
tm_gmtoff field in combination with tm_isdst != -1 seems like it should
work, but using that without also setting tm_zone causes the system zone
to be used for %Z again. That means local_time_format(lt, nullptr, &off)
might work for a locale that uses %z but prints the wrong thing for %Z.
This commit doesn't set tm_gmtoff even if _M_offset_sec is provided for
a local-time-format-t value.

libstdc++-v3/ChangeLog:

PR libstdc++/117214
* configure.ac: Use AC_STRUCT_TIMEZONE.
* config.h.in: Regenerate.
* configure: Regenerate.
* include/bits/chrono_io.h (__formatter_chrono::_M_c): Set
tm_isdst and tm_zone.
* testsuite/std/time/format/pr117214.cc: Check %c formatting of
zoned_time and local time.

4 months agolibstdc++: Fix localized D_T_FMT %c formatting for <chrono> [PR117214]
XU Kailiang [Sat, 1 Mar 2025 05:23:21 +0000 (13:23 +0800)] 
libstdc++: Fix localized D_T_FMT %c formatting for <chrono> [PR117214]

Formatting a time point with %c was implemented by calling
std::vprint_to with format string constructed from locale's D_T_FMT
string, but in some locales this string contains strftime specifiers
which are not valid for chrono-specs, e.g. %l. So just use _M_locale_fmt
to avoid this problem.

libstdc++-v3/ChangeLog:

PR libstdc++/117214
* include/bits/chrono_io.h (__formatter_chrono::_M_c): Use
_M_locale_fmt to format %c time point.
* testsuite/std/time/format/pr117214.cc: New test.

Signed-off-by: XU Kailiang <xu2k3l4@outlook.com>
Co-authored-by: Jonathan Wakely <jwakely@redhat.com>
4 months agolibstdc++: Use formatting locale for std::time_put formats
Jonathan Wakely [Wed, 19 Mar 2025 19:38:15 +0000 (19:38 +0000)] 
libstdc++: Use formatting locale for std::time_put formats

When using std::time_put to format a chrono value, we should imbue the
formatting locale into the stream. This ensures that when
std::time_put::do_put uses a ctype or __timepunct facet from the locale,
it gets the correct facets.

libstdc++-v3/ChangeLog:

* include/bits/chrono_io.h (__formatter_chrono::_M_locale_fmt):
Imbue locale into ostringstream.
* testsuite/std/time/format/localized.cc: Check that correct
locale is used for call to time_put::put.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
4 months agolibstdc++: Simplify std::vector::vector(from_range_t, const Alloc&)
Jonathan Wakely [Thu, 20 Mar 2025 09:52:35 +0000 (09:52 +0000)] 
libstdc++: Simplify std::vector::vector(from_range_t, const Alloc&)

Tomasz suggested replacing this constructor with just append_range(rg),
after using a delegating constructor so that the destructor will run if
append_range exits via an exception.

This is slightly less simple than his suggestion, because I want to
avoid the overhead of reserve's slow path and the ASan annotations.
Neither of those is needed for this constructor, because we have no
existing storage to reallocate and no unused capacity to tell ASan
about.

libstdc++-v3/ChangeLog:

* include/bits/stl_vector.h (vector(from_range_t, Alloc)): Use
delegating constructor instead of RAII guards. Use append_range
for unsized input range case.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
4 months agocobol: Rename COB_{BLOCK,UNSIGNED,SIGNED} to {BLOCK,UNSIGNED,SIGNED}_kw for consistency
Jakub Jelinek [Fri, 21 Mar 2025 09:48:10 +0000 (10:48 +0100)] 
cobol: Rename COB_{BLOCK,UNSIGNED,SIGNED} to {BLOCK,UNSIGNED,SIGNED}_kw for consistency

On Wed, Mar 19, 2025 at 06:03:24PM -0400, James K. Lowden wrote:
> Elsewhere in the parser where there was a conflict like that, I renamed
> the token.  For example, the COBOL word TRUE uses a token named
> TRUE_kw.  I don't mind either way; your solution has less impact on the
> parser.

I think consistency is good and when it is a suffix rather than prefix,
it also sorts alphabetically together with the actual keywords.

2025-03-21  Jakub Jelinek  <jakub@redhat.com>

* parse.y: Rename COB_BLOCK to BLOCK_kw, COB_SIGNED to SIGNED_kw and
COB_UNSIGNED to UNSIGNED_kw.
* scan.l: Likewise.
* token_names.h: Regenerate.

4 months agolibstdc++: Fix std.compat exports of <stdbit.h> and <stdckdint.h>
Jonathan Wakely [Thu, 20 Mar 2025 18:47:33 +0000 (18:47 +0000)] 
libstdc++: Fix std.compat exports of <stdbit.h> and <stdckdint.h>

libstdc++-v3/ChangeLog:

* src/c++23/std.compat.cc.in: Only export <stdbit.h> and
<stdckdint.h> contents for C++26 and later.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
4 months agolibstdc++: Add views::cache_latest and views::to_input to std module
Jonathan Wakely [Thu, 20 Mar 2025 18:48:20 +0000 (18:48 +0000)] 
libstdc++: Add views::cache_latest and views::to_input to std module

Also export the tuple-like helpers from <complex>, and the
std::from_range_t and std::from_range tag.

libstdc++-v3/ChangeLog:

* src/c++23/std.cc.in (tuple_element, tuple_element_t)
(tuple_size, tuple_size_v, get): Export.
(ranges::cache_latest_view, views::cache_latest): Export.
(ranges::to_input_view, views::to_input): Export.
(from_range_t, from_range): Export.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
4 months agomove global data to symbol_table_init
Richard Biener [Thu, 20 Mar 2025 09:48:38 +0000 (10:48 +0100)] 
move global data to symbol_table_init

The following avoids early runtime initialization of cbl_field_t
objects which, when using tree to represent the current _Float128
data, segfaults as tree data like float128_type_node is not yet
initialized.  The solution is to move the global data to
symbol_table_init which is the only user and it already has one
such instance locally, the 'constants' array.

* symbols.cc (empty_float, empty_comp5, empty_literal,
empty_conditional, debug_registers, special_registers): Move
global cbl_field_t typed data to ...
(symbol_table_init): ... local scope here.

4 months agos390: Accept only Pmode for registers AP/FP/RA [PR119235]
Stefan Schulze Frielinghaus [Fri, 21 Mar 2025 09:29:19 +0000 (10:29 +0100)] 
s390: Accept only Pmode for registers AP/FP/RA [PR119235]

gcc/ChangeLog:

PR target/119235
* config/s390/s390.cc (s390_hard_regno_mode_ok): Accept only
Pmode for registers AP/FP/RA.

4 months agomake sources coretypes.h and tree.h clean
Richard Biener [Wed, 19 Mar 2025 14:09:03 +0000 (15:09 +0100)] 
make sources coretypes.h and tree.h clean

The following removes HOWEVER_GCC_DEFINES_TREE and the alternate
definition of tree from symbols.h and instead ensures that both
coretypes.h and tree.h are included where required.  This required
putting GCCs own 'NONE' in a scoped enum (see separate patch) and
renaming the cobol use of UNSIGNED, SIGNED and BLOCK which conflict
with enums from tree.h.

There's a few things in conflict with options.h defines, notably
cobol_dialect and cobol_exceptions but also yy_flex_debug (wherever
that comes from).  I've chosen to simply #undef those where
appropriate.  I've refrained from putting the coretypes.h and
tree.h includes in cobol-system.h since not all files require this.

This helps in making use of real.h instead of using _Float128.

PR cobol/119241
gcc/cobol/
* symbols.h: Do not typedef tree.
* cdf.y: Include coretypes.h and tree.h.
* symbols.cc: Likewise.
* symfind.cc: Likewise.
* util.cc: Likewise.
* parse.y: Include coretypes.h and tree.h where appropriate.
Rename BLOCK to COB_BLOCK, SIGNED to COB_SIGNED, UNSIGNED
to COB_UNSIGNED.
* scan.l: Likewise.
* token_names.h: Likewise.
* cobol1.cc: Do not define HOWEVER_GCC_DEFINES_TREE.
* except.cc: Likewise.
* genapi.cc: Likewise.
* gengen.cc: Likewise.
* genmath.cc: Likewise.
* genutil.cc: Likewise.
* structs.cc: Likewise.

4 months agoFortran: Fix double free on polymorphic array dummy argument [PR119349]
Andre Vehreschild [Thu, 20 Mar 2025 12:37:21 +0000 (13:37 +0100)] 
Fortran: Fix double free on polymorphic array dummy argument [PR119349]

Calling elemental routines with polymorphic formals leads to generation
of a temporary polymorphic variable and code for its deallocation.
Sourcing this element from an array constructor the latter now is
prevented from generating a second deallocation.

PR fortran/119349

gcc/fortran/ChangeLog:

* trans-expr.cc (gfc_conv_procedure_call): Prevent deallocation
of array temporary for polymorphic temporary argument.

gcc/testsuite/ChangeLog:

* gfortran.dg/class_79.f90: New test.

4 months agoPut early debug generation under TV_SYMOUT
Richard Biener [Thu, 20 Mar 2025 18:48:36 +0000 (19:48 +0100)] 
Put early debug generation under TV_SYMOUT

Like all other debug info generation this should be with TV_SYMOUT,
otherwise it's recorded as TV_CGRAPH.

* cgraphunit.cc (symbol_table::finalize_compilation_unit):
Put early debug generation under TV_SYMOUT.

4 months agoDaily bump.
GCC Administrator [Fri, 21 Mar 2025 00:17:25 +0000 (00:17 +0000)] 
Daily bump.

4 months agocombine: Add REG_DEAD notes to the last instruction after a split [PR118914]
Andrew Pinski [Thu, 20 Feb 2025 00:10:31 +0000 (16:10 -0800)] 
combine: Add REG_DEAD notes to the last instruction after a split [PR118914]

So gcc.target/aarch64/rev16_2.c started to fail after r15-268-g9dbff9c05520a7,
the problem is combine now rejects the instruction combine. This happens because
after a different combine which uses a define_split and that define_split creates
a new pseudo register. That new pseudo register is dead after the last instruction
in the stream BUT combine never creates a REG_DEAD for it. So combine thinks it is
still needed after and now with the i2 not changing, combine rejects the combine.

Now combine should be creating a REG_DEAD for the new pseudo registers for the last
instruction of the split. This fixes rev16_2.c and also improves the situtation in
other cases by removing other dead instructions.

Bootstrapped and tested on aarch64-linux-gnu and x86_64-linux-gnu.

gcc/ChangeLog:

PR rtl-optimization/118914
* combine.cc (recog_for_combine): Add old_nregs and new_nregs
argument (defaulting to 0). Update call to recog_for_combine_1.
(combine_split_insns): Add old_nregs and new_nregs arguments,
store the old and new max registers to them.
(try_combine): Update calls to combine_split_insns and
pass old_nregs and new_nregs for the i3 call to recog_for_combine.
(find_split_point): Update call to combine_split_insns; ignoring
the values there.
(recog_for_combine_1): Add old_nregs and new_nregs arguments,
if the insn was recognized (and not to no-op move), add the
REG_DEAD notes to pnotes argument.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
4 months agod: Fix quoted command-line options to match lang.opt [PR118545]
Iain Buclaw [Thu, 20 Mar 2025 23:28:45 +0000 (00:28 +0100)] 
d: Fix quoted command-line options to match lang.opt [PR118545]

It was noticed that not all D language options get a url in diagnostics.
These have been checked and fixed as necessary.

PR d/118545

gcc/d/ChangeLog:

* d-lang.cc (d_handle_option): Adjust quoted options.

4 months agomodula2: Defend against no ENOTBLK definition
Gaius Mulley [Thu, 20 Mar 2025 22:23:38 +0000 (22:23 +0000)] 
modula2: Defend against no ENOTBLK definition

This patch defends against no ENOTBLK definition.

libgm2/ChangeLog:

* libm2iso/ErrnoCategory.cc (IsErrnoHard): Defend against
lack of ENOTBLK.
(UnAvailable): Ditto.
(GetOpenResults): Ditto.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
4 months agoPR modula2/118600 Assigning to a record causes alignment exception
Gaius Mulley [Thu, 20 Mar 2025 20:10:31 +0000 (20:10 +0000)] 
PR modula2/118600 Assigning to a record causes alignment exception

This patch recursively tests every assignment (of a constructor
to a designator) to ensure the types are GCC equivalent.  If they
are equivalent then it uses gimple assignment and if not then it
copies a structure by field and uses __builtin_strncpy to copy a
string cst into an array.  Unions are copied by __builtin_memcpy.

gcc/m2/ChangeLog:

PR modula2/118600
* gm2-compiler/M2GenGCC.mod (PerformCodeBecomes): New procedure.
(CodeBecomes): Refactor and call PerformCodeBecomes.
* gm2-gcc/m2builtins.cc (gm2_strncpy_node): New global variable.
(DoBuiltinStrNCopy): New function.
(m2builtins_BuiltinStrNCopy): New function.
(m2builtins_init): Initialize gm2_strncpy_node.
* gm2-gcc/m2builtins.def (BuiltinStrNCopy): New procedure
function.
* gm2-gcc/m2builtins.h (m2builtins_BuiltinStrNCopy): New
function.
* gm2-gcc/m2statement.cc (copy_record_fields): New function.
(copy_array): Ditto.
(copy_strncpy): Ditto.
(copy_memcpy): Ditto.
(CopyByField_Lower): Ditto.
(m2statement_CopyByField): Ditto.
* gm2-gcc/m2statement.def (CopyByField): New procedure function.
* gm2-gcc/m2statement.h (m2statement_CopyByField): New function.
* gm2-gcc/m2type.cc (check_record_fields): Ditto.
(check_array_types): Ditto.
(m2type_IsGccStrictTypeEquivalent): Ditto.
* gm2-gcc/m2type.def (IsGccStrictTypeEquivalent): New procedure
function.
* gm2-gcc/m2type.h (m2type_IsAddress): Replace return type int
with bool.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
4 months agocobol: Do not overload int64_t, overload long and long long.
Iain Sandoe [Sun, 16 Mar 2025 00:18:01 +0000 (00:18 +0000)] 
cobol: Do not overload int64_t, overload long and long long.

Since the type that is ued for int64_t varies between platforms trying
to overload it creates ambiguous or conflicting overloads.

gcc/cobol/ChangeLog:

* cdfval.h (struct cdfval_t): Overload long instead of int64_t.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
4 months agolibgcobol: Add configure checks for iconv.
Iain Sandoe [Sun, 16 Mar 2025 08:58:09 +0000 (08:58 +0000)] 
libgcobol: Add configure checks for iconv.

Some targets might need to add libraries to get iconv support.

libgcobol/ChangeLog:

* Makefile.am: Use LIBICONV.
* Makefile.in: Regenerate.
* aclocal.m4: Regenerate.
* config.h.in: Regenerate.
* configure: Regenerate.
* configure.ac: Check for iconv support.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
4 months agoUpdate gcc hr.po
Joseph Myers [Thu, 20 Mar 2025 19:34:30 +0000 (19:34 +0000)] 
Update gcc hr.po

* hr.po: Update.

4 months agotree-optimization/119389 - limit edge processing in dominated_by_p_w_unex
Richard Biener [Thu, 20 Mar 2025 14:08:33 +0000 (15:08 +0100)] 
tree-optimization/119389 - limit edge processing in dominated_by_p_w_unex

The following removes quadraticness when visiting each predecessor
of a large CFG merge with dominated_by_p_w_unex.

PR tree-optimization/119389
* tree-ssa-sccvn.cc (dominated_by_p_w_unex): Limit the number
of predecessors of a CFG merge we try to skip.

4 months agoUpdate cpplib de.po
Joseph Myers [Thu, 20 Mar 2025 17:30:54 +0000 (17:30 +0000)] 
Update cpplib de.po

* de.po: Update.

4 months agoRevert "s390: Deprecate ESA/390 support"
Stefan Schulze Frielinghaus [Thu, 20 Mar 2025 15:48:24 +0000 (16:48 +0100)] 
Revert "s390: Deprecate ESA/390 support"

The intention of -m31 -mesa and -m31 -mzarch was that they are (ABI)
compatible which is almost true except as it turns out they are not for
attribute mode(word).

After doing some archaeology and digging out an over 18 year old thread
[1,2] which is about this very attribute, I come to the conclusion to
revert this patch.  The intention by deprecating and eventually removing
ESA/390 support was to prepare for a future removal of -m31; though in
smaller steps.  Thus, instead of introducing some potential hick ups
along the route, I will revert this patch and will revisit this topic
when time for -m31 in its entirety has come---independent of
-mesa/-mzarch.

[1] https://gcc.gnu.org/pipermail/gcc-patches/2006-September/200465.html
[2] https://gcc.gnu.org/pipermail/gcc-patches/2006-October/201154.html

This reverts commit 3b1bd1fdcd241dd1e5b706b6937400d74ca43146.

4 months agogimple: sccopy: Don't increment i after vec::unordered_remove()
Filip Kastl [Thu, 20 Mar 2025 10:54:59 +0000 (11:54 +0100)] 
gimple: sccopy: Don't increment i after vec::unordered_remove()

I increment the index variable in a loop even when I do
vec::unordered_remove() which causes the vector traversal to miss some
elements.  Mikael notified me of this mistake I made in my last patch.

gcc/ChangeLog:

* gimple-ssa-sccopy.cc (scc_copy_prop::propagate): Don't
increment after vec::unordered_remove().

Reported-by: Mikael Morin <mikael@gcc.gnu.org>
Signed-off-by: Filip Kastl <fkastl@suse.cz>