Owen Avery [Sat, 23 Aug 2025 02:26:05 +0000 (22:26 -0400)]
gccrs: nr1.0: Remove support in borrow checker
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-bir-builder-internal.h: Remove
inclusion of "rust-name-resolver.h".
(BuilderContext::resolver): Change type to nr2.0 resolver.
(BuilderContext::BuilderContext): Change initialization of
resolver reference.
(AbstractBuilder::resolve_label): Assume name resolution 2.0 is
enabled.
(AbstractBuilder::resolve_variable): Likewise.
(AbstractBuilder::resolve_variable_or_fn): Likewise.
Owen Avery [Sat, 23 Aug 2025 02:57:05 +0000 (22:57 -0400)]
gccrs: nr1.0: Remove support in pattern checker
gcc/rust/ChangeLog:
* checks/errors/rust-hir-pattern-analysis.cc: Remove inclusion
of "options.h".
(PatternChecker::PatternChecker): Change initialization of
resolver reference.
(PatternChecker::visit): Assume name resolution 2.0 is enabled.
* checks/errors/rust-hir-pattern-analysis.h: Include nr2.0
header instead of nr1.0 header.
(PatternChecker::resolver): Change type to nr2.0 resolver.
Owen Avery [Sat, 23 Aug 2025 02:12:35 +0000 (22:12 -0400)]
gccrs: nr1.0: Remove support in rust-session-manager.cc
gcc/rust/ChangeLog:
* rust-session-manager.cc: Remove inclusion of name resolution
1.0 headers.
(Session::compile_crate): Assume name resolution 2.0 is enabled.
(Session::expansion): Likewise.
(Session::load_extern_crate): Likewise.
Owen Avery [Sat, 23 Aug 2025 17:29:54 +0000 (13:29 -0400)]
gccrs: nr1.0: Remove support in privacy checker
gcc/rust/ChangeLog:
* checks/errors/privacy/rust-privacy-check.cc: Adjust includes.
(Resolver::resolve): Pass 2.0 name resolution context to
VisibilityResolver and PrivacyReporter.
* checks/errors/privacy/rust-privacy-reporter.cc
(PrivacyReporter::PrivacyReporter): Change type of resolver
parameter.
(is_child_module): Remove static function.
(PrivacyReporter::check_for_privacy_violation): Assume nr2.0 is
enabled and handle removal of is_child_module.
* checks/errors/privacy/rust-privacy-reporter.h: Adjust
includes.
(PrivacyReporter::PrivacyReporter): Change type of resolver
parameter.
(PrivacyReporter::resolver): Change member variable type.
* checks/errors/privacy/rust-visibility-resolver.cc: Adjust
includes.
(VisibilityResolver::VisibilityResolver): Change type of
resolver parameter.
(VisibilityResolver::resolve_module_path): Assume nr2.0 is
enabled.
* checks/errors/privacy/rust-visibility-resolver.h: Adjust
includes.
(VisibilityResolver::VisibilityResolver): Change type of
resolver parameter.
(VisibilityResolver::resolver): Change member variable type.
gccrs: Refactor AST Patterns that hold multiple pattern items
Patterns include TuplePattern, TupleStructPattern & SlicePattern. Besides making their pattern
items container class inherit from a common `PatternItems` base class just like in HIR for
better standardization, mentions of `Range` are also changed to `HasRest` or `NoRest`.
gcc/rust/ChangeLog:
* ast/rust-pattern.h:
- Add a new base abstract class `PatternItems` which are used by pattern items class
class derivatives for `TuplePattern`, `TupleStructPattern` & `SlicePattern`.
- Standardized the derived class names to have `HasRest` or `NoRest` as suffixes.
- Values for the common `ItemType` enum is updated to `HAS_REST` or `NO_REST`.
* ast/rust-pattern.cc: Renamed the classes accordingly.
* ast/rust-ast-collector.cc: Renamed the classes accordingly.
* ast/rust-ast-collector.h: Renamed the classes accordingly.
* ast/rust-ast-full-decls.h: Renamed the classes accordingly.
* ast/rust-ast-visitor.cc: Renamed the classes accordingly.
* ast/rust-ast-visitor.h: Renamed the classes accordingly.
* ast/rust-desugar-for-loops.cc: Renamed the classes accordingly.
* ast/rust-desugar-question-mark.cc: Renamed the classes accordingly.
* expand/rust-cfg-strip.cc: Renamed the classes accordingly.
* expand/rust-cfg-strip.h: Renamed the classes accordingly.
* expand/rust-derive-clone.cc: Renamed the classes accordingly.
* expand/rust-derive-cmp-common.cc: Renamed the classes accordingly.
* expand/rust-derive-hash.cc: Renamed the classes accordingly.
* expand/rust-derive-ord.cc: Renamed the classes accordingly.
* expand/rust-derive-partial-eq.cc: Renamed the classes accordingly.
* expand/rust-derive.h: Renamed the classes accordingly.
* expand/rust-expand-visitor.cc: Renamed the classes accordingly.
* expand/rust-expand-visitor.h: Renamed the classes accordingly.
* hir/rust-ast-lower-base.cc: Renamed the classes accordingly.
* hir/rust-ast-lower-base.h: Renamed the classes accordingly.
* hir/rust-ast-lower-pattern.cc: Renamed the classes accordingly.
* hir/tree/rust-hir-pattern.h: Renamed the classes accordingly.
* parse/rust-parse-impl.h: Renamed the classes accordingly.
* resolve/rust-ast-resolve-base.cc: Renamed the classes accordingly.
* resolve/rust-ast-resolve-base.h: Renamed the classes accordingly.
* resolve/rust-ast-resolve-pattern.cc: Renamed the classes accordingly.
* util/rust-attributes.cc: Renamed the classes accordingly.
* util/rust-attributes.h: Renamed the classes accordingly.
Owen Avery [Sun, 24 Aug 2025 23:37:45 +0000 (19:37 -0400)]
gccrs: Avoid std::unique_ptr<std::string> in Token
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Use
should_have_str instead of has_str.
* ast/rust-ast.cc (Token::as_string): Likewise.
* expand/rust-macro-builtins-offset-of.cc
(MacroBuiltin::offset_of_handler): Likewise.
* lex/rust-lex.cc (Lexer::dump_and_skip): Likewise.
* ast/rust-ast.h (class Token): Remove dead code.
(Token::has_str): Remove function.
(Token::should_have_str): New function.
* lex/rust-token.cc (Token::get_str): Remove function
definition.
* lex/rust-token.h: Include "rust-diagnostics.h".
(Token::str): Change type from std::unique_ptr<std::string> to
std::string.
(Token::Token): Adjust initialization of str member variable and
the type of the parameter used to initialize it.
(Token::make_identifier): Accept std::string instead of rvalue
reference to std::string.
(Token::make_int): Likewise.
(Token::make_float): Likewise.
(Token::make_string): Likewise.
(Token::make_byte_string): Likewise.
(Token::make_raw_string): Likewise.
(Token::make_inner_doc_comment): Likewise.
(Token::make_outer_doc_comment): Likewise.
(Token::make_lifetime): Likewise.
(Token::get_str): Add definition to function declaration.
(Token::has_str): Remove member function.
(Token::should_have_str): Handle INNER_DOC_COMMENT and
OUTER_DOC_COMMENT.
Owen Avery [Fri, 22 Aug 2025 02:22:36 +0000 (22:22 -0400)]
gccrs: Eagerly expand format_args macro
This allows format_args!(some_macro!(...), ...) to compile.
gcc/rust/ChangeLog:
* expand/rust-macro-builtins-format-args.cc
(format_args_parse_arguments): Split format expression parsing
into...
(format_args_parse_expr): ...a new function here, while handling
eager expansion.
(MacroBuiltin::format_args_handler): Use format_args_parse_expr.
This improves our handling of PathInExpression and fixes
https://github.com/Rust-GCC/gccrs/issues/4056.
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::parse_expr): Avoid skipping
or splitting tokens.
(Parser::null_denotation): Assume initial token was not skipped
and adjust function signature to match. Use
parse_path_in_expression instead of
parse_path_in_expression_pratt and handle SCOPE_RESOLUTION.
(Parser::parse_path_in_expression_pratt): Remove function.
* parse/rust-parse.h (null_denotation): Remove initial token
parameter.
(parse_path_in_expression_pratt): Remove function.
Error kind were split between error state and out bool parameter.
gcc/rust/ChangeLog:
* typecheck/rust-coercion.cc (TypeCoercionRules::do_coercion): Adapt
call to new return type.
(TypeCoercionRules::coerce_unsized): Change error handling.
* typecheck/rust-coercion.h: Update function prototype and add new
CoerceUnsizedError error type.
gccrs: Implement rest pattern support for slice patterns
This patch adds support for compiling rest patterns present in slice patterns
(e.g. `[1, .., 2]`). 006t.original output from compiling match-slicepattern-slice-2.rs
for first 2 match arms:
* hir/tree/rust-hir-pattern.h: Add SlicePatternItems base class and
SlicePatternItemsNoRest/SlicePatternItemsHasRest derived classes.
Update SlicePattern to hold patterns using the new classes.
* hir/tree/rust-hir-full-decls.h: Declare new classes.
* hir/tree/rust-hir.cc: Add visits for new classes.
* hir/tree/rust-hir-visitor.h: Add visits for new classes.
* hir/tree/rust-hir-visitor.cc: Implement visits for new classes.
* hir/rust-hir-dump.h: Add visits for new classes.
* hir/rust-hir-dump.cc: Implement Dump::visit for new classes.
* hir/rust-ast-lower-base.h: Declare new lower_slice_pattern_no_rest/has_rest
methods.
* hir/rust-ast-lower-base.cc: Implement lower_slice_pattern_no_rest/has_rest
to lower AST slice pattern items to HIR.
* hir/rust-ast-lower-pattern.cc: Update ASTLoweringPattern::visit for
SlicePattern to use new lowering methods.
* backend/rust-compile-pattern.cc: Update CompilePatternCheckExpr::visit
and CompilePatternBindings::visit for SlicePattern to handle
SlicePatternItemsNoRest/HasRest.
* checks/errors/borrowck/rust-bir-builder-pattern.cc: Update
PatternBindingBuilder::visit for SlicePattern to iterate members correctly.
* checks/errors/borrowck/rust-bir-builder-struct.h: Add visits for new
classes.
* checks/errors/borrowck/rust-function-collector.h: Add visits for new
classes.
* checks/errors/rust-const-checker.h: Add visits for new classes.
* checks/errors/rust-const-checker.cc: Implement empty visits for new classes.
* checks/errors/rust-hir-pattern-analysis.h: Add visits for new classes.
* checks/errors/rust-hir-pattern-analysis.cc: Implement empty visits for new
classes.
* checks/errors/rust-unsafe-checker.h: Add visits for new classes.
* checks/errors/rust-unsafe-checker.cc: Implement empty visits for new
classes.
* typecheck/rust-hir-type-check-pattern.cc: Update TypeCheckPattern::visit
for SlicePattern to handle SlicePatternItemsNoRest/HasRest.
Ryutaro Okada [Tue, 12 Aug 2025 05:17:09 +0000 (22:17 -0700)]
gccrs: Replace old read-only checker with new implementation.
gcc/rust/ChangeLog:
* Make-lang.in: Replace old read-only checker with new implementation.
* checks/errors/rust-readonly-check.cc (ReadonlyChecker::ReadonlyChecker):
Replace old read-only checker with new implementation.
* checks/errors/rust-readonly-check.h:
Replace old read-only checker with new implementation.
* rust-session-manager.cc (Session::compile_crate):
Switch to new read-only checker.
* checks/errors/rust-readonly-check2.cc: Removed.
* checks/errors/rust-readonly-check2.h: Removed.
Ryutaro Okada [Tue, 12 Aug 2025 05:01:08 +0000 (22:01 -0700)]
gccrs: Read-only check if the variable is mutable type.
gcc/rust/ChangeLog:
* checks/errors/rust-readonly-check2.cc (ReadonlyChecker::check_variable):
Read-only check if the variable is mutable type.
(ReadonlyChecker::is_mutable_type): Read-only check if the variable is mutable type.
* checks/errors/rust-readonly-check2.h: Read-only check if the variable is mutable type.
* backend/rust-compile-pattern.cc(CompilePatternLet::visit(IdentifierPattern)):
Add support for subpatterns.
* backend/rust-compile-var-decl.h(CompileVarDecl::visit(IdentifierPattern)):
Implement compilation for subpatterns.
lishin [Wed, 13 Aug 2025 18:16:52 +0000 (19:16 +0100)]
gccrs: fix ICE by skipping invalid (non-FNDEF) candidates
gcc/rust/ChangeLog:
* typecheck/rust-hir-dot-operator.cc (MethodResolver::Select):
Skip asserts by checking candidate type and using early-continue.
(MethodResolver::try_select_predicate_candidates):
Skip invalid candidates.
Owen Avery [Mon, 11 Aug 2025 17:44:25 +0000 (13:44 -0400)]
gccrs: Improve handling of non-final path segments
gcc/rust/ChangeLog:
* resolve/rust-forever-stack.hxx
(ForeverStack::resolve_segments): Remove usage of optional
reference, allow non-final path segments to resolve to types
even outside the type namespace, and allow resolution to
progress past non-final path segments which resolve to modules.
No check was performed and the value was assumed non null.
Path conversion returned an empty path for "Self" due to a hack in
generics Self injection that prevented any "Self!" macro from beeing
recognized correctly.
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::parse_stmt_or_expr): Add null check
on parse_macro_invocation_partial call.
* ast/rust-path.cc (Path::convert_to_simple_path): Do not exclude
capitalized "Self".
Arthur Cohen [Tue, 12 Aug 2025 15:04:03 +0000 (17:04 +0200)]
gccrs: ast: Cleanup SingleASTNode::NodeType
gcc/rust/ChangeLog:
* ast/rust-ast.h: Change NodeType to enum class Kind.
* ast/rust-ast-fragment.cc: Use new names.
* ast/rust-ast-fragment.h: Likewise.
* ast/rust-ast.cc (SingleASTNode::SingleASTNode): Likewise.
Owen Avery [Tue, 12 Aug 2025 02:06:02 +0000 (22:06 -0400)]
gccrs: CfgStrip AST nodes marked with #[test]
gcc/rust/ChangeLog:
* expand/rust-cfg-strip.cc: Include "rust-macro-expand.h".
(fails_cfg): Rename to...
(CfgStrip::fails_cfg): ...here and handle test attributes.
(fails_cfg_with_expand): Rename to...
(CfgStrip::fails_cfg_with_expand): ...here and handle test
attributes.
* expand/rust-cfg-strip.h (struct ExpansionCfg): Forward
declare.
(CfgStrip::fails_cfg): New member function.
(CfgStrip::fails_cfg_with_expand): Likewise.
(CfgStrip::CfgStrip): Accept reference to ExpansionCfg.
(CfgStrip::expansion_cfg): New member variable.
* rust-session-manager.cc (Session::expansion): Pass
ExpansionCfg instance to CfgStrip constructor.
gccrs: Emit an error message on unsupported llvm_asm
llvm_asm was never meant to be completely supported since it has been
replaced with the asm macro but we still need it to compile some parts
of libcore, previously the compiler was aborting when an unsupported
llvm_asm construct was found.
gcc/rust/ChangeLog:
* ast/rust-expr.h: Add const getters to llvm members.
* hir/rust-ast-lower-expr.cc (check_llvm_asm_support): Check llvm_asm
usage validity.
(ASTLoweringExpr::visit): Emit an error message instead of aborting.
Owen Avery [Sat, 9 Aug 2025 22:33:58 +0000 (18:33 -0400)]
gccrs: Add checks to ExpandVisitor
This should help detect issues like
https://github.com/Rust-GCC/gccrs/issues/3444.
gcc/rust/ChangeLog:
* ast/rust-ast.h (Stmt::get_node_id): Make virtual.
(Type::get_node_id): Likewise.
(AssociatedItem::get_node_id): New virtual member function.
* ast/rust-expr.h (TypeCastExpr::get_casted_expr_ptr): New
member function.
(TypeCastExpr::get_type_to_cast_to_ptr): Likewise.
(ClosureExprInner::get_definition_expr_ptr): Likewise.
* ast/rust-item.h (TypeAlias::get_node_id): New member function
to override AssociatedItem::get_node_id.
(ConstantItem::get_node_id): Likewise.
* expand/rust-expand-visitor.cc
(ExpandVisitor::maybe_expand_expr): Adjust
macro_invoc_expect_id.
(ExpandVisitor::maybe_expand_type): Likewise and add an overload
for std::unique_ptr<TypeNoBounds>.
(ExpandVisitor::visit): Check macro_invoc_expect_id and
generally improve visitors so that the testsuite will still
pass.
* expand/rust-expand-visitor.h (ExpandVisitor::ExpandVisitor):
Initialize member variable macro_invoc_expect_id.
(ExpandVisitor::maybe_expand_type): Add an overload for
std::unique_ptr<TypeNoBounds>.
(ExpandVisitor::expand_macro_children): Adjust
macro_invoc_expect_id.
(ExpandVisitor::visit): Add an overload for TypeCastExpr.
(ExpandVisitor::macro_invoc_expect_id): New member variable.
gcc/testsuite/ChangeLog:
* rust/compile/macros/mbe/macro49.rs: Add missing lang items.
lishin [Fri, 8 Aug 2025 21:35:20 +0000 (22:35 +0100)]
gccrs: Fix ICE on exclusive_range_pattern lowering
gcc/rust/ChangeLog:
* backend/rust-compile-pattern.cc (CompilePatternCheckExpr::visit):
Check upper compare operator.
* hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::visit):
Handle lowering of exclusive range pattern.
* hir/tree/rust-hir-pattern.h (class RangePattern):
Add support for exclusive ranges in HIR representation.
* expand/rust-macro-expand.cc (transcribe_expression): Parse any
outer attributes before parsing an expression.
* parse/rust-parse.h (Parser::parse_outer_attributes): Make
public.
Several place built an object before copying it in a vector. This commit
favorise in place construction and use readily available vector size to
reserve memory beforehand.
Owen Avery [Tue, 5 Aug 2025 20:44:02 +0000 (16:44 -0400)]
gccrs: Improve handling of AttrInputLiteral
Also adjusts a few error messages to be more in line with rustc (and
more amenable to extract_string_literal usage).
gcc/rust/ChangeLog:
* util/rust-attributes.cc (Attributes::extract_string_literal):
New function definition.
* util/rust-attributes.h (Attributes::extract_string_literal):
New function declaration.
* ast/rust-collect-lang-items.cc (get_lang_item_attr): Use
extract_string_literal.
* backend/rust-compile-base.cc: Include "rust-attributes.h".
(HIRCompileBase::handle_link_section_attribute_on_fndecl):
Use extract_string_literal.
(HIRCompileBase::handle_must_use_attribute_on_fndecl): Likewise.
* hir/rust-ast-lower-base.cc
(ASTLoweringBase::handle_lang_item_attribute): Likewise.
* rust-session-manager.cc (Session::handle_crate_name):
Likewise.
gccrs: Refactor HIR::PatternItem class and its derivatives
Renames HIR::TupleItems to PatternItems for better generalization because it will be reused for
SlicePattern in the future. Enum values MULTIPLE/RANGED are renamed to NO_REST/HAS_REST
to reduce misleadingness as it is completely different and separate from the ranged values `..`
representation. This results in renaming of all related classes and updates to all code that
references them.
gcc/rust/ChangeLog:
* hir/tree/rust-hir-pattern.h:
- Rename TupleItems to PatternItems.
- Rename TuplePatternItemsMultiple/Ranged & TupleStructItemsRange/NoRange to
TuplePatternItemsNoRest/HasRest and TupleStructItemsNoRest/HasRest.
- Update enum values to NO_REST/HAS_REST.
- Rename clone_tuple_items_impl to clone_pattern_items_impl.
* hir/tree/rust-hir-full-decls.h: Renamed the classes accordingly.
* hir/tree/rust-hir-visitor.h: Renamed the classes accordingly.
* hir/tree/rust-hir-visitor.cc: Renamed the classes accordingly.
* hir/rust-hir-dump.h: Renamed the classes accordingly.
* hir/rust-hir-dump.cc: Renamed the classes accordingly.
* hir/tree/rust-hir.cc: Renamed the classes accordingly.
* hir/rust-ast-lower-base.cc: Renamed the classes accordingly.
* hir/rust-ast-lower-pattern.cc: Renamed the classes accordingly.
* backend/rust-compile-pattern.cc: Renamed the classes accordingly.
* backend/rust-compile-var-decl.h: Renamed the classes accordingly.
* checks/errors/borrowck/rust-bir-builder-pattern.cc: Renamed the classes accordingly.
* checks/errors/borrowck/rust-bir-builder-struct.h: Renamed the classes accordingly.
* checks/errors/borrowck/rust-function-collector.h: Renamed the classes accordingly.
* checks/errors/rust-const-checker.cc: Renamed the classes accordingly.
* checks/errors/rust-const-checker.h: Renamed the classes accordingly.
* checks/errors/rust-hir-pattern-analysis.cc: Renamed the classes accordingly.
* checks/errors/rust-hir-pattern-analysis.h: Renamed the classes accordingly.
* checks/errors/rust-unsafe-checker.cc: Renamed the classes accordingly.
* checks/errors/rust-unsafe-checker.h: Renamed the classes accordingly.
* checks/errors/rust-readonly-check2.cc: Renamed the classes accordingly.
* typecheck/rust-hir-type-check-pattern.cc: Update references to renamed classes and enum
values.
David Faust [Tue, 28 Oct 2025 18:13:25 +0000 (11:13 -0700)]
dwarf: handle repeated decl with different btf_decl_tags [PR122248]
The check in gen_btf_tag_dies which asserted that if the target DIE
already had an annotation then it must be the same as the one we are
attempting to add was too strict. It is valid for multiple declarations
of the same object to appear with different decl_tags, in which case the
tags from each are accumulated in DECL_ATTRIBUTES. The existing
annotation may not be the same as the one being added, since new tags
will be added to the head of the chain.
The proper behavior is to always replace any existing AT_GNU_annotation
to refer to the chain of annotations we have just constructed, whether
the head of that chain is the same or not.
PR debug/122248
gcc/
* dwarf2out.cc (gen_btf_tag_dies): Always replace an existing
AT_GNU_annotation on the target die.
David Faust [Wed, 29 Oct 2025 22:21:16 +0000 (15:21 -0700)]
btf: do not prune at typedefs
The existing BTF pruning logic meant that an anonymous struct or
union type hidden behind a typedef, such as in the common construct:
typedef struct { ... } my_struct_type;
could be pruned if 'my_struct_type' was only ever referenced via pointer
members in other structs/unions types used in the program.
The result of pruning is to skip emitting full type information for
a struct or union type by replacing it with a BTF_KIND_FWD, indicating
that it exists but its definition is omitted. Any types used only by
pruned types are fully omitted from the generated BTF.
In cases like this where the struct/union type is anonymous, the result
is an anonymous BTF_KIND_FWD, which is useless. The presence of such a
type record rightly causes complaints from BTF loaders. Worse, since
the TYPEDEF for 'my_struct_type' itself may _not_ be pruned, its type
information will be incomplete.
Change the BTF pruner so that we never consider pruning at a typedef,
and always either keep or discard both the type and the typedef.
gcc/
* btfout.cc (btf_add_used_type_1): Do not consider creating
fixups at typedefs.
Michal Jires [Mon, 25 Aug 2025 16:23:24 +0000 (18:23 +0200)]
lto: Partition toplevel assembly in 1to1
1to1 partitioning now also partitions toplevel assembly.
Other partitionings keep the old behavior of putting all
toplevel assembly into single partition.
Michal Jires [Mon, 25 Aug 2025 16:07:29 +0000 (18:07 +0200)]
lto: Use toplevel_node in lto_symtab_encoder
This patch replaces symtab_node with toplevel_node in lto_symtab_encoder
and modifies all places where lto_symtab_encoder is used to handle
(ignore) asm_node.
Michal Jires [Mon, 25 Aug 2025 15:37:19 +0000 (17:37 +0200)]
cgraph: Add toplevel_node
asm_node and symbol_node will now inherit from toplevel_node.
This is now useful for lto partitioning, in future it should be also
useful for toplevel extended assembly.
Michal Jires [Thu, 15 May 2025 14:37:12 +0000 (16:37 +0200)]
lto: Fix reversed sorting of node order.
Sorting by node order in lto partitioning is incorrectly reversed.
For default balanced partitioning this caused all noreorder symbols
to be partitioned into a single partition where they were sorted again,
but correctly.
Qing Zhao [Fri, 24 Oct 2025 18:02:06 +0000 (18:02 +0000)]
Extend the attribute "counted_by" to support VOID pointer under GNU extension.
This extension is requested by linux kernel to ease the adoption of counted_by
attribute into linux kernel.
Please refer to
https://lore.kernel.org/lkml/20251021095447.GL3245006@noisy.programming.kicks-ass.net/
for the initial request for this feature.
The attribute is allowed for a pointer to void, However,
Warnings will be issued for such cases when -Wpointer-arith is
specified. When this attribute is applied on a pointer to void, the
size of each element of this pointer array is treated as 1.
gcc/c-family/ChangeLog:
* c-attribs.cc (handle_counted_by_attribute): Allow counted_by for
void pointer. Issue warnings when -Wpointer-arith is present.
gcc/c/ChangeLog:
* c-typeck.cc (build_access_with_size_for_counted_by): When the element
type is void, assign size one as the element_size.
gcc/ChangeLog:
* doc/extend.texi: Clarification when the counted_by attribute is applied
on a void pointer.
gcc/testsuite/ChangeLog:
* gcc.dg/pointer-counted-by.c: Update for void pointers.
* gcc.dg/pointer-counted-by-10.c: New test.
* gcc.dg/pointer-counted-by-4-void.c: New test.
Andrew Pinski [Wed, 29 Oct 2025 18:58:31 +0000 (11:58 -0700)]
MATCH: Optimize `VEC_SHL_INSERT (dup (A), A)` to just `dup (A) [PR116075]
It was noticed if we have `.VEC_SHL_INSERT ({ 0, ... }, 0)` it was not being
simplified to just `{ 0, ... }`. This was generated from the autovectorizer
(maybe even on accident, see PR tree-optmization/116081).
This adds a few SVE testcases to see if this is optimized since the
auto-vectorizer or intrinsics are the only two ways of getting this
produced.
Changes since:
* v1: Move the constant case over to fold-const-call.cc.
Simplify match pattern to use handle vec_duplicate.
Build and tested for aarch64-linux-gnu with no regressions.
PR target/116075
gcc/ChangeLog:
* fold-const-call.cc (fold_const_vec_shl_insert): New function.
(fold_const_call): Call fold_const_vec_shl_insert for CFN_VEC_SHL_INSERT.
* match.pd (`VEC_SHL_INSERT (dup (A), A)`): New pattern.
gcc/testsuite/ChangeLog:
* gcc.target/aarch64/sve/dup-insr-1.c: New test.
* gcc.target/aarch64/sve/dup-insr-2.c: New test.
Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
The two two clobber can be considered the same.
So starting at `bb 4`'s. Bofore we walk back to the call of g statement
and would notice that the use in the phi node of `bb5` and that would cause
the walk to stop. But in this case since he phi node has a single use of the
clobber and the clobber matches the original clobber it can be considered the
same "one". So with the patch now, we walk back one more statement and allow it.
Similar to the at the call to p statement.
Bootstrapped and tested on x86_64-linux-gnu.
PR tree-optimization/122247
gcc/ChangeLog:
* tree-ssa-forwprop.cc (do_simple_agr_dse): Allow phi node for the usage
if the usage of the phi result is just the "same" as the original clobber.
gcc/testsuite/ChangeLog:
* g++.dg/tree-ssa/copy-prop-aggregate-sra-2.C: New test.
Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
So when the simple DSE looks at the clobber from `bb3`, we find the use of
MEM_6 is in a non dominating BB of BB3 so it gets rejected. But since this usage
is also a clobber which isthe same as the original clobber; it can be safely assumed
to do the same thing as the first clobber. So it can be safely ignored.
Bootstrapped and tested on x86_64-linux-gnu.
PR tree-optimization/122247
gcc/ChangeLog:
* tree-ssa-forwprop.cc (do_simple_agr_dse): Allow
use to be a clobber of the same kind to the same lhs.
gcc/testsuite/ChangeLog:
* g++.dg/tree-ssa/copy-prop-aggregate-sra-1.C: New test.
Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
Robin Dapp [Fri, 17 Oct 2025 09:07:17 +0000 (11:07 +0200)]
niter: Use ranger to query ctz range.
When niter runs after the copy-header pass it sometimes fails to
simplify assumptions in a ctz loop.
As the assumption is a simple nonzero test here we can have
ranger get us the range of the shifted expression, then verify that
this range is nonzero.
This helps recognize a ctz loop in 502.gcc's compute_transp.
PR/tree-optimization 122207
gcc/ChangeLog:
* tree-ssa-loop-niter.cc (shifted_range_nonzero_p): New
function.
(number_of_iterations_cltz): Call new function.
* tree-ssa-loop.cc (pass_scev_cprop::execute): Enable ranger.
Eric Botcazou [Thu, 30 Oct 2025 14:41:09 +0000 (15:41 +0100)]
[Ada] Fix formal parameter incorrectly visible from outside of instance
The problem had been partially fixed two decades ago and the original
testcase correctly rejected, but almost 4 years later the submitter
made a small tweak to it which exposed the issue again...
The original fix was a change to Find_Expanded_Name, this additional fix
is to make exactly the same change to the processing of Collect_Interps
for expanded names.
gcc/ada/
PR ada/15610
* sem_type.adb (Collect_Interps): Apply the same visibility
criterion to expanded names as Find_Expanded_Name.
gcc/testsuite/
* gnat.dg/specs/generic_inst7.ads: New test.
* gnat.dg/specs/generic_inst8.ads: New test.
Robin Dapp [Thu, 30 Oct 2025 13:48:07 +0000 (07:48 -0600)]
[PATCH v2] RISC-V: avlprop: Scale AVL by subreg ratio [PR122445].
Hi,
Since r16-4391-g85ab3a22ed11c9 we can use a punned type/mode for grouped
loads and stores. Vineet reported an x264 wrong-code bug since that
commit. The crux of the issue is that in avlprop we back-propagate
the AVL from consumers (like stores) to producers.
When e.g. a V4QI vector is type-punned by a V1SI vector
(subreg:V1SI (reg:V4QI ...)
the AVL of that instruction refers to the outer subreg mode, i.e. for an
AVL of 1 in a store we store one SImode element. The producer of the
store data is not type punned and still uses V4QI and we produce 4
QImode elements. Due to this mismatch we back-propagate the consumer
AVL of 1 to the producers, causing wrong code.
This patch looks if the use is inside a subreg and scales the immediate
AVL by the ratio of inner and outer mode.
Changes from v1:
- Move NULL check into loop.
- Add REG_P check.
Regtested on rv64gcv_zvl512b.
Regards
Robin
PR target/122445
gcc/ChangeLog:
* config/riscv/riscv-avlprop.cc (pass_avlprop::get_vlmax_ta_preferred_avl):
Scale AVL of subreg uses.
gcc/testsuite/ChangeLog:
* gcc.target/riscv/rvv/autovec/pr122445.c: New test.
Artemiy Volkov [Thu, 30 Oct 2025 13:42:03 +0000 (07:42 -0600)]
[PATCH][PR tree-optimization/122478] match.pd: fix simplify pattern for view_convert (BIT_FIELD_REF)
The pattern introduced in r16-4682-g5eafa8d16be873 couldn't handle
conversion from <unnamed-unsigned:1> to unsigned char, which ended up
causing a gimple checking failure reported in PR122478. This patch fixes
the pattern by prohibiting widening integral conversions in addition to
the narrowing ones, or equivalently, requiring that the converted-to and
converted-from types of the VCE both have precision equal to their size.
Since type_has_mode_precision_p () does not apply to vector types, filter
them out by adding a !INTEGRAL_TYPE_P () check on TREE_TYPE (@0).
Bootstrapped and regtested on aarch64 and x86_64, regtested on i386 and
riscv64, one GIMPLE test added.
PR tree-optimization/122478
gcc/ChangeLog:
* match.pd: Fix the view_convert (BIT_FIELD_REF) pattern.
Richard Biener [Thu, 30 Oct 2025 13:24:46 +0000 (14:24 +0100)]
Adjust gcc.dg/tree-ssa/pr92834.c
Scanning the optimized dump is fragile due to vectorization. The
following instead scans after early phiopt1, adjusting for not
yet eliminated static functions.
* gcc.dg/tree-ssa/pr92834.c: Scan phiopt1 instead of optimized.
Richard Biener [Thu, 30 Oct 2025 12:30:21 +0000 (13:30 +0100)]
[i386] Fix type in ix86_move_max setup
There's a typo in the way we compute opts->x_ix86_move_max:
if (opts_set->x_ix86_move_max == PVW_NONE)
{
/* Set the maximum number of bits can be moved from memory to
memory efficiently. */
if (opts_set->x_prefer_vector_width_type != PVW_NONE)
opts->x_ix86_move_max = opts->x_prefer_vector_width_type;
else if (ix86_tune_features[X86_TUNE_AVX512_MOVE_BY_PIECES])
opts->x_ix86_move_max = PVW_AVX512;
else if (ix86_tune_features[X86_TUNE_AVX256_MOVE_BY_PIECES])
opts->x_ix86_move_max = PVW_AVX256;
else
{
opts->x_ix86_move_max = opts->x_prefer_vector_width_type;
/* */ if (opts_set->x_ix86_move_max == PVW_NONE)
{
if (TARGET_AVX512F_P (opts->x_ix86_isa_flags))
opts->x_ix86_move_max = PVW_AVX512;
/* Align with vectorizer to avoid potential STLF issue. */
else if (TARGET_AVX_P (opts->x_ix86_isa_flags))
opts->x_ix86_move_max = PVW_AVX256;
else
opts->x_ix86_move_max = PVW_AVX128;
}
}
}
as written the /* */ condition is redundant with the outermost one.
But intended is (IMO) that the earlier set opts->x_prefer_vector_width_type
via X86_TUNE_{AVX128,AVX256}_OPTIMAL takes precedence over the ISA
based setup that follows. So instead of checking opts_set we want
to check whether the previous assignment left us with still PVW_NONE.
The issue makes us ignore X86_TUNE_AVX128_OPTIMAL/X86_TUNE_AVX256_OPTIMAL
when determining opts->x_ix86_move_max.
* config/i386/i386-options.cc (ix86_option_override_internal):
Fix check during opts->x_ix86_move_max initialization.
lra: Fix computing reg class for hard register constraints [PR121198]
Currently the register class derived from a hard register constraint is
solely determined from a single register. This even works for register
pairs if all the required registers are contained in this very register
class and falls apart if not. For example:
long
test (void)
{
long x;
__asm__ ("..." : "={r22}" (x));
return x;
}
For AVR -mmcu=atmega8, variable `x` requires a register quadruple and
the minimal class for single register r22 is SIMPLE_LD_REGS which itself
entails registers r16 up to r23. However, variable `x` is bound to
registers r22 up to r25. Thus, the minimal class containing those is
LD_REGS. Therefore, compute the least upper bound of all register
classes over all required registers.
PR rtl-optimization/121198
gcc/ChangeLog:
* lra-constraints.cc (process_alt_operands): Compute least upper
bound of all register classes over all required registers in
order to determine register class for a hard register constraint.
Gaius Mulley [Thu, 30 Oct 2025 11:19:08 +0000 (11:19 +0000)]
PR modula2/122485: add spell checking to module names
This patch introduces spell checking during module imports.
If the correct module name has been seen prior to the incorrect import
then it will attempt to provide a hint during the error message.
gcc/m2/ChangeLog:
PR modula2/122485
* gm2-compiler/M2Comp.mod (Pass0CheckDef): Add spell check
format specifier filtering on module names.
* gm2-compiler/M2MetaError.mod (errorBlock): New field
filterDef.
(initErrorBlock): Initialize filterDef.
(continuation): Add 'D' filter on definition module specifier.
(SpellHint): Rewrite to check for filterDef and defimp symbols.
(FilterOnDefinitionModule): New procedure.
* gm2-compiler/M2Quads.mod (BuildSizeFunction): Rewrite to
ensure variables are initialized.
* gm2-compiler/M2StackSpell.def (GetDefModuleSpellHint): New
procedure function.
* gm2-compiler/M2StackSpell.mod (GetDefModuleSpellHint): New
procedure function.
(CandidatePushName): New procedure.
(BuildHintStr): New procedure.
(CheckForHintStr): Rewrite.
gcc/testsuite/ChangeLog:
PR modula2/122485
* gm2.dg/spell/iso/fail/badimport.mod: New test.
Richard Biener [Thu, 30 Oct 2025 09:38:13 +0000 (10:38 +0100)]
Swap operands during SLP discovery for mismatching STMT_VINFO_REDUC_IDX
When we are unlucky operand canonicalization can end up presenting
us with different order, making a possible SLP reduction group
not match up. The following allows swapping operands in this case.
* tree-vect-slp.cc (vect_get_operand_map): Handle commutative
operands when swapping is requested.
(vect_build_slp_tree_1): Allow STMT_VINFO_REDUC_IDX differences
when operand swapping makes them match and request swapping.
(vect_build_slp_instance): Indicate we have successfully
discovered a SLP reduction group.
* gcc.dg/vect/slp-reduc-13.c: New testcase.
Co-authored-by: Eric Botcazou <ebotcazou@adacore.com>
* config/i386/i386.md (ovf_add_cmp): New code attribute.
(udf_sub_cmp): Ditto.
(ovf_comm): New int iterator.
(*plus_within_<code><mode>3_<ovf_comm>): New insn and split pattern.
(*minus_within_<code><mode>3): Ditto.
gcc/testsuite/ChangeLog:
* gcc.dg/pr116815.c: New test.
* gcc.target/i386/pr116815.c: New test.
Andrew Pinski [Wed, 29 Oct 2025 23:30:50 +0000 (16:30 -0700)]
gimple-fold: Remove assume_aligned folding
So in the end I agree with Richi's comment at
https://gcc.gnu.org/pipermail/gcc-patches/2025-October/698856.html:
> I see. I wonder whether it would be better to leave __builtin_assume_aligned
> around then, because that inherently introduces the copy and it would show why.
> TER / SSA coalescing might make a mess our of the copies you leave in place
> anyway, no?
This leaves __builtin_assume_aligned around.
Will also push the revert of r16-4637-g8590b32deac05e along side this.
* c-c++-common/ubsan/align-5.c: Xfail.
* gcc.dg/pr107389.c: Move to...
* gcc.dg/torture/pr107389.c: ...here. Skip for lto.
* gcc.dg/builtin-assume-aligned-1.c: Instead of
testing for deleting of assume-align, test for
the alignment/misalignment. Also disable the
vectorizer.
Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>