]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
2 months agogccrs: nr2.0: Improve StructPatternFieldIdent handling
Owen Avery [Fri, 23 May 2025 20:19:59 +0000 (16:19 -0400)] 
gccrs: nr2.0: Improve StructPatternFieldIdent handling

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Use
visit_identifier_as_pattern to handle IdentifierPattern and
StructPatternFieldIdent.
(visit_identifier_as_pattern): New function.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 months agogccrs: Add new function ClosureExpr::get_definition_expr
Owen Avery [Mon, 9 Jun 2025 21:11:39 +0000 (17:11 -0400)] 
gccrs: Add new function ClosureExpr::get_definition_expr

gcc/rust/ChangeLog:

* ast/rust-expr.h (ClosureExpr::get_definition_expr): New
virtual member function.
(ClosureExprInner::get_definition_expr): Add override specifier.
(ClosureExprInnerTyped::get_definition_block): Rename to...
(ClosureExprInnerTyped::get_definition_expr): ...here and add
override specifier.

* ast/rust-ast-collector.cc (TokenCollector::visit): Handle
rename of ClosureExprInnerTyped::get_definition_block to
ClosureExprInnerTyped::get_definition_expr.
* 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-expr.cc (ASTLoweringExpr::visit): Likewise.
* resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit):
Likewise.
* resolve/rust-late-name-resolver-2.0.cc (Late::visit):
Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 months agogccrs: nr2.0: Separate out canonical path handling
Owen Avery [Fri, 2 May 2025 22:38:50 +0000 (18:38 -0400)] 
gccrs: nr2.0: Separate out canonical path handling

This should improve our canonical path handling, without requiring
further tweaks to ForeverStack. This may also help if, in the future, we
have to move canonical path calculation to later compilation phases for
proper handling of generics.

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc
(HIRCompileBase::compile_function): Since canonical paths
returned from nr2.0 now include the crate name, avoid prepending
the crate name again.

* backend/rust-compile-implitem.cc (CompileTraitItem::visit):
Use NameResolutionContext::to_canonical_path instead of
ForeverStack::to_canonical_path.
* backend/rust-compile-item.cc (CompileItem::visit): 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.cc
(TraitItemReference::get_type_from_fn): Likewise.

* resolve/rust-default-resolver.cc (DefaultResolver::visit): Add
Crate and EnumItem instance visitors, handle canonical path
context scoping.
* resolve/rust-default-resolver.h (DefaultResolver::visit): Add
Crate and EnumItem instance visitors.
* resolve/rust-early-name-resolver-2.0.cc (Early::go): Visit
instances of Crate using the virtual member function visit.
* resolve/rust-forever-stack.h
(ForeverStack::to_canonical_path): Remove function declaration.
* resolve/rust-forever-stack.hxx
(ForeverStack::to_canonical_path): Remove function definition.
* resolve/rust-late-name-resolver-2.0.cc (Late::go): Visit
instances of Crate using the virtual member function visit.
* resolve/rust-name-resolution-context.cc
(CanonicalPathRecordCrateRoot::as_path): New function definition.
(CanonicalPathRecordNormal::as_path): Likewise.
(CanonicalPathRecordLookup::as_path): Likewise.
(CanonicalPathRecordImpl::as_path): Likewise.
(CanonicalPathRecordTraitImpl::as_path): Likewise.
(NameResolutionContext::NameResolutionContext): Initialize
member variable canonical_ctx.
* resolve/rust-name-resolution-context.h: Include "rust-item.h".
(class NameResolutionContext): Forward declare class.
(class CanonicalPathRecord): New class.
(class CanonicalPathRecordWithParent): Likewise.
(class CanonicalPathRecordCrateRoot): Likewise.
(class CanonicalPathRecordNormal): Likewise.
(class CanonicalPathRecordLookup): Likewise.
(class CanonicalPathRecordImpl): Likewise.
(class CanonicalPathRecordTraitImpl): Likewise.
(class CanonicalPathCtx): Likewise.
(NameResolutionContext::canonical_ctx): New member variable.
(NameResolutionContext::to_canonical_path): New member function.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::go):
Visit instances of Crate with the virtual member function visit.
(TopLevel::visit): Handle canonical path context scoping for
external crates, use DefaultResolver::visit when visiting
instances of StructStruct.
* util/rust-canonical-path.h (CanonicalPath::new_seg): Take path
parameter by-value, as a duplicate instance will be constructed
regardless.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove canonical_paths1.rs.

2 months agogccrs: Lower IdentifierPattern's to_bind to HIR
Zhi Heng [Sat, 7 Jun 2025 14:30:25 +0000 (22:30 +0800)] 
gccrs: Lower IdentifierPattern's to_bind to HIR

gcc/rust/ChangeLog:

* hir/rust-ast-lower-pattern.cc: Lower of IdentifierPattern's to_bind to HIR.
* hir/rust-hir-dump.cc: Update IdentifierPattern's dump to properly show to_bind's full
full properties.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2 months agogccrs: fix: ICE when parsing unterminated raw byte strings
Vishruth-Thimmaiah [Wed, 28 May 2025 17:33:27 +0000 (23:03 +0530)] 
gccrs: fix: ICE when parsing unterminated raw byte strings

Fixes an ICE when a raw byte string is not terminated

Fixes Rust-GCC#3731

gcc/rust/ChangeLog:

* lex/rust-lex.cc (Lexer::parse_raw_byte_string):
Fix infinite looping when a raw byte string is not terminated.

gcc/testsuite/ChangeLog:

* rust/compile/torture/unended-raw-byte-string.rs:
New test to ensure correct error message for unended raw byte string.

Signed-off-by: Vishruth Thimmaiah <vishruththimmaiah@gmail.com>
2 months agogccrs: nr2.0: Catch Self in impl block self types
Owen Avery [Fri, 16 May 2025 02:04:34 +0000 (22:04 -0400)] 
gccrs: nr2.0: Catch Self in impl block self types

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc (DefaultResolver::visit): Use
visit_impl_type to visit the self types of impl blocks.
* resolve/rust-default-resolver.h
(DefaultResolver::visit_impl_type): New member function
declaration.
* resolve/rust-late-name-resolver-2.0.cc (Late::Late):
Initialize member variable block_big_self.
(Late::visit_impl_type): New member function definition.
(Late::visit): Check for Self while inside impl block self
types.
* resolve/rust-late-name-resolver-2.0.h (Late::visit_impl_type):
New member function.
(Late::block_big_self): New member variable.

gcc/testsuite/ChangeLog:

* rust/compile/issue-3671.rs: Remove usage of Self.
* rust/compile/nr2/exclude: Remove issue-3671.rs.
* rust/compile/self-in-impl.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 months agogccrs: nr2.0: Improve visibility path handling
Owen Avery [Fri, 9 May 2025 00:44:47 +0000 (20:44 -0400)] 
gccrs: nr2.0: Improve visibility path handling

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.h
(enum ResolutionMode): New.
(ForeverStack::get): Add a private overload that takes a
starting node as a parameter.
(ForeverStack::resolve_path): Replace boolean parameter
has_opening_scope_resolution with ResolutionMode parameter mode.
* resolve/rust-forever-stack.hxx
(ForeverStack::resolve_path): Likewise.
(ForeverStack::get): Add a private overload that takes a
starting node as a parameter.
* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Add Visibility visitor.
* resolve/rust-late-name-resolver-2.0.h
(Late::visit): Likewise.
* resolve/rust-name-resolution-context.h
(NameResolutionContext::resolve_path): Rework overloading a bit
and accept ResolutionMode parameter.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 months agogccrs: parser: fix ICE std::out_of_range with path attrs to nonexisting path
Vishruth-Thimmaiah [Tue, 22 Apr 2025 14:34:22 +0000 (20:04 +0530)] 
gccrs: parser: fix ICE std::out_of_range with path attrs to nonexisting path

Stops an ICE from occuring when path attribute is empty

Fixes Rust-GCC#3607.

gcc/rust/ChangeLog:

* parse/rust-parse.cc (Rust::extract_module_path):
Handle empty or whitespace-only path attributes.

gcc/testsuite/ChangeLog:

* rust/compile/torture/extern_mod2.rs:
New test to ensure an error is emitted for empty path attributes.

Signed-off-by: Vishruth Thimmaiah <vishruththimmaiah@gmail.com>
2 months agogccrs: Make ConstantItem use Identifier
Owen Avery [Wed, 4 Jun 2025 05:06:06 +0000 (01:06 -0400)] 
gccrs: Make ConstantItem use Identifier

The change to ASTLoweringExternItem is necessary, since with this patch
Identifier can be implicitly converted to std::string.

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): Handle
changed type of ConstantItem::identifier.
* ast/rust-ast.cc (ConstantItem::as_string): Likewise.
* ast/rust-ast.h (operator const std::string &): New member
function.
* ast/rust-item.h (ConstantItem::identifier): Change type from
std::string to Identifier.
(ConstantItem::ConstantItem): Handle changed type of identifier
field.
(ConstantItem::is_unnamed): Likewise.
(ConstantItem::get_identifier): Likewise.
* hir/rust-ast-lower-extern.h (ASTLoweringExternItem::visit):
Avoid discarding location of wildcard patterns.
* lex/rust-token.cc: Include "rust-ast.h".
(Token::make_identifier): Add overload accepting an Identifier
instance.
* lex/rust-token.h (class Identifier): Add forward declaration
in order to...
(Token::make_identifier): ...declare an overload for this static
member function.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 months agogccrs: const-block: Add testcase
Arthur Cohen [Tue, 15 Apr 2025 11:41:41 +0000 (13:41 +0200)] 
gccrs: const-block: Add testcase

gcc/testsuite/ChangeLog:

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

2 months agogccrs: hir: Add const blocks
Arthur Cohen [Tue, 15 Apr 2025 11:34:38 +0000 (13:34 +0200)] 
gccrs: hir: Add const blocks

gcc/rust/ChangeLog:

* hir/tree/rust-hir-expr.h: New classes.
* hir/tree/rust-hir-full-decls.h: Likewise.
* hir/tree/rust-hir.cc: Handle AnonConst and ConstBlock.
* backend/rust-compile-block.cc: Likewise.
* backend/rust-compile-block.h: Likewise.
* backend/rust-compile-expr.cc (CompileExpr::visit): Likewise.
* 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-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-expr.cc (ASTLoweringExpr::visit): Likewise.
(translate_operand_out): Likewise.
(translate_operand_inout): Likewise.
(translate_operand_const): Likewise.
* hir/rust-ast-lower-expr.h: Likewise.
* hir/rust-hir-dump.cc (Dump::visit): Likewise.
* hir/rust-hir-dump.h: Likewise.
* hir/tree/rust-hir-expr-abstract.h: Likewise.
* hir/tree/rust-hir-expr.cc (AnonConst::AnonConst): Likewise.
(AnonConst::operator=): Likewise.
(ConstBlock::ConstBlock): Likewise.
(ConstBlock::operator=): Likewise.
* hir/tree/rust-hir-visitor.h:
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise.
(typecheck_inline_asm_operand): Likewise.
* typecheck/rust-hir-type-check-expr.h: Likewise.

2 months agogccrs: parser: Add base for parsing const blocks
Arthur Cohen [Tue, 15 Apr 2025 15:33:11 +0000 (17:33 +0200)] 
gccrs: parser: Add base for parsing const blocks

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_const_block_expr): New function.
* parse/rust-parse.h: Declare it.

2 months agogccrs: ast: Add ConstBlock and AnonConst nodes
Arthur Cohen [Wed, 9 Apr 2025 16:18:30 +0000 (18:18 +0200)] 
gccrs: ast: Add ConstBlock and AnonConst nodes

gcc/rust/ChangeLog:

* ast/rust-expr.h: Declare AnonConst and ConstBlock and use them.
* ast/rust-ast-full-decls.h: Likewise.
* ast/rust-ast.cc: Add implementation for AnonConst and ConstBlock.
* ast/rust-ast.h: Likewise.
* ast/rust-ast-collector.cc (TokenCollector::visit): Likewise.
* ast/rust-ast-collector.h: Likewise.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise.
* ast/rust-ast-visitor.h: Likewise.
* expand/rust-derive.h: Likewise.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise.
* hir/rust-ast-lower-base.h: Likewise.
* hir/rust-ast-lower-expr.cc (translate_operand_const): Likewise.
* resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise.
* resolve/rust-ast-resolve-base.h: Likewise.
* resolve/rust-ast-resolve-expr.h: Likewise.
* resolve/rust-ast-resolve-expr.cc: Likewise.

2 months agogccrs: Always emit the error highest in the type hierarchy
Philip Herron [Tue, 20 May 2025 17:44:57 +0000 (18:44 +0100)] 
gccrs: Always emit the error highest in the type hierarchy

The unify code was a bit dumb here where we always set emit_error to false for any
subtypes for example in comparing tuples we always emitted the whole tuple didnt
match the other tuple but really its much better to say expected bool got i32 because
the element types didn't match.

gcc/rust/ChangeLog:

* typecheck/rust-coercion.cc (TypeCoercionRules::coerce_unsized): dont emit error here
* typecheck/rust-unify.cc (UnifyRules::resolve_subtype): new helper to handle emit error
(UnifyRules::expect_adt): call resolve_subtype
(UnifyRules::expect_reference): likewise
(UnifyRules::expect_pointer): likewise
(UnifyRules::expect_array): likewise
(UnifyRules::expect_slice): likewise
(UnifyRules::expect_fndef): likewise
(UnifyRules::expect_fnptr): likewise
(UnifyRules::expect_tuple): likewise
(UnifyRules::expect_closure): likewise
(UnifyRules::expect_opaque): likeiwse
* typecheck/rust-unify.h: add new helper to header

gcc/testsuite/ChangeLog:

* rust/compile/traits9.rs: update errors
* rust/compile/unify-errors1.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 months agogccrs: nr2.0: Fix IfLet pattern handling
Owen Avery [Thu, 15 May 2025 00:03:01 +0000 (20:03 -0400)] 
gccrs: nr2.0: Fix IfLet pattern handling

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc
(DefaultResolver::visit_if_let_patterns): New function
definition.
(DefaultResolver::visit): New IfLetExpr visitor definition.
* resolve/rust-default-resolver.h
(DefaultResolver::visit_if_let_patterns): New function
declaration.
(DefaultResolver::visit): New IfLetExpr visitor declaration.
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Remove
IfLetExpr visitor definition.
(Late::visit_if_let_patterns): New function definition.
* resolve/rust-late-name-resolver-2.0.h (Late::visit): Remove
IfLetExpr visitor declaration.
(Late::visit_if_let_patterns): New function declaration.
* resolve/rust-name-resolution-context.h (BindingSource::IfLet):
New enumerator.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 months agogccrs: Initial support for Return Position Impl Trait
Philip Herron [Mon, 19 May 2025 17:02:13 +0000 (18:02 +0100)] 
gccrs: Initial support for Return Position Impl Trait

This is the initial patch for RPIT, we can build on this to handle the
more complex cases but there are enough distinct changes going on here
that it should just get merged now.

RPIT is really a sneaky generic so for example:

  fn foo() -> impl Bar {
      Baz
  }

This is represented as: fn () -> OpaqueType Bar. But when we handle the
coercion site for Baz on impl Bar when we type resolve the function we
know that the underlying type  is Baz. Note this function is _not_ generic
so its using this special OpaqueType and keeping track of the underlying type
in its ty_ref reference hir-id which will resolve to Baz.

This also means if we have a case where maybe this was in an if statement:

  fn foo(a: i32) -> impl Bar {
      if a > 10 {
        Baz
      } else {
        Qux
      }
  }

The rules of impl Bar is that Baz is handled but Baz and Qux are different
underlying types so this is not allowed. The reason is impl traits are not
generic and although from a programmer perspective the callers dont know what
the underlying type is, the compiler _knows_ what it is. So really when
you call a function and get its return position impl trait the compiler knows
what to do and does all whats nessecary to handle calling functions using that
type etc.

gcc/rust/ChangeLog:

* backend/rust-compile-type.cc (TyTyResolveCompile::visit): we need to resolve the
underlying type
* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit): just clone
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit):
ensure we monomphize to get the underlying
* typecheck/rust-tyty.cc (BaseType::destructure): handle opaque types
(OpaqueType::resolve): this is much simpler now
(OpaqueType::handle_substitions): no longer needed
* typecheck/rust-tyty.h: update header
* typecheck/rust-unify.cc (UnifyRules::expect_opaque): unify rules for opaque

gcc/testsuite/ChangeLog:

* rust/compile/bad-rpit1.rs: New test.
* rust/execute/torture/impl_rpit1.rs: New test.
* rust/execute/torture/impl_rpit2.rs: New test.
* rust/execute/torture/impl_rpit3.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 months agogccrs: Fix non canonical type bug with tuples
Philip Herron [Mon, 26 May 2025 18:30:45 +0000 (19:30 +0100)] 
gccrs: Fix non canonical type bug with tuples

When working on rpit we needed to change to use a monomorphized clone of
the result of function calls. This ended up causing a verify gimple issue
with tuples because:

  fn test<A, B>(a: A, b: B) -> (A, B)

When passing for example:

  let a = test::<i32, i32> (123, 456) -> (A=i32, B=i32)

The resulting gimple types became:

  const struct (A=i32, B=i32) vs struct (i32, i32)

We removed the VIEW_CONVERT_EXPR support to auto fix this stuff a good
while ago because it hides these kinds of issues because the type hasher
included the A=i32, B=i32 vs the i32, i32 name so updating this to use
get_name instead keeps the naming the same as well as the fields meaning
these types are 100% equivilant and therefore no conversion is required.
This only occurs because tuples are not named types we should really add
more rust specific info on our gimple TYPES.

gcc/rust/ChangeLog:

* backend/rust-compile-type.cc (TyTyResolveCompile::visit): use get_name
* typecheck/rust-tyty.cc (TupleType::get_name): likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 months agogccrs: Remove unneeded clones untill we have an arena allocator for these tmps
Philip Herron [Mon, 19 May 2025 16:42:17 +0000 (17:42 +0100)] 
gccrs: Remove unneeded clones untill we have an arena allocator for these tmps

Cloning inference variables is very expensive because it means we are indirectly
creating an implicit new inference variable added to the reference chain.

gcc/rust/ChangeLog:

* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::check_base_type_privacy):
no need for unreachable here
* typecheck/rust-unify.cc (UnifyRules::commit): dont clone infer vars
(UnifyRules::expect_inference_variable): likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 months agogccrs: refactor default infer vars to be its own function
Philip Herron [Mon, 19 May 2025 16:55:53 +0000 (17:55 +0100)] 
gccrs: refactor default infer vars to be its own function

This is just a simple refactor to pull all the logic outside of the
closure which makes it more readable.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check.h: new function
* typecheck/rust-typecheck-context.cc (TypeCheckContext::compute_inference_variables):
call the new helper
(TypeCheckContext::compute_infer_var): refactored code

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 months agogccrs: Revert 10-second timeout for each test
Parthib [Sat, 21 Jan 2023 18:33:07 +0000 (18:33 +0000)] 
gccrs: Revert 10-second timeout for each test

gcc/testsuite/ChangeLog:

* lib/rust.exp: Remove timeout.

Signed-off-by: Parthib <parthibdutta02@gmail.com>
2 months agogccrs: nr2.0: Fix some paths in test files
Owen Avery [Wed, 14 May 2025 22:22:33 +0000 (18:22 -0400)] 
gccrs: nr2.0: Fix some paths in test files

This is similar to 9faba024ef18b9c4d67f22bd3b020b5e445fad0a, but it
applies to execute tests.

gcc/testsuite/ChangeLog:

* rust/execute/torture/for-loop1.rs: Adjust paths.
* rust/execute/torture/for-loop2.rs: Likewise.
* rust/execute/torture/iter1.rs: Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 months agogccrs: nr2.0: Fix test builtin_abort.rs
Owen Avery [Thu, 15 May 2025 00:05:55 +0000 (20:05 -0400)] 
gccrs: nr2.0: Fix test builtin_abort.rs

gcc/testsuite/ChangeLog:

* rust/execute/torture/builtin_abort.rs: Fix path to
intrinsics::abort.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 months agogccrs: Fix NR2 ICE in visit_attributes
Tom Schollenberger [Mon, 12 May 2025 02:57:28 +0000 (22:57 -0400)] 
gccrs: Fix NR2 ICE in visit_attributes

Undefined attribute macros have no proc macro definition, which results
in a failing `rust_assert`. This changes that assert to an if statement,
that returns early if there is no proc macro definition. Fixes #3661.

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc (Early::visit_attributes): rust_assert to if

gcc/testsuite/ChangeLog:

* rust/compile/issue-3661.rs: Test NR2 has expected behavior

Signed-off-by: Tom Schollenberger <tss2344@g.rit.edu>
2 months agogccrs: Remove rvalue reference binding
Owen Avery [Tue, 13 May 2025 22:01:33 +0000 (18:01 -0400)] 
gccrs: Remove rvalue reference binding

This should be unnecessary, since even C++11 has implicit move.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_expr_stmt): Avoid
reference binding and remove std::move in return statements.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 months agoRust: Move 'libformat_parser' build into the GCC build directory
Thomas Schwinge [Wed, 28 Feb 2024 22:26:39 +0000 (23:26 +0100)] 
Rust: Move 'libformat_parser' build into the GCC build directory

Fixes Rust-GCC#2883.

* .gitignore: Remove 'libgrust/*/target/'.

2 months agogccrs: Small improvements to DefaultASTVisitor and nr2.0
Owen Avery [Thu, 8 May 2025 21:32:05 +0000 (17:32 -0400)] 
gccrs: Small improvements to DefaultASTVisitor and nr2.0

gcc/rust/ChangeLog:

* ast/rust-ast-visitor.cc
(DefaultASTVisitor::visit): Only visit the path of an instance
of Visibility if the instance has a path.
* ast/rust-ast.h
(SimplePath::SimplePath): Make sure constructors are explicit.
* resolve/rust-early-name-resolver-2.0.cc
(Early::visit_attributes): Pass entire paths to
NameResolutionContext::resolve_path.
(Early::visit): Likewise and avoid copying a path.
* resolve/rust-forever-stack.hxx
(ForeverStack::resolve_path): Assert that at least one path
segment has been passed in.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 months agogccrs: remove now useless clang-format comments
Marc Poulhiès [Tue, 13 May 2025 19:28:16 +0000 (21:28 +0200)] 
gccrs: remove now useless clang-format comments

Config has been updated upstream to correctly indent declaration.

gcc/rust/ChangeLog:

* rust-attribs.cc (handle_hot_attribute): Remove clang-format comment.

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
2 months agogccrs: Reindent using last clang-format configuration
Marc Poulhiès [Sat, 10 May 2025 18:51:38 +0000 (20:51 +0200)] 
gccrs: Reindent using last clang-format configuration

It changes declaration and switch case indentation to follow GNU coding
style.

gcc/rust/ChangeLog:

* ast/rust-ast-builder-type.cc (ASTTypeBuilder::visit): Reindent.
* ast/rust-ast-builder.cc (Builder::new_generic_args): Likewise.
* ast/rust-ast-collector.cc (TokenCollector::visit): Likewise.
* ast/rust-ast-dump.h (debug): Likewise.
* ast/rust-ast-formatting.h (indent_spaces): Likewise.
(get_string_in_delims): Likewise.
(get_mode_dump_desc): Likewise.
(append_attributes): Likewise.
(unquote_string): Likewise.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise.
* ast/rust-ast.cc (Attribute::get_traits_to_derive): Likewise.
(UseTreeGlob::as_string): Likewise.
(UseTreeList::as_string): Likewise.
(AttributeParser::parse_path_meta_item): Likewise.
(FormatArgs::set_outer_attrs): Likewise.
* ast/rust-ast.h (operator<<): Likewise.
* ast/rust-cond-compilation.h: Likewise.
* ast/rust-desugar-apit.cc: Likewise.
* ast/rust-fmt.h (collect_pieces): Likewise.
(clone_pieces): Likewise.
* ast/rust-pattern.h (tokenid_to_rangekind): Likewise.
* backend/rust-compile-context.cc (Context::type_hasher): Likewise.
* backend/rust-compile-expr.cc (CompileExpr::visit): Likewise.
* backend/rust-compile-intrinsic.cc (get_identifier): Likewise.
(offset_handler): Likewise.
(sizeof_handler): Likewise.
(transmute_handler): Likewise.
(rotate_handler): Likewise.
(wrapping_op_handler_inner): Likewise.
(op_with_overflow_inner): Likewise.
(uninit_handler): Likewise.
(move_val_init_handler): Likewise.
(assume_handler): Likewise.
(discriminant_value_handler): Likewise.
(variant_count_handler): Likewise.
(prefetch_data_handler): Likewise.
(atomic_store_handler_inner): Likewise.
(atomic_load_handler_inner): Likewise.
(unchecked_op_inner): Likewise.
(copy_handler_inner): Likewise.
(expect_handler_inner): Likewise.
(try_handler_inner): Likewise.
* backend/rust-compile-pattern.cc (compile_range_pattern_bound): Likewise.
(CompilePatternCheckExpr::visit): Likewise.
(CompilePatternBindings::visit): Likewise.
(CompilePatternLet::visit): Likewise.
* backend/rust-compile-var-decl.h: Likewise.
* backend/rust-constexpr.cc (verify_constant): Likewise.
(find_array_ctor_elt): Likewise.
(array_index_cmp): Likewise.
(potential_constant_expression_1): Likewise.
(unshare_constructor): Likewise.
(maybe_save_constexpr_fundef): Likewise.
(returns): Likewise.
(breaks): Likewise.
(continues): Likewise.
(switches): Likewise.
(constant_value_1): Likewise.
(decl_constant_value): Likewise.
(non_const_var_error): Likewise.
(eval_constant_expression): Likewise.
(constexpr_fn_retval): Likewise.
(eval_store_expression): Likewise.
(eval_call_expression): Likewise.
(eval_binary_expression): Likewise.
(get_function_named_in_call): Likewise.
(eval_statement_list): Likewise.
(extract_string_elt): Likewise.
(eval_conditional_expression): Likewise.
(eval_bit_field_ref): Likewise.
(eval_loop_expr): Likewise.
(eval_switch_expr): Likewise.
(eval_unary_expression): Likewise.
(get_or_insert_ctor_field): Likewise.
(eval_and_check_array_index): Likewise.
* backend/rust-constexpr.h (maybe_save_constexpr_fundef): Likewise.
* backend/rust-mangle-v0.cc (v0_path): Likewise.
(v0_complex_type_prefix): Likewise.
* backend/rust-mangle.h (legacy_mangle_item): Likewise.
(v0_mangle_item): Likewise.
* backend/rust-tree.cc (convert_to_void): Likewise.
(find_parameter_packs_r): Likewise.
(rs_tree_equal): Likewise.
(publicly_uniquely_derived_p): Likewise.
(instantiation_dependent_expression_p): Likewise.
(type_has_nontrivial_copy_init): Likewise.
(is_normal_capture_proxy): Likewise.
(is_bitfield_expr_with_lowered_type): Likewise.
(undeduced_auto_decl): Likewise.
(require_deduced_type): Likewise.
(gt_pch_nx): Likewise.
(lvalue_kind): Likewise.
* backend/rust-tree.h (LANG_DECL_MIN_CHECK): Likewise.
(LANG_DECL_FN_CHECK): Likewise.
(LANG_DECL_NS_CHECK): Likewise.
(LANG_DECL_PARM_CHECK): Likewise.
(LANG_DECL_DECOMP_CHECK): Likewise.
(resort_type_member_vec): Likewise.
(convert_to_void): Likewise.
(mark_discarded_use): Likewise.
(mark_exp_read): Likewise.
(mark_use): Likewise.
(mark_rvalue_use): Likewise.
(mark_lvalue_use): Likewise.
(mark_lvalue_use_nonread): Likewise.
(convert_from_reference): Likewise.
(maybe_warn_nodiscard): Likewise.
(expr_loc_or_loc): Likewise.
(expr_loc_or_input_loc): Likewise.
(get_fndecl_from_callee): Likewise.
(pointer_offset_expression): Likewise.
(is_empty_class): Likewise.
(is_really_empty_class): Likewise.
(rs_type_quals): Likewise.
(init_modules): Likewise.
(lookup_add): Likewise.
(ovl_make): Likewise.
(struct c_fileinfo): Likewise.
(get_fileinfo): Likewise.
(cxx_make_type): Likewise.
(build_cplus_array_type): Likewise.
(comptypes): Likewise.
(rs_build_qualified_type_real): Likewise.
(vector_targets_convertible_p): Likewise.
(get_class_binding_direct): Likewise.
(lang_check_failed): Likewise.
(check_for_uninitialized_const_var): Likewise.
(cp_fold_maybe_rvalue): Likewise.
(fold_offsetof): Likewise.
(fold_non_dependent_expr): Likewise.
(in_immediate_context): Likewise.
(cxx_mark_addressable): Likewise.
(decl_constant_value): Likewise.
(is_class_type): Likewise.
(fold_builtin_is_pointer_inverconvertible_with_class): Likewise.
(c_common_type_for_mode): Likewise.
(next_common_initial_seqence): Likewise.
(fold_builtin_is_corresponding_member): Likewise.
(maybe_constant_value): Likewise.
(rs_walk_subtrees): Likewise.
(make_tree_vector): Likewise.
(release_tree_vector): Likewise.
(location_of): Likewise.
(maybe_constant_init): Likewise.
(explain_invalid_constexpr_fn): Likewise.
(literal_type_p): Likewise.
(maybe_constexpr_fn): Likewise.
(fold_non_dependent_init): Likewise.
* checks/errors/borrowck/polonius/rust-polonius.h (polonius_run): Likewise.
(FFIVector__new): Likewise.
(FFIVector__new_vec_pair): Likewise.
(FFIVector__new_vec_triple): Likewise.
(FFIVector__push): Likewise.
(FFIVector__push_vec_triple): Likewise.
* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
(ExprStmtBuilder::visit): Likewise.
* checks/errors/borrowck/rust-bir-builder-pattern.cc
(PatternBindingBuilder::visit): Likewise.
* checks/errors/borrowck/rust-bir-dump.cc (Dump::visit): Likewise.
* checks/errors/borrowck/rust-bir-fact-collector.h (points): Likewise.
* checks/errors/borrowck/rust-bir-place.h: Likewise.
* checks/errors/borrowck/rust-bir-visitor.h: Likewise.
* checks/errors/privacy/rust-privacy-check.cc (saw_errors): Likewise.
* checks/errors/privacy/rust-privacy-ctx.h (rust_privacy_ctx_test): Likewise.
* checks/errors/privacy/rust-privacy-reporter.cc
(PrivacyReporter::check_for_privacy_violation): Likewise.
(PrivacyReporter::check_base_type_privacy): Likewise.
(PrivacyReporter::visit): Likewise.
* checks/errors/privacy/rust-reachability.cc (ReachabilityVisitor::visit): Likewise.
* checks/errors/privacy/rust-visibility-resolver.cc
(VisibilityResolver::resolve_visibility): Likewise.
* checks/errors/rust-hir-pattern-analysis.cc (Constructor::is_covered_by): Likewise.
(PlaceInfo::specialize): Likewise.
(WitnessPat::to_string): Likewise.
(WitnessMatrix::apply_constructor): Likewise.
(lower_pattern): Likewise.
(lower_tuple_pattern): Likewise.
(lower_struct_pattern): Likewise.
* checks/errors/rust-hir-pattern-analysis.h (check_match_usefulness): Likewise.
* expand/rust-cfg-strip.cc (CfgStrip::maybe_strip_generic_args): Likewise.
* expand/rust-derive-eq.cc (DeriveEq::visit_enum): Likewise.
* expand/rust-derive.cc: Likewise.
* expand/rust-expand-format-args.cc (expand_format_args): Likewise.
* expand/rust-expand-visitor.h (is_derive): Likewise.
(is_builtin): Likewise.
* expand/rust-macro-builtins-asm.cc (expand_inline_asm_strings): Likewise.
* expand/rust-macro-builtins-asm.h (parse_asm): Likewise.
(check_identifier): Likewise.
(check_and_set): Likewise.
(parse_label): Likewise.
(parse_llvm_outputs): Likewise.
(parse_llvm_inputs): Likewise.
(parse_llvm_clobbers): Likewise.
(parse_llvm_options): Likewise.
* expand/rust-macro-builtins-helpers.h (make_macro_path_str): Likewise.
(make_token): Likewise.
(make_string): Likewise.
(macro_end_token): Likewise.
(parse_single_string_literal): Likewise.
(source_relative_path): Likewise.
(load_file_bytes): Likewise.
* expand/rust-macro-expand.cc (MacroExpander::match_fragment): Likewise.
(MacroExpander::match_matcher): Likewise.
(MacroExpander::match_n_matches): Likewise.
* expand/rust-macro-substitute-ctx.cc (SubstituteCtx::substitute_token): Likewise.
* expand/rust-proc-macro.h (load_macros): Likewise.
(generate_proc_macro_decls_symbol): Likewise.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_generic_args): Likewise.
(ASTLoweringBase::lower_range_pattern_bound): Likewise.
* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Likewise.
* hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::visit): Likewise.
* hir/rust-ast-lower.h (struct_field_name_exists): Likewise.
(translate_visibility): Likewise.
* hir/rust-hir-dump.cc (Dump::visit): Likewise.
* hir/rust-hir-dump.h (debug): Likewise.
* hir/tree/rust-hir.cc (UseTreeGlob::as_string): Likewise.
(UseTreeList::as_string): Likewise.
* lex/rust-lex.cc (Lexer::parse_escape): Likewise.
(Lexer::parse_utf8_escape): Likewise.
* lex/rust-lex.h (rust_input_source_test): Likewise.
* lex/rust-token.cc (RS_TOKEN_KEYWORD_2015): Likewise.
* lex/rust-token.h (get_token_description): Likewise.
(token_id_to_str): Likewise.
(token_id_is_keyword): Likewise.
(token_id_keyword_string): Likewise.
(get_type_hint_string): Likewise.
(nfc_normalize_token_string): Likewise.
* metadata/rust-export-metadata.cc (PublicInterface::write_to_path): Likewise.
* metadata/rust-import-archive.cc: Likewise.
* metadata/rust-imports.h (add_search_path): Likewise.
* parse/rust-cfg-parser.h (parse_cfg_option): Likewise.
(rust_cfg_parser_test): Likewise.
* parse/rust-parse-impl.h (Parser::skip_generics_right_angle): Likewise.
(Parser::parse_attr_input): Likewise.
(Parser::parse_macro_match): Likewise.
(Parser::parse_visibility): Likewise.
(Parser::parse_module): Likewise.
(Parser::parse_use_tree): Likewise.
(Parser::parse_generic_param): Likewise.
(Parser::parse_struct): Likewise.
(Parser::parse_enum_item): Likewise.
(Parser::parse_inherent_impl_item): Likewise.
(Parser::parse_external_item): Likewise.
(Parser::parse_generic_arg): Likewise.
(Parser::parse_type_path_segment): Likewise.
(Parser::parse_expr_stmt): Likewise.
(Parser::parse_if_expr): Likewise.
(Parser::parse_if_let_expr): Likewise.
(Parser::parse_type): Likewise.
(Parser::parse_for_prefixed_type): Likewise.
(Parser::parse_slice_or_array_type): Likewise.
(Parser::parse_type_no_bounds): Likewise.
(Parser::parse_range_pattern_bound): Likewise.
(Parser::parse_pattern_no_alt): Likewise.
(Parser::parse_grouped_or_tuple_pattern): Likewise.
(Parser::parse_ident_leading_pattern): Likewise.
(Parser::parse_tuple_struct_items): Likewise.
(Parser::parse_stmt_or_expr): Likewise.
(Parser::parse_struct_expr_field): Likewise.
(Parser::null_denotation): Likewise.
(Parser::left_denotation): Likewise.
(Parser::parse_closure_expr_pratt): Likewise.
* parse/rust-parse.cc (peculiar_fragment_match_compatible): Likewise.
(is_match_compatible): Likewise.
* parse/rust-parse.h (extract_module_path): Likewise.
(is_match_compatible): Likewise.
* resolve/rust-ast-resolve-expr.cc (translate_operand): Likewise.
* resolve/rust-ast-resolve-item.cc (flatten_glob): Likewise.
(flatten_rebind): Likewise.
(flatten_list): Likewise.
(flatten): Likewise.
* resolve/rust-ast-resolve-item.h (rust_simple_path_resolve_test): Likewise.
* resolve/rust-ast-resolve-pattern.cc (PatternDeclaration::visit): Likewise.
(resolve_range_pattern_bound): Likewise.
* resolve/rust-ast-resolve-type.cc (ResolveRelativeTypePath::go): Likewise.
(ResolveTypeToCanonicalPath::visit): Likewise.
* resolve/rust-ast-resolve.cc (saw_errors): Likewise.
* resolve/rust-early-name-resolver-2.0.cc (Early::finalize_rebind_import): Likewise.
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Likewise.
* resolve/rust-toplevel-name-resolver-2.0.cc (flatten_glob): Likewise.
* rust-backend.h (init): Likewise.
(debug): Likewise.
(get_identifier_node): Likewise.
(wchar_type): Likewise.
(get_pointer_size): Likewise.
(raw_str_type): Likewise.
(integer_type): Likewise.
(float_type): Likewise.
(pointer_type): Likewise.
(reference_type): Likewise.
(immutable_type): Likewise.
(function_type): Likewise.
(function_type_variadic): Likewise.
(function_ptr_type): Likewise.
(struct_type): Likewise.
(union_type): Likewise.
(array_type): Likewise.
(named_type): Likewise.
(type_field_offset): Likewise.
(var_expression): Likewise.
(float_constant_expression): Likewise.
(string_constant_expression): Likewise.
(char_constant_expression): Likewise.
(wchar_constant_expression): Likewise.
(boolean_constant_expression): Likewise.
(convert_expression): Likewise.
(struct_field_expression): Likewise.
(compound_expression): Likewise.
(conditional_expression): Likewise.
(negation_expression): Likewise.
(arithmetic_or_logical_expression): Likewise.
(arithmetic_or_logical_expression_checked): Likewise.
(comparison_expression): Likewise.
(lazy_boolean_expression): Likewise.
(constructor_expression): Likewise.
(array_constructor_expression): Likewise.
(array_initializer): Likewise.
(array_index_expression): Likewise.
(call_expression): Likewise.
(init_statement): Likewise.
(assignment_statement): Likewise.
(return_statement): Likewise.
(if_statement): Likewise.
(loop_expression): Likewise.
(exit_expression): Likewise.
(statement_list): Likewise.
(exception_handler_statement): Likewise.
(block): Likewise.
(block_add_statements): Likewise.
(global_variable): Likewise.
(global_variable_set_init): Likewise.
(local_variable): Likewise.
(parameter_variable): Likewise.
(static_chain_variable): Likewise.
(temporary_variable): Likewise.
(label): Likewise.
(function): Likewise.
(function_defer_statement): Likewise.
(function_set_parameters): Likewise.
(write_global_definitions): Likewise.
(fill_in_fields): Likewise.
* rust-diagnostics.cc (expand_format): Likewise.
(expand_message): Likewise.
(va_constructor): Likewise.
* rust-diagnostics.h (RUST_ATTRIBUTE_GCC_DIAG): Likewise.
(rust_open_quote): Likewise.
(rust_close_quote): Likewise.
(rust_debug_loc): Likewise.
* rust-gcc.cc (non_zero_size_type): Likewise.
* rust-object-export.h (rust_field_alignment): Likewise.
(rust_read_export_data): Likewise.
(rust_write_export_data): Likewise.
* rust-session-manager.cc (saw_errors): Likewise.
(rust_get_linemap): Likewise.
(validate_crate_name): Likewise.
(Session::load_extern_crate): Likewise.
* rust-session-manager.h (rust_crate_name_validation_test): Likewise.
* rust-system.h (rust_preserve_from_gc): Likewise.
(rust_localize_identifier): Likewise.
* rust-target.h (rust_add_target_info): Likewise.
* typecheck/rust-autoderef.cc:
* typecheck/rust-casts.cc (TypeCastRules::cast_rules): Likewise.
* typecheck/rust-coercion.cc (TypeCoercionRules::do_coercion): Likewise.
(TypeCoercionRules::coerce_unsafe_ptr): Likewise.
(TypeCoercionRules::coerce_borrowed_pointer): Likewise.
* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): Likewise.
(TraitItemReference::is_object_safe): Likewise.
* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::resolve_literal): Likewise.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise.
(typecheck_inline_asm_operand): Likewise.
* typecheck/rust-hir-type-check-implitem.cc (TypeCheckImplItem::visit): Likewise.
(TypeCheckImplItemWithTrait::visit): Likewise.
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): Likewise.
* typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::visit): Likewise.
* typecheck/rust-hir-type-check-type.cc
(TypeResolveGenericParam::apply_trait_bounds): Likewise.
(ResolveWhereClauseItem::visit): Likewise.
* typecheck/rust-hir-type-check.cc (saw_errors): Likewise.
(TraitItemReference::get_type_from_fn): Likewise.
* typecheck/rust-type-util.h (query_type): Likewise.
(types_compatable): Likewise.
(unify_site): Likewise.
(unify_site_and): Likewise.
(coercion_site): Likewise.
(try_coercion): Likewise.
(cast_site): Likewise.
* typecheck/rust-tyty-bounds.cc:
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Likewise.
* typecheck/rust-tyty-cmp.h:
* typecheck/rust-tyty-variance-analysis.h (query_field_regions): Likewise.
* typecheck/rust-tyty.cc (BaseType::is_unit): Likewise.
(BaseType::has_substitutions_defined): Likewise.
(BaseType::needs_generic_substitutions): Likewise.
(BaseType::get_subst_argument_mappings): Likewise.
(InferType::default_type): Likewise.
(InferType::apply_primitive_type_hint): Likewise.
* typecheck/rust-tyty.h (is_primitive_type_kind): Likewise.
* typecheck/rust-unify.cc (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_never): Likewise.
(UnifyRules::expect_placeholder): Likewise.
(UnifyRules::expect_projection): Likewise.
(UnifyRules::expect_dyn): Likewise.
(UnifyRules::expect_closure): Likewise.
(UnifyRules::expect_opaque): Likewise.
* util/rust-abi.h (get_abi_from_string): Likewise.
(get_string_from_abi): Likewise.
* util/rust-attributes.cc (check_doc_attribute): Likewise.
* util/rust-base62.h (base62_integer): Likewise.
* util/rust-dir-owner.h (get_file_subdir): Likewise.
* util/rust-edition.h (get_rust_edition): Likewise.
* util/rust-punycode.h (encode_punycode): Likewise.
(rust_punycode_encode_test): Likewise.
* util/rust-token-converter.cc (convert): Likewise.
(from_tokenstream): Likewise.
* util/rust-token-converter.h (convert): Likewise.
(convert_literal): Likewise.
* util/rust-unicode.h (is_alphabetic): Likewise.
(is_ascii_only): Likewise.
(is_numeric): Likewise.
(is_nfc_qc_no): Likewise.
(is_nfc_qc_maybe): Likewise.
(nfc_quick_check): Likewise.
(rust_nfc_qc_test): Likewise.
(rust_utf8_normalize_test): Likewise.
(rust_utf8_property_test): Likewise.
* util/rust-unwrap-segment.h (unwrap_segment_node_id): Likewise.

