]> gcc.gnu.org Git - gcc.git/log
gcc.git
7 months agogccrs: Remove class AST::InherentImplItem
Owen Avery [Tue, 28 Nov 2023 06:07:00 +0000 (01:07 -0500)]
gccrs: Remove class AST::InherentImplItem

gcc/rust/ChangeLog:

* ast/rust-ast-full-decls.h
(class InherentImplItem): Remove.
* ast/rust-ast.h
(class InherentImplItem): Remove.
(class SingleASTNode):
Store pointer to AssociatedItem instead of InherentImplItem.

* ast/rust-ast.cc
(SingleASTNode::SingleASTNode):
Use clone_associated_item instead of clone_inherent_impl_item.
(SingleASTNode::operator=): Likewise.

* ast/rust-item.h
(class InherentImpl):
Use AssociatedItem rather than InherentImplItem.
(class Function): Likewise.
(class ConstantItem): Likewise.
* ast/rust-macro.h
(class MacroInvocation): Likewise.
* expand/rust-expand-visitor.cc
(ExpandVisitor::visit): Likewise.
* parse/rust-parse-impl.h
(Parser::parse_impl): Likewise.
(Parser::parse_inherent_impl_item): Likewise.
(Parser::parse_inherent_impl_function_or_method): Likewise.
* parse/rust-parse.h
(Parser::parse_inherent_impl_item): Likewise.
(Parser::parse_inherent_impl_function_or_method): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
7 months agogccrs: Remove backend dependancy on resolution rib information
Philip Herron [Mon, 2 Oct 2023 17:41:33 +0000 (18:41 +0100)]
gccrs: Remove backend dependancy on resolution rib information

When making more desugaring for the HIR we can need to add new Let bindings
which will require namesolution information but also rib information for
which block the let binding is associated which was very unnessecary. This
patch simply updates the BLOCK_CONTEXT of the current scope as we are
compiling and encounter HIR::LetStmts instead of trying to do it all
upfront which lots of wierd checks

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc (HIRCompileBase::compile_locals_for_block): removed
* backend/rust-compile-base.h: update header
* backend/rust-compile-block.cc (CompileBlock::visit): remove old logic
* backend/rust-compile-expr.cc (CompileExpr::generate_closure_function): likewise
* backend/rust-compile-stmt.cc (CompileStmt::visit): likewise
* backend/rust-compile-var-decl.h: ensure we setup tuple bindings correctly

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
7 months agogccrs: Add a regression test for unsafe module validation
Pierre-Emmanuel Patry [Tue, 21 Nov 2023 18:34:36 +0000 (19:34 +0100)]
gccrs: Add a regression test for unsafe module validation

Add a new test to check for unsafe modules during AST validation pass.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Emit an error on unsafe modules
Pierre-Emmanuel Patry [Tue, 21 Nov 2023 17:51:21 +0000 (18:51 +0100)]
gccrs: Emit an error on unsafe modules

An error should be emitted on unsafe modules during the AST validation
pass as the syntax allows those even though they're not alowed later down
the line.

gcc/rust/ChangeLog:

* ast/rust-item.h: Add safety getter to modules.
* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Check
a module's safety and emit an error when meeting an unsafe module.
* checks/errors/rust-ast-validation.h: Add function prototype.
* parse/rust-parse-impl.h (Parser::parse_module): Move the module locus
to the first token instead of the mod keyword.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Parse module safety
Pierre-Emmanuel Patry [Tue, 21 Nov 2023 17:28:30 +0000 (18:28 +0100)]
gccrs: Parse module safety

Unsafe module are rejected at a later stage but could not be parsed
properly. This commit changes the parser in order to allow unsafe module
in the AST.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_vis_item): Dispatch to parse
module when meeting an unsafe module.
(Parser::parse_module): Set unsafe status when the parser encounter an
unsafe keyword.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add unsafety member to modules
Pierre-Emmanuel Patry [Tue, 21 Nov 2023 16:56:10 +0000 (17:56 +0100)]
gccrs: Add unsafety member to modules

The rust syntax allows unsafe module even if those are rejected at a
later stage.

gcc/rust/ChangeLog:

* ast/rust-item.h: Add safety status to Modules in the AST.
* parse/rust-parse-impl.h (Parser::parse_module): Adapt constructors.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Create base class for TupleStructItems and TuplePatternItems
Owen Avery [Tue, 3 Oct 2023 21:50:14 +0000 (17:50 -0400)]
gccrs: Create base class for TupleStructItems and TuplePatternItems

gcc/rust/ChangeLog:

* hir/tree/rust-hir-pattern.h
(class TupleItems): New.
(class TupleStructItems): Inherit from TupleItems.
(class TuplePatternItems): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
7 months agogccrs: toplevel: Resolve `use` declarations
Arthur Cohen [Wed, 23 Aug 2023 11:51:06 +0000 (13:51 +0200)]
gccrs: toplevel: Resolve `use` declarations

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::insert_or_error_out): New functions.
(TopLevel::handle_use_dec): New function.
(flatten_rebind): Likewise.
(flatten_list): Likewise.
(flatten_glob): Likewise.
(flatten): Likewise.
(TopLevel::visit): Visit various `use` declaration nodes.
* resolve/rust-toplevel-name-resolver-2.0.h: Declare functions and
visitors.

7 months agogccrs: early: Move `use` declaration resolving to TopLevel
Arthur Cohen [Wed, 23 Aug 2023 11:50:54 +0000 (13:50 +0200)]
gccrs: early: Move `use` declaration resolving to TopLevel

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc
(Early::visit): Remove visitors.
* resolve/rust-early-name-resolver-2.0.h: Likewise.

7 months agogccrs: ast: Add NodeId to UseTree base class
Arthur Cohen [Wed, 23 Aug 2023 11:49:24 +0000 (13:49 +0200)]
gccrs: ast: Add NodeId to UseTree base class

gcc/rust/ChangeLog:

* ast/rust-item.h (class UseTree): Add `node_id` member.

7 months agogccrs: toplevel: Add comment about running the collector twice
Arthur Cohen [Tue, 22 Aug 2023 15:29:56 +0000 (17:29 +0200)]
gccrs: toplevel: Add comment about running the collector twice

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::insert_or_error_out): Add documentation comment.
(TopLevel::go): Likewise.

7 months agogccrs: early: Resolve paths properly
Arthur Cohen [Mon, 21 Aug 2023 14:52:48 +0000 (16:52 +0200)]
gccrs: early: Resolve paths properly

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc
(Early::insert_once): New function.
(Early::visit): Likewise.
* resolve/rust-early-name-resolver-2.0.h: Likewise.

7 months agogccrs: late: Start storing mappings properly in the resolver
Arthur Cohen [Tue, 22 Aug 2023 15:29:05 +0000 (17:29 +0200)]
gccrs: late: Start storing mappings properly in the resolver

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Store mappings
after having resolved them.
* resolve/rust-late-name-resolver-2.0.h: Add `TypePath` visitor.

7 months agogccrs: late: Start setting up builtin types
Arthur Cohen [Tue, 22 Aug 2023 14:58:28 +0000 (16:58 +0200)]
gccrs: late: Start setting up builtin types

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc
(Late::setup_builtin_types): New function.
(Late::go): Setup builtin types.
* resolve/rust-late-name-resolver-2.0.h:
* resolve/rust-name-resolution-context.cc
(NameResolutionContext::map_usage): New function.
* resolve/rust-name-resolution-context.h: Likewise.

7 months agogccrs: nr2.0: Store mappings in NameResolutionContext
Arthur Cohen [Tue, 22 Aug 2023 13:40:25 +0000 (15:40 +0200)]
gccrs: nr2.0: Store mappings in NameResolutionContext

gcc/rust/ChangeLog:

* resolve/rust-name-resolution-context.h: Store a reference to the
mappings.
* resolve/rust-name-resolution-context.cc
(NameResolutionContext::NameResolutionContext): Likewise.

7 months agogccrs: toplevel: Use DefaultResolver for Function
Arthur Cohen [Wed, 15 Nov 2023 10:33:25 +0000 (11:33 +0100)]
gccrs: toplevel: Use DefaultResolver for Function

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Use
the DefaultResolver in the toplevel visitor.

7 months agogccrs: nr2.0: Add base for late name resolution
Arthur Cohen [Fri, 23 Jun 2023 14:37:51 +0000 (16:37 +0200)]
gccrs: nr2.0: Add base for late name resolution

gcc/rust/ChangeLog:

* Make-lang.in: Compile late name resolver.
* resolve/rust-late-name-resolver-2.0.cc: New file.
* resolve/rust-late-name-resolver-2.0.h: New file.

7 months agogccrs: ctx: Add Labels ForeverStack to the resolver.
Arthur Cohen [Thu, 17 Aug 2023 12:07:27 +0000 (14:07 +0200)]
gccrs: ctx: Add Labels ForeverStack to the resolver.

Not sure if dealing with "labels" is the proper way of doing so, so we
might eventually change this to use `resolver.values` later on.

gcc/rust/ChangeLog:

* resolve/rust-name-resolution-context.h: Add a Labels stack.

7 months agogccrs: Added support to Parse ASYNC function
M V V S Manoj Kumar [Tue, 21 Nov 2023 16:34:24 +0000 (22:04 +0530)]
gccrs: Added support to Parse ASYNC function

Fixes issue #2650
The parser now parses ASYNC functions. Added ASYNC case to parse_item
Added a new function parse_async_item which is called in
parse_vis_item to handle the ASYNC case. Parse_async_item
also checks the current Rust edition and generates an error if the
edition is 2015

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_item): Likewise.
(Parser::parse_vis_item): Likewise.
(Parser::parse_async_item): Likewise.
* parse/rust-parse.h: Made declaration for parse_async_item.

gcc/testsuite/ChangeLog:

* rust/compile/issue-2650-1.rs: New test.(edition=2018)
* rust/compile/issue-2650-2.rs: New test.(edition=2015)

Signed-off-by: M V V S Manoj Kumar <mvvsmanojkumar@gmail.com>
7 months agogccrs: Introduce a proper keyword list
Pierre-Emmanuel Patry [Thu, 16 Nov 2023 15:20:49 +0000 (16:20 +0100)]
gccrs: Introduce a proper keyword list

