]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
4 months agogccrs: ast-builder: Improve function generation.
Arthur Cohen [Thu, 30 Jan 2025 13:56:37 +0000 (14:56 +0100)] 
gccrs: ast-builder: Improve function generation.

gcc/rust/ChangeLog:

* ast/rust-ast-builder.cc (Builder::block): Change return type.
(Builder::loop): Use new APIs.
* ast/rust-ast-builder.h: Change return type of block functions.

4 months agogccrs: derive(Eq): Add implementation.
Arthur Cohen [Thu, 30 Jan 2025 13:04:17 +0000 (14:04 +0100)] 
gccrs: derive(Eq): Add implementation.

gcc/rust/ChangeLog:

* expand/rust-derive.cc (DeriveVisitor::derive): Call into DeriveEq.
* expand/rust-derive-eq.cc: New file.
* expand/rust-derive-eq.h: New file.
* Make-lang.in: Compile them.

gcc/testsuite/ChangeLog:

* rust/compile/derive-eq-invalid.rs: New test.

4 months agogccrs: nr2.0: Run DefaultResolver::visit on PathInExpression
Owen Avery [Tue, 4 Feb 2025 10:53:10 +0000 (05:53 -0500)] 
gccrs: nr2.0: Run DefaultResolver::visit on PathInExpression

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): When visiting a PathInExpression instance, call
into DefaultResolver::visit, ensuring generic arguments are
visited.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: nr2.0: Fix issue with external crates
Owen Avery [Tue, 18 Feb 2025 07:03:56 +0000 (02:03 -0500)] 
gccrs: nr2.0: Fix issue with external crates

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): When visiting an external crate declaration,
handle failed crate name lookups. This can happen when
Session::load_extern_crate fails to load a crate during the
CfgStrip phase.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Add comments to resolve_segments
Owen Avery [Mon, 17 Feb 2025 23:33:08 +0000 (18:33 -0500)] 
gccrs: Add comments to resolve_segments

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.hxx
(ForeverStack::resolve_segments): Add comments explaining
the behaviour of a while loop.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Add type check on if-expr
Benjamin Thos [Mon, 16 Dec 2024 13:11:38 +0000 (14:11 +0100)] 
gccrs: Add type check on if-expr

Check if an if-expr returns void type or a coercible type like an early return.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
Add check on if-expr.

gcc/testsuite/ChangeLog:

* rust/compile/implicit_returns_err3.rs: Change test to be valid.
* rust/compile/torture/if.rs: Likewise.
* rust/compile/if-without-else.rs: New test.

Signed-off-by: Benjamin Thos <benjamin.thos@epita.fr>
4 months agogccrs: nr2.0: Resolve paths which start with Self
Owen Avery [Tue, 4 Feb 2025 10:02:38 +0000 (05:02 -0500)] 
gccrs: nr2.0: Resolve paths which start with Self

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.hxx
(ForeverStack::find_starting_point): Be more careful about
applying ForeverStack::find_closest_module.
(ForeverStack::resolve_segments): Allow traversal into parent
nodes when not in a module node or root node, which
ForeverStack::find_starting_point previously made moot through
use of ForeverStack::find_closest_module. Also, when a child
node lookup fails when resolving in the type namespace, attempt
a rib lookup as a fallback.
* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Avoid throwing a resolution error for type paths
when the typechecker may be able to finish the resolution. Also,
throw an error when a resolution is ambiguous.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: initial setup for new OpaqueType to represent Impl types
Philip Herron [Sun, 16 Feb 2025 01:42:05 +0000 (01:42 +0000)] 
gccrs: initial setup for new OpaqueType to represent Impl types

This completes the initial setup and boilerplate for the new type in the
typesystem. This is not functional yet but its a big patch already.

gcc/rust/ChangeLog:

* backend/rust-compile-type.cc (TyTyResolveCompile::visit): new tyty::OpaqueType
* backend/rust-compile-type.h: likewise
* checks/errors/borrowck/rust-bir-fact-collector.h: likewise
* checks/errors/borrowck/rust-bir-place.h: likewise
* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::check_base_type_privacy):
likewise
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): likewise
* typecheck/rust-hir-type-check-type.h: likewise
* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit): likewise
* typecheck/rust-substitution-mapper.h: likewise
* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::assemble_sized_builtin): likewise
* typecheck/rust-tyty-call.h: likewise
* typecheck/rust-tyty-cmp.h (class OpaqueCmp): likewise
* typecheck/rust-tyty-variance-analysis-private.h: likewise
* typecheck/rust-tyty-visitor.h: likewise
* typecheck/rust-tyty.cc (TypeKindFormat::to_string): likewise
(BaseType::is_unit): likewise
(BaseType::destructure): likewise
(BaseType::has_substitutions_defined): likewise
(BaseType::needs_generic_substitutions): likewise
(OpaqueType::OpaqueType): likewise
(OpaqueType::can_resolve): likewise
(OpaqueType::accept_vis): likewise
(OpaqueType::as_string): likewise
(OpaqueType::get_name): likewise
(OpaqueType::can_eq): likewise
(OpaqueType::clone): likewise
(OpaqueType::resolve): likewise
(OpaqueType::is_equal): likewise
(OpaqueType::handle_substitions): likewise
* typecheck/rust-tyty.h (enum TypeKind): likewise
(class OpaqueType): likewise
* typecheck/rust-unify.cc (UnifyRules::go): likewise
(UnifyRules::expect_inference_variable): likewise
(UnifyRules::expect_adt): likewise
(UnifyRules::expect_str): likewise
(UnifyRules::expect_reference): likewise
(UnifyRules::expect_pointer): likewise
(UnifyRules::expect_param): likewise
(UnifyRules::expect_array): likewise
(UnifyRules::expect_slice): likewise
(UnifyRules::expect_fndef): likewise
(UnifyRules::expect_fnptr): likewise
(UnifyRules::expect_tuple): likewise
(UnifyRules::expect_bool): likewise
(UnifyRules::expect_char): likewise
(UnifyRules::expect_int): likewise
(UnifyRules::expect_uint): likewise
(UnifyRules::expect_float): likewise
(UnifyRules::expect_isize): likewise
(UnifyRules::expect_usize): likewise
(UnifyRules::expect_placeholder): likewise
(UnifyRules::expect_projection): likewise
(UnifyRules::expect_dyn): likewise
(UnifyRules::expect_opaque): likewise
* typecheck/rust-unify.h: likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: Add name resolution and HIR lowering for ImplTraitType's
Philip Herron [Sat, 15 Feb 2025 21:22:16 +0000 (21:22 +0000)] 
gccrs: Add name resolution and HIR lowering for ImplTraitType's

Our AST has ImplTraitType for multiple bounds and a singular
ImplTraitTypeOneBound, this patch desugars these into a simple
HIR::ImplTraitType. It also does the name resolution for this.

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder-struct.h: remove HIR::ImplTraitTypeOneBound
* checks/errors/borrowck/rust-function-collector.h: likewise
* checks/errors/rust-const-checker.cc (ConstChecker::visit): likewise
* checks/errors/rust-const-checker.h: likewise
* checks/errors/rust-hir-pattern-analysis.cc (PatternChecker::visit): likewise
* checks/errors/rust-hir-pattern-analysis.h: likewise
* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): likewise
* checks/errors/rust-unsafe-checker.h: likewise
* hir/rust-ast-lower-type.cc (ASTLoweringType::translate): likewise
(ASTLoweringType::visit): likewise
* hir/rust-ast-lower-type.h: cleanup
* hir/rust-hir-dump.cc (Dump::visit): remove ImplTraitTypeOneBound
* hir/rust-hir-dump.h: likewise
* hir/tree/rust-hir-full-decls.h (class ImplTraitTypeOneBound): likewise
* hir/tree/rust-hir-type.h (class ImplTraitTypeOneBound): likewise
* hir/tree/rust-hir-visitor.h: likewise
* hir/tree/rust-hir.cc (ImplTraitTypeOneBound::as_string):  likewise
(ImplTraitTypeOneBound::accept_vis):  likewise
* resolve/rust-ast-resolve-type.cc (ResolveType::go): likewise
(ResolveType::visit): likewise
* resolve/rust-ast-resolve-type.h: add name resolution
* typecheck/rust-hir-type-check-type.h: likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: improve error diagnostic for bad type-resolution in CallExpr
Philip Herron [Fri, 14 Feb 2025 17:32:20 +0000 (17:32 +0000)] 
gccrs: improve error diagnostic for bad type-resolution in CallExpr

We have the type information for the resolved call lets tell the user about
it in the diagnostic and apply the correct error code.

Fixes Rust-GCC#2035

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): improve error diag

gcc/testsuite/ChangeLog:

* rust/compile/generics4.rs: cleanup
* rust/compile/generics6.rs: likewise
* rust/compile/type-bindings1.rs: likewise
* rust/compile/unconstrained_type_param.rs: likewise
* rust/compile/issue-2035.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: self paths are patterns but we dont have mappings for it
Philip Herron [Thu, 13 Feb 2025 17:45:09 +0000 (17:45 +0000)] 
gccrs: self paths are patterns but we dont have mappings for it

With simple patterns we dont introduce any more inference varaibles as
they are already declared in a specific way. This would only lead to
more unconstrained inference varaibles than is required.

Fixes Rust-GCC#3022

gcc/rust/ChangeLog:

* hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_self): add location mappings
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_root_path): check for self

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: fix name resolution for generics where type param is declared later
Philip Herron [Thu, 13 Feb 2025 17:01:31 +0000 (17:01 +0000)] 
gccrs: fix name resolution for generics where type param is declared later

Rust allows you to use generics within type bounds when they are declared
later on. This changes the name resolution to walk the genric params
in two passes to ensure the type parameters are setup before drilling down
into the type parameters