libgrust/ChangeLog:

* libproc_macro_internal/ffistring.h (FFIString__new): Likewise.
(FFIString__drop): Likewise.
* libproc_macro_internal/ident.h (Ident__new): Likewise.
(Ident__new_raw): Likewise.
(Ident__drop): Likewise.
(Ident__clone): Likewise.
* libproc_macro_internal/literal.h (Literal__from_string): Likewise.
* libproc_macro_internal/proc_macro.h (bridge_is_available): Likewise.
* libproc_macro_internal/tokenstream.h (TokenStream__new): Likewise.
(TokenStream__with_capacity): Likewise.
(TokenSream__push): Likewise.
(TokenStream__from_string): Likewise.
(TokenStream__clone): Likewise.
(TokenStream__drop): Likewise.

2 months agogccrs: remove unused file
Marc Poulhiès [Tue, 13 May 2025 19:21:18 +0000 (21:21 +0200)] 
gccrs: remove unused file

gcc/rust/ChangeLog:

* Make-lang.in (GRS_OBJS): Remove rust-macro.o.
* ast/rust-macro.cc: Removed.

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
2 months agogccrs: Fix Attr metavariable binding
Owen Avery [Sat, 10 May 2025 02:17:55 +0000 (22:17 -0400)] 
gccrs: Fix Attr metavariable binding

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h
(Parser::parse_attr_input): Handle more delimeter tokens and the
END_OF_FILE token.
(Parser::skip_after_end_attribute): Handle the END_OF_FILE
token.

gcc/testsuite/ChangeLog:

* rust/compile/macros/mbe/meta-param.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 months agogccrs: Fix test same_field_name.rs
Owen Avery [Sat, 10 May 2025 00:48:18 +0000 (20:48 -0400)] 
gccrs: Fix test same_field_name.rs

gcc/rust/ChangeLog:

* hir/rust-ast-lower-item.cc
(ASTLoweringItem::visit): Keep going after a duplicate field is
found.

gcc/testsuite/ChangeLog:

* rust/execute/same_field_name.rs: Move to...
* rust/compile/same_field_name.rs: ...here and adjust expected
errors.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 months agogccrs: nr2.0: Fix borrow checking
Owen Avery [Fri, 9 May 2025 22:02:29 +0000 (18:02 -0400)] 
gccrs: nr2.0: Fix borrow checking

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder-internal.h: Include
"rust-immutable-name-resolution-context.h" and "options.h".
(AbstractBuilder::resolve_label): Use the 2.0 name resolver when
it's enabled.
(AbstractBuilder::resolve_variable): Likewise.
(AbstractBuilder::resolve_variable_or_fn): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 months agogccrs: We cant clone types as it will dup the node-id
Philip Herron [Sun, 11 May 2025 14:03:05 +0000 (15:03 +0100)] 
gccrs: We cant clone types as it will dup the node-id

This patch ensuers we reuse the Builder for new type to
ensure we create a new type from scratch ensuring consistent
new node-ids.

gcc/rust/ChangeLog:

* expand/rust-derive-default.cc (DeriveDefault::visit_struct): use builder
(DeriveDefault::visit_tuple): likewise
* expand/rust-derive-eq.cc (DeriveEq::visit_tuple): likewise
(DeriveEq::visit_struct): likewise
(DeriveEq::visit_enum): likewise
(DeriveEq::visit_union): likewise

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: these are fixed now

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 months agogccrs: Adapt attribute lang hook and do some cleanup
Marc Poulhiès [Fri, 9 May 2025 09:09:58 +0000 (11:09 +0200)] 
gccrs: Adapt attribute lang hook and do some cleanup

Since r14-6076, the LANG_HOOKS_COMMON_ATTRIBUTE_TABLE should not be used and
LANG_HOOKS_ATTRIBUTE_TABLE replaces it.

Add the "cold" attribute to fix PR120018 (and the matching "hot" attribute).

Replace some gcc_assert() by explicit warnings (same as D frontend).

Add some clang-format off/on comment around code that's not correctly
formatted.

gcc/rust/ChangeLog:
PR rust/120018

* rust-attribs.cc (handle_noreturn_attribute): Reindent declaration.
(handle_leaf_attribute): Likewise.
(handle_const_attribute): Likewise.
(handle_malloc_attribute): Likewise.
(handle_pure_attribute): Likewise.
(handle_novops_attribute): Likewise.
(handle_nonnull_attribute): Likewise.
(handle_nothrow_attribute): Likewise.
(handle_type_generic_attribute): Likewise.
(handle_transaction_pure_attribute): Likewise.
(handle_returns_twice_attribute): Likewise.
(handle_fnspec_attribute): Likewise.
(handle_omp_declare_simd_attribute): Likewise.
(handle_cold_attribute): New.
(handle_hot_attribute): New.
(attribute_spec::exclusions attr_cold_hot_exclusions): New.
(grs_langhook_common_attributes): Make it static.
(grs_langhook_common_attribute_table): New.
(grs_langhook_gnu_attributes): New.
(grs_langhook_gnu_attribute_table): New.
(handle_malloc_attribute): Make it static.
(handle_fnspec_attribute): Likewise.
(handle_pure_attribute): Replace gcc_assert by explicit warning.
(handle_novops_attribute): Likewise.
(handle_nothrow_attribute): Likewise.
(handle_returns_twice_attribute): Likewise.
(handle_omp_declare_simd_attribute): Likewise and make it static.
* rust-lang.cc (grs_langhook_gnu_attribute_table): New.
(grs_langhook_common_attribute_table): Adjust type to new hook.
(LANG_HOOKS_COMMON_ATTRIBUTE_TABLE): Remove.
(LANG_HOOKS_ATTRIBUTE_TABLE): New.

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
2 months agogccrs: nr2.0: Adjust resolution of impl items
Owen Avery [Fri, 25 Apr 2025 22:06:41 +0000 (18:06 -0400)] 
gccrs: nr2.0: Adjust resolution of impl items

gcc/rust/ChangeLog:

* ast/rust-path.cc
(TypePath::make_debug_string): Add definition.
* ast/rust-path.h
(TypePath::make_debug_string): Add declaration.
* resolve/rust-default-resolver.cc
(DefaultResolver::visit): Adjust InherentImpl and TraitImpl
visitors to better handle associated item scope.
* resolve/rust-default-resolver.h
(DefaultResolver::maybe_insert_big_self): Add.
* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Adjust type path resolution errors.
* resolve/rust-rib.h
(Rib::Kind): Add Generics kind.
* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Remove InherentImpl and TraitImpl visitor
overrides.
(TopLevel::maybe_insert_big_self): Add override in order to add
a definition of 'Self'.
* resolve/rust-toplevel-name-resolver-2.0.h
(TopLevel::visit): Remove InherentImpl and TraitImpl visitor
overrides.
(TopLevel::maybe_insert_big_self): Add override.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 months agogccrs: ast: collector: visit InlineAsm node during ast dump
0xn4utilus [Wed, 7 May 2025 16:51:10 +0000 (22:21 +0530)] 
gccrs: ast: collector: visit InlineAsm node during ast dump

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): Implement for InlineAsm.
* ast/rust-ast-full-decls.h (enum class): Move InlineAsmOption enum inside InlineAsm.
* ast/rust-expr.h (enum class): Likewise.
(class InlineAsm): Likewise.
* expand/rust-macro-builtins-asm.cc (check_and_set): Likewise.
(parse_options): Likewise.
* expand/rust-macro-builtins-asm.h (check_and_set): Likewise.
* hir/tree/rust-hir-expr.cc (InlineAsm::InlineAsm): Likewise.
* hir/tree/rust-hir-expr.h: Likewise.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise.

2 months agogccrs: fix ICE on empty constexpr loops
Tom Schollenberger [Thu, 8 May 2025 11:26:07 +0000 (07:26 -0400)] 
gccrs: fix ICE on empty constexpr loops

Empty loops have no body which means this is a NULL_TREE during const
evaluation which needs a check. Fixes Rust-GCC #3618.

gcc/rust/ChangeLog:

* backend/rust-constexpr.cc (eval_constant_expression):  Check if t is a NULL_TREE

gcc/testsuite/ChangeLog:

* rust/compile/issue-3618.rs: Test empty loops error properly.

Signed-off-by: Tom Schollenberger <tss2344@g.rit.edu>
2 months agogccrs: Prevent passing generic arguments to impl traits in argument position
Philip Herron [Wed, 7 May 2025 15:07:43 +0000 (16:07 +0100)] 
gccrs: Prevent passing generic arguments to impl traits in argument position

When using impl traits in argument position (APIT), they are desugared into generics,
and supplying explicit generic arguments is not allowed. This commit adds the error
diagnostic E0632 for attempting to pass generic arguments to impl traits, completing
the implementation of the APIT feature.

gcc/rust/ChangeLog:

* ast/rust-desugar-apit.cc: track if this is a impl-trait generic
* ast/rust-item.h (class TypeParam): add field to track if from impl trait
* hir/rust-ast-lower-type.cc (ASTLowerGenericParam::visit): likewise
* hir/tree/rust-hir-item.cc (TypeParam::TypeParam): upate hir as well
(TypeParam::operator=): likewise
* hir/tree/rust-hir-item.h (class TypeParam): likewise
* typecheck/rust-tyty-subst.cc (SubstitutionParamMapping::get_generic_param): add error
* typecheck/rust-tyty-subst.h: add const getter for the associated TypeParm

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/impl_trait_generic_arg.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 months agogccrs: nr2.0: Adjust enum item visitors
Owen Avery [Fri, 2 May 2025 22:37:45 +0000 (18:37 -0400)] 
gccrs: nr2.0: Adjust enum item visitors

gcc/rust/ChangeLog:

* ast/rust-ast-visitor.cc
(DefaultASTVisitor::visit): Make call to EnumItem visitor from
EnumItem derived class visitors non-virtual.
* ast/rust-collect-lang-items.cc
(CollectLangItems::visit): Handle visitation of classes derived
from EnumItem.
* ast/rust-collect-lang-items.h
(CollectLangItems::visit): Likewise.
* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Call DefaultResolver::visit on EnumItem
instances.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 months agogccrs: Improve struct pattern compilation
Owen Avery [Thu, 1 May 2025 01:54:53 +0000 (21:54 -0400)] 
gccrs: Improve struct pattern compilation

gcc/rust/ChangeLog:

* backend/rust-compile-pattern.cc
(CompilePatternCheckExpr::visit): Fix GENERIC generation in
light of enum layout changes since this code was written.
(CompilePatternBindings::handle_struct_pattern_ident_pat):
Delegate handling of child patterns to another
CompilePatternBindings::Compile call.
(CompilePatternBindings::make_struct_access): Make field name
parameter const qualified.
* backend/rust-compile-pattern.h
(CompilePatternBindings::make_struct_access): Likewise.

gcc/testsuite/ChangeLog:

* rust/execute/torture/struct-pattern-match.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 months agogccrs: Improve canonical path handling for impl items
Owen Avery [Sat, 3 May 2025 00:28:15 +0000 (20:28 -0400)] 
gccrs: Improve canonical path handling for impl items

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-item.cc
(ResolveItem::visit): Use the return values of
CanonicalPath::inherent_impl_seg and
CanonicalPath::trait_impl_projection_seg more directly.
* util/rust-canonical-path.h
(CanonicalPath::trait_impl_projection_seg): Append "<impl "
instead of "<" to the beginning of the returned path segment.
(CanonicalPath::inherent_impl_seg): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 months agogccrs: desugar APIT impl traits
Philip Herron [Wed, 30 Apr 2025 13:37:49 +0000 (14:37 +0100)] 
gccrs: desugar APIT impl traits