The old "keyword" list was used for the lexer, and could therefore not
be used with keyword spanning over multiple tokens as those tokens should
remain lexed as is. Hence the introduction of a new list macro for
keyword exclusive tasks. This also means we can no longer match a token
id for each keyword. The token id map has been renamed to keep it's
properties.

gcc/rust/ChangeLog:

* lex/rust-lex.cc (Lexer::classify_keyword): Update keyword map name.
* lex/rust-token.h (enum PrimitiveCoreType): Remove some deprecated
comments.
* util/rust-keyword-values.cc (get_keywords): Update the keyword map
name.
(RS_TOKEN): Define as empty
(RS_TOKEN_KEYWORD_2015): Add the emission value.
(RS_TOKEN_KEYWORD_2018): Likewise.
* util/rust-keyword-values.h (RS_KEYWORD_LIST): Introduce the keyword
list.
(RS_TOKEN_KEYWORD_2018): Define multiple new keywords.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Replace some weak keyword raw value with constexpr
Pierre-Emmanuel Patry [Thu, 16 Nov 2023 14:18:41 +0000 (15:18 +0100)]
gccrs: Replace some weak keyword raw value with constexpr

Raw values may have typos or contain error, replacing those will
improve the codebase.

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): Replace raw value.
* parse/rust-parse-impl.h (Parser::is_macro_rules_def): Likewise.
(Parser::parse_item): Likewise.
(Parser::parse_vis_item): Likewise.
(Parser::parse_macro_rules_def): Likewise.
(Parser::parse_union): Likewise.
(Parser::parse_trait_impl_item): Likewise.
(Parser::parse_stmt): Likewise.
(Parser::parse_stmt_or_expr): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add a list of weak keyword
Pierre-Emmanuel Patry [Thu, 16 Nov 2023 14:02:11 +0000 (15:02 +0100)]
gccrs: Add a list of weak keyword

Retrieving a weak keyword value is done using raw values. Introducing a
list of weak keywords means this could change.

gcc/rust/ChangeLog:

* util/rust-keyword-values.h (class WeakKeywords): Add new class with
weak keyword constexpr.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Replace some keyword raw values
Pierre-Emmanuel Patry [Thu, 16 Nov 2023 12:41:46 +0000 (13:41 +0100)]
gccrs: Replace some keyword raw values

Raw values cannot be understood easily by most tools. This commit replace
some raw values with their variable counterpart.

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): Replace raw value
with keyword call.
* ast/rust-ast.h: Likewise.
* parse/rust-parse-impl.h (Parser::parse_path_ident_segment): Likewise.
(Parser::parse_macro_match_fragment): Likewise.
(Parser::parse_extern_crate): Likewise.
(Parser::parse_use_tree): Likewise.
(Parser::parse_const_item): Likewise.
(Parser::parse_literal_expr): Likewise.
(Parser::parse_maybe_named_param): Likewise.
(Parser::parse_pattern_no_alt): Likewise.
(Parser::left_denotation): Likewise.
(Parser::parse_path_in_expression_pratt): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add await keyword
Pierre-Emmanuel Patry [Thu, 16 Nov 2023 12:11:33 +0000 (13:11 +0100)]
gccrs: Add await keyword

The 2018 edition await keyword was missing from the keyword list.

gcc/rust/ChangeLog:

* lex/rust-token.h (enum PrimitiveCoreType): Add await keyword
definition.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Treat underscore as a keyword
Pierre-Emmanuel Patry [Thu, 16 Nov 2023 11:39:37 +0000 (12:39 +0100)]
gccrs: Treat underscore as a keyword

Make the underscore token a 2015 keyword.

gcc/rust/ChangeLog:

* lex/rust-token.h (enum PrimitiveCoreType): Change macro for
underscore in token list.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add edition separation for keywords
Pierre-Emmanuel Patry [Thu, 16 Nov 2023 10:42:35 +0000 (11:42 +0100)]
gccrs: Add edition separation for keywords

It might be required in the future to get only the keywords from a
specific edition. To do so we need a mean to differentiate keywords based
on their edition. This commit changes the existing keyword macro to
allow such behavior.

gcc/rust/ChangeLog:

* lex/rust-token.h (enum PrimitiveCoreType): Change enum macro calls.
(RS_TOKEN_KEYWORD): Remove generic token keyword macro.
(RS_TOKEN_KEYWORD_2015): Introduce keywords for edition 2015.
(RS_TOKEN_KEYWORD_2018): Likewise with edition 2018.
* lex/rust-token.cc (RS_TOKEN_KEYWORD): Remove old macro definition.
(RS_TOKEN_KEYWORD_2015): Replace with 2015 definition...
(RS_TOKEN_KEYWORD_2018): ... and 2018 definition.
* util/rust-keyword-values.cc (RS_TOKEN_KEYWORD):  Likewise.
(RS_TOKEN_KEYWORD_2015): Likewise.
(RS_TOKEN_KEYWORD_2018): Likewise.
* util/rust-keyword-values.h (RS_TOKEN_KEYWORD): Likewise.
(RS_TOKEN_KEYWORD_2015): Likewise.
(RS_TOKEN_KEYWORD_2018): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Replace TOK suffix with KW
Pierre-Emmanuel Patry [Wed, 15 Nov 2023 15:24:56 +0000 (16:24 +0100)]
gccrs: Replace TOK suffix with KW

TOK suffix was chosen to disambiguate some identifiers with c++ reserved
keyword. Even though this list lies within the rust-token header, this
macro is used in many context sometimes unrelated with the lexer and
tokens. This TOK suffix may appear surprising in such context.

gcc/rust/ChangeLog:

* lex/rust-token.h (enum PrimitiveCoreType): Change keyword suffix from
tok to kw.
* ast/rust-ast-collector.cc (TokenCollector::visit): Update suffix to
match the new declaration.
* lex/rust-lex.cc (Lexer::parse_raw_identifier): Likewise.
* parse/rust-parse-impl.h (can_tok_start_type): Likewise.
(Parser::parse_item): Likewise.
(Parser::parse_vis_item): Likewise.
(Parser::parse_extern_crate): Likewise.
(Parser::parse_function): Likewise.
(Parser::parse_function_qualifiers): Likewise.
(Parser::parse_struct): Likewise.
(Parser::parse_enum): Likewise.
(Parser::parse_static_item): Likewise.
(Parser::parse_trait_item): Likewise.
(Parser::parse_inherent_impl_item): Likewise.
(Parser::parse_trait_impl_item): Likewise.
(Parser::parse_extern_block): Likewise.
(Parser::parse_external_item): Likewise.
(Parser::parse_stmt): Likewise.
(Parser::parse_return_expr): Likewise.
(Parser::parse_match_expr): Likewise.
(Parser::parse_type): Likewise.
(Parser::parse_for_prefixed_type): Likewise.
(Parser::parse_type_no_bounds): Likewise.
(Parser::parse_stmt_or_expr): Likewise.
* parse/rust-parse.cc (peculiar_fragment_match_compatible): Likewie.
* util/rust-token-converter.cc (convert): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add ast validation check on union variant number
Pierre-Emmanuel Patry [Mon, 20 Nov 2023 14:41:39 +0000 (15:41 +0100)]
gccrs: Add ast validation check on union variant number

Unions with zero fields are forbidden. Add regression test for empty
unions.

gcc/rust/ChangeLog:

* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add
zero field check during ast validation pass.
* checks/errors/rust-ast-validation.h: Add union visit function
prototype.

gcc/testsuite/ChangeLog:

* rust/compile/const_generics_8.rs: Fill the union with dummy values.
* rust/compile/empty_union.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add a test regular variadic functions errors
Pierre-Emmanuel Patry [Mon, 20 Nov 2023 10:37:12 +0000 (11:37 +0100)]
gccrs: Add a test regular variadic functions errors

Add a new regression test for the error message in regular function
variadic errors during ast validation pass.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Emit an error on variadic non extern functions
Pierre-Emmanuel Patry [Mon, 20 Nov 2023 10:19:46 +0000 (11:19 +0100)]
gccrs: Emit an error on variadic non extern functions

Variadic regular functions were recently added in the parser as they
should be rejected in the ast validation pass. This commit add the ast
validation pass rejecting this kind of variadic arguments.

gcc/rust/ChangeLog:

* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add
ast validation pass to reject variadic arguments on regular functions.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add check for associated items on auto traits
Pierre-Emmanuel Patry [Mon, 20 Nov 2023 13:59:56 +0000 (14:59 +0100)]
gccrs: Add check for associated items on auto traits

Reject rust code with associated items on auto traits.

gcc/rust/ChangeLog:

* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add auto
trait associated item check in AST validation pass.
* parse/rust-parse-impl.h: Remove old error emission done during
parsing pass.

gcc/testsuite/ChangeLog:

* rust/compile/auto_trait_invalid.rs: Update old test with updated
error message.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add a regression test for super trait on auto trait
Pierre-Emmanuel Patry [Mon, 20 Nov 2023 13:16:41 +0000 (14:16 +0100)]
gccrs: Add a regression test for super trait on auto trait

Add a new regression test to highlight the error behavior with a super
trait on an auto trait.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Reject auto traits with super trait
Pierre-Emmanuel Patry [Mon, 20 Nov 2023 13:04:35 +0000 (14:04 +0100)]
gccrs: Reject auto traits with super trait

Reject auto traits containing a super trait bound during AST validation
pass.

gcc/rust/ChangeLog:

* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Reject
auto traits with super traits.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add regression test for generic auto traits
Pierre-Emmanuel Patry [Mon, 20 Nov 2023 12:53:51 +0000 (13:53 +0100)]
gccrs: Add regression test for generic auto traits

Generics are forbidden on auto traits and an error should be emitted.
This commit highlight this behavior.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Reject auto traits with generic parameters
Pierre-Emmanuel Patry [Mon, 20 Nov 2023 12:43:48 +0000 (13:43 +0100)]
gccrs: Reject auto traits with generic parameters

Generic parameters are not allowed on auto traits, the compiler should
emit an error.

gcc/rust/ChangeLog:

* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add
check for generics on auto traits.
* checks/errors/rust-ast-validation.h: Add visit function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: forever stack: Remove development debug info
Arthur Cohen [Tue, 21 Nov 2023 10:14:12 +0000 (11:14 +0100)]
gccrs: forever stack: Remove development debug info

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.hxx: Remove debug log.