This issue has exposed another type checking issue which needs fixed in
a subseqent patch.

Addresses Rust-GCC#3022

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-item.cc (ResolveTraitItems::visit): use new api
(ResolveItem::visit): likewise
(ResolveExternItem::visit): likewise
* resolve/rust-ast-resolve-stmt.h: likewise
* resolve/rust-ast-resolve-type.h (class ResolveGenericParam): remove
(class ResolveGenericParams): added new api

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: fix unconstrained generics check to handle recursive generics
Philip Herron [Thu, 13 Feb 2025 14:09:17 +0000 (14:09 +0000)] 
gccrs: fix unconstrained generics check to handle recursive generics

Generics can be constrained within other generic types so this check needs
to be recursive.

Fixes Rust-GCC#3031

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-base.cc (walk_types_to_constrain): recursive walker
* typecheck/rust-tyty.cc (BaseType::get_subst_argument_mappings): new helper
* typecheck/rust-tyty.h: prototype

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: add diagnostic for E0229 no associated type arguments allowed here
Philip Herron [Wed, 12 Feb 2025 17:10:31 +0000 (17:10 +0000)] 
gccrs: add diagnostic for E0229 no associated type arguments allowed here

It seems bounds in qualified paths are not allowed to specify associated
type bindings because its going to be associated with the impl block
anyway.

Fixes Rust-GCC#2369

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-base.h: add flag
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): likewise
* typecheck/rust-tyty-bounds.cc: new diagnostic

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: remove name resolution inserts from type-path
Philip Herron [Wed, 12 Feb 2025 16:44:55 +0000 (16:44 +0000)] 
gccrs: remove name resolution inserts from type-path

We resolve path segments and inserted their resolution into the name
resolution space which was an old hack to use this as information in
code-gen/check-passes in order to help things move forward but this is
not nessecary

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): remove name resolution info
(TypeCheckType::resolve_root_path): likewise
* typecheck/rust-hir-type-check-type.h: likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: enum type layout needs to respect the enum repr type
Philip Herron [Tue, 11 Feb 2025 17:51:22 +0000 (17:51 +0000)] 
gccrs: enum type layout needs to respect the enum repr type

Addresses Rust-GCC#3352

gcc/rust/ChangeLog:

* backend/rust-compile-type.cc (TyTyResolveCompile::get_implicit_enumeral_node_type):
use repr
(TyTyResolveCompile::visit): update prototype
* backend/rust-compile-type.h: likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: add variant_count intrinsic
Philip Herron [Tue, 11 Feb 2025 17:42:24 +0000 (17:42 +0000)] 
gccrs: add variant_count intrinsic

Addresses Rust-GCC#3348

gcc/rust/ChangeLog:

* backend/rust-compile-intrinsic.cc (variant_count_handler): new intrinsic

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: add discriminant value intrinsic
Philip Herron [Mon, 10 Feb 2025 16:28:30 +0000 (16:28 +0000)] 
gccrs: add discriminant value intrinsic

This is pretty nasty piece of rust in my opinion the return type of this
intrinsic results into a lang item associated type:

  <T as DiscriminantKind>::Discriminant

This is a special case which needs to support mapping onto the repr type
of the associated ADT that is passed in, but defaults to iszie otherwise.

This patch assumes we only come accross this case in a HIR::CALL_EXPR, so
and makes assumutions that its always of this function signiture. I will
do some checking in libcore to verify that assumption. More work is needed
to parse the repr type on enums but the code is there to support this when
its in to change the types etc.

Addresses Rust-GCC#3348

gcc/rust/ChangeLog:

* backend/rust-compile-intrinsic.cc (discriminant_value_handler): new handler
* typecheck/rust-hir-trait-resolve.cc (TraitItemReference::resolve_item): track the defid
* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::parse_repr_options): default isize
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): special case CallExpr
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): parse repr options enum
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): remove bad diagnostic
* typecheck/rust-tyty.cc (PlaceholderType::PlaceholderType): track defid
(PlaceholderType::clone): likewise
(PlaceholderType::get_def_id): likeiwse
* typecheck/rust-tyty.h: placeholder track defid
* util/rust-lang-item.cc: add new lang items
* util/rust-lang-item.h: likewise

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: Get rid of duplicate interface gccrs#3396
GS-GOAT [Sat, 8 Feb 2025 06:33:18 +0000 (12:03 +0530)] 
gccrs: Get rid of duplicate interface gccrs#3396

gcc/rust/ChangeLog:

* typecheck/rust-autoderef.cc
(insert_implicit_type): Update single-parameter call to
pass explicit HirId.
* typecheck/rust-hir-type-check-expr.cc: Same.
* typecheck/rust-hir-type-check-pattern.cc: Same.
* typecheck/rust-hir-type-check.h: Removed call
to the duplicate interface.
* typecheck/rust-typecheck-context.cc
(TypeCheckContext::insert_implicit_type): Removed the
interface with no HirId field.

Signed-off-by: Guransh Singh <guransh766@gmail.com>
4 months agogccrs: remove bad type checking diagnostic
Philip Herron [Tue, 4 Feb 2025 17:15:15 +0000 (17:15 +0000)] 
gccrs: remove bad type checking diagnostic

This was a bad diagnostic added when I was working on slices and iterators
also the name of the function is also bad. This is all about setting up
associated types based on the current context of the bounds assocated with
the associated trait bounds on this function.

The tell tale is that this didnt have an associated rust error code so
this is most definetly not the correct error diagnostic.

Fixes Rust-GCC#3403

gcc/rust/ChangeLog:

* typecheck/rust-tyty-subst.cc (SubstitutionRef::monomorphize): remove diagnostic

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: session manager: Call into DesugarForLoops
Arthur Cohen [Wed, 22 Jan 2025 14:14:45 +0000 (14:14 +0000)] 
gccrs: session manager: Call into DesugarForLoops

gcc/rust/ChangeLog:

* rust-session-manager.cc (Session::compile_crate): Call the visitor.

4 months agogccrs: ast: Add DesugarForLoop class
Arthur Cohen [Sun, 22 Dec 2024 15:59:27 +0000 (15:59 +0000)] 
gccrs: ast: Add DesugarForLoop class

gcc/rust/ChangeLog:

* ast/rust-desugar-for-loops.cc: New file.
* ast/rust-desugar-for-loops.h: New file.
* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Make lowering of for-loops an
unreachable.
* Make-lang.in: Compile it.

gcc/testsuite/ChangeLog:

* rust/compile/for-loop1.rs: New test.
* rust/compile/for-loop2.rs: New test.
* rust/execute/torture/for-loop1.rs: New test.
* rust/execute/torture/for-loop2.rs: New test.
* rust/compile/nr2/exclude: Exclude for-loop1.rs

4 months agogccrs: ast: builder: Fix arguments of Builder::let
Arthur Cohen [Wed, 22 Jan 2025 14:07:05 +0000 (14:07 +0000)] 
gccrs: ast: builder: Fix arguments of Builder::let

gcc/rust/ChangeLog:

* ast/rust-ast-builder.h: Mark all arguments as &&.
* ast/rust-ast-builder.cc (Builder::let): Likewise.

4 months agogccrs: nr2.0: Resolve instances of TypePath more accurately
Owen Avery [Thu, 23 Jan 2025 01:12:46 +0000 (20:12 -0500)] 
gccrs: nr2.0: Resolve instances of TypePath more accurately

gcc/rust/ChangeLog:

* util/rust-unwrap-segment.cc: New file.
* util/rust-unwrap-segment.h: New file.
* Make-lang.in: Add rust-unwrap-segment.o to the object list.
* resolve/rust-forever-stack.hxx: Include rust-unwrap-segment.h.
(ForeverStack::find_starting_point): Use unwrap_type_segment.
(ForeverStack::resolve_segments): Likewise.
(ForeverStack::resolve_path): Likewise.
* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Resolve type paths using
NameResolutionContext::resolve_path.
* resolve/rust-name-resolution-context.h
(NameResolutionContext::resolve_path): Use
unwrap_segment_node_id.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: inline-asm: Fix some warnings
Arthur Cohen [Wed, 29 Jan 2025 14:41:19 +0000 (14:41 +0000)] 
gccrs: inline-asm: Fix some warnings

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-asm.cc (strip_double_quotes): Special case empty
strings ("\"\"").
(parse_reg_operand): Remove use of the `struct` keyword.
(parse_reg_operand_in): Likewise.
(parse_reg_operand_out): Likewise.
* expand/rust-macro-builtins.cc: Add llvm_asm! built-in macro as an alias to asm!.

4 months agogccrs: Add warning about default visitor usage
Pierre-Emmanuel Patry [Tue, 4 Feb 2025 12:53:30 +0000 (13:53 +0100)] 
gccrs: Add warning about default visitor usage

We already lost some time on this unusual pattern, a comment will
hopefully prevent this from happening again.

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Add
warning about current code.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add test case to show issue is fixed
Philip Herron [Mon, 3 Feb 2025 20:43:57 +0000 (20:43 +0000)] 
gccrs: Add test case to show issue is fixed

This was fixed as part of: "gccrs: Fix compilation of trait-items which map to impl items"

Fixes Rust-GCC#3402

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: derive(Default): Add implementation
Arthur Cohen [Thu, 30 Jan 2025 12:10:51 +0000 (13:10 +0100)] 
gccrs: derive(Default): Add implementation

gcc/rust/ChangeLog:

* expand/rust-derive.cc (DeriveVisitor::derive): Call DeriveDefault.
* expand/rust-derive-default.cc: New file.
* expand/rust-derive-default.h: New file.
* Make-lang.in: Compile them.

gcc/testsuite/ChangeLog:

* rust/compile/derive-default1.rs: New test.
* rust/execute/torture/derive-default1.rs: New test.
* rust/compile/nr2/exclude: Exclude them.

4 months agogccrs: ast-builder: Add methods for QualifiedPathInExpressions
Arthur Cohen [Thu, 30 Jan 2025 12:07:48 +0000 (13:07 +0100)] 
gccrs: ast-builder: Add methods for QualifiedPathInExpressions

gcc/rust/ChangeLog:

* ast/rust-ast-builder.cc (Builder::qualified_path_in_expression): New.
(Builder::function): Change the return type.
* ast/rust-ast-builder.h: Declare qualified_path_in_expression functions.
* expand/rust-derive-debug.cc (DeriveDebug::stub_debug_fn): Adapt to new APIs.

4 months agogccrs: Fix compilation of trait-items which map to impl items
Philip Herron [Mon, 3 Feb 2025 16:19:30 +0000 (16:19 +0000)] 
gccrs: Fix compilation of trait-items which map to impl items

When we have paths such as Try::from_error the Try references the Trait
and then from_error references the from_error trait item. So this resolves
directly to a trait implementation which has the type:

  fn <Self> (v: placeholder) -> Self

Remember that a path such as: Try::from_error gets handled by doing a
clever substitution: <T? as Try>::from_error

The main piece here is that we resolve this function type and for
monomoprhization we know this is a trait call but we know that all trait's
have an implicit Self type param which in this case is Result<i32, i32>
so when it comes to knowing which impl block this is we got rid of the old
bad insert/lookup receiver hack and use the specified type to know which
impl block we are talking about to generate the function.

The hard part here is inside rust-compil-item.cc, where we have the
'concete' type which is the trait item fntype of:

  fn <Result<i32, i32>> (v : i32) -> Result<i32,i32>

This does not really match the signiture of the impl item for Result
which is:

  fn <T, E> (v: i32) -> Result<T, E>

So what we need to do is actually infer this by inputing inference
variables on the impl fntype then unify'ing the trait object to this to
compute the types of this to monomorphize this.

Fixes Rust-GCC#3381

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): remove receiver interface
* backend/rust-compile-item.cc (CompileItem::visit): monomorphize trait to impl item
* backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): use trait item Self
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): remove receiver interface
(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::visit): likewise
* typecheck/rust-hir-type-check.h: likewise
* typecheck/rust-typecheck-context.cc (TypeCheckContext::insert_receiver): remove
(TypeCheckContext::lookup_receiver): remove

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: Fix bad generic substitution error on fn/adt types
Philip Herron [Mon, 3 Feb 2025 15:25:50 +0000 (15:25 +0000)] 
gccrs: Fix bad generic substitution error on fn/adt types

When passing generics around we try to adjust them because there are cases
where the names are adjusted from other generics this can fail for traits
because of the implicit Self and we just need to continue on without
adjustment.

Fxies Rust-GCC#3382

gcc/rust/ChangeLog:

* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit):
continue on for trait item mode.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: Fix crash in privay reporter for placeholder types
Philip Herron [Mon, 3 Feb 2025 15:14:48 +0000 (15:14 +0000)] 
gccrs: Fix crash in privay reporter for placeholder types

This guards against a crash but i think this should actually be treated
as if its a generic type like below. But for now this addresses a crash which can occur.

gcc/rust/ChangeLog:

* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::check_base_type_privacy):
Add guard for placeholder

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: coercion sites allow for type inference as well.
Philip Herron [Mon, 3 Feb 2025 15:45:12 +0000 (15:45 +0000)] 
gccrs: coercion sites allow for type inference as well.

Addresses Rust-GCC#3382 and Rust-GCC#3381

gcc/rust/ChangeLog:

* typecheck/rust-type-util.cc (coercion_site): allow inference vars

gcc/testsuite/ChangeLog:

* rust/compile/reference1.rs: fix error message

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: Fix ICE during path probe
Philip Herron [Mon, 3 Feb 2025 15:15:40 +0000 (15:15 +0000)] 
gccrs: Fix ICE during path probe

It is valid for the query to fail here so its valid to not assert here.

gcc/rust/ChangeLog:

* typecheck/rust-hir-path-probe.cc (PathProbeType::visit): remove assertion

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: Fix ICE when fn_once and fn_once_output lang item is not defined
Philip Herron [Mon, 3 Feb 2025 15:14:01 +0000 (15:14 +0000)] 
gccrs: Fix ICE when fn_once and fn_once_output lang item is not defined

We needed to check for the optional has a value here or not it leads to an
ICE.

gcc/rust/ChangeLog:

* typecheck/rust-tyty.cc (ClosureType::setup_fn_once_output): add checks for lang items

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: Fix bug in type resolution of paths
Owen Avery [Sat, 4 Jan 2025 19:59:54 +0000 (14:59 -0500)] 
gccrs: Fix bug in type resolution of paths

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc
(Early::resolve_glob_import): Use
NameResolutionContext::resolve_path instead of
ForeverStack::resolve_path.
(Early::visit): Likewise.
(Early::visit_attributes): Likewise.
* resolve/rust-early-name-resolver-2.0.h
(Early::resolve_path_in_all_ns): Likewise.
* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Likewise, insert segment resolutions not
handled by NameResolutionContext::resolve_path, and avoid throwing
an error when path resolution could be finished by the typechecker.
* resolve/rust-name-resolution-context.h
(NameResolutionContext::resolve_path): Add.
* typecheck/rust-hir-type-check-path.cc
(TypeCheckExpr::resolve_root_path): Use segment node ids instead
of the path node id to look up segment resolutions when using
the 2.0 resolver, as is done with the 1.0 resolver.
* typecheck/rust-hir-type-check-type.cc
(TypeCheckType::resolve_root_path): Likewise.
* resolve/rust-forever-stack.h
(ForeverStack::resolve_path): Add callback parameter for
inserting segment resolutions.
(ForeverStack::find_starting_point): Likewise.
(ForeverStack::resolve_segments): Likewise.
* resolve/rust-forever-stack.hxx
(ForeverStack::find_starting_point): Likewise.
(ForeverStack::resolve_segments): Likewise.
(ForeverStack::resolve_path): Likewise and avoid resolving
inside TraitOrImpl ribs.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: nr2.0: Remove accidental copies of resolver
Owen Avery [Mon, 21 Oct 2024 22:02:48 +0000 (18:02 -0400)] 
gccrs: nr2.0: Remove accidental copies of resolver

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc
(CompileExpr::generate_closure_function): Take
NameResolutionContext by reference instead of by value.
* backend/rust-compile-item.cc
(CompileItem::visit): Likewise.
* backend/rust-compile-resolve-path.cc
(ResolvePathRef::resolve): Likewise.
* checks/lints/rust-lint-marklive.cc
(MarkLive::find_ref_node_id): Likewise.
* typecheck/rust-hir-type-check-enumitem.cc
(TypeCheckEnumItem::visit): Likewise.
* typecheck/rust-hir-type-check-implitem.cc
(TypeCheckImplItem::visit): Likewise.
* typecheck/rust-hir-type-check-item.cc
(TypeCheckItem::visit): Likewise.
* typecheck/rust-hir-type-check-path.cc
(TypeCheckExpr::resolve_root_path): Likewise.
* typecheck/rust-hir-type-check-type.cc
(TypeCheckType::resolve_root_path): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: ast: builder: Add Return expression builder
Arthur Cohen [Thu, 23 Jan 2025 11:42:38 +0000 (11:42 +0000)] 
gccrs: ast: builder: Add Return expression builder

gcc/rust/ChangeLog:

* ast/rust-ast-builder.h: Declare it.
* ast/rust-ast-builder.cc (Builder::return_expr): Define it.

4 months agogccrs: derive(Debug): Add stub implementation.
Arthur Cohen [Wed, 29 Jan 2025 18:10:01 +0000 (18:10 +0000)] 
gccrs: derive(Debug): Add stub implementation.

gcc/rust/ChangeLog:

* expand/rust-derive-debug.cc: New file.
* expand/rust-derive-debug.h: New file.
* Make-lang.in: Compile them.
* expand/rust-derive.cc (DeriveVisitor::derive): Call into DeriveDebug.

gcc/testsuite/ChangeLog:

* rust/compile/derive-debug1.rs: New test.
* rust/compile/nr2/exclude: Exclude it.

4 months agogccrs: derive(Clone, Copy): Cleanup using new method from DeriveVisitor
Arthur Cohen [Thu, 30 Jan 2025 10:01:33 +0000 (11:01 +0100)] 
gccrs: derive(Clone, Copy): Cleanup using new method from DeriveVisitor

gcc/rust/ChangeLog:

* expand/rust-derive-clone.cc: Cleanup using DeriveVisitor::setup_impl_generics.
* expand/rust-derive-copy.cc: Likewise.

4 months agogccrs: derive-visitor: Add method for setting up derived impl generics
Arthur Cohen [Thu, 30 Jan 2025 09:50:30 +0000 (10:50 +0100)] 
gccrs: derive-visitor: Add method for setting up derived impl generics

gcc/rust/ChangeLog:

* expand/rust-derive.cc (DeriveVisitor::setup_impl_generics): New method.
* expand/rust-derive.h: Declare it, define DeriveVisitor::ImplGenerics struct.

4 months agogccrs: ast-builder: Add new methods for functions, traits and tuples.
Arthur Cohen [Thu, 30 Jan 2025 09:50:13 +0000 (10:50 +0100)] 
gccrs: ast-builder: Add new methods for functions, traits and tuples.

gcc/rust/ChangeLog:

* ast/rust-ast-builder.cc: New methods.
* ast/rust-ast-builder.h: Declare them.

4 months agogccrs: ast-builder: Add new functions to create type paths.
Arthur Cohen [Wed, 29 Jan 2025 18:11:28 +0000 (18:11 +0000)] 
gccrs: ast-builder: Add new functions to create type paths.

