This doesn't actually handle the attribute, although it does allow us to
recognize it as valid.
gcc/rust/ChangeLog:
* util/rust-attribute-values.h
(Attributes::RUSTC_ALLOW_CONST_FN_UNSTABLE): New static
constexpr member variable.
* util/rust-attributes.cc (__definitions): Add entry for
RUSTC_ALLOW_CONST_FN_UNSTABLE.
Philip Herron [Sun, 3 Aug 2025 18:53:23 +0000 (19:53 +0100)]
gccrs: allow unifications against non const types
When type resolving a function which returns a const generic for example
this means its unifying the ConstType vs the the specified type so this
mean unwrapping the type of the const.
gcc/rust/ChangeLog:
* typecheck/rust-unify.cc (UnifyRules::go): unwrap the const type
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Fri, 29 Aug 2025 16:54:54 +0000 (17:54 +0100)]
gccrs: Remove fully the can_eq TyTy::BaseType::can_eq interface
This was an initial helper from back in the day which was not maintained
but was a nice const simple way to check if types are compatable. But
reusing our unify code is much much more acurate and single source of
truth on the type system.
Philip Herron [Fri, 29 Aug 2025 16:42:10 +0000 (17:42 +0100)]
gccrs: simplify cloning of types during unify
We should only clone when we commit and it was successful. With no
cloning there is a regression in min specialization 2. Probably because
it needs to know the unify site hirid and ensure we have it set there.
Philip Herron [Mon, 25 Aug 2025 12:30:22 +0000 (13:30 +0100)]
gccrs: respect the unify rules commit flag
We use the types compatable interface for unify here and so if
we dont respect the commit flag the interface can have unintended
side effects with infer type hints throwing things off down the line.
Philip Herron [Mon, 25 Aug 2025 10:34:25 +0000 (11:34 +0100)]
gccrs: Remove some const usage so we can get rid of more can_eq usage
I needed to remove som usage of const so we can get rid of can_eq in
type bounds probe. This means we can use the types_compatable interface
instead. Which is much better.
Philip Herron [Mon, 25 Aug 2025 19:44:16 +0000 (20:44 +0100)]
gccrs: Make the coerce borrowed pointer consistent with try flag
This interface is not respecting the coercion api commit is always false,
we need to ensure this is respected via the try flag like the rest of the
coercion logic.
gcc/rust/ChangeLog:
* typecheck/rust-coercion.cc (TypeCoercionRules::select): respect try flag
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gccrs: Error out on unsuffixed self list use declaration
gcc/rust/ChangeLog:
* resolve/rust-early-name-resolver-2.0.cc (Early::finalize_rebind_import):
Replace assert with early break and remove early return.
(Early::visit): Check for unsuffixed lower self list.
* resolve/rust-early-name-resolver-2.0.h: Add visit function prototype.
gcc/testsuite/ChangeLog:
* rust/compile/use_self_alone_in_list.rs: New test.
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.