7 months agogccrs: resolve: Format if properly
Arthur Cohen [Tue, 21 Nov 2023 10:13:59 +0000 (11:13 +0100)]
gccrs: resolve: Format if properly

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path): Format.

7 months agogccrs: foreverstack: Add `to_rib` method
Arthur Cohen [Fri, 25 Aug 2023 12:19:31 +0000 (14:19 +0200)]
gccrs: foreverstack: Add `to_rib` method

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.h: New method.
* resolve/rust-forever-stack.hxx: Likewise.

7 months agogccrs: foreverstack: Add `to_canonical_path` method
Arthur Cohen [Fri, 25 Aug 2023 11:40:44 +0000 (13:40 +0200)]
gccrs: foreverstack: Add `to_canonical_path` method

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.h: New method.
* resolve/rust-forever-stack.hxx: Likewise.

7 months agogccrs: forever stack: Improve resolve_path implementation
Arthur Cohen [Wed, 23 Aug 2023 11:50:16 +0000 (13:50 +0200)]
gccrs: forever stack: Improve resolve_path implementation

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.hxx: Do not copy segment when
dereferencing iterator in `find_starting_point`.

7 months agogccrs: forever stack: Fix resolve_path signature
Arthur Cohen [Thu, 21 Sep 2023 13:55:03 +0000 (15:55 +0200)]
gccrs: forever stack: Fix resolve_path signature

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.h: Fix `ForeverStack::resolve_path`
signature.
* resolve/rust-forever-stack.hxx: Likewise.
* resolve/rust-early-name-resolver-2.0.cc (Early::visit): Use new API.
(Early::visit_attributes): Likewise.

7 months agogccrs: foreverstack: Specialize `get` for Namespace::Labels
Arthur Cohen [Mon, 21 Aug 2023 14:05:22 +0000 (16:05 +0200)]
gccrs: foreverstack: Specialize `get` for Namespace::Labels

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.hxx: Add specific behavior for
`ForeverStack::get` when dealing with labels.

7 months agogccrs: forever-stack: Fix basic get logic
Arthur Cohen [Mon, 21 Aug 2023 13:52:06 +0000 (15:52 +0200)]
gccrs: forever-stack: Fix basic get logic

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.h: Improve resolve_path API.
* resolve/rust-forever-stack.hxx: Likewise and fix implementation.

7 months agogccrs: rib: Add Namespace enum
Arthur Cohen [Thu, 17 Aug 2023 12:06:50 +0000 (14:06 +0200)]
gccrs: rib: Add Namespace enum

gcc/rust/ChangeLog:

* resolve/rust-rib.h: Add Namespace enum.

7 months agogccrs: ast: Change *Path nodes API
Arthur Cohen [Thu, 17 Aug 2023 12:05:49 +0000 (14:05 +0200)]
gccrs: ast: Change *Path nodes API

gcc/rust/ChangeLog:

* ast/rust-ast.h: Change Path API to be more consistent.
* ast/rust-path.h: Likewise.
* ast/rust-ast-collector.cc (TokenCollector::visit): Use new API.
* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Likewise.
* resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path): Likewise.
* resolve/rust-forever-stack.hxx: Likewise.

7 months agogccrs: Add new test for parsing errors on self pointers
Pierre-Emmanuel Patry [Wed, 15 Nov 2023 12:53:23 +0000 (13:53 +0100)]
gccrs: Add new test for parsing errors on self pointers

Add new tests to highlight the behavior of errors thrown when meeting a
self pointer.

gcc/testsuite/ChangeLog:

* rust/compile/self_const_ptr.rs: New test.
* rust/compile/self_mut_ptr.rs: New test.
* rust/compile/self_ptr.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Report self parameter parsing error kind
Pierre-Emmanuel Patry [Wed, 15 Nov 2023 12:02:28 +0000 (13:02 +0100)]
gccrs: Report self parameter parsing error kind

Self parameter parsing errors may come from different situations, which
should not be handled in the same way. It is now possible to
differentiate a missing self parameter from a self pointer or a parsing
error.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_function): Early return on
unrecoverable errors.
(Parser::parse_trait_item): Likewise.
(Parser::parse_self_param): Update return type.
* parse/rust-parse.h (enum ParseSelfError): Add enumeration to describe
different self parameter parsing errors.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Fix error emission for self pointers
Pierre-Emmanuel Patry [Wed, 15 Nov 2023 10:08:09 +0000 (11:08 +0100)]
gccrs: Fix error emission for self pointers

Self pointer checking loop condition was inverted, the latter was
therefore never executed.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_self_param): Fix the loop
exit condition.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add a test to highlight public trait type parsing
Pierre-Emmanuel Patry [Thu, 2 Nov 2023 16:29:16 +0000 (17:29 +0100)]
gccrs: Add a test to highlight public trait type parsing

This new test highlight the parser's behavior around public trait types.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add visibility to trait item
Pierre-Emmanuel Patry [Thu, 2 Nov 2023 16:10:33 +0000 (17:10 +0100)]
gccrs: Add visibility to trait item

The compiler shall parse visibility modifiers on trait items and reject
those at a later stage (ast validation).

gcc/rust/ChangeLog:

* ast/rust-item.h (struct Visibility): Move Visibility from here...
* ast/rust-ast.h (struct Visibility): ...to here.
* parse/rust-parse-impl.h (Parser::parse_trait_item): Parse visibility
before giving it back to the item parsing function.
(Parser::parse_trait_type): Add visibility modifier.
* parse/rust-parse.h (RUST_PARSE_H): Change function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agotree-optimization/113659 - early exit vectorization and missing VUSE
Richard Biener [Tue, 30 Jan 2024 08:42:08 +0000 (09:42 +0100)]
tree-optimization/113659 - early exit vectorization and missing VUSE

The following handles the case of the main exit going to a path without
virtual use and handles it similar to the alternate exit handling.

PR tree-optimization/113659
* tree-vect-loop-manip.cc (slpeel_tree_duplicate_loop_to_edge_cfg):
Handle main exit without virtual use.

* gcc.dg/pr113659.c: New testcase.

7 months agoriscv: Move UNSPEC_XTHEAD* from unspecv to unspec
Christoph Müllner [Tue, 30 Jan 2024 09:22:27 +0000 (10:22 +0100)]
riscv: Move UNSPEC_XTHEAD* from unspecv to unspec

The UNSPEC_XTHEAD* macros ended up in the unspecv enum,
which broke gcc/testsuite/gcc.target/riscv/xtheadfmv-fmv.c.
The INSNs expect these unspecs to be not volatile.
Further, there is not reason to have them defined volatile.
So let's simply move the macros into the unspec enum.

With this patch we have again 0 fails in riscv.exp.

gcc/ChangeLog:

* config/riscv/riscv.md: Move UNSPEC_XTHEADFMV* to unspec enum.

Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
7 months agotestsuite, GDC: Update link flags [PR112861].
Iain Sandoe [Wed, 24 Jan 2024 08:05:01 +0000 (08:05 +0000)]
testsuite, GDC: Update link flags [PR112861].

The regressions here are because we do not generate a runpath for
the uninstalled libstdc++.  This patch updates the link flags handling
to simplify it.

We need to add options to locate both libgphobos and libstdc++
Usually '-L' options are added to point to the relevant directories for
the uninstalled libraries.

In cases where libraries are available as both shared and convenience
some additional checks are made.

For some targets -static-xxxx options are handled by specs substitution
and need a '-B' option rather than '-L'.  For Darwin, when embedded
runpaths are in use (the default for all versions after macOS 10.11),
'-B' is also needed to provide the runpath.

When '-B' is used, this results in a '-L' for each path that exists (so
that appending a '-L' as well is a needless duplicate).  There are also
cases where tools warn for duplicates, leading to spurious fails.
Therefore the objective is to add a single -B/-L option for each needed
path.

PR target/112861

gcc/testsuite/ChangeLog:

* lib/gdc.exp: Decide on whether to present -B or -L to reference
the paths to uninstalled libphobos and libstdc++ and use that to
generate the link flags.

7 months agolibgcc: Make heap trampoline support dynamic [PR113403].
Iain Sandoe [Sun, 28 Jan 2024 13:31:56 +0000 (13:31 +0000)]
libgcc: Make heap trampoline support dynamic [PR113403].

In order to handle system security constraints during GCC build
and test and that most platform versions cannot link to libgcc_eh
since the unwinder there is incompatible with the system one.

1. We make the support functions weak definitions.
2. We include them as a CRT for platform conditions that do not
   allow libgcc_eh.
3. We ensure that the weak symbols are exported from DSOs (which
   includes exes on Darwin) so that the dynamic linker will
   pick one instance (which avoids duplication of trampoline
   caches).

PR libgcc/113403

gcc/ChangeLog:

* config/darwin.h (DARWIN_SHARED_WEAK_ADDS, DARWIN_WEAK_CRTS): New.
(REAL_LIBGCC_SPEC): Move weak CRT handling to separate spec.
* config/i386/darwin.h (DARWIN_HEAP_T_LIB): New.
* config/i386/darwin32-biarch.h (DARWIN_HEAP_T_LIB): New.
* config/i386/darwin64-biarch.h (DARWIN_HEAP_T_LIB): New.
* config/rs6000/darwin.h (DARWIN_HEAP_T_LIB): New.

libgcc/ChangeLog:

* config.host: Build libheap_t.a for i686/x86_64 Darwin.
* config/aarch64/heap-trampoline.c (HEAP_T_ATTR): New.
(allocate_tramp_ctrl): Allow a target to build this as a weak def.
(__gcc_nested_func_ptr_created): Likewise.
* config/i386/heap-trampoline.c (HEAP_T_ATTR): New.
(allocate_tramp_ctrl): Allow a target to build this as a weak def.
(__gcc_nested_func_ptr_created): Likewise.
* config/t-darwin: Build libheap_t.a (a CRT with heap trampoline
support).

7 months agolibgcc: Make heap trampoline support dynamic [PR113403].
Iain Sandoe [Fri, 19 Jan 2024 15:57:04 +0000 (15:57 +0000)]
libgcc: Make heap trampoline support dynamic [PR113403].

This removes the heap trampoline support functions from libgcc.a and
adds them to libgcc_eh.a.  They are also present in libgcc_s.

PR libgcc/113403

libgcc/ChangeLog:

* config/aarch64/t-heap-trampoline: Move the heap trampoline
support functions from libgcc.a to libgcc_eh.a.
* config/i386/t-heap-trampoline: Likewise.

7 months agoaarch64: Avoid allocating FPRs to address registers [PR113623]
Richard Sandiford [Tue, 30 Jan 2024 09:30:35 +0000 (09:30 +0000)]
aarch64: Avoid allocating FPRs to address registers [PR113623]

For something like:

void
foo (void)
{
  int *ptr;
  asm volatile ("%0" : "=w" (ptr));
  asm volatile ("%0" :: "m" (*ptr));
}

early-ra would allocate ptr to an FPR for the first asm, thus
leaving an FPR address in the second asm.  The address was then
reloaded by LRA to make it valid.

But early-ra shouldn't be allocating at all in that kind of
situation.  Doing so caused the ICE in the PR (with LDP fusion).

Fixed by making sure that we record address references as
GPR references.

gcc/
PR target/113623
* config/aarch64/aarch64-early-ra.cc (early_ra::preprocess_insns):
Mark all registers that occur in addresses as needing a GPR.

gcc/testsuite/
PR target/113623
* gcc.c-torture/compile/pr113623.c: New test.

7 months agoaarch64: Handle debug references to removed registers [PR113636]
Richard Sandiford [Tue, 30 Jan 2024 09:30:35 +0000 (09:30 +0000)]
aarch64: Handle debug references to removed registers [PR113636]

In this PR, we entered early-ra with quite a bit of dead code.
The code was duly removed (to avoid wasting registers), but there
was a dangling reference in debug instructions, which caused an
ICE later.

Fixed by resetting a debug instruction if it references a register
that is no longer needed by non-debug instructions.

gcc/
PR target/113636
* config/aarch64/aarch64-early-ra.cc (early_ra::replace_regs): Take
the containing insn as an extra parameter.  Reset debug instructions
if they reference a register that is no longer used by real insns.
(early_ra::apply_allocation): Update calls accordingly.

gcc/testsuite/
PR target/113636
* go.dg/pr113636.go: New test.

7 months agotree-ssa-strlen: Fix up handle_store [PR113603]
Jakub Jelinek [Tue, 30 Jan 2024 08:58:05 +0000 (09:58 +0100)]
tree-ssa-strlen: Fix up handle_store [PR113603]

Since r10-2101-gb631bdb3c16e85f35d3 handle_store uses
count_nonzero_bytes{,_addr} which (more recently limited to statements
with the same vuse) can walk earlier statements feeding the rhs
of the store and call get_stridx on it.
Unlike most of the other functions where get_stridx is called first on
rhs and only later on lhs, handle_store calls get_stridx on the lhs before
the count_nonzero_bytes* call and does some si->nonzero_bytes comparison
on it.
Now, strinfo structures are refcounted and it is important not to screw
it up.
What happens on the following testcase is that we call get_strinfo on the
destination idx's base (g), which returns a strinfo at that moment
with refcount of 2, one copy referenced in bb 2 final strinfos, one in bb 3
(the vector of strinfos was unshared from the dominator there because some
other strinfo was added) and finally we process a store in bb 6.
Now, count_nonzero_bytes is called and that sees &g[1] in a PHI and
calls get_stridx on it, which in turn calls get_stridx_plus_constant
because &g + 1 address doesn't have stridx yet.  This creates a new
strinfo for it:
  si = new_strinfo (ptr, idx, build_int_cst (size_type_node, nonzero_chars),
                    basesi->full_string_p);
  set_strinfo (idx, si);
and the latter call, because it is the first one in bb 6 that needs it,
unshares the stridx_to_strinfo vector (so refcount of the g strinfo becomes
3).
Now, get_stridx_plus_constant needs to chain the new strinfo of &g[1] in
between the related strinfos, so after the g record.  Because the strinfo
is now shared between the current bb and 2 other bbs, it needs to
unshare_strinfo it (creating a new strinfo which can be modified as a copy
of the old one, decrementing refcount of the old shared one and setting
refcount of the new one to 1):
  if (strinfo *nextsi = get_strinfo (chainsi->next))
    {
      nextsi = unshare_strinfo (nextsi);
      si->next = nextsi->idx;
      nextsi->prev = idx;
    }
  chainsi = unshare_strinfo (chainsi);
  if (chainsi->first == 0)
    chainsi->first = chainsi->idx;
  chainsi->next = idx;
Now, the bug is that the caller of this a couple of frames above,
handle_store, holds on a pointer to this g strinfo (but doesn't know
about the unsharing, so the pointer is to the old strinfo with refcount
of 2), and later needs to update it, so it
          si = unshare_strinfo (si);
and modifies some fields in it.
This creates a new strinfo (with refcount of 1 which is stored into
the vector of the current bb) based on the old strinfo for g and
decrements refcount of the old one to 1.  So, now we are in inconsistent
state, because the old strinfo for g is referenced in bb 2 and bb 3
vectors, but has just refcount of 1, and then have one strinfo (the one
created by unshare_strinfo (chainsi) in get_stridx_plus_constant) which
has refcount of 1 but isn't referenced from anywhere anymore.
Later on when we free one of the bb 2 or bb 3 vectors (forgot which)
that decrements refcount from 1 to 0 and poisons the strinfo/returns it to
the pool, but then maybe_invalidate when looking at the other bb's pointer
to it ICEs.

The following patch fixes it by calling get_strinfo again, it is guaranteed
to return non-NULL, but could be an unshared copy instead of the originally
fetched shared one.

I believe we only need to do this refetching for the case where get_strinfo
is called on the lhs before get_stridx is called on other operands, because
we should be always modifying (apart from the chaining changes) the strinfo
for the destination of the statements, not other strinfos just consumed in
there.

2024-01-30  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/113603
* tree-ssa-strlen.cc (strlen_pass::handle_store): After
count_nonzero_bytes call refetch si using get_strinfo in case it
has been unshared in the meantime.

* gcc.c-torture/compile/pr113603.c: New test.

7 months agoexcept: Fix __builtin_eh_return_data_regno (-42) expansion [PR101195]
Jakub Jelinek [Tue, 30 Jan 2024 08:57:21 +0000 (09:57 +0100)]
except: Fix __builtin_eh_return_data_regno (-42) expansion [PR101195]

The expansion of this builtin emits an error if the argument is not
INTEGER_CST, otherwise uses tree_to_uhwi on the argument (which is declared
int) and then uses EH_RETURN_DATA_REGNO macro which on most targets returns
INVALID_REGNUM for all values but some small number (2 or 4); if it returns
INVALID_REGNUM, we silently expand to -1.

Now, I think the error for non-INTEGER_CST makes sense to catch when people
unintentionally don't call it with a constant (but, users shouldn't really
use this builtin anyway, it is for the unwinder only).  Initially I thought
about emitting an error for the negative values as well on which
tree_to_uhwi otherwise ICEs, but given that the function will silently
expand to -1 for INT_MAX - 1 or INT_MAX - 3 other values, I think treating
the negatives the same silently is fine too.

2024-01-30  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/101195
* except.cc (expand_builtin_eh_return_data_regno): If which doesn't
fit into unsigned HOST_WIDE_INT, return constm1_rtx.

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

7 months agotestsuite: Fix up pr113622-{2,3}.c for i686-linux [PR113622]
Jakub Jelinek [Tue, 30 Jan 2024 08:31:22 +0000 (09:31 +0100)]
testsuite: Fix up pr113622-{2,3}.c for i686-linux [PR113622]

The 2 new tests FAIL for me on i686-linux:
.../gcc/testsuite/gcc.target/i386/pr113622-2.c:5:14: error: data type of 'a' isn't suitable for a register
.../gcc/testsuite/gcc.target/i386/pr113622-2.c:5:29: error: data type of 'b' isn't suitable for a register
.../gcc/testsuite/gcc.target/i386/pr113622-2.c:5:44: error: data type of 'c' isn't suitable for a register
The problem is that the tests use vectors of double, something added
only in SSE2, while the testcases ask for just -msse which only provides
vectors of floats.

So, either it should be using floats instead of doubles, or we need
to add -msse2 to dg-options.

I've done the latter.

2024-01-30  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/113622
* gcc.target/i386/pr113622-2.c: Use -msse2 instead of -msse in
dg-options.
* gcc.target/i386/pr113622-3.c: Likewise.

7 months agoRISC-V: THEAD: Fix improper immediate value for MODIFY_DISP instruction on 32-bit...
Jin Ma [Mon, 29 Jan 2024 09:57:00 +0000 (17:57 +0800)]
RISC-V: THEAD: Fix improper immediate value for MODIFY_DISP instruction on 32-bit systems.

When using  '%ld' to print 'long long int' variable, 'fprintf' will
produce messy output on a 32-bit system, in an incorrect instruction
being generated, such as 'th.lwib a1,(a0),-16,4294967295'. And the
following error occurred during compilation:

Assembler messages:
Error: improper immediate value (18446744073709551615)

gcc/ChangeLog:

* config/riscv/thead.cc (th_print_operand_address): Change %ld
to %lld.

7 months agoc++: Handle error header names in modules [PR107594]
Nathaniel Shead [Sat, 27 Jan 2024 11:46:44 +0000 (22:46 +1100)]
c++: Handle error header names in modules [PR107594]

When there are no include paths while preprocessing a header-name token,
an empty STRING_CST is returned. This patch ensures this is handled when
attempting to create a module for this name.

PR c++/107594

gcc/cp/ChangeLog:

* module.cc (get_module): Bail on empty name.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
7 months agoRevert "testsuite: Disable strub on AIX."
Alexandre Oliva [Tue, 30 Jan 2024 03:31:18 +0000 (00:31 -0300)]
Revert "testsuite: Disable strub on AIX."

This reverts commit 9773ca519864e2e0706424b805c3314f1fbe7d10.

The fix was in commit cb62101787555b7b32607b431fdfe6fcc8f3830f.

The changes to strub-unsupported* were incorrect, those tests verify
the error messages issued when strub support is properly disabled with
TARGET_HAVE_STRUB_SUPPORT_FOR.

7 months agox86: Limit -mcmodel=large tests to lp64 target
H.J. Lu [Tue, 30 Jan 2024 02:12:14 +0000 (18:12 -0800)]
x86: Limit -mcmodel=large tests to lp64 target