gcc/rust/ChangeLog:

* ast/rust-ast-builder.cc (Builder::type_path): New functions.
* ast/rust-ast-builder.h: Declare them.

4 months agogccrs: scan-deadcode: Do not warn unused fields if they start with '_'
Arthur Cohen [Thu, 30 Jan 2025 12:08:33 +0000 (13:08 +0100)] 
gccrs: scan-deadcode: Do not warn unused fields if they start with '_'

gcc/rust/ChangeLog:

* checks/lints/rust-lint-scan-deadcode.h: Check if the field name starts with an
underscore before warning.

4 months agogccrs: lang-items: Add structural_{peq, teq}
Arthur Cohen [Thu, 30 Jan 2025 13:19:03 +0000 (14:19 +0100)] 
gccrs: lang-items: Add structural_{peq, teq}

These lang items are used when deriving Eq and PartialEq, and will be checked when compiling pattern matching.

gcc/rust/ChangeLog:

* util/rust-lang-item.cc: New items.
* util/rust-lang-item.h: Likewise.

gcc/testsuite/ChangeLog:

* rust/compile/structural-eq-peq.rs: New test.

4 months agogccrs: nr2.0: late: Add proper handling for lang item PathInExpressions
Arthur Cohen [Fri, 31 Jan 2025 12:26:21 +0000 (12:26 +0000)] 
gccrs: nr2.0: late: Add proper handling for lang item PathInExpressions

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Special case lang item paths.

4 months agogccrs: Fix an issue with ForeverStack::dfs_rib
Owen Avery [Sat, 1 Feb 2025 04:03:03 +0000 (23:03 -0500)] 
gccrs: Fix an issue with ForeverStack::dfs_rib

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.hxx
(ForeverStack::dfs_rib): Fix const implementation.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Add option_env! support
Liam Naddell [Fri, 31 Jan 2025 01:51:21 +0000 (20:51 -0500)] 
gccrs: Add option_env! support

gcc/rust/ChangeLog:
* expand/rust-macro-builtins-utility.cc: Add macro expansion for
option_env with eager expansion
* expand/rust-macro-builtins.cc: Add option_env to builtin list
* expand/rust-macro-builtins.h: Add option_env handler to header
file
* resolve/rust-late-name-resolver-2.0.cc: Prevent NR2.0 from
recursing into lang-item segments

gcc/testsuite/ChangeLog:
* rust/compile/macros/builtin/option_env1.rs: Add success case for option_env
* rust/compile/macros/builtin/option_env2.rs: Add failure case for option_env
* rust/execute/torture/builtin_macro_option_env.rs: Add
execution case for option_env

4 months agogccrs: ast: Add new Expr::Kinds
Arthur Cohen [Thu, 23 Jan 2025 11:43:31 +0000 (11:43 +0000)] 
gccrs: ast: Add new Expr::Kinds

Collapses all of the OperatorExprs into Expr instead of first having to check for OperatorExpr and
then check for each OperatorExpr::Kind.

gcc/rust/ChangeLog:

* ast/rust-ast.h: Add new Expr::Kinds.
* ast/rust-expr.h: Implement missing get_expr_kind(), Add get_function_expr_ptr()

4 months agogccrs: add support for ref literal patterns
Philip Herron [Tue, 21 Jan 2025 17:20:06 +0000 (17:20 +0000)] 
gccrs: add support for ref literal patterns

Fixes Rust-GCC#3174

gcc/rust/ChangeLog:

* backend/rust-compile-pattern.cc (CompilePatternBindings::visit): make recursive
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): handle ref flag

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: lang-items: Add From::from
Arthur Cohen [Thu, 23 Jan 2025 11:46:48 +0000 (11:46 +0000)] 
gccrs: lang-items: Add From::from

gcc/rust/ChangeLog:

* util/rust-lang-item.h: Declare it.
* util/rust-lang-item.cc: Use it.

4 months agogccrs: add new -frust-overflow-checks flag to control overflow checks
Philip Herron [Thu, 23 Jan 2025 14:44:20 +0000 (14:44 +0000)] 
gccrs: add new -frust-overflow-checks flag to control overflow checks

This will be crucial for more complex gimple debugging to make it easier
to follow the code vs the original rust code.

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): disable overflow checks
* lang.opt: new flag

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: Remove some passing test from exclude file
Pierre-Emmanuel Patry [Sat, 11 Jan 2025 21:35:08 +0000 (22:35 +0100)] 
gccrs: Remove some passing test from exclude file

Those tests are now passing.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove some tests.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Compile unit struct with constructor
Pierre-Emmanuel Patry [Mon, 13 Jan 2025 17:26:37 +0000 (18:26 +0100)] 
gccrs: Compile unit struct with constructor

gcc/rust/ChangeLog:

* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve): Do
not use query system for unit struct but compile it's constructor
instead.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Resolved item type shall be differentiated later
Pierre-Emmanuel Patry [Mon, 6 Jan 2025 14:55:53 +0000 (15:55 +0100)] 
gccrs: Resolved item type shall be differentiated later

We need to query all namespaces and error out at a later stage if the
retrieved item is wrong.

gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_path_to_trait):
Query all namespaces.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Make foreverstack debug string const
Pierre-Emmanuel Patry [Mon, 6 Jan 2025 14:53:31 +0000 (15:53 +0100)] 
gccrs: Make foreverstack debug string const

Those function should not change anything within the foreverstack, it
can therefore be made const.

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.h: Make debug functions const.
* resolve/rust-forever-stack.hxx: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Clone expr instead of taking it
Pierre-Emmanuel Patry [Thu, 12 Dec 2024 17:30:09 +0000 (18:30 +0100)] 
gccrs: Clone expr instead of taking it

We're reusing the value, it could therefore not be taken be should be
cloned.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-enumitem.cc (TypeCheckEnumItem::visit):
Clone expr instead of taking it.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Remove some tests from nr2 exclusion file
Pierre-Emmanuel Patry [Thu, 12 Dec 2024 13:39:12 +0000 (14:39 +0100)] 
gccrs: Remove some tests from nr2 exclusion file

Those test are now passing.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Remove query mode on CompileItem
Pierre-Emmanuel Patry [Thu, 12 Dec 2024 12:16:14 +0000 (13:16 +0100)] 
gccrs: Remove query mode on CompileItem

Query mode was a hack to catch up some compile errors early, it was
deemed to be removed at some time. Recent changes to NR1 highlighted
an incompatibility with it hence it's removal.

gcc/rust/ChangeLog:

* backend/rust-compile-item.h: Remove query mode.
* backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile):
Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add unit struct to name namespace in old resolver
Pierre-Emmanuel Patry [Wed, 11 Dec 2024 14:12:00 +0000 (15:12 +0100)] 
gccrs: Add unit struct to name namespace in old resolver

We missed the name namespace for unit struct in the old resolver.

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-toplevel.h: Add struct to name namespace.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add debug dump to old name resolver
Pierre-Emmanuel Patry [Wed, 11 Dec 2024 13:19:44 +0000 (14:19 +0100)] 
gccrs: Add debug dump to old name resolver

It might be necessary to compare both name resolution' internal states
during the transition. This new debug representation could help with
that.

gcc/rust/ChangeLog:

* resolve/rust-name-resolver.h: Add new degug dump for old name
resolver.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Labels shall be pushed within label namespace
Pierre-Emmanuel Patry [Wed, 11 Dec 2024 11:04:32 +0000 (12:04 +0100)] 
gccrs: Labels shall be pushed within label namespace

Labels were using the wrong namespace.

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Change label
push function from type rib to label rib.
* resolve/rust-ast-resolve-item.cc (ResolveTraitItems::visit):
Likewise.
(ResolveItem::visit): Likewise.
(ResolveExternItem::visit): Likewise.
* resolve/rust-ast-resolve-stmt.h: Likewise.
* resolve/rust-ast-resolve.cc (NameResolution::go): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: backend: Improve handling of lang-item PathInExpressions
Arthur Cohen [Fri, 24 Jan 2025 09:42:54 +0000 (10:42 +0100)] 
gccrs: backend: Improve handling of lang-item PathInExpressions

gcc/rust/ChangeLog:

* backend/rust-compile-resolve-path.cc (ResolvePathRef::visit): Call into
resolve_path_like instead.
(ResolvePathRef::resolve_path_like): New.
(ResolvePathRef::resolve): Call into resolve_with_node_id.
* backend/rust-compile-resolve-path.h: Declare new functions and document them.

4 months agogccrs: ast: Add Path::is_lang_item()
Arthur Cohen [Wed, 22 Jan 2025 16:52:26 +0000 (16:52 +0000)] 
gccrs: ast: Add Path::is_lang_item()

gcc/rust/ChangeLog:

* ast/rust-path.h: New function.

4 months agogccrs: marklive: Fix handling for lang item PathInExpressions.
Arthur Cohen [Tue, 24 Dec 2024 11:45:25 +0000 (11:45 +0000)] 
gccrs: marklive: Fix handling for lang item PathInExpressions.

gcc/rust/ChangeLog:

* checks/lints/rust-lint-marklive.cc (MarkLive::visit): Adapt to lang items.

4 months agogccrs: hir: Adapt visitors to lang item PathInExpressions
Arthur Cohen [Wed, 22 Jan 2025 12:36:59 +0000 (12:36 +0000)] 
gccrs: hir: Adapt visitors to lang item PathInExpressions

gcc/rust/ChangeLog:

* backend/rust-compile-resolve-path.cc (ResolvePathRef::visit): Adapt visitor to lang item
HIR::PathInExpressions.
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::visit): Likewise.