Argument position impl traits are simply syntatic sugar for generics. This
adds a new desugar pass to do this. So for example:

    fn foo(a: impl Value, b: impl Value) -> i32

Is desugared into:

    fn foo<T: Value, U: Value> (a: T, b: U) -> i32

So it just works like any normal generic function. There are more complex cases such as:

    fn foo(_value: impl Bar<Baz = impl Foo>) -> i32

Which has a generic argument binding which needs to be turned into a where constraint:

    fn foo<T, U>(_value: T) -> i32
        where
            T: Bar<Baz = U>,
            U: Foo,

Fixes Rust-GCC#2015
Fixes Rust-GCC#1487
Fixes Rust-GCC#3454
Fixes Rust-GCC#1482

gcc/rust/ChangeLog:

* Make-lang.in: new desugar file
* ast/rust-ast.cc (ImplTraitTypeOneBound::as_string): its a unique_ptr now
(FormatArgs::set_outer_attrs): reformat
* ast/rust-path.h: remove has_generic_args assertion (can be empty because of desugar)
* ast/rust-type.h (class ImplTraitTypeOneBound): add copy ctor and use unique_ptr
* hir/rust-ast-lower-type.cc (ASTLoweringType::visit): update to use unique_ptr
* parse/rust-parse-impl.h (Parser::parse_type): reuse the existing unique_ptr instead
(Parser::parse_type_no_bounds): likewise
(Parser::parse_pattern): likewise
* resolve/rust-ast-resolve-type.cc (ResolveType::visit): its a unique_ptr now
* rust-session-manager.cc (Session::compile_crate): call desugar
* ast/rust-desugar-apit.cc: New file.
* ast/rust-desugar-apit.h: New file.

gcc/testsuite/ChangeLog:

* rust/compile/issue-2015.rs: fully supported now
* rust/compile/nr2/exclude: nr2 cant handle some of these
* rust/compile/issue-1487.rs: New test.
* rust/compile/issue-3454.rs: New test.
* rust/execute/torture/impl_desugar-2.rs: New test.
* rust/execute/torture/impl_desugar.rs: New test.
* rust/execute/torture/impl_trait1.rs: New test.
* rust/execute/torture/impl_trait2.rs: New test.
* rust/execute/torture/impl_trait3.rs: New test.
* rust/execute/torture/impl_trait4.rs: New test.
* rust/execute/torture/issue-1482.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 months agogccrs: Emit error diagnostic for bad impl type usage
Philip Herron [Mon, 5 May 2025 20:07:20 +0000 (21:07 +0100)] 
gccrs: Emit error diagnostic for bad impl type usage

Rust only allows impl traits to be used in the return position of
functions.

Fixes Rust-GCC#1485

gcc/rust/ChangeLog:

* hir/rust-ast-lower-implitem.cc (ASTLowerImplItem::visit): allow impl type
* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): likewise
* hir/rust-ast-lower-type.cc (ASTLoweringType::ASTLoweringType): new flag for impl trait
(ASTLoweringType::translate): pass flag
(ASTLoweringType::visit): track impl trait tag
(ASTLoweringType::emit_impl_trait_error): new diagnostic
* hir/rust-ast-lower-type.h: add new field

gcc/testsuite/ChangeLog:

* rust/compile/impl_trait_diag.rs: New test.
* rust/compile/issue-1485.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 months agogccrs: derive(PartialEq): Fix raw strings in test
CohenArthur [Thu, 24 Apr 2025 16:41:11 +0000 (18:41 +0200)] 
gccrs: derive(PartialEq): Fix raw strings in test

gcc/testsuite/ChangeLog:

* rust/execute/torture/derive-partialeq2.rs: Add missing terminating nul char.

Co-authored-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 months agogccrs: derive(PartialEq): Allow deriving enum structs
Arthur Cohen [Wed, 16 Apr 2025 15:38:27 +0000 (17:38 +0200)] 
gccrs: derive(PartialEq): Allow deriving enum structs

gcc/rust/ChangeLog:

* expand/rust-derive-partial-eq.cc (DerivePartialEq::match_enum_tuple): Remove debug call.
(DerivePartialEq::match_enum_struct): Add proper implementation.
(DerivePartialEq::visit_enum): Call it.

gcc/testsuite/ChangeLog:

* rust/execute/torture/derive-partialeq2.rs: New test.

2 months agogccrs: ast: builder: Allow building struct ident patterns
Arthur Cohen [Wed, 16 Apr 2025 15:37:31 +0000 (17:37 +0200)] 
gccrs: ast: builder: Allow building struct ident patterns

gcc/rust/ChangeLog:

* ast/rust-ast-builder.cc (Builder::struct_pattern_ident_pattern): New.
* ast/rust-ast-builder.h: New declaration.

2 months agogccrs: backend: Compile struct rebinding patterns
Arthur Cohen [Wed, 16 Apr 2025 14:32:35 +0000 (16:32 +0200)] 
gccrs: backend: Compile struct rebinding patterns

Allow matching on a struct instance and rebinding its fields to new names:

match X {
Foo {
field0: new_name0,
field1: new_name1,
} => {
do_something(new_name0, new_name1);
},
}

This will enable us to finish derives for PartialEq and PartialOrd but
isn't a complete implementation of these patterns yet.

gcc/rust/ChangeLog:

* backend/rust-compile-pattern.cc (CompilePatternBindings::make_struct_access):
New function.
(CompilePatternBindings::visit): Properly implement patterns mentioned above
and call make_struct_accesss.
* backend/rust-compile-pattern.h: New declaration.

gcc/testsuite/ChangeLog:

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

2 months agogccrs: backend: Refactor struct pattern compilation
Arthur Cohen [Wed, 16 Apr 2025 14:03:26 +0000 (16:03 +0200)] 
gccrs: backend: Refactor struct pattern compilation

gcc/rust/ChangeLog:

* backend/rust-compile-pattern.h: Split struct pattern compilation into three functions.
* backend/rust-compile-pattern.cc: Implement them.

2 months agogccrs: nr2.0: late: Correctly initialize funny_error member
Arthur Cohen [Mon, 28 Apr 2025 19:45:13 +0000 (21:45 +0200)] 
gccrs: nr2.0: late: Correctly initialize funny_error member

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::Late): False initialize the
funny_error field.

2 months agofortran: Use array descriptor offset setter when possible
Mikael Morin [Sun, 3 Aug 2025 13:21:08 +0000 (15:21 +0200)] 
fortran: Use array descriptor offset setter when possible

Regression-tested on x86_64-pc-linux-gnu.
OK for master?

-- >8 --

    In some places, a write to an array descriptor offset field was
    generated simply by adding a modification of a reference to it that
    was already available.  This change uses the existing setter
    function instead in those places, to generate the same code.  It
    makes it more explicit that in those areas a write to the field is
    generated.

gcc/fortran/ChangeLog:

* trans-array.cc (gfc_alloc_allocatable_for_assignment): Use the
offset setter instead of generating a write to the offset.
(gfc_conv_array_parameter): Use the offset setter instead of
generating a write to the value returned by the offset getter.
* trans-expr.cc (gfc_trans_alloc_subarray_assign): Likewise.

2 months agofortran: Remove array descriptor data address accessor function
Mikael Morin [Sun, 3 Aug 2025 13:21:07 +0000 (15:21 +0200)] 
fortran: Remove array descriptor data address accessor function

Regression-tested on x86_64-pc-linux-gnu.
OK for master?

-- >8 --

The function gfc_conv_descriptor_data_addr generates an address to the
data field of an array descriptor.  It is only used once, and in the
single place where it is used, the address is immediately dereferenced.

This change replaces the single usage with a plain access to the data
field, and removes the function.  As the previous patch removed the
usage of the data field to write to it, the data getter can be used.

gcc/fortran/ChangeLog:

* trans-array.cc (gfc_conv_descriptor_data_addr): Remove.
* trans-array.h (gfc_conv_descriptor_data_addr): Remove.
* trans-decl.cc (gfc_trans_deferred_vars): Use
gfc_conv_descriptor_data_get.

2 months agofortran: Use array descriptor data setter when possible
Mikael Morin [Sun, 3 Aug 2025 13:21:06 +0000 (15:21 +0200)] 
fortran: Use array descriptor data setter when possible

Regression-tested on x86_64-pc-linux-gnu.
OK for master?

-- >8 --

In some places, a write to an array descriptor data field was generated
simply by adding a modification of a reference to it that was already
available.  This change uses the existing setter function instead in
those places, to generate the same code.  It makes it more explicit that
in those areas a write to the field is generated.

We have to be careful because in some of the places, the pointer that is
to be modified is an array descriptor field only under some conditions.
Add a conditional in those places to separate the cases, and keep
generating the reference modification as before if the conditions are
not met.

gcc/fortran/ChangeLog:

* trans.cc (gfc_finalize_tree_expr): Use the data setter instead
of writing to the value returned by the data getter.
* trans-decl.cc (gfc_trans_deferred_vars): Likewise.
* trans-stmt.cc (trans_associate_var): Use the data setter
instead of writing to the value dereferenced from the data
address.

2 months agoi386: Extend recognition of high-reg rvalues [PR121306]
Richard Sandiford [Tue, 5 Aug 2025 13:42:34 +0000 (14:42 +0100)] 
i386: Extend recognition of high-reg rvalues [PR121306]

The i386 high-register patterns used things like:

    (match_operator:SWI248 2 "extract_operator"
      [(match_operand 0 "int248_register_operand" "Q")
       (const_int 8)
       (const_int 8)])

to match an extraction of a high register such as AH from AX/EAX/RAX.

This construct is used in contexts where only the low 8 bits of the
value matter.  This is either done explicitly using a (subreg:QI ... 0)
or implicitly by assigning to an 8-bit zero_extract destination.

extract_operator therefore matches both sign_extract and zero_extract,
since the signedness of the extension beyond 8 bits is irrelevant.

But the fact that only the low 8 bits of the value are significant
means that a shift right by 8 is as good as an extraction.  Shifts
right would already be used for things like:

  struct s {
    long a:8;
    long b:8;
    long c:48;
  };

  struct s f(struct s x, long y, long z) {
    x.b = (y & z) >> 8;
    return x;
  }

but are used more after g:965564eafb721f8000013a3112f1bba8d8fae32b.

This patch therefore replaces extract_operator with a new predicate
called extract_high_operator that matches both extractions and shifts.
The predicate checks the extraction field and shift amount itself,
so that patterns only need to match the first operand.