-mcmodel=large is only supported for lp64 targets.  Limit -mcmodel=large
tests of libcall-1.c and pr107057.c to lp64 target.

* gcc.target/i386/libcall-1.c: Limit to lp64 target.
* gcc.target/i386/pr107057.c: Likewise.

7 months agoRISC-V: Fix regression
Juzhe-Zhong [Tue, 30 Jan 2024 01:19:06 +0000 (09:19 +0800)]
RISC-V: Fix regression

Due to recent middle-end loop vectorizer changes, these tests have regression and
the changes are reasonable. Adapt test to fix the regression.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/binop/shift-rv32gcv.c: Adapt test.
* gcc.target/riscv/rvv/autovec/binop/shift-rv64gcv.c: Ditto.
* gcc.target/riscv/rvv/autovec/vls/mod-1.c: Ditto.
* gcc.target/riscv/rvv/autovec/vls/shift-1.c: Ditto.
* gcc.target/riscv/rvv/autovec/vls/shift-2.c: Ditto.

7 months agoDaily bump.
GCC Administrator [Tue, 30 Jan 2024 00:18:41 +0000 (00:18 +0000)]
Daily bump.

7 months agoaarch64: fix handling of reversed mem ops in ldp/stp policy model
Manos Anagnostakis [Tue, 21 Nov 2023 14:06:26 +0000 (15:06 +0100)]
aarch64: fix handling of reversed mem ops in ldp/stp policy model

The current ldp/stp policy framework implementation would miss cases,
where the memory operands were reversed. To address this, the call to
the framework function is moved after the lower mem check with the
suitable parameters.

This change removes the mode of aarch64_operands_ok_for_ldpstp, which
becomes unused.

gcc/ChangeLog:

* config/aarch64/aarch64-ldpstp.md: Remove unused mode.
* config/aarch64/aarch64-protos.h (aarch64_operands_ok_for_ldpstp):
Likewise.
* config/aarch64/aarch64.cc (aarch64_operands_ok_for_ldpstp):
Call on framework moved later.

Signed-off-by: Manos Anagnostakis <manos.anagnostakis@vrull.eu>
Co-Authored-by: Manolis Tsamis <manolis.tsamis@vrull.eu>
Co-Authored-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
7 months agolibstdc++: Fix _GLIBCXX_DEBUG_BACKTRACE macro documentation
François Dumont [Mon, 29 Jan 2024 18:20:25 +0000 (19:20 +0100)]
libstdc++: Fix _GLIBCXX_DEBUG_BACKTRACE macro documentation

libstdc++-v3/ChangeLog:

* doc/xml/manual/debug_mode.xml: Link against libstdc++exp.a to use
_GLIBCXX_DEBUG_BACKTRACE macro.

7 months agotestsuite: require libc sym for -shared
Alexandre Oliva [Mon, 29 Jan 2024 18:08:35 +0000 (15:08 -0300)]
testsuite: require libc sym for -shared

Targets whose binutils support -shared, but that don't have a shared
libc, and that can't add PDC (non-PIC) to shared libraries, may
succeed at the effective target test for -shared, because it brings
nothing from libc, but tests that rely on -shared and that use bits
from libc, such as g++.dg/lto/pr108772, fail despite requiring the
shared effective target.

Extend the effective target test to bring malloc() from libc, that's
likely to be present in libc and bring a substantial amount of code if
no shared libc is available.

for  gcc/testsuite/ChangeLog

* lib/target-supports.exp (check_effective_target_shared):
Check for a static-only libc.

7 months agotestsuite: no dfp run without dfprt
Alexandre Oliva [Mon, 29 Jan 2024 18:08:32 +0000 (15:08 -0300)]
testsuite: no dfp run without dfprt

newlib-src/libc/include/sys/fenv.h doesn't define the FE_* macros that
libgcc expects to enable decimal float support.  Only after newlib is
configured and built does an overriding header that defines those
macros become available in objdir/<target>/newlib/targ-include/, but
by then, libgcc has already been built without dfp and libbid.

This has exposed a number of tests that attempt to link dfp programs
without requiring a dfprt effective target.

dfp.exp already skips if dfp support is missing altogether, and sets
the default to compile rather than run if dfp support is present in
the compiler but missing in the runtime libraries.

However, some of the dfp tests override the default without requiring
dfprt.  Drop the overriders where reasonable, and add the explicit
requirement elsewhere.

for  gcc/testsuite/ChangeLog

* c-c++-common/dfp/pr36800.c: Drop dg-do overrider.
* c-c++-common/dfp/pr39034.c: Likewise.
* c-c++-common/dfp/pr39035.c: Likewise.
* gcc.dg/dfp/bid-non-canonical-d32-1.c: Likewise.
* gcc.dg/dfp/bid-non-canonical-d32-2.c: Likewise.
* gcc.dg/dfp/bid-non-canonical-d64-1.c: Likewise.
* gcc.dg/dfp/bid-non-canonical-d64-2.c: Likewise.
* gcc.dg/dfp/builtin-snan-1.c: Likewise.
* gcc.dg/dfp/builtin-tgmath-dfp.c: Likewise.
* gcc.dg/dfp/c23-float-dfp-4.c: Likewise.
* gcc.dg/dfp/c23-float-dfp-5.c: Likewise.
* gcc.dg/dfp/c23-float-dfp-6.c: Likewise.
* gcc.dg/dfp/c23-float-dfp-7.c: Likewise.
* gcc.dg/dfp/pr108068.c: Likewise.
* gcc.dg/dfp/pr97439.c: Likewise.
* g++.dg/compat/decimal/pass-1_main.C: Require dfprt.
* g++.dg/compat/decimal/pass-2_main.C: Likewise.
* g++.dg/compat/decimal/pass-3_main.C: Likewise.
* g++.dg/compat/decimal/pass-4_main.C: Likewise.
* g++.dg/compat/decimal/pass-5_main.C: Likewise.
* g++.dg/compat/decimal/pass-6_main.C: Likewise.
* g++.dg/compat/decimal/return-1_main.C: Likewise.
* g++.dg/compat/decimal/return-2_main.C: Likewise.
* g++.dg/compat/decimal/return-3_main.C: Likewise.
* g++.dg/compat/decimal/return-4_main.C: Likewise.
* g++.dg/compat/decimal/return-5_main.C: Likewise.
* g++.dg/compat/decimal/return-6_main.C: Likewise.
* g++.dg/eh/dfp-1.C: Likewise.
* g++.dg/eh/dfp-2.C: Likewise.
* g++.dg/eh/dfp-saves-aarch64.C: Likewise.
* gcc.c-torture/execute/pr80692.c: Likewise.
* gcc.dg/dfp/bid-non-canonical-d128-1.c: Likewise.
* gcc.dg/dfp/bid-non-canonical-d128-2.c: Likewise.
* gcc.dg/dfp/bid-non-canonical-d128-3.c: Likewise.
* gcc.dg/dfp/bid-non-canonical-d128-4.c: Likewise.

7 months agobpf: emit empty epilogues in naked functions
Jose E. Marchesi [Mon, 29 Jan 2024 16:47:00 +0000 (17:47 +0100)]
bpf: emit empty epilogues in naked functions