4 months agogccrs: hir: Add LangItem paths to PathPattern class
Arthur Cohen [Mon, 16 Dec 2024 12:01:13 +0000 (13:01 +0100)] 
gccrs: hir: Add LangItem paths to PathPattern class

gcc/rust/ChangeLog:

* hir/tree/rust-hir-path.h: Adapt PathPattern to accept lang-item paths.
* hir/tree/rust-hir-path.cc: Assert we are dealing with a segmented path, create lang-item
constructors.
* hir/tree/rust-hir.cc (PathPattern::convert_to_simple_path): Likewise.

4 months agogccrs: ast: More visitors to allow lang item paths in expressions
Arthur Cohen [Wed, 22 Jan 2025 14:09:08 +0000 (14:09 +0000)] 
gccrs: ast: More visitors to allow lang item paths in expressions

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): Adapt visitor to lang item
PathInExpressions.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise.
* expand/rust-cfg-strip.cc (CfgStrip::visit): Likewise.
* expand/rust-expand-visitor.cc (ExpandVisitor::visit): Likewise.
* hir/rust-ast-lower.cc (ASTLoweringExprWithBlock::visit): Likewise.
(ASTLowerPathInExpression::visit): Likewise.
* resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path): Likewise.
* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit): Likewise.

4 months agogccrs: lang-items: Add LangItem::IsEnumVariant
Arthur Cohen [Mon, 23 Dec 2024 16:43:35 +0000 (16:43 +0000)] 
gccrs: lang-items: Add LangItem::IsEnumVariant

gcc/rust/ChangeLog:

* util/rust-lang-item.cc (LangItem::IsEnumVariant): New function.
* util/rust-lang-item.h: Declare it.

4 months agogccrs: mappings: Improve error message for get_lang_item_node
Arthur Cohen [Wed, 22 Jan 2025 12:37:58 +0000 (12:37 +0000)] 
gccrs: mappings: Improve error message for get_lang_item_node

gcc/rust/ChangeLog:

* util/rust-hir-map.cc (Mappings::get_lang_item_node): Better formatting when a lang
item does not exist when it should.

4 months agogccrs: lang-items: Collect enum variants as lang items
Arthur Cohen [Mon, 23 Dec 2024 10:27:13 +0000 (10:27 +0000)] 
gccrs: lang-items: Collect enum variants as lang items

gcc/rust/ChangeLog:

* ast/rust-collect-lang-items.h: Declare visitor.
* ast/rust-collect-lang-items.cc (CollectLangItems::visit): New.

4 months agogccrs: catch missing guard for optional result
Philip Herron [Tue, 21 Jan 2025 17:19:13 +0000 (17:19 +0000)] 
gccrs: catch missing guard for optional result

When we lookup here it returns an optional which can lead to a crash
because it needs a guard if it has a value.

gcc/rust/ChangeLog:

* backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): add guard

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: these tests now work it seems

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: Infer crate name after file opening
Dylan Gardner [Thu, 29 Aug 2024 11:43:42 +0000 (04:43 -0700)] 
gccrs: Infer crate name after file opening

Fixes #3129.

gcc/rust/ChangeLog:

* rust-session-manager.cc (Session::handle_crate_name): Remove
crate name inference
(Session::compile_crate): Add crate name inference and error if
inferred name is empty. Remove CompileOptions::get_instance ()
that returned a local copy of the options. Rename
crate_name_changed to crate_name_found to match semantics.
(rust_crate_name_validation_test): Test inferring ".rs" name
* rust-session-manager.h: Modify handle_crate_name definition to
include filename.

4 months agogccrs: Add captures for ClosureExprInnerTyped with nr2
Pierre-Emmanuel Patry [Fri, 24 Jan 2025 15:02:10 +0000 (16:02 +0100)] 
gccrs: Add captures for ClosureExprInnerTyped with nr2

Captures were only processed for regular ClosureExprInner.

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add
ClosureExprInnerTyped visit implementation.
(add_captures): Add a function to avoid code duplication.
* resolve/rust-late-name-resolver-2.0.h: Add function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add environment capture to NR2
Pierre-Emmanuel Patry [Mon, 20 Jan 2025 12:49:25 +0000 (13:49 +0100)] 
gccrs: Add environment capture to NR2

The compiler was still relying on NR1 for closure captures when using nr2
even though the resolver was not used and thus it's state empty.

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add environment
collection.
* resolve/rust-late-name-resolver-2.0.h: Add function prototype.
* resolve/rust-name-resolver.cc (Resolver::get_captures): Add assertion
to prevent NR2 usage with nr1 capture functions.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Use
nr2 captures.
* util/rust-hir-map.cc (Mappings::add_capture): Add function to
register capture for a given closure.
(Mappings::lookup_captures):  Add a function to lookup all captures
available for a given closure.
* util/rust-hir-map.h: Add function prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Check for type paths nr2.0 can't handle yet
Owen Avery [Tue, 21 Jan 2025 22:02:35 +0000 (17:02 -0500)] 
gccrs: Check for type paths nr2.0 can't handle yet

Some of our tests only work with name resolution 2.0 because the latter
misinterprets type paths. This change should cause the compiler to error out
if it would otherwise misinterpret a type path. A fix for type path
resolution isn't included in this comment, since doing so would make it
harder to track the meaningfulness of test regressions.

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Error out if a type path has multiple segments,
as we currently ignore every segment except the last.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: backend: Allow anything as a match scrutinee
Arthur Cohen [Tue, 24 Dec 2024 11:45:09 +0000 (11:45 +0000)] 
gccrs: backend: Allow anything as a match scrutinee

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (check_match_scrutinee): Allow anything to be used as a
match scrutinee, not just ADTs.

4 months agogccrs: lang-items: Add Result and Try lang items
Arthur Cohen [Tue, 21 Jan 2025 15:13:11 +0000 (16:13 +0100)] 
gccrs: lang-items: Add Result and Try lang items

gcc/rust/ChangeLog:

* util/rust-lang-item.h: Add handling for Result::Ok, Result::Err, Try, Try::into_result,
Try::from_ok, Try::from_err.
* util/rust-lang-item.cc: Likewise.

gcc/testsuite/ChangeLog:

* rust/compile/try-trait.rs: New test.

4 months agogccrs: Fix rust breakage with nr2
Pierre-Emmanuel Patry [Mon, 25 Nov 2024 17:04:06 +0000 (18:04 +0100)] 
gccrs: Fix rust breakage with nr2

Nr2 did not emit the correct error message for break identifier "rust".

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add "rust"
identifier detection akin to nr1.
(funny_ice_finalizer): Copy ICE finalizer from nr1.
* resolve/rust-late-name-resolver-2.0.h: Add funny_error member
context state.
* Make-lang.in: Add new translation unit for new ice finalizer.
* resolve/rust-ast-resolve-expr.cc: Move ice
finalizer to it's own file.
* resolve/rust-ice-finalizer.cc: New file.
* resolve/rust-ice-finalizer.h: New file.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove break-rust3.rs from exclude list.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: derive(Copy): Improve bounds when deriving Copy
Arthur Cohen [Thu, 16 Jan 2025 13:46:06 +0000 (14:46 +0100)] 
gccrs: derive(Copy): Improve bounds when deriving Copy

gcc/rust/ChangeLog:

* expand/rust-derive-copy.cc: Always add an extra Copy bound on generic Copy impls.

4 months agogccrs: derive(Clone): Use lang item bounds on AssertParamIsCopy
Arthur Cohen [Mon, 20 Jan 2025 11:36:53 +0000 (11:36 +0000)] 
gccrs: derive(Clone): Use lang item bounds on AssertParamIsCopy

gcc/rust/ChangeLog:

* expand/rust-derive-clone.cc (DeriveClone::visit_union): Use lang items for Copy and
Sized bounds.

gcc/testsuite/ChangeLog:

* rust/compile/derive_macro6.rs: Add lang item attribute to Copy trait.

4 months agogccrs: derive(Clone): Add Clone bound on generated impl blocks
Arthur Cohen [Wed, 15 Jan 2025 13:00:45 +0000 (13:00 +0000)] 
gccrs: derive(Clone): Add Clone bound on generated impl blocks

gcc/rust/ChangeLog:

* expand/rust-derive-clone.cc: Add extra bound when deriving generic Clone

4 months agogccrs: ast-builder: Add extra parameter for TypeParam builder
Arthur Cohen [Wed, 15 Jan 2025 12:59:51 +0000 (12:59 +0000)] 
gccrs: ast-builder: Add extra parameter for TypeParam builder

gcc/rust/ChangeLog:

* ast/rust-ast-builder.cc (Builder::new_type_param): Add optional extra trait bounds.
* ast/rust-ast-builder.h: Likewise.

4 months agogccrs: hir-dump: Improve handling of typepathsegments that are lang items.
Arthur Cohen [Wed, 15 Jan 2025 12:58:53 +0000 (12:58 +0000)] 
gccrs: hir-dump: Improve handling of typepathsegments that are lang items.

gcc/rust/ChangeLog:

* hir/rust-hir-dump.cc (Dump::do_typepathsegment): Add handling for lang items.

4 months agogccrs: lang-item:Add LangItem::Kind::RECEIVER
lishin [Mon, 20 Jan 2025 17:53:18 +0000 (17:53 +0000)] 
gccrs: lang-item:Add LangItem::Kind::RECEIVER

Add and implement a lang item (receiver) in source code.

gcc/rust/ChangeLog:

* util/rust-lang-item.cc: Add receiver to map.
* util/rust-lang-item.h: Define LangItem::Kind::RECEIVER.

gcc/testsuite/ChangeLog:

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

Signed-off-by: lishin <lishin1008@gmail.com>
4 months agogccrs: typecheck: Add basic handling for applying auto trait bounds
Arthur Cohen [Thu, 16 Jan 2025 16:10:02 +0000 (17:10 +0100)] 
gccrs: typecheck: Add basic handling for applying auto trait bounds