Splitters used match_op_dup to preserve the choice of extraction.
But the fact that the extractions (and now shifts) are equivalent
means that we can just as easily canonicalise on one of them.
(In theory, canonicalisation would also promote CSE, although
that's unlikely in practice.)  The patch goes for zero_extract,
for consistency with destinations.

gcc/
PR target/121306
* config/i386/predicates.md (extract_operator): Replace with...
(extract_high_operator): ...this new predicate.
* config/i386/i386.md (*cmpqi_ext<mode>_1, *cmpqi_ext<mode>_2)
(*cmpqi_ext<mode>_3, *cmpqi_ext<mode>_4, *movstrictqi_ext<mode>_1)
(*extzv<mode>, *insvqi_2, *extendqi<SWI24:mode>_ext_1)
(*addqi_ext<mode>_1_slp, *addqi_ext<mode>_1_slp, *addqi_ext<mode>_0)
(*addqi_ext2<mode>_0, *addqi_ext<mode>_1, *<insn>qi_ext<mode>_2)
(*subqi_ext<mode>_1_slp, *subqi_ext<mode>_2_slp, *subqi_ext<mode>_0)
(*subqi_ext2<mode>_0, *subqi_ext<mode>_1, *testqi_ext<mode>_1)
(*testqi_ext<mode>_2, *<code>qi_ext<mode>_1_slp)
(*<code>qi_ext<mode>_2_slp. *<code>qi_ext<mode>_0)
(*<code>qi_ext2<mode>_0, *<code>qi_ext<mode>_1)
(*<code>qi_ext<mode>_1_cc, *<code>qi_ext<mode>_1_cc)
(*<code>qi_ext<mode>_2, *<code>qi_ext<mode>_3, *negqi_ext<mode>_1)
(*one_cmplqi_ext<mode>_1, *ashlqi_ext<mode>_1, *<insn>qi_ext<mode>_1)
(define_peephole2): Replace uses of extract_operator with
extract_high_operator, matching only the first operand.
Use zero_extract rather than match_op_dup when splitting.

2 months agoRemove hybrid SLP detection
Richard Biener [Tue, 5 Aug 2025 11:20:07 +0000 (13:20 +0200)] 
Remove hybrid SLP detection

The following removes hybrid SLP detection - it existed as sanity
check that all stmts are covered by SLP, but it proved itself
incomplete at that.  Its job is taken by early terminating SLP
build when SLP discovery fails for one root and the hope that
we now do catch all of them.

* tree-vectorizer.h (vect_relevant::hybrid): Remove.
* tree-vect-loop.cc (vect_analyze_loop_2): Do not call
vect_detect_hybrid_slp.
* tree-vect-slp.cc (maybe_push_to_hybrid_worklist): Remove.
(vect_detect_hybrid_slp): Likewise.

2 months agoAVR: target/121359: Remove -mlra and remains of reload.
Georg-Johann Lay [Sun, 3 Aug 2025 09:40:37 +0000 (11:40 +0200)] 
AVR: target/121359: Remove -mlra and remains of reload.

PR target/121359
gcc/
* config/avr/avr.h: Remove -mlra and remains of reload.
* config/avr/avr.cc: Same.
* config/avr/avr.md: Same.
* config/avr/avr-log.cc: Same.
* config/avr/avr-protos.h: Same.
* config/avr/avr.opt: Same.
* config/avr/avr.opt.urls: Same.
gcc/testsuite/
* gcc.target/avr/torture/pr118591-1.c: Remove -mlra.
* gcc.target/avr/torture/pr118591-2.c: Same.

2 months agox86: Update *one_cmplqi_ext<mode>_1
H.J. Lu [Fri, 1 Aug 2025 15:34:49 +0000 (08:34 -0700)] 
x86: Update *one_cmplqi_ext<mode>_1

After

commit 965564eafb721f8000013a3112f1bba8d8fae32b
Author: Richard Sandiford <richard.sandiford@arm.com>
Date:   Tue Jul 29 15:58:34 2025 +0100

    simplify-rtx: Simplify subregs of logic ops

combine generates

(set (zero_extract:SI (reg/v:SI 101 [ a ])
        (const_int 8 [0x8])
        (const_int 8 [0x8]))
    (not:SI (sign_extract:SI (reg:SI 107 [ b ])
            (const_int 8 [0x8])
            (const_int 8 [0x8]))))

instead of

(set (zero_extract:SI (reg/v:SI 101 [ a ])
        (const_int 8 [0x8])
        (const_int 8 [0x8]))
    (subreg:SI (not:QI (subreg:QI (sign_extract:SI (reg:SI 107 [ b ])
                    (const_int 8 [0x8])
                    (const_int 8 [0x8])) 0)) 0))

Update *one_cmplqi_ext<mode>_1 to support the new pattern.

PR target/121306
* config/i386/i386.md (*one_cmplqi_ext<mode>_1): Updated to
support the new pattern.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2 months agotree-optimization/121395 - SLP of SIMD calls w/o LHS
Richard Biener [Mon, 4 Aug 2025 12:45:53 +0000 (14:45 +0200)] 
tree-optimization/121395 - SLP of SIMD calls w/o LHS

The following records the alternate SLP instance entries coming from
stmts with stores that have no SSA def, like OMP SIMD calls without LHS.
There's a bit of fallout with having a SLP tree with a NULL vectype,
but nothing too gross.

PR tree-optimization/121395
* tree-vectorizer.h (_loop_vec_info::alternate_defs): New member.
(LOOP_VINFO_ALTERNATE_DEFS): New.
* tree-vect-stmts.cc (vect_stmt_relevant_p): Populate it.
(vectorizable_simd_clone_call): Do not register a SLP def
when there is none.
* tree-vect-slp.cc (vect_build_slp_tree_1): Allow a NULL
vectype when there's no LHS.  Allow all calls w/o LHS.
(vect_analyze_slp): Process LOOP_VINFO_ALTERNATE_DEFS as
SLP graph entries.
(vect_make_slp_decision): Handle a NULL SLP_TREE_VECTYPE.
(vect_slp_analyze_node_operations_1): Likewise.
(vect_schedule_slp_node): Likewise.

* gcc.dg/vect/pr59984.c: Adjust.

2 months agoRename loop_vect SLP_TYPE and clarify docs
Richard Biener [Mon, 4 Aug 2025 12:36:03 +0000 (14:36 +0200)] 
Rename loop_vect SLP_TYPE and clarify docs

The following renames loop_vect to not_vect, removes the unused
HYBRID_SLP_STMT macro and rewords the slp_vect_type docs to clarify
STMT_SLP_TYPE is mainly used for BB vectorization, tracking what is
vectorized and what not.

* tree-vectorizer.h (enum slp_vect_type): Rename loop_vect
to not_vect, clarify docs.
(HYBRID_SLP_STMT): Remove.
* tree-vectorizer.cc (vec_info::new_stmt_vec_info): Adjust.
* tree-vect-loop.cc (vect_analyze_loop_2): Likewise.

2 months agoPrune some unnecessary PURE_SLP_STMT checks
Richard Biener [Mon, 4 Aug 2025 12:30:28 +0000 (14:30 +0200)] 
Prune some unnecessary PURE_SLP_STMT checks

We now never have hybrid SLP (if we have, we fail immediately).

* tree-vect-data-refs.cc (vect_get_data_access_cost): Use
ncopies == 1.
* tree-vect-slp.cc (vect_remove_slp_scalar_calls): Remove
hybrid/loop SLP skip.
* tree-vect-stmts.cc (vectorizable_store): Remove pure SLP assert.

2 months agotree-optimization/121382 - avoid UB in IVOPTs inserted step computation
Richard Biener [Tue, 5 Aug 2025 08:38:03 +0000 (10:38 +0200)] 
tree-optimization/121382 - avoid UB in IVOPTs inserted step computation

IVOPTs, when replacing an IV, inserts the computation of the new IVs
step in the loop preheader without considering the case of the loop
not iterating.  This means we have to ensure the step computation
does not invoke UB.  There is also SCEV which does not care about
signed arithmetic UB when re-associating expressions to form CHRECs,
so even when we know the loop iterates this is required.

PR tree-optimization/121382
* tree-ssa-loop-ivopts.cc (create_new_iv): Rewrite the IV
step to defined form.

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

2 months agotree-optimization/121370 - avoid UB in building a CHREC
Richard Biener [Tue, 5 Aug 2025 06:59:18 +0000 (08:59 +0200)] 
tree-optimization/121370 - avoid UB in building a CHREC

When there is obvious UB involved in the process of re-associating
a series of IV increments to build up a CHREC, fail.  This catches
a few degenerate cases where SCEV introduces UB with its inherent
re-associating of IV increments.

PR tree-optimization/121370
* tree-scalar-evolution.cc (scev_dfs::add_to_evolution_1):
Avoid UB integer overflow in accumulating CHREC_RIGHT.

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

2 months agobitint: Allow unused bits when testing extended _BitInt ABIs
Yang Yujie [Tue, 5 Aug 2025 10:59:30 +0000 (12:59 +0200)] 
bitint: Allow unused bits when testing extended _BitInt ABIs

In LoongArch psABI, large _BitInt(N) (N > 64) objects are only
extended to fill the highest 8-byte chunk that contains any used bit,
but the size of such a large _BitInt type is a multiple of their
16-byte alignment.  So there may be an entire unused 8-byte
chunk that is not filled by extension, and this chunk shouldn't be
checked when testing if the object is properly extended.

The original bitintext.h assumed that all bits within
sizeof(_BitInt(N)) beyond used bits are filled by extension.
This patch changes that for LoongArch and possibly
any future ports with a similar behavior.

P.S. For encoding this test as well as type-generic programming,
it would be nice to have a builtin function to obtain "N" at
compile time from _BitInt(N)-typed expressions.  But here
we stick to existing ones (__builtin_clrsbg / __builtin_clzg).

* gcc.dg/bitintext.h (S, CEIL, PROMOTED_SIZE): Define.
(BEXTC): Generalize to only check extension within PROMOTED_SIZE bits.

2 months agoexpand: Reduce unneeded _BitInt extensions
Yang Yujie [Tue, 5 Aug 2025 10:53:27 +0000 (12:53 +0200)] 
expand: Reduce unneeded _BitInt extensions

For targets that set the "extended" flag in TARGET_C_BITINT_TYPE_INFO,
we assume small _BitInts to be internally extended after arithmetic
operations. In this case, an extra extension during RTL expansion
can be avoided.

* expr.cc (expand_expr_real_1): Do not call
reduce_to_bit_field_precision if the target assumes the _BitInt
results to be already extended.
(EXTEND_BITINT): Same.
* expr.h (bitint_extended): Declare the cache variable.
* function.cc (prepare_function_start): Initialize it.

2 months agobitint: Allow mode promotion of _BitInt types
Yang Yujie [Tue, 5 Aug 2025 10:52:27 +0000 (12:52 +0200)] 
bitint: Allow mode promotion of _BitInt types

For targets that treat small _BitInts like the fundamental
integral types, we should allow their machine modes to be promoted
in the same way.

* explow.cc (promote_function_mode): Add a case for
small/medium _BitInts.
(promote_mode): Same.

2 months agolibstdc++: Remove 2 exports [PR121373]
Jakub Jelinek [Tue, 5 Aug 2025 06:27:05 +0000 (08:27 +0200)] 
libstdc++: Remove 2 exports [PR121373]

On Mon, Aug 04, 2025 at 11:33:17AM -0400, Patrick Palka wrote:
> > @@ -1693,6 +1697,8 @@ export namespace std
> >    {
> >      using std::ranges::advance;
> >      using std::ranges::distance;
> > +    using std::ranges::iter_move;
> > +    using std::ranges::iter_swap;
>
> Actually a few lines above we already do:
>
>   // _Cpo is an implementation detail we can't avoid exposing; if we do the
>   // using in ranges directly, it conflicts with any friend functions of the
>   // same name, which is why the customization points are in an inline
>   // namespace in the first place.
>   namespace ranges::inline _Cpo
>   {
>     using _Cpo::iter_move;
>     using _Cpo::iter_swap;
>   }
>
> So I think we don't want to export iter_move and iter_swap directly...  Sorry
> for not catching this sooner :/

Here is a patch which does that.

2025-08-05  Jakub Jelinek  <jakub@redhat.com>

PR libstdc++/121373
* src/c++23/std.cc.in (std::ranges::iter_move, std::ranges::iter_swap):
Remove exports.

2 months agolibcpp: Add testcase for CWG2579 [PR120778]
Jakub Jelinek [Tue, 5 Aug 2025 06:21:55 +0000 (08:21 +0200)] 
libcpp: Add testcase for CWG2579 [PR120778]

Another easy part from the paper.

Part of the CWG2579 has been already done in an earlier paper (with
test commits by Marek) and the remaining part is implemented correctly,
we diagnose as error when token pasting doesn't form a valid token.

Except that message
pasting """" and """" does not give a valid preprocessing token
looked weird and so I've updated the message to use %< and %> instead
of \" quoting.

2025-08-05  Jakub Jelinek  <jakub@redhat.com>

PR preprocessor/120778
* macro.cc (paste_tokens): Use %< and %> instead of \" in
diagnostics around %.*s.

* g++.dg/DRs/dr2579.C: New test.
* c-c++-common/cpp/va-opt-6.c: Expect ' rather than \" around
tokens in incorrect pasting diagnostics.
* gcc.dg/c23-attr-syntax-6.c: Likewise.
* gcc.dg/cpp/paste12.c: Likewise.
* gcc.dg/cpp/paste12-2.c: Likewise.
* gcc.dg/cpp/paste14.c: Likewise.
* gcc.dg/cpp/paste14-2.c: Likewise.

2 months agodoc: Mark up function name in installation docs
Gerald Pfeifer [Tue, 5 Aug 2025 05:44:47 +0000 (07:44 +0200)] 
doc: Mark up function name in installation docs

gcc:
PR target/69374
* doc/install.texi (Configuration): Mark up atexit as code.

2 months agoRISC-V: Fix scalar code-gen of unsigned SAT_MUL
Pan Li [Thu, 31 Jul 2025 04:32:24 +0000 (12:32 +0800)] 
RISC-V: Fix scalar code-gen of unsigned SAT_MUL

The previous code-gen of scalar unsigned SAT_MUL, aka usmul.
Leverage the mulhs by mistake, it should be mulhu for the
hight bit result of mul.  Thus, this patch would like to make
it correct.

gcc/ChangeLog:

* config/riscv/riscv.cc (riscv_expand_xmode_usmul): Take
umulhu for high bits mul result.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/sat/sat_u_mul-1-u32-from-u64.c: Add mulhu
asm check.
* gcc.target/riscv/sat/sat_u_mul-1-u64-from-u128.c: Ditto.

Signed-off-by: Pan Li <pan2.li@intel.com>
2 months agoDaily bump.
GCC Administrator [Tue, 5 Aug 2025 00:19:57 +0000 (00:19 +0000)] 
Daily bump.

2 months agoc++: add another testcase [PR121351]
Patrick Palka [Mon, 4 Aug 2025 21:09:28 +0000 (17:09 -0400)] 
c++: add another testcase [PR121351]

Here's a previously accepted testcase that is now ambiguous after
r16-2771-gb9f1cc4e119da, since the uninstantiated constraints are
equivalent but the partially instantiated constraints aren't, so
the two member functions no longer correspond.

PR c++/121351

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/concepts-using6.C: New test.

2 months agoc++: constrained memfn vs corresponding using [PR121351]
Patrick Palka [Mon, 4 Aug 2025 20:51:00 +0000 (16:51 -0400)] 
c++: constrained memfn vs corresponding using [PR121351]

The b.f(42) calls in the below testcases started to get rejected as
ambiguous after r15-3740 which corrected our inheritedness tiebreaker to
only apply to constructors (and not all member functions) as per CWG2273.

But arguably these calls should still be valid regardless of the
tiebreaker because B::f corresponds to and therefore hides A::f, so
there should only be a single candidate in the first place.  This
doesn't happen because when determining correspondence we compare
the members' uninstantiated constraints instead of their partially
substituted constraints as in other declaration matching situations.
It doesn't really make sense to compare uninstantiated constraints
from two different template contexts.

This patch fixes this by substituting in outer template arguments before
comparing constraints of two potentially corresponding member functions.

PR c++/121351
PR c++/119859

gcc/cp/ChangeLog:

* class.cc (add_method): Substitute outer template arguments
into constraints before comparing them if the declarations are
from different classes.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/concepts-using5.C: New test.
* g++.dg/cpp2a/concepts-using5a.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
2 months agoc++: constexpr evaluation of abi::__dynamic_cast [PR120620]
Patrick Palka [Mon, 4 Aug 2025 20:43:33 +0000 (16:43 -0400)] 
c++: constexpr evaluation of abi::__dynamic_cast [PR120620]

r13-3299 changed our internal declaration of __dynamic_cast to reside
inside the abi/__cxxabiv1:: namespace instead of the global namespace,
matching the real declaration.  This inadvertently made us now attempt
constexpr evaluation of user-written calls to abi::__dynamic_cast since
cxx_dynamic_cast_fn_p now also returns true for them, but we're not
prepared to handle arbitrary calls to __dynamic_cast, and therefore ICE.

This patch restores cxx_dynamic_cast_fn_p to return true only for
synthesized calls to __dynamic_cast, which can be distinguished by
DECL_ARTIFICIAL, since apparently the synthesized declaration of
__dynamic_cast doesn't get merged with the actual declaration.

PR c++/120620

gcc/cp/ChangeLog:

* constexpr.cc (cxx_dynamic_cast_fn_p): Return true only
for synthesized __dynamic_cast.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/constexpr-dynamic19.C: New test.
* g++.dg/cpp2a/constexpr-dynamic1a.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
2 months agodefaults.h: Default MAX_FIXED_MODE_SIZE to MAX (BITS_PER_WORD * 2, 64)
Hans-Peter Nilsson [Wed, 16 Jul 2025 03:29:05 +0000 (05:29 +0200)] 
defaults.h: Default MAX_FIXED_MODE_SIZE to MAX (BITS_PER_WORD * 2, 64)

The old GET_MODE_SIZE (DImode) (i.e. 64) made sense before
64-bitters.  Now the default is just a trap: when using the
default 64, things like TImode (128 bits) still mostly works,
but general corner cases related to computing large-size objects
numbers, like (1 << 64)/8 break, as exposed by
gcc.dg/pr105094.c.

So, keep the floor at 64 for 32-bitters and smaller targets, but
for larger targets, make it 2 * BITS_PER_WORD.  Also, express it
more directly with focus on BITS_PER_WORD, not the size of a
mode.  Add "by GCC internally" in an attempt to tell that this
is when gcc cooks something up, not when plain input uses a type
with such a mode.

* defaults.h (MAX_FIXED_MODE_SIZE): Default to 2 * BITS_PER_WORD
for larger-than-32-bitters.
* doc/tm.texi.in (MAX_FIXED_MODE_SIZE): Adjust accordingly.  Tweak
wording.
* doc/tm.texi: Regenerate.

2 months agolibstdc++: Add various missing exports [PR121373]
Jakub Jelinek [Mon, 4 Aug 2025 15:12:55 +0000 (17:12 +0200)] 
libstdc++: Add various missing exports [PR121373]

On Sat, Aug 02, 2025 at 09:05:07PM +0200, Jakub Jelinek wrote:
> Wonder how to automatically discover other missing exports (like in PR121373
> std::byteswap), maybe one could dig that stuff somehow from the raw
> dump (look for identifiers in std namespace (and perhaps inlined namespaces
> thereof at least) which don't start with underscore.

To answer that question, I wrote a simple plugin which just dumps the names
(which do not start with underscore) in std namespace (and its inlined
namespaces) and for non-inline namespaces in there which do not start with
underscore also recurses on those namespaces.

Plugin source in
https://gcc.gnu.org/pipermail/libstdc++/2025-August/062859.html

I went through it all now, using cppreference as a quick check for stuff
removed in C++17/C++20 and for everything added verified it is in
corresponding eel.is/c++-draft/*.syn etc. and looked it up in the libstdc++
headers for guarding macros.

After all the additions I've compiled std.cc with -std=c++20, -std=c++23 and
-std=c++26, the first one revealed std::ranges::shift_{left,right} emitted an
error in that case, the patch fixes that too.

2025-08-04  Jakub Jelinek  <jakub@redhat.com>
    hexne  <printfne@gmail.com>

PR libstdc++/121373
* src/c++23/std.cc.in (std::ranges::shift_left,
std::ranges::shift_right): Only export for C++23 and later.
(std::ranges::fold_left_first_with_iter_result,
std::ranges::fold_left_with_iter_result): Export.
(std::byteswap): Export for C++23 and later.
(std::ranges::iter_move, std::ranges::iter_swap): Export.
(std::projected_value_t): Export for C++26 and later.
(std::out_ptr_t, std::inout_ptr_t): Export.
(std::ranges::iota_result): Export.
(std::regex_constants): Export a lot of constants.
(std::is_scoped_enum, std::is_scoped_enum_v): Export.

2 months agooptinfo: use enum class
David Malcolm [Mon, 4 Aug 2025 14:45:31 +0000 (10:45 -0400)] 
optinfo: use enum class

Modernization; no functional change intended.

gcc/ChangeLog:
* dump-context.h: Convert "enum optinfo_item_kind" into
"enum class kind" within class optinfo_item.
* dumpfile.cc: Likewise.  Use "auto" in a few places.
Convert "enum optinfo_kind" to "enum class kind" within
class optinfo.
* opt-problem.cc: Likewise.
* optinfo-emit-json.cc: Likewise.
* optinfo.cc: Likewise.
* optinfo.h: Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 months agodiagnostics: improve support for nesting levels [PR116253]
David Malcolm [Mon, 4 Aug 2025 14:45:31 +0000 (10:45 -0400)] 
diagnostics: improve support for nesting levels [PR116253]

This patch adds support to sarif-replay for "nestingLevel"
from "P3358R0 SARIF for Structured Diagnostics"
https://wg21.link/P3358R0

Doing so revealed a bug where libgdiagnostics was always
creating new location_t values (and thus also
diagnostic_physical_location instances), rather than reusing
existing location_t values, leading to excess source printing.
The patch also fixes this bug, adding a new flag to libgdiagnostics
for debugging physical locations, and exposing this in sarif-replay
via a new "-fdebug-physical-locations" maintainer option.

Finally, the patch adds test coverage for the HTML sink's output
of nested diagnostics (both from a GCC plugin, and from sarif-replay).

gcc/ChangeLog:
PR diagnostics/116253
* diagnostics/context.cc (context::set_nesting_level): New.
* diagnostics/context.h (context::set_nesting_level): New decl.
* doc/libgdiagnostics/topics/compatibility.rst
(LIBGDIAGNOSTICS_ABI_5): New.
* doc/libgdiagnostics/topics/physical-locations.rst
(diagnostic_manager_set_debug_physical_locations): New.
* libgdiagnostics++.h (manager::set_debug_physical_locations):
New.
* libgdiagnostics-private.h
(private_diagnostic_set_nesting_level): New decl.
* libgdiagnostics.cc (diagnostic_manager::diagnostic_manager):
Initialize m_debug_physical_locations.
(diagnostic_manager::new_location_from_file_and_line): Add debug
printing.
(diagnostic_manager::new_location_from_file_line_column):
Likewise.
(diagnostic_manager::new_location_from_range): Likewise.
(diagnostic_manager::set_debug_physical_locations): New.
(diagnostic_manager::ensure_linemap_for_file_and_line): Avoid
redundant calls to linemap_add.
(diagnostic_manager::new_location): Add debug printing.
(diagnostic_manager::m_debug_physical_locations): New field.
(diagnostic::diagnostic): Initialize m_nesting_level.
(diagnostic::get_nesting_level): New accessor.
(diagnostic::set_nesting_level): New.
(diagnostic::m_nesting_level): New field.
(diagnostic_manager::emit_va): Set and reset the nesting level
of the context from that of the diagnostic.
(diagnostic_manager_set_debug_physical_locations): New.
(private_diagnostic_set_nesting_level): New.
* libgdiagnostics.h
(diagnostic_manager_set_debug_physical_locations): New decl.
* libgdiagnostics.map (LIBGDIAGNOSTICS_ABI_5): New.
* libsarifreplay.cc (sarif_replayer::handle_result_obj): Support
the "nestingLevel" property.
* libsarifreplay.h (replay_options::m_debug_physical_locations):
New field.
* sarif-replay.cc: Add -fdebug-physical-locations.

gcc/testsuite/ChangeLog:
PR diagnostics/116253
* gcc.dg/plugin/diagnostic-test-nesting-html.c: New test.
* gcc.dg/plugin/diagnostic-test-nesting-html.py: New test script.
* gcc.dg/plugin/plugin.exp: Add it.
* libgdiagnostics.dg/test-multiple-lines.c: Update expected output
to show fix-it hint.
* sarif-replay.dg/2.1.0-valid/nested-diagnostics-1.sarif: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 months agodiagnostics: avoid stray trailing space in html sink in sarif-replay [PR116792]
David Malcolm [Mon, 4 Aug 2025 14:45:31 +0000 (10:45 -0400)] 
diagnostics: avoid stray trailing space in html sink in sarif-replay [PR116792]

For the common case where a diagnostic has no metadata, sarif-replay's
html output was adding a stray space followed by an empty <div> for
the metadata.

Fixed thusly.

gcc/ChangeLog:
PR diagnostics/116792
* diagnostics/html-sink.cc
(html_builder::make_element_for_diagnostic): Don't add the
metadata element if it's empty.
(html_builder::make_element_for_metadata): Return null rather than
an empty element.

gcc/testsuite/ChangeLog:
PR diagnostics/116792
* gcc.dg/plugin/diagnostic-test-graphs-html.py: Remove trailing
space from expected text of message.
* sarif-replay.dg/2.1.0-valid/embedded-links-check-html.py:
Likewise.
* sarif-replay.dg/2.1.0-valid/graphs-check-html.py: Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 months agodiagnostics: move diagnostics::counters to its own header
David Malcolm [Mon, 4 Aug 2025 14:45:30 +0000 (10:45 -0400)] 
diagnostics: move diagnostics::counters to its own header

gcc/ChangeLog:
* diagnostics/context.h: Move struct counters to its own header
and include it.
* diagnostics/counters.h: New file, from the above.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 months agodiagnostics: split source_printing_options out into its own header
David Malcolm [Mon, 4 Aug 2025 14:45:30 +0000 (10:45 -0400)] 
diagnostics: split source_printing_options out into its own header

No functional change intended.

gcc/ChangeLog:
* diagnostics/context.h: Split struct source_printing_options out
into "diagnostics/source-printing-options.h" and include it.
* diagnostics/source-printing-options.h: New file, from the above.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 months agodiagnostics: rename option_manager to option_id_manager and split out from context.h
David Malcolm [Mon, 4 Aug 2025 14:45:30 +0000 (10:45 -0400)] 
diagnostics: rename option_manager to option_id_manager and split out from context.h

This patch splits out class option_manager to its own header,
and renames it to class option_id_manager to better describe its
purpose.

No functional change intended.

gcc/ChangeLog:
* diagnostics/context.cc: Update for renaming of option_manager to
option_id_manager and of context::m_option_mgr to
context::m_option_id_mgr.
* diagnostics/context.h: Likewise, moving class declaration to a
new diagnostics/option-id-manager.h.
* diagnostics/lazy-paths.cc: Likewise.
* diagnostics/option-id-manager.h: New file, from material in
diagnostics/context.h.
* lto-wrapper.cc: Update for renaming of option_manager to
option_id_manager.
* opts-common.cc: Likewise.
* opts-diagnostic.h: Likewise.
* opts.cc: Likewise.
* toplev.cc: Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 months agodiagnostics: fix comment in buffering.h
David Malcolm [Mon, 4 Aug 2025 14:45:30 +0000 (10:45 -0400)] 
diagnostics: fix comment in buffering.h

gcc/ChangeLog:
* diagnostics/buffering.h: Update comment to refer to output sinks
rather than output formats.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 months agogimple-warn-recursion.cc: add missing auto_diagnostic_group
David Malcolm [Mon, 4 Aug 2025 14:45:29 +0000 (10:45 -0400)] 
gimple-warn-recursion.cc: add missing auto_diagnostic_group

gcc/ChangeLog:
* gimple-warn-recursion.cc (pass_warn_recursion::execute): Add
missing auto_diagnostic_group.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 months agoasf: Fix null pointer dereference in is_store_forwarding [PR121303]
Konstantinos Eleftheriou [Wed, 30 Jul 2025 15:06:33 +0000 (17:06 +0200)] 
asf: Fix null pointer dereference in is_store_forwarding [PR121303]

We were calling `is_store_forwarding` with a NULL value for `off_val`,
which was causing a null pointer dereference in `is_constant`, leading
to an ICE.

This patch updates the call to `is_constant` in `is_store_forwarding`
and adds a check for `off_val`, in order to update it with the right
value.

Bootstrapped/regtested on AArch64 and x86_64.

PR rtl-optimization/121303

gcc/ChangeLog:

* avoid-store-forwarding.cc (is_store_forwarding): Add check
for `off_val` in `is_store_forwarding`.

gcc/testsuite/ChangeLog:

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

2 months agoc++: Add #line testcase for CWG2580 [PR120778]
Jakub Jelinek [Mon, 4 Aug 2025 13:28:29 +0000 (15:28 +0200)] 
c++: Add #line testcase for CWG2580 [PR120778]

Contrary to what the paper says, I think for #line directives we diagnose
everything we should (sure, some diagnostics are pedwarns).

2025-08-04  Jakub Jelinek  <jakub@redhat.com>

PR preprocessor/120778
* g++.dg/DRs/dr2580.C: New test.

2 months agoada: Update Assertion_Policy handling in GNATProve mode
Viljar Indus [Wed, 16 Jul 2025 11:57:51 +0000 (14:57 +0300)] 
ada: Update Assertion_Policy handling in GNATProve mode

Previously in GNATProve_Mode the frontend would overwrite all of
the assertion policies to check in order to force the generation
of all of the assertions.

This however prevents GNATProve from performing policy related
checks in the tool. Since they are all artificially changed to
check.

This patch removes the modifications to the applicable assertion
policies and instead prevents code from ignored entities being
removed when in GNATProve_Mode.

gcc/ada/ChangeLog:

* contracts.adb: Use Is_Ignored_In_Codegen instead of just
using Is_Ignored.
* exp_ch6.adb: Likewise.
* exp_prag.adb: Likewise.
* exp_util.adb: Likewise.
* frontend.adb: Avoid removal of ignored nodes in GNATProve_Mode.
* gnat1drv.adb: Avoid forcing Assertions_Enabled in GNATProve_Mode.
* lib-writ.adb (Write_With_File_Names): Avoid early exit
with ignored entities in GNATProve_Mode.
* lib-xref.adb: Likewise.
* opt.adb: Remove check for Assertions_Enabled.
* sem_attr.adb: Use Is_Ignored_In_Codegen instead of Is_Ignored.
* sem_ch13.adb: Likewise. Additionally always add predicates in
GNATProve_Mode.
* sem_prag.adb: Likewise. Additionally remove modifications
to applied policies in GNATProve_Mode.
* sem_util.adb (Is_Ignored_In_Codegen): New function that overrides
Is_Ignored in GNATProve_Mode and Codepeer_Mode.
(Is_Ignored_Ghost_Pragma_In_Codegen): Likewise for
Is_Ignored_Ghost_Pragma.
(Is_Ignored_Ghost_Entity_In_Codegen): Likewise for
Is_Ignored_Ghost_Entity.
(Policy_In_List): Remove overriding of policies in GNATProve_Mode.
* sem_util.ads: Add specs for new functions.
* (Predicates_Enabled): Always generate predicates in
GNATProve_Mode.

2 months agoada: Make pp and friends more robust
Bob Duff [Wed, 23 Jul 2025 18:46:13 +0000 (14:46 -0400)] 
ada: Make pp and friends more robust

Print_Node_Ref, which is called by pp, sometimes calls
Compile_Time_Known_Value, which blows up if Entity (N)
is empty. Rearrange the tests here, and test for
Present (Entity (N)) before calling Compile_Time_Known_Value.
Remove test "Nkind (N) in N_Subexpr", which is redundant with other
tests.

We don't want to make Compile_Time_Known_Value more
robust; you shouldn't call it on half-baked nodes.
But ideally pp should be able to print such nodes.

This change fixes one of many such cases.

gcc/ada/ChangeLog:

* treepr.adb (Print_Node_Ref): Protect against
Entity (N) being empty before calling
Compile_Time_Known_Value.

2 months agoada: Check Compile_Time_Errors removed in Ghost code
Viljar Indus [Thu, 24 Jul 2025 07:49:11 +0000 (10:49 +0300)] 
ada: Check Compile_Time_Errors removed in Ghost code

gcc/ada/ChangeLog:

* sem_prag.adb (Validate_Compile_Time_Warning_Errors):
Check if the original compile time pragma was replaced and
validate the original node instead.

2 months agoada: Refactor Validate_Compile_Time_Warning_Or_Error
Viljar Indus [Thu, 24 Jul 2025 06:55:45 +0000 (09:55 +0300)] 
ada: Refactor Validate_Compile_Time_Warning_Or_Error

Simplify the creation of the control characters in
Validate_Compile_Time_Warning_Or_Error.

gcc/ada/ChangeLog:

* sem_prag.adb (Validate_Compile_Time_Warning_Or_Error):
simplify the implementation.

2 months agoada: Implement accessibility legality check for discriminated function result.
Steve Baird [Tue, 22 Jul 2025 19:34:50 +0000 (12:34 -0700)] 
ada: Implement accessibility legality check for discriminated function result.

If a function result type has an access discriminant, then we already
generate a run-time accessibility check for a return statement. But if
we know statically that the check (if executed) is going to fail, then
that should be rejected at compile-time as a violation of RM 6.5(5.9).
Add this additional compile-time check.

gcc/ada/ChangeLog:

* exp_ch6.adb (Apply_Access_Discrims_Accessibility_Check): If the
accessibility level being checked is known statically, then
statically check it against the level of the function being
returned from.

2 months agoada: Keep Ghost_Mode related variables in a record
Viljar Indus [Wed, 23 Jul 2025 08:59:10 +0000 (11:59 +0300)] 
ada: Keep Ghost_Mode related variables in a record

Simplify the storing process for ghost mode related variables and
make the process more extendable if new ghost mode related features
are added.

gcc/ada/ChangeLog:

* atree.adb: update references to Ghost_Mode.
* exp_ch3.adb: use a structure type to store all of the existing
ghost mode related state variables.
* exp_disp.adb: Likewise.
* exp_spark.adb: Likewise.
* exp_util.adb: Likewise.
* expander.adb: Likewise.
* freeze.adb: Likewise and replace references to existing ghost
mode variables.
* ghost.adb (Install_Ghost_Region): install the changes of
the region in to the new Ghost_Config structure.
(Restore_Ghost_Region): Use the new Ghost_Config instead.
In general replace all references to the existing ghost mode
variables with the new structure equivalent.
* ghost.ads (Restore_Ghost_Region): update the spec.
* opt.ads (Ghost_Config_Type): A new type that has two of the
previous ghost code related global variables as memembers -
Ghost_Mode and Ignored_Ghost_Region.
(Ghost_Config) New variable to store the previous Ghost_Mode and
Ignored_Ghost_Region info.
* rtsfind.adb: Replace references to existing ghost mode variables.
* sem.adb: Likewise.
* sem_ch12.adb: Likewise.
* sem_ch13.adb: Likewise.
* sem_ch3.adb: Likewise.
* sem_ch5.adb: Likewise.
* sem_ch6.adb: Likewise.
* sem_ch7.adb: Likewise.
* sem_prag.adb: Likewise.
* sem_util.adb: Likewise.

2 months agoada: Avoid generating incorrect warning
Steve Baird [Mon, 21 Jul 2025 23:23:20 +0000 (16:23 -0700)] 
ada: Avoid generating incorrect warning

Do not generate a warning stating that the size of a formal parameter
is 8 bits unless the size of the formal parameter is 8 bits.

gcc/ada/ChangeLog:

* freeze.adb (Freeze_Profile): Do not emit a warning stating that
a formal parameter's size is 8 if the parameter's size is not 8.

2 months agoada: Fix code quality issue in table.adb
Viljar Indus [Tue, 22 Jul 2025 07:17:59 +0000 (10:17 +0300)] 
ada: Fix code quality issue in table.adb

gcc/ada/ChangeLog:

* table.adb (Max): Move variable to the body and initialize
it with the same value as in the Init function.
* table.ads (Max): Likewise.

2 months agoada: Misc parser cleanup
Bob Duff [Mon, 21 Jul 2025 13:43:24 +0000 (09:43 -0400)] 
ada: Misc parser cleanup

...which might make it easier to deal with incorrectly shared
subtrees created during parsing.

There were several Idents arrays, with duplicated code and commentary.
And the related code had somewhat diverged -- different comments,
different index subtypes (Pos vs. Int), etc.

DRY: Move at least some of the code into Par.Util. Raise
Program_Error if the array overflows; there is really no
reason not to check, along with several comments saying
we don't check. In the unlikely event that the array
overflows, the compiler will now crash, which seems better
than erroneous execution (which could conceivably cause
bad code to be generated).

Move the block comments titled
"Handling Semicolon Used in Place of IS" and
"Handling IS Used in Place of Semicolon" so they
are together, which seems obviously desirable.
Rewrite the latter comment.
No need to denigrate other parsers.

gcc/ada/ChangeLog:

* par.adb: Move and rewrite some comments.
(Util): Shared code and comments for dealing with
defining_identifier_lists.
* par-util.adb (Append): Shared code for appending
one identifier onto Defining_Identifiers.
(P_Def_Ids): Shared code for parsing a defining_identifier_list.
Unfortunately, this is not used in all cases, because some of
them mix in sophisticated error recovery, which we do not
modify here.
* par-ch12.adb (P_Formal_Object_Declarations):
Use Defining_Identifiers and related code.
* par-ch3.adb (P_Identifier_Declarations): Likewise.
(P_Known_Discriminant_Part_Opt): Likewise.
(P_Component_Items): Likewise.
* par-ch6.adb (P_Formal_Part): Likewise.

2 months agoFail early when SLP instance build fails
Richard Biener [Mon, 4 Aug 2025 11:29:16 +0000 (13:29 +0200)] 
Fail early when SLP instance build fails

The following makes us fail earlier when parts of the SLP build fails.
Currently we rely on hybrid stmt detection later to discover not all
stmts are covered by SLP, but this code should go away.  I've also
seen a case of a missed gcond SLP build that went undetected.  So
the following makes us fail during vect_analyze_slp if any of the
SLP instances we expect to discover fails.

* tree-vect-slp.cc (vect_analyze_slp): When analyzing a loop
and slp instance discovery fails, immediately fail the whole
process.

2 months agolibcpp: Use pedwarn instead of warning for CWG2578 diagnostics [PR120778]
Jakub Jelinek [Mon, 4 Aug 2025 12:27:14 +0000 (14:27 +0200)] 
libcpp: Use pedwarn instead of warning for CWG2578 diagnostics [PR120778]

This is another case which changed from compile time undefined behavior
to ill-formed, diagnostic required.  Now, we warn on this, so pedantically
that is good enough, maybe all we need is a testcase, but the following
patch changes it to a pedwarn for C++26.

2025-08-04  Jakub Jelinek  <jakub@redhat.com>

PR preprocessor/120778
* macro.cc (stringify_arg): For C++26 emit a pedarn instead of warning
for \ at the end of stringification.

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

2 months agolibstdc++: Fix dereferencing of std::indirect xvalues [PR121128]
Tomasz Kamiński [Fri, 1 Aug 2025 07:21:27 +0000 (09:21 +0200)] 
libstdc++: Fix dereferencing of std::indirect xvalues [PR121128]

Forr rvalues the _Self parameter deduces a non-reference type. Consequently,
((_Self)__self) moved the object to a temporary, which then destroyed on
function exit.

This patch fixes this by using a C-style cast __self to (const indirect&).
This not only resolves the above issue but also correctly handles types that
are derived (publicly and privately) from indirect. Allocator requirements in
[allocator.requirements.general] p22 guarantee that dereferencing const _M_objp
works with equivalent semantics to dereferencing _M_objp.

PR libstdc++/121128

libstdc++-v3/ChangeLog:

* include/bits/indirect.h (indirect::operator*):
Cast __self to approparietly qualified indirect.
* testsuite/std/memory/indirect/access.cc: New test.
* testsuite/std/memory/polymorphic/access.cc: New test.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2 months agoaarch64: Check the mode of SVE ACLE function results
Richard Sandiford [Mon, 4 Aug 2025 10:45:36 +0000 (11:45 +0100)] 
aarch64: Check the mode of SVE ACLE function results

After previous patches, we should always get a VNx16BI result
for ACLE intrinsics that return svbool_t.  This patch adds
an assert that checks a more general condition than that.

gcc/
* config/aarch64/aarch64-sve-builtins.cc
(function_expander::expand): Assert that the return value
has an appropriate mode.

2 months agoaarch64: Use VNx16BI for svdupq_b*
Richard Sandiford [Mon, 4 Aug 2025 10:45:36 +0000 (11:45 +0100)] 
aarch64: Use VNx16BI for svdupq_b*

This patch continues the work of making ACLE intrinsics use VNx16BI
for svbool_t results.  It deals with the predicate forms of svdupq.

The general predicate expansion builds an equivalent integer vector
and then compares it with zero.  This patch therefore relies on
the earlier patches to the comparison patterns.

gcc/
* config/aarch64/aarch64-protos.h
(aarch64_convert_sve_data_to_pred): Remove the mode argument.
* config/aarch64/aarch64.cc
(aarch64_sve_emit_int_cmp): Allow PRED_MODE to be VNx16BI or
the natural predicate mode for the data mode.
(aarch64_convert_sve_data_to_pred): Remove the mode argument
and instead always create a VNx16BI result.
(aarch64_expand_sve_const_pred): Update call accordingly.
* config/aarch64/aarch64-sve-builtins-base.cc
(svdupq_impl::expand): Likewise, ensuring that the result
has mode VNx16BI.

gcc/testsuite/
* gcc.target/aarch64/sve/acle/general/dupq_13.c: New test.

2 months agoaarch64: Use VNx16BI for svdup_b*
Richard Sandiford [Mon, 4 Aug 2025 10:45:35 +0000 (11:45 +0100)] 
aarch64: Use VNx16BI for svdup_b*

This patch continues the work of making ACLE intrinsics use VNx16BI
for svbool_t results.  It deals with the predicate forms of svdup.

gcc/
* config/aarch64/aarch64-protos.h
(aarch64_emit_sve_pred_vec_duplicate): Declare.
* config/aarch64/aarch64.cc
(aarch64_emit_sve_pred_vec_duplicate): New function.
* config/aarch64/aarch64-sve.md (vec_duplicate<PRED_ALL:mode>): Use it.
* config/aarch64/aarch64-sve-builtins-base.cc
(svdup_impl::expand): Handle boolean values specially.  Check for
constants and fall back on aarch64_emit_sve_pred_vec_duplicate
for the variable case, ensuring that the result has mode VNx16BI.

gcc/testsuite/
* gcc.target/aarch64/sve/acle/general/dup_1.c: New test.

2 months agoaarch64: Use VNx16BI for svpnext*
Richard Sandiford [Mon, 4 Aug 2025 10:45:34 +0000 (11:45 +0100)] 
aarch64: Use VNx16BI for svpnext*

This patch continues the work of making ACLE intrinsics use VNx16BI
for svbool_t results.  It deals with the svpnext* intrinsics.

gcc/
* config/aarch64/iterators.md (PNEXT_ONLY): New int iterator.
* config/aarch64/aarch64-sve.md
(@aarch64_sve_<sve_pred_op><mode>): Restrict SVE_PITER pattern
to VNx16BI_ONLY.
(@aarch64_sve_<sve_pred_op><mode>): New PNEXT_ONLY pattern for
PRED_HSD.
(*aarch64_sve_<sve_pred_op><mode>): Likewise.
(*aarch64_sve_<sve_pred_op><mode>_cc): Likewise.

gcc/testsuite/
* gcc.target/aarch64/sve/acle/general/pnext_3.c: New test.