This patch fixes the BPF backend to not generate `exit' (return)
instructions in epilogues of functions that are declared as naked via
the corresponding compiler attribute.  Having extra exit instructions
upsets the kernel BPF verifier.

Tested in bpf-unknown-none target in x86_64-linux-gnu host.

gcc/ChangeLog

* config/bpf/bpf.cc (bpf_expand_epilogue): Do not emit a return
instruction in naked function epilogues.

gcc/testsuite/ChangeLog

* gcc.target/bpf/naked-1.c: Update test to not expect an exit
instruction in naked function.
* gcc.target/bpf/naked-2.c: New test.

7 months agoRISC-V: Add require-effective-target to pr113429 testcase
Patrick O'Neill [Sat, 27 Jan 2024 02:38:46 +0000 (18:38 -0800)]
RISC-V: Add require-effective-target to pr113429 testcase

The pr113429 testcase fails with newlib spike runs. Adding
require-effective-target rv64 and riscv_v fixes the issue.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/vsetvl/pr113429.c: Add
require-effective-target rv64 and riscv_v

Signed-off-by: Patrick O'Neill <patrick@rivosinc.com>
7 months agoc++: local class in generic lambda [PR113544]
Jason Merrill [Fri, 26 Jan 2024 22:33:51 +0000 (17:33 -0500)]
c++: local class in generic lambda [PR113544]

My earlier commit r14-278-gd60cbbfaa9a3ad was a start toward better
handling of local classes in generic lambdas, but isn't actually useful by
itself and breaks this testcase, so let's revert it for now.

PR c++/113544

gcc/cp/ChangeLog:

* pt.cc (instantiate_class_template): Don't partially instantiate.
(tsubst_stmt): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1y/lambda-generic-nested3.C: New test.

7 months agoMAINTAINERS: Update my work email address
Kwok Cheung Yeung [Mon, 29 Jan 2024 16:40:49 +0000 (16:40 +0000)]
MAINTAINERS: Update my work email address

* MAINTAINERS: Update my work email address.

7 months agoMIPS: Fix typo in gcc/configure.ac: gcc_cv_as_mips_explicit
YunQiang Su [Mon, 29 Jan 2024 16:26:28 +0000 (00:26 +0800)]
MIPS: Fix typo in gcc/configure.ac: gcc_cv_as_mips_explicit

gcc_cv_as_mips_explicit should be gcc_cv_as_mips_explicit_relocs.
This was introduced in commit
58af788d1d0825187def434c95cab35a690a31b0.

gcc
PR target/113655
* configure.ac: Fix typo gcc_cv_as_mips_explicit should be
gcc_cv_as_mips_explicit_relocs.
* configure: Regnerated.

7 months agoarm: Add pattern for bswap + rotate -> rev16 [Bug 108933]
Matthieu Longo [Mon, 29 Jan 2024 15:54:35 +0000 (15:54 +0000)]
arm: Add pattern for bswap + rotate -> rev16 [Bug 108933]

The rev16 pattern was not recognised anymore as a change in the bswap
tree pass was introducing a new GIMPLE form, not recognized by the
assembly final transformation pass.

Also, fix the output patterns for arm_rev16si_alt[12] to correctly
handle the instructions being made conditional.

More details in the PR.

gcc/ChangeLog:

PR target/108933
* config/arm/arm.md (arm_rev16si2): Convert to define_insn.
Correct generated RTL.
(arm_rev16si2_alt1): Correctly handle conditional execution.
(arm_rev16si2_alt2): Likewise.

gcc/testsuite/ChangeLog:

PR target/108933
* gcc.target/arm/rev16.c: Moved to...
* gcc.target/arm/rev16_1.c: ...here.
* gcc.target/arm/rev16_2.c: New test to check that rev16 is emitted.

7 months agomiddle-end/113622 - handle store with variable index to register
Richard Biener [Mon, 29 Jan 2024 09:24:39 +0000 (10:24 +0100)]
middle-end/113622 - handle store with variable index to register

The following implements storing to a non-MEM_P with a variable
offset.  We usually avoid this by forcing expansion to memory but
this doesn't work for hard register variables.  The solution is
to spill and operate on the stack.

PR middle-end/113622
* expr.cc (expand_assignment): Spill hard registers if
we index them with a variable offset.

* gcc.target/i386/pr113622-2.c: New testcase.
* gcc.target/i386/pr113622-3.c: Likewise.

7 months agomiddle-end/113622 - allow .VEC_SET and .VEC_EXTRACT for global hard regs
Richard Biener [Mon, 29 Jan 2024 08:47:31 +0000 (09:47 +0100)]
middle-end/113622 - allow .VEC_SET and .VEC_EXTRACT for global hard regs

The following expands .VEC_SET and .VEC_EXTRACT instruction selection
to global hard registers, not only automatic variables (possibly)
promoted to registers.  This can avoid some ICEs later and create
better code.

PR middle-end/113622
* gimple-isel.cc (gimple_expand_vec_set_extract_expr):
Also allow DECL_HARD_REGISTER variables.

* gcc.target/i386/pr113622-1.c: New testcase.

7 months agoaarch64: Ensure iterator validity when updating debug uses [PR113616]
Alex Coplan [Mon, 29 Jan 2024 13:28:04 +0000 (13:28 +0000)]
aarch64: Ensure iterator validity when updating debug uses [PR113616]

The fix for PR113089 introduced range-based for loops over the
debug_insn_uses of an RTL-SSA set_info, but in the case that we reset a
debug insn, the use would get removed from the use list, and thus we
would end up using an invalidated iterator in the next iteration of the
loop.  In practice this means we end up terminating the loop
prematurely, and hence ICE as in PR113089 since there are debug uses
that we failed to fix up.

This patch fixes that by introducing a general mechanism to avoid this
sort of problem.  We introduce a safe_iterator to iterator-utils.h which
wraps an iterator, and also holds the end iterator value.  It then
pre-computes the next iterator value at all iterations, so it doesn't
matter if the original iterator got invalidated during the loop body, we
can still move safely to the next iteration.

We introduce an iterate_safely helper which effectively adapts a
container such as iterator_range into a container of safe_iterators over
the original iterator type.

We then use iterate_safely around all loops over debug_insn_uses () in
the aarch64 ldp/stp pass to fix PR113616.  While doing this, I
remembered that cleanup_tombstones () had the same problem.  I
previously worked around this locally by manually maintaining the next
nondebug insn, so this patch also refactors that loop to use the new
iterate_safely helper.

While doing that I noticed that a couple of cases in cleanup_tombstones
could be converted from using dyn_cast<set_info *> to as_a<set_info *>,
which should be safe because there are no clobbers of mem in RTL-SSA, so
all defs of memory should be set_infos.

gcc/ChangeLog:

PR target/113616
* config/aarch64/aarch64-ldp-fusion.cc (fixup_debug_uses_trailing_add):
Use iterate_safely when iterating over debug uses.
(fixup_debug_uses): Likewise.
(ldp_bb_info::cleanup_tombstones): Use iterate_safely to iterate
over nondebug insns instead of manually maintaining the next insn.
* iterator-utils.h (class safe_iterator): New.
(iterate_safely): New.

gcc/testsuite/ChangeLog:

PR target/113616
* gcc.c-torture/compile/pr113616.c: New test.

7 months agox86: Save callee-saved registers in noreturn functions for -O0/-Og
H.J. Lu [Sat, 27 Jan 2024 13:48:45 +0000 (05:48 -0800)]
x86: Save callee-saved registers in noreturn functions for -O0/-Og

Save callee-saved registers in noreturn functions for -O0/-Og so that
debugger can restore callee-saved registers in caller's frame.

Also add the TREE_THIS_VOLATILE check to minimize noreturn attribute
lookup.

gcc/

PR target/38534
* config/i386/i386-options.cc (ix86_set_func_type): Save
callee-saved registers in noreturn functions for -O0/-Og.

gcc/testsuite/

PR target/38534
* gcc.target/i386/pr38534-5.c: New file.
* gcc.target/i386/pr38534-6.c: Likewise.

7 months agoPR112950: Use #pragma GCC for including arm_sve.h.
Prathamesh Kulkarni [Mon, 29 Jan 2024 13:12:44 +0000 (18:42 +0530)]
PR112950: Use #pragma GCC for including arm_sve.h.

gcc/testsuite/ChangeLog:
PR target/112950
* gcc.target/aarch64/sve/acle/general/dupq_5.c: Remove include directive
and instead use #pragma GCC for including arm_sve.h.

7 months agogcn/gcn-valu.md: Disable fold_left_plus for TARGET_RDNA2_PLUS [PR113615]
Tobias Burnus [Mon, 29 Jan 2024 12:51:25 +0000 (13:51 +0100)]
gcn/gcn-valu.md: Disable fold_left_plus for TARGET_RDNA2_PLUS [PR113615]

gcc/ChangeLog:

PR target/113615
* config/gcn/gcn-valu.md (fold_left_plus_<mode>): Only
define for !TARGET_RDNA2_PLUS.

Signed-off-by: Tobias Burnus <tburnus@baylibre.com>
7 months agovect: Tighten vect_determine_precisions_from_range [PR113281]
Richard Sandiford [Mon, 29 Jan 2024 12:33:08 +0000 (12:33 +0000)]
vect: Tighten vect_determine_precisions_from_range [PR113281]

This was another PR caused by the way that
vect_determine_precisions_from_range handles shifts.  We tried to
narrow 32768 >> x to a 16-bit shift based on range information for
the inputs and outputs, with vect_recog_over_widening_pattern
(after PR110828) adjusting the shift amount.  But this doesn't
work for the case where x is in [16, 31], since then 32-bit
32768 >> x is a well-defined zero, whereas no well-defined
16-bit 32768 >> y will produce 0.

We could perhaps generate x < 16 ? 32768 >> x : 0 instead,
but since vect_determine_precisions_from_range was never really
supposed to rely on fix-ups, it seems better to fix that instead.

The patch also makes the code more selective about which codes
can be narrowed based on input and output ranges.  This showed
that vect_truncatable_operation_p was missing cases for
BIT_NOT_EXPR (equivalent to BIT_XOR_EXPR of -1) and NEGATE_EXPR
(equivalent to BIT_NOT_EXPR followed by a PLUS_EXPR of 1).

pr113281-1.c is the original testcase.  pr113281-[23].c failed
before the patch due to overly optimistic narrowing.  pr113281-[45].c
previously passed and are meant to protect against accidental
optimisation regressions.

gcc/
PR target/113281
* tree-vect-patterns.cc (vect_recog_over_widening_pattern): Remove
workaround for right shifts.
(vect_truncatable_operation_p): Handle NEGATE_EXPR and BIT_NOT_EXPR.
(vect_determine_precisions_from_range): Be more selective about
which codes can be narrowed based on their input and output ranges.
For shifts, require at least one more bit of precision than the
maximum shift amount.

gcc/testsuite/
PR target/113281
* gcc.dg/vect/pr113281-1.c: New test.
* gcc.dg/vect/pr113281-2.c: Likewise.
* gcc.dg/vect/pr113281-3.c: Likewise.
* gcc.dg/vect/pr113281-4.c: Likewise.
* gcc.dg/vect/pr113281-5.c: Likewise.

7 months agonvptx.opt: Add sm_89 and sm_90a to -march-map=
Tobias Burnus [Mon, 29 Jan 2024 12:06:27 +0000 (13:06 +0100)]
nvptx.opt: Add sm_89 and sm_90a to -march-map=

The -march-map= options maps the compute capability to the closest
lower compute capability that has been implemented; for sm_89 and
sm_90a, that were previously missing, that's currently -march=sm_80
alias -misa=sm_80.

gcc/ChangeLog:

* config/nvptx/nvptx.opt (march-map=): Add sm_89 and sm_90a.

Signed-off-by: Tobias Burnus <tburnus@baylibre.com>
7 months agoinstall.texi: For gcn, recommend LLVM 15, unless gfx1100 is disabled
Tobias Burnus [Mon, 29 Jan 2024 10:20:49 +0000 (11:20 +0100)]
install.texi: For gcn, recommend LLVM 15, unless gfx1100 is disabled

gcc/ChangeLog:

* doc/install.texi (amdgcn): Recommend LLVM 15+ and newlib 4.4+,
but keep requiring only newlib 4.3+ and, if gfx1100 is disabled,
LLVM 13.0.1+.

Signed-off-by: Tobias Burnus <tburnus@baylibre.com>
7 months agogcn/mkoffload.cc: Fix SRAM_ECC and XNACK handling [PR111966]
Tobias Burnus [Mon, 29 Jan 2024 10:10:33 +0000 (11:10 +0100)]
gcn/mkoffload.cc: Fix SRAM_ECC and XNACK handling [PR111966]

Some more '-g' fixes as the .mkoffload.dbg.o debug file's has elf flags
which did not match those generated for the compilation, leading to linker
errors.  For .mkoffload.dbg.o, the elf flags are generated by mkoffload
itself - while for the other .o files, that's done by the compiler via
setting default and mainly via the ASM_SPEC.

This is a follow up to r14-8332-g13127dac106724 which fixed an issue
caused by the default arch.  In this patch, it is mainly for gfx1100
and gfx1030 which always failed.  It also affects gfx906 and possibly
gfx900 but only when using the -mxnack/-msram-ecc flags explicitly.

What happens on the compiler side is mainly determined by gcn-hsa.h's
and otherwise by some default setting. In particular for xnack and
sram_ecc, there is:

For gfx1100 and gfx1030, neither xnack nor sram_ecc is set (only
'+wavefrontsize64').

For fiji, gfx900, gfx906 and gfx908 there is always -mattr=-xnack and
for all but gfx908 also -msram-ecc=no - independent of what has been
passed to the compiler. However, on the elf flags, the result differs:
For fiji, due to the HSACOv3, it is always set to 0 via
copy_early_debug_info; for gfx900, gfx906 and gfx908, xnack is OFF.
For sram-ecc, it is 'unset' for gfx900, 'any' for gfx906 and for
gfx908 it is 'any' unless overridden.

For gfx90a, the -msram-ecc= and -mxnack= are passed on, or if not present,
...=any is passed on.  Note that this "any" is different from argument
nor present at elf flag level:
For XNACK: unset/unsupported is 0, any = 0x100, off = 0x200, on = 0x300.
For SRAMECC: unset/unsupported is 0, any = 0x400, off = 0x800, on = 0xc00.

The obstack_ptr_grow changes are more to avoid confusion than having an
actual effect as they would overwise be filtered out via the ASM_SPEC.

gcc/ChangeLog:

PR other/111966
* config/gcn/mkoffload.cc (SET_XNACK_UNSET, TEST_SRAM_ECC_UNSET): New.
(SET_SRAM_ECC_UNSUPPORTED): Renamed to ...
(SET_SRAM_ECC_UNSET): ... this.
(copy_early_debug_info): Remove gfx900 special case, now handled as
part of the generic handling.
(main): Update SRAM_ECC and XNACK for the -march as done in gcn-hsa.h.

Signed-off-by: Tobias Burnus <tburnus@baylibre.com>
7 months agolibgomp.c/declare-variant-4.h: Fix used variant function for gfx1030/gfx1100
Tobias Burnus [Mon, 29 Jan 2024 10:06:15 +0000 (11:06 +0100)]
libgomp.c/declare-variant-4.h: Fix used variant function for gfx1030/gfx1100

libgomp/ChangeLog:

* testsuite/libgomp.c/declare-variant-4.h: Use gfx1100/gfx1030
function not gfx90a for gfx1100/gfx1030 context selector.

Signed-off-by: Tobias Burnus <tburnus@baylibre.com>
7 months agotree-ssa-strlen: Fix pdata->maxlen computation [PR110603]
Jakub Jelinek [Mon, 29 Jan 2024 09:20:32 +0000 (10:20 +0100)]
tree-ssa-strlen: Fix pdata->maxlen computation [PR110603]

On the following testcase we emit an invalid range of [2, 1] due to
UB in the source.  Older VRP code silently swapped the boundaries and
made [1, 2] range out of it, but newer code just ICEs on it.

The reason for pdata->minlen 2 is that we see a memcpy in this case
setting both elements of the array to non-zero value, so strlen (a)
can't be smaller than 2.  The reason for pdata->maxlen 1 is that in
char a[2] array without UB there can be at most 1 non-zero character
because there needs to be '\0' termination in the buffer too.

IMHO we shouldn't create invalid ranges like that and even creating
for that case a range [1, 2] looks wrong to me, so the following patch
just doesn't set maxlen in that case to the array size - 1, matching
what will really happen at runtime when triggering such UB (strlen will
be at least 2, perhaps more or will crash).
This is what the second hunk of the patch does.

The first hunk fixes a fortunately harmless thinko.
If the strlen pass knows the string length (i.e. get_string_length
function returns non-NULL), we take a different path, we get to this
only if all we know is that there are certain number of non-zero
characters but we don't know what it is followed with, whether further
non-zero characters or zero termination or either of that.
If we know exactly how many non-zero characters it is, such as
char a[42];
...
  memcpy (a, "01234567890123456789", 20);
then we take an earlier if for the INTEGER_CST case and set correctly
just pdata->minlen to 20 in that case, but if we have something like
  int len;
  ...
  if (len < 15 || len > 32) return;
  memcpy (a, "0123456789012345678901234567890123456789", len);
then we have [15, 32] range for the nonzero_chars and we set pdata->minlen
correctly to 15, but incorrectly set also pdata->maxlen to 32.  That is
not what the above implies, it just means that in some cases we know that
there are at least 32 non-zero characters, followed by something we don't
know.  There is no guarantee that there is '\0' right after it, so it
means nothing.
The reason this is harmless, just confusing, is that the code a few lines
later fortunately overwrites this incorrect pdata->maxlen value with
something different (either array length - 1 or all ones etc.).

2024-01-29  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/110603
* tree-ssa-strlen.cc (get_range_strlen_dynamic): Remove incorrect
setting of pdata->maxlen to vr.upper_bound (which is unconditionally
overwritten anyway).  Avoid creating invalid range with minlen
larger than maxlen.  Formatting fix.

* gcc.c-torture/compile/pr110603.c: New test.

7 months agodebug/103047 - argument order of inlined functions
Richard Biener [Fri, 26 Jan 2024 14:11:47 +0000 (15:11 +0100)]
debug/103047 - argument order of inlined functions

The inliner puts variables for parameters of the inlined functions
in the inline scope in reverse order.  The following reverses them
again so that we get consistent ordering between the
DW_TAG_subprogram DW_TAG_formal_parameter and the
DW_TAG_inlined_subroutine DW_TAG_formal_parameter set.

I failed to create a testcase with regexps since the inline
instances have just abstract origins and so I can't match them up.

PR debug/103047
* tree-inline.cc (initialize_inlined_parameters): Reverse
the decl chain of inlined parameters.

7 months agotestsuite: Fix vect_long_mult for 32-bit Power [PR109705]
Andrew Pinski [Mon, 29 Jan 2024 02:35:05 +0000 (20:35 -0600)]
testsuite: Fix vect_long_mult for 32-bit Power [PR109705]

As PR109705#c17, commit r14-7270 missed to consider long
type is 32bit with option -m32.  This patch is take care of
it accordingly.

Note that the vect_long_mult is supposed to be only used in
vect/ (generic), powerpc_altivec_ok would be guaranteed.

PR testsuite/109705

gcc/testsuite/ChangeLog:

* lib/target-supports.exp (check_effective_target_vect_long_mult):
Fix powerpc*-*-* checks by considering ilp32.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
7 months agoDaily bump.
GCC Administrator [Mon, 29 Jan 2024 00:18:44 +0000 (00:18 +0000)]
Daily bump.

7 months agoLibatomic: Add checks in ifunc selectors for LSE/LSE2 requirements.
Victor Do Nascimento [Tue, 19 Dec 2023 23:19:22 +0000 (23:19 +0000)]
Libatomic: Add checks in ifunc selectors for LSE/LSE2 requirements.

At present, Evaluation of both `has_lse2(hwcap)' and
`has_lse128(hwcap)' may require issuing an `mrs' instruction to query
a system register.  This instruction, when issued from user-space
results in a trap by the kernel which then returns the value read in
by the system register.  Given the undesirable nature of the
computational expense associated with the context switch, it is
important to implement mechanisms to, wherever possible, forgo the
operation.