gcc/rust/ChangeLog:

* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Register auto traits in mappings.
* util/rust-hir-map.cc (Mappings::insert_auto_trait): New.
(Mappings::get_auto_traits): New.
* util/rust-hir-map.h: Declare them.
* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::scan): Add auto trait bounds when
scanning.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Some parts of nr2.0 can't handle auto traits yet.
* rust/compile/auto_traits3.rs: Removed in favor of...
* rust/compile/auto_traits2.rs: ...this one.
* rust/compile/auto_traits4.rs: New test.

4 months agogccrs: typecheck: Separate assemble_builtin_candidate in two
Arthur Cohen [Thu, 16 Jan 2025 15:55:56 +0000 (16:55 +0100)] 
gccrs: typecheck: Separate assemble_builtin_candidate in two

This paves the way for adding trait bounds that aren't necessarily Sized.

gcc/rust/ChangeLog:

* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::add_trait_bound): New function.
* typecheck/rust-hir-type-bounds.h: Declare it.
(TypeBoundsProbe::assemble_builtin_candidate): Call into add_trait_bound.

4 months agolibstdc++: Ensure that std::vector<bool> allocator has bool value_type
Jonathan Wakely [Fri, 21 Mar 2025 22:49:44 +0000 (22:49 +0000)] 
libstdc++: Ensure that std::vector<bool> allocator has bool value_type

This is the subject of LWG 4228 which notes that libstdc++ doesn't
enforce this requirement. That's just a bug because I forgot to add it
to vector<bool> when adding it elsewhere.