In light of this, given how other architectural requirements serving
as prerequisites have long been assigned HWCAP bits by the kernel, we
can inexpensively query for their availability before attempting to
read any system registers.  Where one of these early tests fail, we
can assert that the main feature of interest (be it LSE2 or LSE128)
cannot be present, allowing us to return from the function early and
skip the unnecessary expensive kernel-mediated access to system
registers.

libatomic/ChangeLog:

* config/linux/aarch64/host-config.h (has_lse2): Add test for LSE.
(has_lse128): Add test for LSE2.

7 months agolibatomic: Enable LSE128 128-bit atomics for Armv9.4-a
Victor Do Nascimento [Tue, 1 Aug 2023 10:07:56 +0000 (11:07 +0100)]
libatomic: Enable LSE128 128-bit atomics for Armv9.4-a

The armv9.4-a architectural revision adds three new atomic operations
associated with the LSE128 feature:

  * LDCLRP - Atomic AND NOT (bitclear) of a location with 128-bit
  value held in a pair of registers, with original data loaded into
  the same 2 registers.
  * LDSETP - Atomic OR (bitset) of a location with 128-bit value held
  in a pair of registers, with original data loaded into the same 2
  registers.
  * SWPP - Atomic swap of one 128-bit value with 128-bit value held
  in a pair of registers.