For consistency with the other containers we should not allow incorrect
allocator types for strict -std=c++NN modes, but it is very late to make
that change for GCC 15 so this only enables the assertion for C++20
(where it's required). For GCC 16 we can enable it for strict modes too.

libstdc++-v3/ChangeLog:

* include/bits/stl_bvector.h (vector<bool, A>): Enforce the
C++20 requirement that the allocator's value_type matches the
container.
* testsuite/23_containers/vector/bool/cons/from_range.cc: Fix
incorrect allocator type.

Reviewed-by: Tomasz KamiƄski <tkaminsk@redhat.com>
4 months agoarm: testsuite: tighten scan-assembler in unaligned-memcpy-4.c
Richard Earnshaw [Mon, 24 Mar 2025 11:22:05 +0000 (11:22 +0000)] 
arm: testsuite: tighten scan-assembler in unaligned-memcpy-4.c

The scan-assembler-not pattern in this test was too broad and matched
the 'unaligned' from the .file directive from the file name.  Tighten it
to require a leading comment character.

gcc/testsuite:

* gcc.target/arm/unaligned-memcpy-4.c: Tighten scan-assembler-not
pattern.

4 months agoAdd 'libgomp.c++/pr96835-1{,-O0}.C', 'libgomp.oacc-c++/pr96835-1.C' [PR96835]
Thomas Schwinge [Tue, 8 Oct 2024 07:59:45 +0000 (09:59 +0200)] 
Add 'libgomp.c++/pr96835-1{,-O0}.C', 'libgomp.oacc-c++/pr96835-1.C' [PR96835]

PR libgomp/96835
libgomp/
* testsuite/libgomp.c++/pr96835-1.C: New.
* testsuite/libgomp.c++/pr96835-1-O0.C: Likewise.
* testsuite/libgomp.oacc-c++/pr96835-1.C: Likewise.

4 months agoAdd 'libgomp.c++/pr101544-1{,-O0}.C', 'libgomp.oacc-c++/pr101544-1.C' [PR101544]
Thomas Schwinge [Tue, 12 Jul 2022 07:59:10 +0000 (09:59 +0200)] 
Add 'libgomp.c++/pr101544-1{,-O0}.C', 'libgomp.oacc-c++/pr101544-1.C' [PR101544]

PR target/101544
libgomp/
* testsuite/libgomp.c++/pr101544-1.C: New.
* testsuite/libgomp.c++/pr101544-1-O0.C: Likewise.
* testsuite/libgomp.oacc-c++/pr101544-1.C: Likewise.

4 months agonvptx: In offloading compilation, special-case certain host-setup symbol aliases...
Thomas Schwinge [Thu, 20 Mar 2025 13:21:26 +0000 (14:21 +0100)] 
nvptx: In offloading compilation, special-case certain host-setup symbol aliases [PR101544]

Namely, use PTX '.alias' even for (default) '-mno-alias' if the host made the
C++ "base and complete [cd]tor aliases".

PR target/101544
gcc/
* config/nvptx/nvptx.cc (nvptx_asm_output_def_from_decls)
[ACCEL_COMPILER]: Special-case certain host-setup symbol aliases.
* varasm.cc (do_assemble_alias) [ACCEL_COMPILER]: Adjust.

4 months agonvptx: Default at least to '-mptx=6.3'
Thomas Schwinge [Thu, 20 Mar 2025 13:21:26 +0000 (14:21 +0100)] 
nvptx: Default at least to '-mptx=6.3'

gcc/
* config/nvptx/nvptx.cc (default_ptx_version_option): Default at
least to '-mptx=6.3'.
* doc/invoke.texi (Nvidia PTX Options): Update '-mptx=[...]'.
gcc/testsuite/
* gcc.target/nvptx/march-map=sm_30.c: Adjust.
* gcc.target/nvptx/march-map=sm_32.c: Likewise.
* gcc.target/nvptx/march-map=sm_35.c: Likewise.
* gcc.target/nvptx/march-map=sm_37.c: Likewise.
* gcc.target/nvptx/march-map=sm_50.c: Likewise.
* gcc.target/nvptx/march=sm_30.c: Likewise.
* gcc.target/nvptx/march=sm_35.c: Likewise.
* gcc.target/nvptx/march=sm_37.c: Likewise.

4 months agoi386: Raise deprecate warning for -mavx10.1-256/512 and -mevex512 while add -mavx10...
Haochen Jiang [Mon, 24 Mar 2025 06:24:39 +0000 (14:24 +0800)] 
i386: Raise deprecate warning for -mavx10.1-256/512 and -mevex512 while add -mavx10.1 back with 512 bit alias

When AVX10.1 options are added into GCC 14, E-core is supposed to
support up to 256 bit vector width, while P-core up to 512 bit vector
width. Therefore, we added avx10.1-256 and avx10.1-512 options into
compiler since there will be real platforms with 256 bit only support.
At the same time, for old platforms could also compile a 256 bit only
binary, we introduced -mno-evex512 to disable 512 bit vector.

However, all the future platforms will now support 512 bit vector width,
including P-core and E-core. It will result in no need for split the
option for vector width. Therefore, we will remove them in this patch.
Unlike AVX10.2 options, AVX10.1 options has been there in a major
release, so we have to raise a deprecate warning in GCC 15 and remove
them in GCC 16. At the same time, to align with avx10.2 options, we will
add just removed avx10.1 option back with warning to mention its
behavior change.

gcc/ChangeLog:

* common/config/i386/cpuinfo.h
(get_available_features): Change to FEATURE_AVX10_1.
* common/config/i386/i386-common.cc
(OPTION_MASK_ISA2_AVX10_1_512_SET): Renamed to ...
(OPTION_MASK_ISA2_AVX10_1_SET): ... this.
(OPTION_MASK_ISA2_AVX10_2_SET): Use renamed macro.
(OPTION_MASK_ISA2_AVX10_1_UNSET): Ditto.
(ix86_handle_option): Ditto.
(processor_alias_table): Use P_PROC_AVX10_1.
* common/config/i386/i386-cpuinfo.h
(enum feature_priority): Rename from AVX10_1_512 to AVX10_1.
(enum processor_features): Ditto.
* common/config/i386/i386-isas.h: Add avx10.1.
* config/i386/driver-i386.cc
(host_detect_local_cpu): Use renamed enum.
* config/i386/i386-c.cc
(ix86_target_macros_internal): Rename to avx10.1.
* config/i386/i386-isa.def (AVX10_1_512): Rename to ...
(AVX10_1): ... this.
* config/i386/i386-options.cc (isa2_opts): Rename to avx10.1.
(ix86_valid_target_attribute_inner_p): Add avx10.1.
(ix86_option_override_internal): Rename to AVX10_1.
Revise warnings to mention behavior change for option
combination in GCC 16.
* config/i386/i386.h (PTA_DIAMONDRAPIDS): Use AVX10_1.
* config/i386/i386.opt: Add avx10.1.
Add deprecate warnings for mevex512 and mavx10.1-256/512.
* config/i386/i386.opt.urls: Add avx10.1.
* doc/extend.texi: Ditto.
* doc/sourcebuild.texi: Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/i386/avx10-check.h: Change to avx10.1.
* gcc.target/i386/avx10_1-1.c: Add warning check.
* gcc.target/i386/avx10_1-10.c: Ditto.
* gcc.target/i386/avx10_1-11.c: Ditto.
* gcc.target/i386/avx10_1-12.c: Ditto.
* gcc.target/i386/avx10_1-13.c: Ditto.
* gcc.target/i386/avx10_1-15.c: Ditto.
* gcc.target/i386/avx10_1-16.c: Ditto.
* gcc.target/i386/avx10_1-18.c: Ditto.
* gcc.target/i386/avx10_1-19.c: Ditto.
* gcc.target/i386/avx10_1-2.c: Ditto.
* gcc.target/i386/avx10_1-20.c: Ditto.
* gcc.target/i386/avx10_1-21.c: Ditto.
* gcc.target/i386/avx10_1-22.c: Ditto.
* gcc.target/i386/avx10_1-23.c: Ditto.
* gcc.target/i386/avx10_1-26.c: Ditto.
* gcc.target/i386/avx10_1-3.c: Ditto.
* gcc.target/i386/avx10_1-4.c: Ditto.
* gcc.target/i386/avx10_1-7.c: Ditto.
* gcc.target/i386/avx10_1-8.c: Ditto.
* gcc.target/i386/avx10_1-9.c: Ditto.
* gcc.target/i386/noevex512-1.c: Ditto.
* gcc.target/i386/noevex512-2.c: Ditto.
* gcc.target/i386/pr111068.c: Ditto.
* gcc.target/i386/pr111907.c: Ditto.
* gcc.target/i386/pr117240_avx512f.c: Ditto.
* gcc.target/i386/pr117304-1.c: Ditto.
* gcc.target/i386/pr117946.c: Ditto.
* gcc.target/i386/avx10_1-24.c: Removed.
* gcc.target/i386/avx10_1-25.c: Removed.
* gcc.target/i386/avx10_1-5.c: Removed.
* gcc.target/i386/avx10_1-6.c: Removed.

4 months agoi386: Remove avx10.2-256 and avx10.2-512 options
Haochen Jiang [Mon, 24 Mar 2025 06:24:36 +0000 (14:24 +0800)] 
i386: Remove avx10.2-256 and avx10.2-512 options

When AVX10.2 options are added into GCC 15, E-core is supposed to
support up to 256 bit vector width, while P-core up to 512 bit vector
width. Therefore, we added avx10.2-256 and avx10.2-512 options into
compiler since there will be real platforms with 256 bit only support.

However, all the future platforms will now support 512 bit vector width,
including P-core and E-core. It will result in no need for split the
option for vector width. Therefore, we will remove them in this patch.

gcc/ChangeLog:

* common/config/i386/cpuinfo.h
(get_available_features): Revise the logic AVX10 version.
* common/config/i386/i386-common.cc
(OPTION_MASK_ISA2_AVX10_2_256_SET): Removed.
(OPTION_MASK_ISA2_AVX10_2_512_SET): Ditto.
(OPTION_MASK_ISA2_AVX10_2_SET): New.
(OPTION_MASK_ISA2_AMX_AVX512_SET): Use AVX10.2 macro.
(OPTION_MASK_ISA2_AVX10_2_UNSET): Ditto.
(ix86_handle_option): Remove avx10.2-256 part. Adjust avx10.2.
* common/config/i386/i386-cpuinfo.h
(enum processor_features): Remove FEATURE_AVX10_2_256 and skip
the value for it. Change the name from FEATURE_AVX10_2_512 to
FEATURE_AVX10_2.
* common/config/i386/i386-isas.h: Remove avx10.2-256/512.
* config/i386/avx10_2-512bf16intrin.h: Use avx10.2 instead of
avx10.2-256/512.
* config/i386/avx10_2-512convertintrin.h: Ditto.
* config/i386/avx10_2-512mediaintrin.h: Ditto.
* config/i386/avx10_2-512minmaxintrin.h: Ditto.
* config/i386/avx10_2-512satcvtintrin.h: Ditto.
* config/i386/avx10_2bf16intrin.h: Ditto.
* config/i386/avx10_2convertintrin.h: Ditto.
* config/i386/avx10_2mediaintrin.h: Ditto.
* config/i386/avx10_2minmaxintrin.h: Ditto.
* config/i386/avx10_2satcvtintrin.h: Ditto.
* config/i386/movrsintrin.h: Ditto.
* config/i386/sm4intrin.h: Ditto.
* config/i386/cpuid.h (bit_AVX10_256): Removed.
(bit_AVX10_512): Ditto.
* config/i386/driver-i386.cc (host_detect_local_cpu): Adjust
Diamond Rapids and -march=native condition.
* config/i386/i386-builtin.def (BDESC): Use AVX10.2 macro
instead of AVX10.2-256/512.
* config/i386/i386-c.cc (ix86_target_macros_internal): Ditto.
* config/i386/i386-expand.cc
(ix86_expand_branch): Use TARGET_AVX10_2 instead of specifying
vector size.
(ix86_prepare_fp_compare_args): Ditto.
(ix86_expand_fp_compare): Ditto.
(ix86_ssecom_setcc): Ditto.
(ix86_expand_sse_comi): Ditto.
(ix86_expand_sse_comi_round): Ditto.
(ix86_check_builtin_isa_match): Ditto.
* config/i386/i386.cc (ix86_fp_compare_code_to_integer): Ditto.
(ix86_get_mask_mode): Ditto.
* config/i386/i386.h (SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P): Ditto.
* config/i386/i386.md: Ditto.
* config/i386/mmx.md: Ditto.
* config/i386/sse.md: Ditto.
* config/i386/predicates.md: Ditto.
* config/i386/i386-isa.def (AVX10_2_256): Removed.
(AVX10_2_512): Removed.
(AVX10_2): New.
* config/i386/i386-options.cc
(isa2_opts): Remove avx10.2-256/512.
(ix86_valid_target_attribute_inner_p): Ditto.
(PTA_DIAMONDRAPIDS): Use PTA_AVX10_2.
* config/i386/i386.opt: Remove avx10.2-256/512.
* config/i386/i386.opt.urls: Ditto.
* doc/extend.texi: Ditto.
* doc/invoke.texi: Ditto.
* doc/sourcebuild.texi: Ditto.

4 months agoi386: Adjust AVX10.2 testcases options
Haochen Jiang [Mon, 24 Mar 2025 06:24:35 +0000 (14:24 +0800)] 
i386: Adjust AVX10.2 testcases options

Before we change AVX10.2 options in GCC 15, we need to adjust
all related test options to -mavx10.2 to avoid breakage. Since
-mavx10.2 is now 512 bit and will be the final option we will
use. It will also be an one-time change for these tests on
options.

gcc/testsuite/ChangeLog:

* g++.dg/other/i386-2.C: Use -mavx10.2.
* g++.dg/other/i386-3.C: Ditto.
* gcc.target/i386/avx-1.c: Ditto.
* gcc.target/i386/avx10_2-512-bf16-1.c: Ditto.
* gcc.target/i386/avx10_2-512-bf16-vector-cmp-1.c: Ditto.
* gcc.target/i386/avx10_2-512-bf16-vector-fma-1.c: Ditto.
* gcc.target/i386/avx10_2-512-bf16-vector-operations-1.c: Ditto.
* gcc.target/i386/avx10_2-512-bf16-vector-smaxmin-1.c: Ditto.
* gcc.target/i386/avx10_2-512-convert-1.c: Ditto.
* gcc.target/i386/avx10_2-512-media-1.c: Ditto.
* gcc.target/i386/avx10_2-512-minmax-1.c: Ditto.
* gcc.target/i386/avx10_2-512-movrs-1.c: Ditto.
* gcc.target/i386/avx10_2-512-satcvt-1.c: Ditto.
* gcc.target/i386/avx10_2-512-vaddbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcmpbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvt2ph2bf8-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvt2ph2bf8s-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvt2ph2hf8-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvt2ph2hf8s-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvt2ps2phx-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvtbf162ibs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvtbf162iubs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvtbiasph2bf8-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvtbiasph2bf8s-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvtbiasph2hf8-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvtbiasph2hf8s-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvthf82ph-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvtph2bf8-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvtph2bf8s-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvtph2hf8-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvtph2hf8s-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvtph2ibs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvtph2iubs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvtps2ibs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvtps2iubs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvttbf162ibs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvttbf162iubs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvttpd2dqs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvttpd2qqs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvttpd2udqs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvttpd2uqqs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvttph2ibs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvttph2iubs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvttps2dqs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvttps2ibs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvttps2iubs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvttps2qqs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvttps2udqs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvttps2uqqs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vdivbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vdpphps-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vfmaddXXXbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vfmsubXXXbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vfnmaddXXXbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vfnmsubXXXbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vfpclassbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vgetexpbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vgetmantbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vmaxbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vminbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vminmaxbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vminmaxpd-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vminmaxph-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vminmaxps-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vmpsadbw-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vmulbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vpdpbssd-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vpdpbssds-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vpdpbsud-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vpdpbsuds-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vpdpbuud-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vpdpbuuds-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vpdpwsud-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vpdpwsuds-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vpdpwusd-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vpdpwusds-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vpdpwuud-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vpdpwuuds-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vrcpbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vreducebf16-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vrndscalebf16-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vrsqrtbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vscalefbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vsqrtbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vsubbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-bf16-1.c: Ditto.
* gcc.target/i386/avx10_2-bf16-vector-cmp-1.c: Ditto.
* gcc.target/i386/avx10_2-bf16-vector-fma-1.c: Ditto.
* gcc.target/i386/avx10_2-bf16-vector-operations-1.c: Ditto.
* gcc.target/i386/avx10_2-bf16-vector-smaxmin-1.c: Ditto.
* gcc.target/i386/avx10_2-builtin-1.c: Ditto.
* gcc.target/i386/avx10_2-builtin-2.c: Ditto.
* gcc.target/i386/avx10_2-comibf-1.c: Ditto.
* gcc.target/i386/avx10_2-comibf-2.c: Ditto.
* gcc.target/i386/avx10_2-comibf-3.c: Ditto.
* gcc.target/i386/avx10_2-comibf-4.c: Ditto.
* gcc.target/i386/avx10_2-compare-1.c: Ditto.
* gcc.target/i386/avx10_2-compare-1b.c: Ditto.
* gcc.target/i386/avx10_2-convert-1.c: Ditto.
* gcc.target/i386/avx10_2-media-1.c: Ditto.
* gcc.target/i386/avx10_2-minmax-1.c: Ditto.
* gcc.target/i386/avx10_2-movrs-1.c: Ditto.
* gcc.target/i386/avx10_2-partial-bf16-vector-fast-math-1.c: Ditto.
* gcc.target/i386/avx10_2-partial-bf16-vector-fma-1.c: Ditto.
* gcc.target/i386/avx10_2-partial-bf16-vector-operations-1.c: Ditto.
* gcc.target/i386/avx10_2-partial-bf16-vector-smaxmin-1.c: Ditto.
* gcc.target/i386/avx10_2-satcvt-1.c: Ditto.
* gcc.target/i386/avx10_2-vaddbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-vcmpbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-vcomisbf16-1.c: Ditto.
* gcc.target/i386/avx10_2-vcomisbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-vcvt2ph2bf8-2.c: Ditto.
* gcc.target/i386/avx10_2-vcvt2ph2bf8s-2.c: Ditto.
* gcc.target/i386/avx10_2-vcvt2ph2hf8-2.c: Ditto.
* gcc.target/i386/avx10_2-vcvt2ph2hf8s-2.c: Ditto.
* gcc.target/i386/avx10_2-vcvt2ps2phx-2.c: Ditto.
* gcc.target/i386/avx10_2-vcvtbf162ibs-2.c: Ditto.
* gcc.target/i386/avx10_2-vcvtbf162iubs-2.c: Ditto.
* gcc.target/i386/avx10_2-vcvtbiasph2bf8-2.c: Ditto.
* gcc.target/i386/avx10_2-vcvtbiasph2bf8s-2.c: Ditto.
* gcc.target/i386/avx10_2-vcvtbiasph2hf8-2.c: Ditto.
* gcc.target/i386/avx10_2-vcvtbiasph2hf8s-2.c: Ditto.
* gcc.target/i386/avx10_2-vcvthf82ph-2.c: Ditto.
* gcc.target/i386/avx10_2-vcvtph2bf8-2.c: Ditto.
* gcc.target/i386/avx10_2-vcvtph2bf8s-2.c: Ditto.
* gcc.target/i386/avx10_2-vcvtph2hf8-2.c: Ditto.
* gcc.target/i386/avx10_2-vcvtph2hf8s-2.c: Ditto.
* gcc.target/i386/avx10_2-vcvtph2ibs-2.c: Ditto.
* gcc.target/i386/avx10_2-vcvtph2iubs-2.c: Ditto.
* gcc.target/i386/avx10_2-vcvtps2ibs-2.c: Ditto.
* gcc.target/i386/avx10_2-vcvtps2iubs-2.c: Ditto.
* gcc.target/i386/avx10_2-vcvttbf162ibs-2.c: Ditto.
* gcc.target/i386/avx10_2-vcvttbf162iubs-2.c: Ditto.
* gcc.target/i386/avx10_2-vcvttpd2dqs-2.c: Ditto.
* gcc.target/i386/avx10_2-vcvttpd2qqs-2.c: Ditto.
* gcc.target/i386/avx10_2-vcvttpd2udqs-2.c: Ditto.
* gcc.target/i386/avx10_2-vcvttpd2uqqs-2.c: Ditto.
* gcc.target/i386/avx10_2-vcvttph2ibs-2.c: Ditto.
* gcc.target/i386/avx10_2-vcvttph2iubs-2.c: Ditto.
* gcc.target/i386/avx10_2-vcvttps2dqs-2.c: Ditto.
* gcc.target/i386/avx10_2-vcvttps2ibs-2.c: Ditto.
* gcc.target/i386/avx10_2-vcvttps2iubs-2.c: Ditto.
* gcc.target/i386/avx10_2-vcvttps2qqs-2.c: Ditto.
* gcc.target/i386/avx10_2-vcvttps2udqs-2.c: Ditto.
* gcc.target/i386/avx10_2-vcvttps2uqqs-2.c: Ditto.
* gcc.target/i386/avx10_2-vcvttsd2sis-2.c: Ditto.
* gcc.target/i386/avx10_2-vcvttsd2usis-2.c: Ditto.
* gcc.target/i386/avx10_2-vcvttss2sis-2.c: Ditto.
* gcc.target/i386/avx10_2-vcvttss2usis-2.c: Ditto.
* gcc.target/i386/avx10_2-vdivbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-vdpphps-2.c: Ditto.
* gcc.target/i386/avx10_2-vfmaddXXXbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-vfmsubXXXbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-vfnmaddXXXbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-vfnmsubXXXbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-vfpclassbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-vgetexpbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-vgetmantbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-vmaxbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-vminbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-vminmaxbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-vminmaxpd-2.c: Ditto.
* gcc.target/i386/avx10_2-vminmaxph-2.c: Ditto.
* gcc.target/i386/avx10_2-vminmaxps-2.c: Ditto.
* gcc.target/i386/avx10_2-vminmaxsd-2.c: Ditto.
* gcc.target/i386/avx10_2-vminmaxsh-2.c: Ditto.
* gcc.target/i386/avx10_2-vminmaxss-2.c: Ditto.
* gcc.target/i386/avx10_2-vmovd-1.c: Ditto.
* gcc.target/i386/avx10_2-vmovd-2.c: Ditto.
* gcc.target/i386/avx10_2-vmovw-1.c: Ditto.
* gcc.target/i386/avx10_2-vmovw-2.c: Ditto.
* gcc.target/i386/avx10_2-vmpsadbw-2.c: Ditto.
* gcc.target/i386/avx10_2-vmulbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-vpdpbssd-2.c: Ditto.
* gcc.target/i386/avx10_2-vpdpbssds-2.c: Ditto.
* gcc.target/i386/avx10_2-vpdpbsud-2.c: Ditto.
* gcc.target/i386/avx10_2-vpdpbsuds-2.c: Ditto.
* gcc.target/i386/avx10_2-vpdpbuud-2.c: Ditto.
* gcc.target/i386/avx10_2-vpdpbuuds-2.c: Ditto.
* gcc.target/i386/avx10_2-vpdpwsud-2.c: Ditto.
* gcc.target/i386/avx10_2-vpdpwsuds-2.c: Ditto.
* gcc.target/i386/avx10_2-vpdpwusd-2.c: Ditto.
* gcc.target/i386/avx10_2-vpdpwusds-2.c: Ditto.
* gcc.target/i386/avx10_2-vpdpwuud-2.c: Ditto.
* gcc.target/i386/avx10_2-vpdpwuuds-2.c: Ditto.
* gcc.target/i386/avx10_2-vrcpbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-vreducebf16-2.c: Ditto.
* gcc.target/i386/avx10_2-vrndscalebf16-2.c: Ditto.
* gcc.target/i386/avx10_2-vrsqrtbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-vscalefbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-vsqrtbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-vsubbf16-2.c: Ditto.
* gcc.target/i386/funcspec-56.inc: Ditto.
* gcc.target/i386/part-vect-vec_cmpbf.c: Ditto.
* gcc.target/i386/pr117495.c: Ditto.
* gcc.target/i386/pr118815.c: Ditto.
* gcc.target/i386/sm4-avx10_2-1.c: Ditto.
* gcc.target/i386/sm4-avx10_2-512-1.c: Ditto.
* gcc.target/i386/sm4key4-avx10_2-512-2.c: Ditto.
* gcc.target/i386/sm4rnds4-avx10_2-512-2.c: Ditto.
* gcc.target/i386/sse-12.c: Ditto.
* gcc.target/i386/sse-13.c: Ditto.
* gcc.target/i386/sse-14.c: Ditto.
* gcc.target/i386/sse-22.c: Ditto.
* gcc.target/i386/sse-23.c: Ditto.
* gcc.target/i386/vnniint16-auto-vectorize-3.c: Ditto.
* gcc.target/i386/vnniint16-auto-vectorize-4.c: Ditto.
* gcc.target/i386/vnniint8-auto-vectorize-3.c: Ditto.
* gcc.target/i386/vnniint8-auto-vectorize-4.c: Ditto.
* gcc.target/i386/avx10-check.h: Remove avx10.2-512 and
use avx10.2.
* gcc.target/i386/sm4-check.h: Ditto.
* lib/target-supports.exp: Ditto.

4 months agoRevert "AVX10.2 ymm rounding: Support vadd{s,d,h} and vcmp{s,d,h} intrins"
Haochen Jiang [Mon, 24 Mar 2025 06:24:33 +0000 (14:24 +0800)] 
Revert "AVX10.2 ymm rounding: Support vadd{s,d,h} and vcmp{s,d,h} intrins"

This reverts commit e22e3af1954469c40b139b7cfa8e7708592f4bfd.

4 months agoRevert "AVX10.2 ymm rounding: Support vcvtdq2p{s,h} and vcvtpd2p{s,h} intrins"
Haochen Jiang [Mon, 24 Mar 2025 06:24:31 +0000 (14:24 +0800)] 
Revert "AVX10.2 ymm rounding: Support vcvtdq2p{s,h} and vcvtpd2p{s,h} intrins"

This reverts commit 85e874d19548f0dcb9a3f14f9e4b1e3411c88c4b.

4 months agoRevert "AVX10.2 ymm rounding: Support vcvtpd2{,u}{dq,qq} intrins"
Haochen Jiang [Mon, 24 Mar 2025 06:24:29 +0000 (14:24 +0800)] 
Revert "AVX10.2 ymm rounding: Support vcvtpd2{,u}{dq,qq} intrins"

This reverts commit 508ac49e1a94c28346642bff512d0ed5f4f58b64.

4 months agoRevert "AVX10.2 ymm rounding: Support vcvtph2p{s,d,sx} and vcvtph2{,u}{dq,qq} intrins"
Haochen Jiang [Mon, 24 Mar 2025 06:24:27 +0000 (14:24 +0800)] 
Revert "AVX10.2 ymm rounding: Support vcvtph2p{s,d,sx} and vcvtph2{,u}{dq,qq} intrins"

This reverts commit 6f2eac53b6026836f3222961c32312e02c2c7dbc.