It is worth noting that in keeping with existing 128-bit atomic
operations in `atomic_16.S', we have chosen to merge certain
less-restrictive orderings into more restrictive ones.  This is done
to minimize the number of branches in the atomic functions, minimizing
both the likelihood of branch mispredictions and, in keeping code
small, limit the need for extra fetch cycles.

Past benchmarking has revealed that acquire is typically slightly
faster than release (5-10%), such that for the most frequently used
atomics (CAS and SWP) it makes sense to add support for acquire, as
well as release.

Likewise, it was identified that combining acquire and release typically
results in little to no penalty, such that it is of negligible benefit
to distinguish between release and acquire-release, making the
combining release/acq_rel/seq_cst a worthwhile design choice.

This patch adds the logic required to make use of these when the
architectural feature is present and a suitable assembler available.

In order to do this, the following changes are made:

  1. Add a configure-time check to check for LSE128 support in the
  assembler.
  2. Edit host-config.h so that when N == 16, nifunc = 2.
  3. Where available due to LSE128, implement the second ifunc, making
  use of the novel instructions.
  4. For atomic functions unable to make use of these new
  instructions, define a new alias which causes the _i1 function
  variant to point ahead to the corresponding _i2 implementation.

libatomic/ChangeLog:

* Makefile.am (AM_CPPFLAGS): add conditional setting of
-DHAVE_FEAT_LSE128.
* acinclude.m4 (LIBAT_TEST_FEAT_AARCH64_LSE128): New.
* config/linux/aarch64/atomic_16.S (LSE128): New macro
definition.
(libat_exchange_16): New LSE128 variant.
(libat_fetch_or_16): Likewise.
(libat_or_fetch_16): Likewise.
(libat_fetch_and_16): Likewise.
(libat_and_fetch_16): Likewise.
* config/linux/aarch64/host-config.h (IFUNC_COND_2): New.
(IFUNC_NCOND): Add operand size checking.
(has_lse2): Renamed from `ifunc1`.
(has_lse128): New.
(HWCAP2_LSE128): Likewise.
* configure.ac: Add call to
LIBAT_TEST_FEAT_AARCH64_LSE128.
* configure (ac_subst_vars): Regenerated via autoreconf.
* Makefile.in: Likewise.
* auto-config.h.in: Likewise.

7 months agolibatomic: Add support for __ifunc_arg_t arg in ifunc resolver
Victor Do Nascimento [Thu, 18 Jan 2024 19:27:25 +0000 (19:27 +0000)]
libatomic: Add support for __ifunc_arg_t arg in ifunc resolver

With support for new atomic features in Armv9.4-a being indicated by
HWCAP2 bits, Libatomic's ifunc resolver must now query its second
argument, of type __ifunc_arg_t*.

We therefore make this argument known to libatomic, allowing us to
query hwcap2 bits in the following manner:

  bool
  resolver (unsigned long hwcap, const __ifunc_arg_t *features);
  {
    return (features->hwcap2 & HWCAP2_<FEAT_NAME>);
  }

libatomic/ChangeLog:

* config/linux/aarch64/host-config.h (__ifunc_arg_t):
Conditionally-defined if `sys/ifunc.h' not found.
(_IFUNC_ARG_HWCAP): Likewise.
(IFUNC_COND_1): Pass __ifunc_arg_t argument to ifunc.
(ifunc1): Modify function signature to accept __ifunc_arg_t
argument.
* configure.tgt: Add second `const __ifunc_arg_t *features'
argument to IFUNC_RESOLVER_ARGS.

7 months agolibatomic: atomic_16.S: Improve ENTRY, END and ALIAS macro interface
Victor Do Nascimento [Fri, 15 Sep 2023 15:04:01 +0000 (16:04 +0100)]
libatomic: atomic_16.S: Improve ENTRY, END and ALIAS macro interface

The introduction of further architectural-feature dependent ifuncs
for AArch64 makes hard-coding ifunc `_i<n>' suffixes to functions
cumbersome to work with.  It is awkward to remember which ifunc maps
onto which arch feature and makes the code harder to maintain when new
ifuncs are added and their suffixes possibly altered.

This patch uses pre-processor `#define' statements to map each suffix to
a descriptive feature name macro, for example:

  #define LSE(NAME) NAME##_i1

Where we wish to generate ifunc names with the pre-processor's token
concatenation feature, we add a level of indirection to previous macro
calls.  If before we would have had`MACRO(<name>_i<n>)', we now have
`MACRO_FEAT(name, feature)'.  Where we wish to refer to base
functionality (i.e., functions where ifunc suffixes are absent), the
original `MACRO(<name>)' may be used to bypass suffixing.

Consequently, for base functionality, where the ifunc suffix is
absent, the macro interface remains the same.  For example, the entry
and endpoints of `libat_store_16' remain defined by:

  ENTRY (libat_store_16)

and

  END (libat_store_16)

For the LSE2 implementation of the same 16-byte atomic store, we now
have:

  ENTRY_FEAT (libat_store_16, LSE2)

and

  END_FEAT (libat_store_16, LSE2)

For the aliasing of function names, we define the following new
implementation of the ALIAS macro:

  ALIAS (FN_BASE_NAME, FROM_SUFFIX, TO_SUFFIX)

Defining the `CORE(NAME)' macro to be the identity operator, it
returns the base function name unaltered and allows us to alias
target-specific ifuncs to the corresponding base implementation.
For example, we'd alias the LSE2 `libat_exchange_16' to it base
implementation with:

  ALIAS (libat_exchange_16, LSE2, CORE)

libatomic/ChangeLog:
* config/linux/aarch64/atomic_16.S (CORE): New macro.
(LSE2): Likewise.
(ENTRY_FEAT): Likewise.
(ENTRY_FEAT1): Likewise.
(END_FEAT): Likewise.
(END_FEAT1): Likewise.
(ALIAS): Modify macro to take in `arch' arguments.
(ALIAS1): New.

7 months agoFortran: NULL actual to optional dummy with VALUE attribute [PR113377]
Harald Anlauf [Thu, 25 Jan 2024 21:19:10 +0000 (22:19 +0100)]
Fortran: NULL actual to optional dummy with VALUE attribute [PR113377]

gcc/fortran/ChangeLog:

PR fortran/113377
* trans-expr.cc (conv_dummy_value): Treat NULL actual argument to
optional dummy with the VALUE attribute as not present.
(gfc_conv_procedure_call): Likewise.

gcc/testsuite/ChangeLog:

PR fortran/113377
* gfortran.dg/optional_absent_11.f90: New test.

7 months agoObjective-C, Darwin: Do not overalign CFStrings and Objective-C metadata.
Iain Sandoe [Thu, 25 Jan 2024 20:11:09 +0000 (20:11 +0000)]
Objective-C, Darwin: Do not overalign CFStrings and Objective-C metadata.

We have reports of regressions in both Objective-C and Objective-C++ on
Darwin23 (macOS 14).  In some cases, these are linker warnings about the
alignment of CFString constants; in other cases the built executables
crash during runtime initialization.  The underlying issue is the same in
both cases; since the objects (CFStrings, Objective-C meta-data) are TU-
local, we are choosing to increase their alignment for efficiency - to
values greater than ABI alignment.

However, although these objects are TU-local, they are also visible to the
linker (since they are placed in specific named sections).  In many cases
the metadata can be regarded as tables of data, and thus it is expected
that these sections can be concatenated from multiple TUs and the data
treated as tabular.  In order for this to work the data cannot be allowed
to exceed ABI alignment - which leads to the crashes.

For GCC-15+ it would be nice to find a more elegant solution to this issue
(perhaps by adjusting the concept of binds-locally to exclude specific
named sections) - but I do not want to do that in stage 4.

The solution here is to force the alignment to be preserved as created by
setting DECL_USER_ALIGN on the relevant objects.

gcc/ChangeLog:

* config/darwin.cc (darwin_build_constant_cfstring): Prevent over-
alignment of CFString constants by setting DECL_USER_ALIGN.

gcc/objc/ChangeLog:

* objc-next-runtime-abi-02.cc (build_v2_address_table): Prevent
over-alignment of Objective-C metadata by setting DECL_USER_ALIGN
on relevant variables.
(build_v2_protocol_list_address_table): Likewise.
(generate_v2_protocol_list): Likewise.
(generate_v2_meth_descriptor_table): Likewise.
(generate_v2_meth_type_list): Likewise.
(generate_v2_property_table): Likewise.
(generate_v2_dispatch_table): Likewise.
(generate_v2_ivars_list): Likewise.
(generate_v2_class_structs): Likewise.
(build_ehtype): Likewise.
* objc-runtime-shared-support.cc (generate_strings): Likewise.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
7 months agotestsuite, Objective-C: Fix duplicate libobjc cases.
Iain Sandoe [Thu, 25 Jan 2024 20:17:42 +0000 (20:17 +0000)]
testsuite, Objective-C: Fix duplicate libobjc cases.

Two of the encode testcases include '-lobjc' as their dg-options.
Since the library is already appended as part of the generic testsuite
handling,  this means that two instances appear on the link line leading
to spurious warnings from Darwin's new linker.

gcc/testsuite/ChangeLog:

* obj-c++.dg/encode-10.mm: Remove unneeded '-lobjc' option addition.
* obj-c++.dg/encode-9.mm: Likewise.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
7 months agoFix __builtin_nested_func_ptr_{created,deleted} symbol versions [PR113402]
Iain Sandoe [Tue, 16 Jan 2024 10:21:14 +0000 (10:21 +0000)]
Fix __builtin_nested_func_ptr_{created,deleted} symbol versions [PR113402]

The symbols for the functions supporting heap-based trampolines were
exported at an incorrect symbol version, the following patch fixes that.

As requested in the PR, this also renames __builtin_nested_func_ptr* to
__gcc_nested_func_ptr*.  In carrying our the rename, we move the builtins
to use DEF_EXT_LIB_BUILTIN.

PR libgcc/113402

gcc/ChangeLog:

* builtins.cc (expand_builtin): Handle BUILT_IN_GCC_NESTED_PTR_CREATED
and BUILT_IN_GCC_NESTED_PTR_DELETED.
* builtins.def (BUILT_IN_GCC_NESTED_PTR_CREATED,
BUILT_IN_GCC_NESTED_PTR_DELETED): Make these builtins LIB-EXT and
rename the library fallbacks to __gcc_nested_func_ptr_created and
__gcc_nested_func_ptr_deleted.
* doc/invoke.texi: Rename these to __gcc_nested_func_ptr_created
and __gcc_nested_func_ptr_deleted.
* tree-nested.cc (finalize_nesting_tree_1): Use builtin_explicit for
BUILT_IN_GCC_NESTED_PTR_CREATED and BUILT_IN_GCC_NESTED_PTR_DELETED.
* tree.cc (build_common_builtin_nodes): Build the
BUILT_IN_GCC_NESTED_PTR_CREATED and BUILT_IN_GCC_NESTED_PTR_DELETED local
builtins only for non-explicit.

libgcc/ChangeLog:

* config/aarch64/heap-trampoline.c: Rename
__builtin_nested_func_ptr_created to __gcc_nested_func_ptr_created and
__builtin_nested_func_ptr_deleted to __gcc_nested_func_ptr_deleted.
* config/i386/heap-trampoline.c: Likewise.
* libgcc2.h: Likewise.
* libgcc-std.ver.in (GCC_7.0.0): Likewise and then move
__gcc_nested_func_ptr_created and
__gcc_nested_func_ptr_deleted from this symbol version to ...
(GCC_14.0.0): ... this one.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
Co-authored-by: Jakub Jelinek <jakub@redhat.com>
7 months agotestsuite, jit: Stabilize error output.
Iain Sandoe [Sat, 13 Jan 2024 21:14:07 +0000 (21:14 +0000)]
testsuite, jit: Stabilize error output.

Currently when a test fails, we print out a lot of information,
this includes items that are not stable between invocations (e.g.
the PID for the executable).  That makes automated comparisons
between test runs flag any persistent fails as new ones each time
which is not usually what is wanted.

This patch amends the error output to drop the variable portion
of the message and retain items that should only change if the
failure mode changes.

gcc/testsuite/ChangeLog:

* jit.dg/jit.exp: Filter error output to remove per-run
variable content.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
This page took 0.119213 seconds and 5 git commands to generate.