Arthur Cohen [Wed, 8 Feb 2023 11:23:06 +0000 (12:23 +0100)]
gccrs: expander: Add documentation for `expand_eager_invocations`
gcc/rust/ChangeLog:
* expand/rust-macro-expand.cc (MacroExpander::expand_eager_invocations):
Add documentation explaining the algorithm.
Arthur Cohen [Wed, 18 Jan 2023 11:23:03 +0000 (12:23 +0100)]
gccrs: macros: Perform macro expansion in a fixed-point fashion.
This commit changes our macro expansion system from an eager and recursive
macro expansion to a fixed-point like system. Instead of, when seeing
a macro invocation, expanding it and all of the macros within it, we
now perform multiple passes of expansion on the entire crate.
This, however, leads to a problem. Rust macros are expanded lazily, but
Rust builtin macros should be expanded eagerly. Due to this, we must
work around the lazy expansion in builtin macros and perform eager
expansion for each pass of the fixed-point, before finally expanding
the builtin when there are no longer any inner macro invocations.
To perform proper macro scoping, the ENR now keeps track of the current
scope (`current_scope` member) and resolves macros accordingly.
This is done through the use of the `scoped` method, which creates a new
scope, runs a specified lambda and then exits the scope. This prevents
pushing/popping errors that we've seen happen already in similar
contexts.
We might think about generalizing it to other classes, providing a
`Scoped<EntryFn, ExitFn>` class or similar
gcc/rust/ChangeLog:
* ast/rust-macro.cc: New file.
* Make-lang.in: Add `rust-macro.o` object
* ast/rust-ast-fragment.cc (Fragment::Fragment): Change API around
the construction of AST fragments.
(Fragment::operator=): Correct `Fragment::operator=` to take into
account the fragment tokens.
(Fragment::create_error): Use new constructor.
(Fragment::complete): Remove in favor of new constructor.
(Fragment::unexpanded): Remove as that Fragment type is no longer used
or possible.
(Fragment::get_tokens): Add helper to access a fragment's tokens.
* ast/rust-ast-fragment.h (enum class): Remove `FragmentKind::Unused`
* ast/rust-ast.cc (MacroInvocation::as_string): Display
builtin macro invocations properly.
* ast/rust-ast.h: Fix `DelimTokenTree` class copy constructors and
handling of its token vector.
* ast/rust-macro.h (class MacroMatcher): Format.
(class MetaItemSeq): Likewise.
(builtin_macro_from_string): Get a `BuiltinMacroKind` from a given
string, i.e the name of the macro (`assert!`, `cfg!` and so on).
* expand/rust-attribute-visitor.cc (AttrVisitor::visit): Do not expand
macros recursively anymore.
(AttrVisitor::maybe_expand_expr): Likewise.
(AttrVisitor::maybe_expand_type): Likewise.
* expand/rust-attribute-visitor.h: Likewise, and remove
`expand_macro_fragment_recursively` function.
* expand/rust-macro-builtins.cc (make_token): Add shorthand for
returning `std::unique_ptr<AST::Token>`s.
(make_macro_invocation): Add shorthand for returning fragments
containing builtin macro invocations.
(try_expand_macro_expression): Do not expand macros recursively.
(try_expand_single_string_literal): Likewise.
(try_expand_many_expr): Likewise.
(parse_single_string_literal): Error out more appropriately.
(MacroBuiltin::compile_error_handler): Add explanation for eager
invocation
(MacroBuiltin::file_handler): Return the proper tokens associated with
macro invocation, and builtin macros in the case of necessary eager
expansion.
(MacroBuiltin::column_handler): Likewise.
(MacroBuiltin::include_bytes_handler): Likewise.
(MacroBuiltin::include_str_handler): Likewise.
(MacroBuiltin::concat_handler): Likewise.
(MacroBuiltin::env_handler): Likewise.
(MacroBuiltin::cfg_handler): Likewise.
(MacroBuiltin::include_handler): Likewise.
(MacroBuiltin::line_handler): Likewise.
* expand/rust-macro-expand.cc (MacroExpander::expand_eager_invocations):
Add function to expand eager invocations *once* in the fixed point
pipeline.
(MacroExpander::expand_invoc): Call into `expand_eager_invocations` for
builtin macro invocations.
(MacroExpander::expand_crate): Use new `AttrVisitor` API.
(parse_many): Return tokens in `AST::Fragment`.
(transcribe_expression): Likewise.
(transcribe_type): Likewise.
* expand/rust-macro-expand.h (struct MacroExpander): Add `has_changed`
flag for fixed point checking.
* resolve/rust-early-name-resolver.cc (EarlyNameResolver::EarlyNameResolver):
Keep track of the current macro scope.
(EarlyNameResolver::go): Use `scoped` API.
(EarlyNameResolver::visit): Likewise.
* resolve/rust-early-name-resolver.h: Add `scoped` API.
* rust-session-manager.cc (Session::expansion): Perform macro expansion
in a fixed-point fashion.
gcc/testsuite/ChangeLog:
* rust/compile/macro17.rs: Fix testsuite for new recursion errors.
* rust/compile/macro44.rs: Fix invalid testcase assertions.
* rust/compile/builtin_macro_recurse.rs: Fix invalid test.
* rust/compile/builtin_macro_recurse2.rs: New test.
* rust/compile/macro46.rs: New test.
Arthur Cohen [Tue, 17 Jan 2023 15:44:23 +0000 (16:44 +0100)]
gccrs: expansion: Add `get_token_slice` to `MacroInvocLexer` class
gcc/rust/ChangeLog:
* expand/rust-macro-invoc-lexer.cc (MacroInvocLexer::get_token_slice):
Add API to retrieve token slices when lexing macro expansions.
* expand/rust-macro-invoc-lexer.h: Declare `get_token_slice`.
Arthur Cohen [Fri, 13 Jan 2023 11:16:49 +0000 (12:16 +0100)]
gccrs: parser: Expose parse_macro_invocation as public API
gcc/rust/ChangeLog:
* parse/rust-parse.h: Move `parse_macro_invocation` to public API.
Arthur Cohen [Tue, 17 Jan 2023 14:53:00 +0000 (15:53 +0100)]
gccrs: rust-item: include rust-expr.h
gcc/rust/ChangeLog:
* ast/rust-item.h (class BlockExpr): Remove forward declaration of
class `BlockExpr`.
Owen Avery [Sat, 4 Feb 2023 05:02:22 +0000 (00:02 -0500)]
gccrs: Add support for TuplePattern in let statements
gcc/rust/ChangeLog:
* hir/tree/rust-hir-pattern.h
(TuplePatternItemsRanged::get_lower_patterns): Add method.
(TuplePatternItemsRanged::get_upper_patterns): Add method.
* backend/rust-compile-pattern.cc
(CompilePatternLet::visit): Implement TuplePattern visitor.
* backend/rust-compile-pattern.h
(CompilePatternLet::visit): Move TuplePattern visitor out of header file.
gcc/testsuite/ChangeLog:
* rust/execute/torture/let-pattern-1.rs: New test.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Philip Herron [Sat, 4 Feb 2023 22:53:48 +0000 (22:53 +0000)]
gccrs: Add general TypeBounds checks
Existing tests are updated to use libcore copy and clone implementation.
Addresses #1725
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
* typecheck/rust-unify.cc (UnifyRules::go): ensure the bounds are checked
gcc/testsuite/ChangeLog:
* rust/compile/torture/intrinsics-4.rs: implement Copy trait
* rust/compile/torture/intrinsics-5.rs: likewise
* rust/execute/torture/atomic_load.rs: likewise
* rust/execute/torture/atomic_store.rs: likewise
* rust/bounds1.rs: New test.
Philip Herron [Sat, 4 Feb 2023 23:02:31 +0000 (23:02 +0000)]
gccrs: Remove bad error message on checking function arguments
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): remove error message
gcc/testsuite/ChangeLog:
* rust/compile/func3.rs: update test case
Philip Herron [Tue, 31 Jan 2023 18:52:33 +0000 (18:52 +0000)]
gccrs: Fix higher ranked trait bounds computation of self
This updates the higher ranked trait bounds computation to handle ambigious
cases. When we have a slice for example:
let slice = &a[1..3];
This works by reusing the Index operator overload from libcore, so when the
index range of 1..3 is computed, the type system needs to compute what the
types of index are; this works by integer inference variables
Range<<integer>> that need to be unified with the impl Index for
Range<Usize> which computes the real type of usize for the index. This is
fine but what happens when we have the Copy and Clone traits bounds which
have implementations for all the primitive types i8, i16, i32, i64...
which is valid for any integer inference variable so the code prior to this
patch would have grabbed the first impl it would have found and used it
which is incorrect. When we have integer or float inference variables we
need to look for their respective defaults or emit an ambigious type bound
error.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
* typecheck/rust-hir-trait-reference.h: add const infterface
* typecheck/rust-tyty-subst.cc (SubstitutionParamMapping::get_generic_param): make const
(SubstitutionRef::monomorphize): fix issue
* typecheck/rust-tyty-subst.h: constify interface
Philip Herron [Tue, 31 Jan 2023 14:39:29 +0000 (14:39 +0000)]
gccrs: Add missing Sized, Copy and Clone lang item mappings
We need these lang items to be defined and later down the line the mappings
will be used to implement proper copy and clone logic.
Fixes #1786
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
* util/rust-lang-item.h:
gcc/testsuite/ChangeLog:
* rust/compile/issue-1786.rs: New test.
Philip Herron [Tue, 31 Jan 2023 14:27:49 +0000 (14:27 +0000)]
gccrs: Fix nullptr dereference
When we check if this is concrete the guard checks to ensure the argument
is non null but the check here is wrongly returning early when the check
is non null meaning when it is null and therefore not concrete it will
end up doing a null dereference.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
* typecheck/rust-tyty-subst.cc (SubstitutionArg::is_conrete): fix check
Philip Herron [Mon, 30 Jan 2023 18:19:07 +0000 (18:19 +0000)]
gccrs: Refactor the type unification code
This refactors the unification systems to be a consistent interface using
switch statements and simple functions instead of the old clunky visitor
system. This is more maintainable as it is harder to miss cases when we
can take advantages of switch statements.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
* Make-lang.in: update names
* backend/rust-compile-expr.cc (CompileExpr::resolve_method_address):
update to use new interface
* typecheck/rust-coercion.cc (TypeCoercionRules::coerce_borrowed_pointer): likewise
* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::unify_site): likewise
* typecheck/rust-tyty.cc (BaseType::destructure): likewise
(InferType::unify): removed old unify interface
(ErrorType::unify): likewise
(ADTType::unify): likewise
(TupleType::unify): likewise
(FnType::unify): likewise
(FnPtr::unify): likewise
(ClosureType::unify): likewise
(ArrayType::unify): likewise
(SliceType::unify): likewise
(BoolType::unify): likewise
(IntType::unify): likewise
(UintType::unify): likewise
(FloatType::unify): likewise
(USizeType::unify): likewise
(ISizeType::unify): likewise
(CharType::unify): likewise
(ReferenceType::unify): likewise
(PointerType::unify): likewise
(ParamType::unify): likewise
(StrType::unify): likewise
(NeverType::unify): likewise
(PlaceholderType::unify): likewise
(ProjectionType::unify): likewise
(DynamicObjectType::unify): likewise
* typecheck/rust-tyty.h: update destructure interface
* typecheck/rust-tyty-rules.h: Removed.
* typecheck/rust-unify.cc: New file.
* typecheck/rust-unify.h: New file.
gcc/testsuite/ChangeLog:
* rust/compile/never_type_err1.rs: Moved to...
* rust/compile/never_type1.rs: ...here. It now works
Philip Herron [Fri, 27 Jan 2023 15:38:58 +0000 (15:38 +0000)]
gccrs: Remove monomorphization hack to setup possible associated types
During CallExpr argument type checking we may be calling a default
implementation of a trait function this will require any possible
associated types to be resolved and setup. This monomoprhization call does
this but it will premtivly do extra unification of types which will throw
off type checking later on. This fix is required for my work into type
bounds checking.
Fixes #1773
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
* typecheck/rust-hir-trait-reference.h: change interface to return self
* typecheck/rust-hir-trait-resolve.cc: likewise
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_segments): likewise
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): remove monomorphization hack
gcc/testsuite/ChangeLog:
* rust/compile/issue-1773.rs: New test.
Philip Herron [Fri, 27 Jan 2023 18:49:53 +0000 (18:49 +0000)]
gccrs: Add missing param subst callback
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
* typecheck/rust-tyty-subst.cc: add missing callback
Philip Herron [Fri, 27 Jan 2023 18:31:11 +0000 (18:31 +0000)]
gccrs: Clear the substitution callbacks when copying ArgumentMappings
When we set the callback on substitutions this is not safe to be copied
around since we store the used argument mappings and can reuse them in
different contexts. This clears the callback on copy's to make it safer.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
* typecheck/rust-tyty-subst.cc: update copy constructors
Philip Herron [Fri, 27 Jan 2023 18:28:06 +0000 (18:28 +0000)]
gccrs: Refactor handle_substitutions to take a reference
This patch changes the recusive substitution code to take a reference
instead of a copy. This is important as the callback field is going to be
made non-copyable in a future patch and this pipeline is for recursive
substitutions so its ok to reuse the same mappings here.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
* typecheck/rust-tyty-bounds.cc: refactor to take a reference
* typecheck/rust-tyty-subst.cc: likewise
(SubstitutionRef::get_substitution_arguments): likewise
(SubstitutionRef::infer_substitions): likewise
* typecheck/rust-tyty-subst.h: likewise
* typecheck/rust-tyty.cc (ADTType::handle_substitions): likewise
(TupleType::handle_substitions): likewise
(FnType::handle_substitions): likewise
(ClosureType::handle_substitions): likewise
(ArrayType::handle_substitions): likewise
(SliceType::handle_substitions): likewise
(ReferenceType::handle_substitions): likewise
(PointerType::handle_substitions): likewise
(ParamType::handle_substitions): likewise
(ProjectionType::handle_substitions): likewise
* typecheck/rust-tyty.h: likewise
Philip Herron [Tue, 17 Jan 2023 22:45:52 +0000 (22:45 +0000)]
gccrs: Rename header rust-hir-trait-ref.h to rust-hir-trait-reference.h
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
* typecheck/rust-hir-trait-ref.h: Moved to...
* typecheck/rust-hir-trait-reference.h: ...here.
* typecheck/rust-hir-trait-resolve.cc: refactor
* typecheck/rust-hir-trait-resolve.h (RUST_HIR_TRAIT_RESOLVE_H): likewise
* typecheck/rust-hir-type-check.h: likewise
* typecheck/rust-tyty.cc: likewise
Philip Herron [Mon, 16 Jan 2023 19:31:11 +0000 (19:31 +0000)]
gccrs: Rename rust-tyctx.cc to rust-typecheck-context.cc
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
* Make-lang.in: update name
* typecheck/rust-tyctx.cc: Moved to...
* typecheck/rust-typecheck-context.cc: ...here.
Philip Herron [Mon, 16 Jan 2023 19:27:36 +0000 (19:27 +0000)]
gccrs: Refactor all code out of the rust-tyty.h header
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check.h: refactor
* typecheck/rust-tyctx.cc (TypeCheckContext::iterate): refactor
(TypeCheckContext::have_loop_context): likewise
(TypeCheckContext::push_new_loop_context): likewise
(TypeCheckContext::push_new_while_loop_context): likewise
(TypeCheckContext::peek_loop_context): likewise
(TypeCheckContext::pop_loop_context): likewise
(TypeCheckContext::swap_head_loop_context): likewise
(TypeCheckContext::insert_trait_reference): likewise
(TypeCheckContext::lookup_trait_reference): likewise
(TypeCheckContext::insert_receiver): likewise
(TypeCheckContext::lookup_receiver): likewise
(TypeCheckContext::insert_associated_type_mapping): likewise
(TypeCheckContext::clear_associated_type_mapping): likewise
(TypeCheckContext::lookup_associated_type_mapping): likewise
(TypeCheckContext::insert_variant_definition): likewise
(TypeCheckContext::lookup_variant_definition): likewise
(TypeCheckContext::insert_operator_overload): likewise
(TypeCheckContext::lookup_operator_overload): likewise
(TypeCheckContext::insert_unconstrained_check_marker): likewise
(TypeCheckContext::have_checked_for_unconstrained): likewise
(TypeCheckContext::insert_resolved_predicate): likewise
(TypeCheckContext::lookup_predicate): likewise
(TypeCheckContext::insert_query): likewise
(TypeCheckContext::query_completed): likewise
(TypeCheckContext::query_in_progress): likewise
(TypeCheckContext::insert_trait_query): likewise
(TypeCheckContext::trait_query_completed): likewise
(TypeCheckContext::trait_query_in_progress): likewise
(TypeCheckContextItem::Item::Item): likewise
(TypeCheckContextItem::TypeCheckContextItem): likewise
(TypeCheckContextItem::get_item): likewise
(TypeCheckContextItem::get_impl_item): likewise
(TypeCheckContextItem::get_trait_item): likewise
(TypeCheckContextItem::get_type): likewise
* typecheck/rust-tyty.cc (StructFieldType::StructFieldType): likewise
(StructFieldType::get_ref): likewise
(StructFieldType::get_name): likewise
(StructFieldType::get_field_type): likewise
(StructFieldType::set_field_type): likewise
(StructFieldType::is_concrete): likewise
(StructFieldType::debug): likewise
(StructFieldType::get_locus): likewise
(VariantDef::variant_type_string): likewise
(VariantDef::VariantDef): likewise
(VariantDef::operator=): likewise
(VariantDef::get_error_node): likewise
(VariantDef::is_error): likewise
(VariantDef::get_id): likewise
(VariantDef::get_defid): likewise
(VariantDef::get_variant_type): likewise
(VariantDef::is_data_variant): likewise
(VariantDef::is_dataless_variant): likewise
(VariantDef::get_identifier): likewise
(VariantDef::num_fields): likewise
(VariantDef::get_field_at_index): likewise
(VariantDef::get_fields): likewise
(VariantDef::lookup_field): likewise
(VariantDef::get_discriminant): likewise
(VariantDef::as_string): likewise
(VariantDef::is_equal): likewise
(VariantDef::clone): likewise
(VariantDef::monomorphized_clone): likewise
(VariantDef::get_ident): likewise
(TupleType::TupleType): likewise
(TupleType::get_unit_type): likewise
(TupleType::is_unit): likewise
(TupleType::num_fields): likewise
(TupleType::is_concrete): likewise
(TupleType::get_fields): likewise
(BoolType::BoolType): likewise
(BoolType::get_name): likewise
(BoolType::is_concrete): likewise
(IntType::IntType): likewise
(IntType::get_name): likewise
(IntType::get_int_kind): likewise
(IntType::is_concrete): likewise
(UintType::UintType): likewise
(UintType::get_name): likewise
(UintType::get_uint_kind): likewise
(UintType::is_concrete): likewise
(FloatType::FloatType): likewise
(FloatType::get_name): likewise
(FloatType::get_float_kind): likewise
(FloatType::is_concrete): likewise
(USizeType::USizeType): likewise
(USizeType::get_name): likewise
(USizeType::is_concrete): likewise
(ISizeType::ISizeType): likewise
(ISizeType::get_name): likewise
(ISizeType::is_concrete): likewise
(CharType::CharType): likewise
(CharType::is_concrete): likewise
(CharType::get_name): likewise
(ReferenceType::ReferenceType): likewise
(ReferenceType::is_concrete): likewise
(ReferenceType::mutability): likewise
(ReferenceType::is_mutable): likewise
(ReferenceType::is_dyn_object): likewise
(ReferenceType::is_dyn_slice_type): likewise
(ReferenceType::is_dyn_str_type): likewise
(PointerType::PointerType): likewise
(PointerType::is_concrete): likewise
(PointerType::mutability): likewise
(PointerType::is_mutable): likewise
(PointerType::is_const): likewise
(PointerType::is_dyn_object): likewise
(PointerType::is_dyn_slice_type): likewise
(PointerType::is_dyn_str_type): likewise
(ParamType::ParamType): likewise
(ParamType::get_generic_param): likewise
(ParamType::can_resolve): likewise
(ParamType::is_concrete): likewise
(StrType::StrType): likewise
(StrType::get_name): likewise
(StrType::is_concrete): likewise
(NeverType::NeverType): likewise
(NeverType::get_name): likewise
(NeverType::is_unit): likewise
(NeverType::is_concrete): likewise
(PlaceholderType::PlaceholderType): likewise
(PlaceholderType::get_name): likewise
(PlaceholderType::is_unit): likewise
(PlaceholderType::get_symbol): likewise
(PlaceholderType::is_concrete): likewise
(ProjectionType::is_unit): likewise
(ProjectionType::get_name): likewise
(ProjectionType::needs_generic_substitutions): likewise
(ProjectionType::supports_substitutions): likewise
(ProjectionType::has_subsititions_defined): likewise
(ProjectionType::get): likewise
(ProjectionType::is_concrete): likewise
(DynamicObjectType::is_concrete): likewise
* typecheck/rust-tyty.h: likewise
Philip Herron [Mon, 16 Jan 2023 17:54:41 +0000 (17:54 +0000)]
gccrs: Refactor PathProbeType code into CC file
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
* typecheck/rust-hir-path-probe.cc (PathProbeCandidate::Candidate::Candidate): refactor
(PathProbeCandidate::PathProbeCandidate): likewise
(PathProbeCandidate::as_string): likewise
(PathProbeCandidate::is_enum_candidate): likewise
(PathProbeCandidate::is_impl_candidate): likewise
(PathProbeCandidate::is_trait_candidate): likewise
(PathProbeCandidate::is_full_trait_item_candidate): likewise
(PathProbeCandidate::get_error): likewise
(PathProbeCandidate::is_error): likewise
(PathProbeCandidate::get_defid): likewise
(PathProbeCandidate::operator<): likewise
* typecheck/rust-hir-path-probe.h (struct PathProbeCandidate): likewise
Philip Herron [Mon, 16 Jan 2023 17:08:14 +0000 (17:08 +0000)]
gccrs: Refactor PathProbe into cc file
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
* typecheck/rust-hir-path-probe.cc (PathProbeType::PathProbeType): refactor
(PathProbeType::Probe): likewise
(PathProbeType::visit): likewise
(PathProbeType::process_enum_item_for_candiates): likewise
(PathProbeType::process_impl_items_for_candidates): likewise
(PathProbeType::is_reciever_generic): likewise
(PathProbeImplTrait::PathProbeImplTrait): likewise
(PathProbeImplTrait::Probe): likewise
(PathProbeImplTrait::process_trait_impl_items_for_candidates): likewise
* typecheck/rust-hir-path-probe.h (struct PathProbeCandidate): likewise
* typecheck/rust-hir-trait-resolve.cc
(PathProbeImplTrait::process_trait_impl_items_for_candidates): likewise
Philip Herron [Sat, 14 Jan 2023 23:54:19 +0000 (23:54 +0000)]
gccrs: Refactor BaseType, InferType and ErrorType impl into cc file
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
* typecheck/rust-tyty.cc (BaseType::BaseType): refactor
(BaseType::~BaseType): likewise
(BaseType::get_ref): likewise
(BaseType::set_ref): likewise
(BaseType::get_ty_ref): likewise
(BaseType::set_ty_ref): likewise
(BaseType::is_equal): likewise
(BaseType::is_unit): likewise
(BaseType::get_kind): likewise
(BaseType::get_combined_refs): likewise
(BaseType::append_reference): likewise
(BaseType::supports_substitutions): likewise
(BaseType::has_subsititions_defined): likewise
(BaseType::can_substitute): likewise
(BaseType::needs_generic_substitutions): likewise
(BaseType::contains_type_parameters): likewise
(BaseType::get_ident): likewise
(BaseType::get_locus): likewise
(InferType::InferType): likewise
(InferType::get_infer_kind): likewise
(InferType::get_name): likewise
(InferType::is_concrete): likewise
(ErrorType::ErrorType): likewise
(ErrorType::is_unit): likewise
(ErrorType::is_concrete): likewise
(ErrorType::get_name): likewise
(ErrorType::monomorphized_clone): likewise
* typecheck/rust-tyty.h (class SubstitutionArgumentMappings): likewise
Philip Herron [Sat, 14 Jan 2023 23:36:47 +0000 (23:36 +0000)]
gccrs: Refactor all substitution mapper code implementation into its own CC file
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
* typecheck/rust-substitution-mapper.cc (SubstMapper::SubstMapper): refactor
(SubstMapper::Resolve): likewise
(SubstMapper::InferSubst): likewise
(SubstMapper::have_generic_args): likewise
(SubstMapper::visit): likewise
(SubstMapperInternal::visit): likewise
(SubstMapperFromExisting::SubstMapperFromExisting): likewise
(SubstMapperFromExisting::Resolve): likewise
(SubstMapperFromExisting::visit): likewise
(GetUsedSubstArgs::GetUsedSubstArgs): likewise
(GetUsedSubstArgs::From): likewise
(GetUsedSubstArgs::visit): likewise
* typecheck/rust-substitution-mapper.h: refactor
* typecheck/rust-tyty-subst.cc (SubstitutionParamMapping::get_generic_param): likewise
Philip Herron [Sat, 14 Jan 2023 23:22:59 +0000 (23:22 +0000)]
gccrs: Refactor SubstitutionRef base class into its own CC file
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
* Make-lang.in: update the makefile
* typecheck/rust-tyty.cc (SubstitutionParamMapping::need_substitution): likewise
(SubstitutionParamMapping::override_context): likewise
(SubstitutionRef::get_mappings_from_generic_args): likewise
(SubstitutionRef::infer_substitions): likewise
(SubstitutionRef::are_mappings_bound): likewise
(SubstitutionRef::solve_missing_mappings_from_this): likewise
(SubstitutionRef::monomorphize): likewise
* typecheck/rust-tyty.h (class SubstitutionParamMapping): likewise
(class SubstitutionArg): likewise
(std::function<void): likewise
(class SubstitutionArgumentMappings): likewise
(class SubstitutionRef): likewise
* typecheck/rust-tyty-subst.cc: New file.
* typecheck/rust-tyty-subst.h: New file.
Philip Herron [Thu, 12 Jan 2023 18:00:52 +0000 (18:00 +0000)]
gccrs: Refactor TyVar and TypeBoundPredicates
This extract these helpers into seperate files
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
* Make-lang.in: update makefile
* typecheck/rust-tyty.cc (TyVar::TyVar): move to new file
(TyVar::get_tyty): likewise
(TyVar::get_implicit_infer_var): likewise
(TyVar::subst_covariant_var): likewise
(TyVar::clone): likewise
(TyVar::monomorphized_clone): likewise
(TyWithLocation::TyWithLocation): likewise
* typecheck/rust-tyty.h (class BaseType): cleanup
(class TypeBoundPredicate): move to its own file
(class TypeBoundPredicateItem): likewise
(class TypeBoundsMappings): likewise
(class TyVar): likewise
(class TyWithLocation): likewise
* typecheck/rust-tyty-bounds.h: New file.
* typecheck/rust-tyty-util.cc: New file.
* typecheck/rust-tyty-util.h: New file.
Philip Herron [Thu, 12 Jan 2023 16:40:30 +0000 (16:40 +0000)]
gccrs: Move TypePredicateItem impl out of the header
This moves the implementation code out of the header and into its
respective cc file.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
* typecheck/rust-tyty-bounds.cc (TypeBoundPredicateItem::error): refactor
(TypeBoundPredicateItem::is_error): likewise
(TypeBoundPredicateItem::get_parent): likewise
* typecheck/rust-tyty.h: Move the implementation for the above
Philip Herron [Thu, 12 Jan 2023 16:22:17 +0000 (16:22 +0000)]
gccrs: Add another test case for passing associated type-bounds
This demonstrates that this also works for custom algebraic data types too.
gcc/testsuite/ChangeLog:
* rust/execute/torture/issue-1720-2.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Owen Avery [Sat, 4 Feb 2023 17:07:38 +0000 (12:07 -0500)]
gccrs: Removed comment copy-pasted from gcc/tree.def
gcc/rust/ChangeLog:
* backend/rust-compile-expr.cc (CompileExpr::visit): Removed copy-pasted comment.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
mxlol233 [Thu, 12 Jan 2023 14:08:57 +0000 (22:08 +0800)]
gccrs: Add support for feature check.
This commit implements a very basic feature checking module.
gcc/rust/ChangeLog:
* Make-lang.in: Add object files: `rust-feature.o` and `rust-feature-gate.o`
* checks/errors/rust-feature-gate.cc: New file.
* checks/errors/rust-feature-gate.h: New file.
* checks/errors/rust-feature.cc: New file.
* checks/errors/rust-feature.h: New file.
* rust-session-manager.cc: Add FeatureGate check.
gcc/testsuite/ChangeLog:
* rust/compile/feature.rs: New test.
Signed-off-by: Xiao Ma <mxlol233@outlook.com>
Arthur Cohen [Thu, 2 Feb 2023 14:32:17 +0000 (15:32 +0100)]
gccrs: parser: Fix parsing of closure param list
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::parse_closure_expr): Advance tokens
properly when parsing closure param list.
gcc/testsuite/ChangeLog:
* rust/compile/closure_move_expr.rs: New test.
Arthur Cohen [Wed, 1 Feb 2023 11:41:47 +0000 (12:41 +0100)]
gccrs: parser: Improve parsing of complex generic arguments
The parser was missing code for handling complex type arguments such
as type paths or nested generics.
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::parse_generic_arg): Handle type
paths and nested generics properly.
gcc/testsuite/ChangeLog:
* rust/compile/parse_complex_generic_application.rs: New test.
* rust/compile/parse_complex_generic_application2.rs: New test.
Owen Avery [Thu, 2 Feb 2023 05:05:36 +0000 (00:05 -0500)]
gccrs: Implement lowering ReferencePattern from AST to HIR
gcc/rust/ChangeLog:
* ast/rust-pattern.h:
(ReferencePattern::is_double_reference): Add method.
(ReferencePattern::get_is_mut): Add method.
* hir/rust-ast-lower-pattern.cc
(ASTLoweringPattern::visit): Add ReferencePattern visitor.
* hir/rust-ast-lower-pattern.h:
(ASTLoweringPattern::visit): Add ReferencePattern visitor.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Owen Avery [Thu, 2 Feb 2023 16:38:44 +0000 (11:38 -0500)]
gccrs: Optimize HIR::ReferencePattern
gcc/rust/ChangeLog:
* hir/tree/rust-hir-pattern.h
(class ReferencePattern): Remove has_two_amps field.
* hir/tree/rust-hir-full-test.cc
(ReferencePattern::as_string): Remove usage of ReferencePattern::has_two_amps.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Owen Avery [Tue, 31 Jan 2023 01:14:34 +0000 (20:14 -0500)]
gccrs: Remove HIR::GroupedPattern
gcc/rust/ChangeLog:
* backend/rust-compile-fnparam.h
(CompileFnParam::visit): Remove HIR::GroupedPattern visitor.
* backend/rust-compile-pattern.cc
(CompilePatternCaseLabelExpr::visit): Remove HIR::GroupedPattern visitor.
(CompilePatternBindings::visit): Remove HIR::GroupedPattern visitor.
* backend/rust-compile-pattern.h
(CompilePatternCaseLabelExpr::visit): Remove HIR::GroupedPattern visitor.
(CompilePatternBindings::visit): Remove HIR::GroupedPattern visitor.
(CompilePatternLet::visit): Remove HIR::GroupedPattern visitor.
* backend/rust-compile-resolve-path.h
(ResolvePathRef::visit): Remove HIR::GroupedPattern visitor.
* backend/rust-compile-var-decl.h
(CompileVarDecl::visit): Remove HIR::GroupedPattern visitor.
* checks/errors/rust-const-checker.cc
(ConstChecker::visit): Remove HIR::GroupedPattern visitor.
* checks/errors/rust-const-checker.h
(ConstChecker::visit): Remove HIR::GroupedPattern visitor.
* checks/errors/rust-unsafe-checker.cc
(UnsafeChecker::visit): Remove HIR::GroupedPattern visitor.
* checks/errors/rust-unsafe-checker.h
(UnsafeChecker::visit): Remove HIR::GroupedPattern visitor.
* hir/rust-hir-dump.cc (Dump::visit): Remove HIR::GroupedPattern visitor.
* hir/rust-hir-dump.h (Dump::visit): Remove HIR::GroupedPattern visitor.
* hir/tree/rust-hir-full-decls.h (class GroupedPattern): Remove class.
* hir/tree/rust-hir-full-test.cc (GroupedPattern::accept_vis): Remove method.
* hir/tree/rust-hir-pattern.h (class GroupedPattern): Remove class.
* hir/tree/rust-hir-visitor.h
(HIRFullVisitor::visit): Remove HIR::GroupedPattern visitor.
(HIRFullVisitorBase::visit): Remove HIR::GroupedPattern visitor.
(HIRPatternVisitor::visit): Remove HIR::GroupedPattern visitor.
* typecheck/rust-hir-type-check-pattern.cc
(TypeCheckPattern::visit): Remove HIR::GroupedPattern visitor.
* typecheck/rust-hir-type-check-pattern.h
(TypeCheckPattern::visit): Remove HIR::GroupedPattern visitor.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Owen Avery [Tue, 31 Jan 2023 01:13:52 +0000 (20:13 -0500)]
gccrs: Improve GroupedPattern lowering
gcc/rust/ChangeLog:
* hir/rust-ast-lower-pattern.cc
(ASTLoweringPattern::visit): Lower AST::GroupedPattern to its inner pattern.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
MAHAD [Wed, 1 Feb 2023 17:44:00 +0000 (22:44 +0500)]
gccrs: Move rust-buffered-queue.h to util folder #1766
gcc/rust/ChangeLog:
* rust-buffered-queue.h: Moved to...
* util/rust-buffered-queue.h: ...here.
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Arthur Cohen [Wed, 1 Feb 2023 10:40:13 +0000 (11:40 +0100)]
gccrs: parser: Allow parsing multiple reference types
The parser now recursively tries to parse a reference type after seeing
a `&` or `&&` token.
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::parse_type): Handle double ampersan
properly
(Parser::parse_reference_type): Call into `parse_reference_type_inner`
and wrap double reference types in another `AST::ReferenceType` node
(Parser::parse_reference_type_inner): Add parsing implementation
which does not care about the leading token (& or &&)
(Parser::parse_type_no_bounds): Handle double ampersand properly
* parse/rust-parse.h: Declare `parse_reference_type_inner`
gcc/testsuite/ChangeLog:
* rust/compile/multi_reference_type.rs: New test.
Owen Avery [Fri, 27 Jan 2023 16:47:30 +0000 (11:47 -0500)]
gccrs: Create and use CompilePatternLet visitor for compiling let statments
gcc/rust/ChangeLog:
* backend/rust-compile-pattern.cc (CompilePatternLet::visit): New function.
* backend/rust-compile-stmt.cc (CompileStmt::visit): Likewise.
* backend/rust-compile-pattern.h (class CompilePatternLet): New visitor.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Arthur Cohen [Wed, 11 Jan 2023 14:29:22 +0000 (15:29 +0100)]
gccrs: macro: Allow builtin `MacroInvocation`s within the AST
gcc/rust/ChangeLog:
* ast/rust-macro.h (enum class): Add `BuiltinMacro` enum class.
* expand/rust-attribute-visitor.cc (AttrVisitor::visit): Mention
switching on `macro.kind` once builtin macro invocations are properly
handled.
* parse/rust-parse-impl.h (Parser::parse_macro_invocation): Switch to new MacroInvocation
API.
(Parser::parse_type): Likewise.
(Parser::parse_type_no_bounds): Likewise.
Abdul Rafey [Wed, 1 Feb 2023 05:32:16 +0000 (11:02 +0530)]
gccrs: fixed indentations in AST pretty expanded dump of trait
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit): removed extra indentations in trait ast dump
Signed-off-by: Abdul Rafey <abdulrafeyq@gmail.com>
Abdul Rafey [Sun, 29 Jan 2023 11:35:23 +0000 (17:05 +0530)]
gccrs: fixed compiler error message on wildcard pattern within expression
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::null_denotation): Add proper error
when seeing wildcard var on right side of assignment.
gcc/testsuite/ChangeLog:
* rust/compile/issue-867.rs: New test.
Signed-off-by: Abdul Rafey <abdulrafeyq@gmail.com>
Abdul Rafey [Sun, 29 Jan 2023 11:29:17 +0000 (16:59 +0530)]
gccrs: moved operator.h to util/rust-operators.h
gcc/rust/ChangeLog:
* ast/rust-ast.cc: Fix include list.
* ast/rust-expr.h: Likewise.
* hir/tree/rust-hir-expr.h: Likewise.
* rust-backend.h: Likewise.
* util/rust-lang-item.h: Likewise.
* operator.h: Moved to...
* util/rust-operators.h: ...here.
Signed-off-by: Abdul Rafey <abdulrafeyq@gmail.com>
Parthib [Sat, 28 Jan 2023 16:37:45 +0000 (22:07 +0530)]
gccrs: Rename file rust-ast-full-test.cc to rust-ast.cc
gcc/rust/ChangeLog:
* Make-lang.in: Rename object file.
* ast/rust-ast-full-test.cc: Moved to...
* ast/rust-ast.cc: ...here.
Owen Avery [Wed, 11 Jan 2023 16:57:28 +0000 (11:57 -0500)]
gccrs: Added missing GroupedPattern visitors for code generation
gcc/rust/ChangeLog:
* backend/rust-compile-pattern.cc (CompilePatternCaseLabelExpr::visit): Add proper
visitor.
(CompilePatternBindings::visit): Likewise.
* backend/rust-compile-pattern.h: Declare them.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Owen Avery [Wed, 11 Jan 2023 16:56:05 +0000 (11:56 -0500)]
gccrs: Add type resolution for grouped patterns
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): Add proper
visitor.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Owen Avery [Wed, 25 Jan 2023 18:00:38 +0000 (13:00 -0500)]
gccrs: Add get_item method for HIR::GroupedPattern
gcc/rust/ChangeLog:
* hir/tree/rust-hir-pattern.h: Add get_item method.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Owen Avery [Wed, 11 Jan 2023 16:54:54 +0000 (11:54 -0500)]
gccrs: Add HIR lowering for GroupedPattern
gcc/rust/ChangeLog:
* hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::visit): Add proper visitor.
* hir/rust-ast-lower-pattern.h: Declare it.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Lyra [Tue, 24 Jan 2023 13:15:42 +0000 (14:15 +0100)]
gccrs: Do not crash on empty macros expand. Fixes #1712
This commit fixes a compiler crash when expanding an empty macro into an existing AST.
gcc/rust/ChangeLog:
* expand/rust-macro-expand.cc (transcribe_expression): Fix ICE when expanding
empty macros.
gcc/testsuite/ChangeLog:
* rust/compile/macro45.rs: New test.
Signed-off-by: Lyra Karenai <teromene@teromene.fr>
Owen Avery [Wed, 11 Jan 2023 16:53:51 +0000 (11:53 -0500)]
gccrs: Support GroupedPattern during name resolution
gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-pattern.h: Support GroupedPattern properly.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Arthur Cohen [Wed, 11 Jan 2023 10:36:11 +0000 (11:36 +0100)]
gccrs: testsuite: Handle Windows carriage returns properly
In dg-output, check for \r* carriage returns to make sure execution
tests pass on windows platforms
gcc/testsuite/ChangeLog:
* rust/execute/torture/builtin_macro_cfg.rs: Handle carriage returns
properly.
* rust/execute/torture/builtin_macro_concat.rs: Likewise.
* rust/execute/torture/builtin_macro_env.rs: Likewise.
* rust/execute/torture/builtin_macro_include_bytes.rs: Likewise.
* rust/execute/torture/builtin_macro_include_str.rs: Likewise.
* rust/execute/torture/builtin_macro_line.rs: Likewise.
* rust/execute/torture/builtin_macros1.rs: Likewise.
* rust/execute/torture/builtin_macros3.rs: Likewise.
* rust/execute/torture/cfg1.rs: Likewise.
* rust/execute/torture/cfg2.rs: Likewise.
* rust/execute/torture/cfg3.rs: Likewise.
* rust/execute/torture/cfg4.rs: Likewise.
* rust/execute/torture/coercion1.rs: Likewise.
* rust/execute/torture/coercion2.rs: Likewise.
* rust/execute/torture/extern_mod4.rs: Likewise.
* rust/execute/torture/helloworld1.rs: Likewise.
* rust/execute/torture/helloworld2.rs: Likewise.
* rust/execute/torture/issue-1198.rs: Likewise.
* rust/execute/torture/issue-1231.rs: Likewise.
* rust/execute/torture/issue-1232.rs: Likewise.
* rust/execute/torture/issue-1249.rs: Likewise.
* rust/execute/torture/issue-1436.rs: Likewise.
* rust/execute/torture/issue-1496.rs: Likewise.
* rust/execute/torture/issue-647.rs: Likewise.
* rust/execute/torture/issue-845.rs: Likewise.
* rust/execute/torture/issue-851.rs: Likewise.
* rust/execute/torture/issue-858.rs: Likewise.
* rust/execute/torture/issue-976.rs: Likewise.
* rust/execute/torture/macros10.rs: Likewise.
* rust/execute/torture/macros11.rs: Likewise.
* rust/execute/torture/macros12.rs: Likewise.
* rust/execute/torture/macros13.rs: Likewise.
* rust/execute/torture/macros14.rs: Likewise.
* rust/execute/torture/macros2.rs: Likewise.
* rust/execute/torture/macros22.rs: Likewise.
* rust/execute/torture/macros29.rs: Likewise.
* rust/execute/torture/macros3.rs: Likewise.
* rust/execute/torture/macros30.rs: Likewise.
* rust/execute/torture/macros31.rs: Likewise.
* rust/execute/torture/macros7.rs: Likewise.
* rust/execute/torture/macros8.rs: Likewise.
* rust/execute/torture/macros9.rs: Likewise.
* rust/execute/torture/match1.rs: Likewise.
* rust/execute/torture/match2.rs: Likewise.
* rust/execute/torture/match3.rs: Likewise.
* rust/execute/torture/match_bool1.rs: Likewise.
* rust/execute/torture/match_byte1.rs: Likewise.
* rust/execute/torture/match_char1.rs: Likewise.
* rust/execute/torture/match_int1.rs: Likewise.
* rust/execute/torture/match_loop1.rs: Likewise.
* rust/execute/torture/match_range1.rs: Likewise.
* rust/execute/torture/match_range2.rs: Likewise.
* rust/execute/torture/match_tuple1.rs: Likewise.
* rust/execute/torture/method1.rs: Likewise.
* rust/execute/torture/method2.rs: Likewise.
* rust/execute/torture/method3.rs: Likewise.
* rust/execute/torture/method4.rs: Likewise.
* rust/execute/torture/operator_overload_1.rs: Likewise.
* rust/execute/torture/operator_overload_10.rs: Likewise.
* rust/execute/torture/operator_overload_11.rs: Likewise.
* rust/execute/torture/operator_overload_12.rs: Likewise.
* rust/execute/torture/operator_overload_2.rs: Likewise.
* rust/execute/torture/operator_overload_4.rs: Likewise.
* rust/execute/torture/operator_overload_5.rs: Likewise.
* rust/execute/torture/operator_overload_6.rs: Likewise.
* rust/execute/torture/operator_overload_7.rs: Likewise.
* rust/execute/torture/operator_overload_8.rs: Likewise.
* rust/execute/torture/operator_overload_9.rs: Likewise.
* rust/execute/torture/str-layout1.rs: Likewise.
* rust/execute/torture/str-zero.rs: Likewise.
* rust/execute/torture/trait1.rs: Likewise.
* rust/execute/torture/trait10.rs: Likewise.
* rust/execute/torture/trait11.rs: Likewise.
* rust/execute/torture/trait12.rs: Likewise.
* rust/execute/torture/trait13.rs: Likewise.
* rust/execute/torture/trait2.rs: Likewise.
* rust/execute/torture/trait3.rs: Likewise.
* rust/execute/torture/trait4.rs: Likewise.
* rust/execute/torture/trait5.rs: Likewise.
* rust/execute/torture/trait6.rs: Likewise.
* rust/execute/torture/trait7.rs: Likewise.
* rust/execute/torture/trait8.rs: Likewise.
* rust/execute/torture/trait9.rs: Likewise.
* rust/execute/torture/closure2.rs: Likewise.
* rust/execute/torture/closure3.rs: Likewise.
* rust/execute/torture/loop-condition-eval.rs: Likewise.
* rust/execute/torture/operator_overload_3.rs: Likewise.
Owen Avery [Wed, 11 Jan 2023 17:05:39 +0000 (12:05 -0500)]
gccrs: Change how CompileVarDecl outputs Bvariable's
This allows patterns to declare multiple/no variables
gcc/rust/ChangeLog:
* backend/rust-compile-base.cc (HIRCompileBase::compile_locals_for_block):
Allow patterns to declare zero or multiple variables.
* backend/rust-compile-var-decl.h: Change function declaration.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
mxlol233 [Wed, 11 Jan 2023 12:36:13 +0000 (20:36 +0800)]
gccrs: diagnostics: Add underline for tokens in diagnostics.
Currently, the diagnostics only point to the corresponding token's
start position by carets, and lack of underlines for full token. This
commit add support for such underlines in diagnostics by encoding range
information in location_t.
gcc/rust/ChangeLog:
* lex/rust-lex.cc (Lexer::build_token): Make location enclose entire token.
(Lexer::parse_byte_char): Likewise.
(Lexer::parse_byte_string): Likewise.
(Lexer::parse_raw_byte_string): Likewise.
(Lexer::parse_raw_identifier): Likewise.
(Lexer::parse_string): Likewise.
(Lexer::parse_identifier_or_keyword): Likewise.
(Lexer::parse_raw_string): Likewise.
(Lexer::parse_non_decimal_int_literal): Likewise.
(Lexer::parse_decimal_int_or_float): Likewise.
(Lexer::parse_char_or_lifetime): Likewise.
gcc/testsuite/ChangeLog:
* rust/compile/diagnostic_underline.rs: New test.
Signed-off-by: Xiao Ma <mxlol233@outlook.com>
mxlol233 [Wed, 11 Jan 2023 15:24:07 +0000 (23:24 +0800)]
gccrs: Add get_locus function for abstract class MetaItemInner.
This commit adds virtual function get_locus to base class MetaItemInner,
which is helpful when we need to print diagnostics on some sub-classes of
MetaItemInner.
gcc/rust/ChangeLog:
* ast/rust-ast.h: Add get_locus method.
* ast/rust-expr.h: Likewise.
* ast/rust-macro.h: Likewise.
Signed-off-by: Xiao Ma <mxlol233@outlook.com>
Owen Avery [Tue, 10 Jan 2023 00:54:55 +0000 (19:54 -0500)]
gccrs: Reuse TypeCheckPattern on LetStmt's
Update Rust type-checking to reuse TypeCheckPattern on HIR::LetStmt's.
This will unify the paths and improve error handling.
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-stmt.cc (TypeCheckStmt::visit): Cleanup LetStmt
type checking.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Philip Herron [Sat, 7 Jan 2023 14:41:12 +0000 (14:41 +0000)]
gccrs: Support associated type bound arguments
This patch adds support for the GenercArgsBinding type, where you can
specify the associated types of a trait bound using `<Foo=i32>` style
syntax. Note that the type-resolution relys on the i32 impl for Add
as type resolution will resolve the `a+a` to the core::ops::Add method
so code generation will require this to exist.
I have ameded testsuite/rust/compile/bounds.rs as this code is wrongly
creating an HIR::GenericArgs with a trait-object type and causing issues.
the parsing is still correct but we dont have the mechanism to represent
this in AST and HIR properly. I think we will need a new HIR::GenericArgs
AssociatedTypeBindingBound or something similar. We are still lacking
bounds checking during are type coercions and unifications so running this
example using an f32 will wrongly pass type checking, this will need
addressed next.
Fixes #1720
gcc/rust/ChangeLog:
* hir/tree/rust-hir-path.h: Add const get_identifier and get_type method.
* typecheck/rust-hir-path-probe.h: Use new SubstitutionArgumentMappings constructor.
* typecheck/rust-hir-trait-resolve.cc: Likewise.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise.
* typecheck/rust-tyty-bounds.cc (TypeCheckBase::get_predicate_from_bound):
Do not assert failure on size mismatch anymore.
(TypeBoundPredicate::TypeBoundPredicate): Use new SubstitutionArgumentMappings constructor.
(TypeBoundPredicate::operator=): Likewise.
(TypeBoundPredicate::apply_generic_arguments): Likewise.
(TypeBoundPredicateItem::get_tyty_for_receiver): Likewise.
(TypeBoundPredicate::get_num_associated_bindings): Likewise.
(TypeBoundPredicate::lookup_associated_type): Fix implementation for new system.
(TypeBoundPredicate::get_associated_type_items): Likewise.
* typecheck/rust-tyty.cc (SubstitutionRef::get_mappings_from_generic_args): Add new
behavior.
(SubstitutionRef::infer_substitions): Use new constructor and add comment.
(SubstitutionRef::solve_missing_mappings_from_this): Use new constructor.
* typecheck/rust-tyty.h: Define new constructors.
gcc/testsuite/ChangeLog:
* rust/compile/bounds.rs: change to use -fsyntax-only
* rust/execute/torture/issue-1720.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Sat, 7 Jan 2023 17:15:23 +0000 (17:15 +0000)]
gccrs: Add name resolution to generic argument associated item bindings
When specifying generic arguments to Traits we can also specify the
associated types using `<BindingName=i32>` syntax we need to add
name resolution to the type argument here and rely on the type
resolution pass to ensure the associated type exists and to setup the
associated types accordingly.
Addresses #1720
gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-type.cc (ResolveGenericArgs::go): Add name resolution to
Trait items.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Raiki Tamura [Sun, 18 Dec 2022 16:48:54 +0000 (01:48 +0900)]
gccrs: Implement declarative macro 2.0 parser
gcc/rust/ChangeLog:
* ast/rust-ast-full-decls.h (class MacroItem): Remove forward declaration.
* ast/rust-ast-full-test.cc (MacroRulesDefinition):
Rework MacroRulesDefinition class
* ast/rust-ast.h (class MacroItem): Remove abstract class.
* ast/rust-item.h (class MacroItem): Remove forward declaration.
* ast/rust-macro.h (class MacroItem): Likewise.
(class MacroRulesDefinition): Add MacroKind enum.
(class MacroInvocation): Fix inheritance.
* lex/rust-token.h: Token "macro" is now used.
* parse/rust-parse-impl.h (Parser::parse_item): Add handling for MACRO.
(Parser::parse_vis_item): Call into parse_decl_macro_def.
(Parser::parse_macro_item): Delete function.
(Parser::parse_macro_rules_def): Return MBE macros only.
(Parser::parse_decl_macro_def): New function.
(Parser::parse_stmt): Handle MACRO token.
(Parser::parse_stmt_or_expr_without_block): Call into parse_macro_rules_def.
* parse/rust-parse.h: Declare new function.
gcc/testsuite/ChangeLog:
* rust/compile/decl_macro1.rs: New test.
* rust/compile/decl_macro2.rs: New test.
* rust/compile/decl_macro3.rs: New test.
* rust/compile/decl_macro4.rs: New test.
* rust/compile/decl_macro5.rs: New test.
* rust/compile/decl_macro6.rs: New test.
* rust/compile/decl_macro7.rs: New test.
* rust/execute/torture/decl_macro1.rs: New test.
* rust/execute/torture/decl_macro2.rs: New test.
* rust/execute/torture/decl_macro3.rs: New test.
* rust/execute/torture/decl_macro4.rs: New test.
Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
mxlol233 [Wed, 4 Jan 2023 13:21:59 +0000 (21:21 +0800)]
gccrs: rust: add bound parsing in parse_generic_arg.
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::parse_generic_arg): Add proper bound parsing.
gcc/testsuite/ChangeLog:
* rust/compile/bounds.rs: New test.
Signed-off-by: Xiao Ma <mxlol233@outlook.com>
Dave [Mon, 19 Dec 2022 16:59:00 +0000 (10:59 -0600)]
gccrs: Check for mutable references in const functions
Use StackedContext instead. Fix error string
Signed-off-by: Dave Evans <dave@dmetwo.org>
(Squashed commits) Check for mutable references in const functions using StackedContext
gcc/rust/ChangeLog:
* checks/errors/rust-const-checker.cc (ConstChecker::visit): Use StackedContext
class.
gcc/testsuite/ChangeLog:
* rust/compile/const10.rs: New test.
Signed-off-by: Dave Evans <dave@dmetwo.org>
Prajwal S N [Sat, 31 Dec 2022 07:19:02 +0000 (12:49 +0530)]
gccrs: unsafe: check use of `target_feature` attribute
The `target_feature` attribute is for conditional compilation and may or
may not compile on all platforms. Using it requires an unsafe function
or block.
gcc/rust/ChangeLog:
* checks/errors/rust-unsafe-checker.cc (check_target_attr): New function.
(UnsafeChecker::check_function_attr): Call into `check_target_attr`.
(UnsafeChecker::visit): Check for target_feature attributes.
* checks/errors/rust-unsafe-checker.h: Add declarations.
* util/rust-attributes.cc: Add attribute.
gcc/testsuite/ChangeLog:
* rust/compile/unsafe11.rs: New test.
Signed-off-by: Prajwal S N <prajwalnadig21@gmail.com>
Arthur Cohen [Fri, 16 Dec 2022 12:38:36 +0000 (13:38 +0100)]
gccrs: fatal_error_flag: Fix typo in error message
gcc/rust/ChangeLog:
* rust-session-manager.cc (Session::compile_crate): Fix typo.
Indu Bhagat [Thu, 6 Apr 2023 06:23:33 +0000 (23:23 -0700)]
MAINTAINERS: Add myself as CTF and BTF reviewer
ChangeLog:
* MAINTAINERS: Add myself.
Alexandre Oliva [Wed, 5 Apr 2023 14:27:19 +0000 (11:27 -0300)]
[testsuite] enable -maltivec like vect_int for signbit-2.c
Explicitly enable altivec if it's supported. vect_int tests for
powerpc_altivec_ok, but without the explicit option, if altivec is not
enabled by default, we end up expecting vectorization that doesn't
occur.
for gcc/testsuite/ChangeLog
* gcc.dg/signbit-2.c: Add -maltivec if supported.
Andrew Pinski [Thu, 6 Apr 2023 04:13:00 +0000 (21:13 -0700)]
Fix typo in -param=vect-induction-float= attributes
There was a typo in the attributes of the option
-param=vect-induction-float= for IntegerRange.
This fixes that typo.
Committed as obvious after a build/test.
gcc/ChangeLog:
PR tree-optimization/109427
* params.opt (-param=vect-induction-float=):
Fix option attribute typo for IntegerRange.
Alexandre Oliva [Wed, 5 Apr 2023 14:27:28 +0000 (11:27 -0300)]
testsuite: fix proc unsupported overriding in modules.exp [PR108899]
The overrider of proc unsupported in modules.exp had two problems
reported by Thomas Schwinge, even after Jakub JelÃnek's fix:
- it remained in effect while running other dejagnu testsets
- it didn't quote correctly the argument list passed to it, which
caused test names to be surrounded by curly braces, as in:
UNSUPPORTED: {...}
This patch fixes both issues, obsoleting and reverting Jakub's change,
by dropping the overrider and renaming the saved proc back, and by
using uplevel's argument list splicing.
Co-authored-by: Thomas Schwinge <thomas@codesourcery.com>
for gcc/testsuite/ChangeLog
PR testsuite/108899
* g++.dg/modules/modules.exp (unsupported): Drop renaming.
Fix quoting.
GCC Administrator [Thu, 6 Apr 2023 00:16:43 +0000 (00:16 +0000)]
Daily bump.
Gaius Mulley [Wed, 5 Apr 2023 22:07:46 +0000 (23:07 +0100)]
PR modula2/109423 cc1gm2 ICE if an INCL or EXCL is performed on an unknown set
This patch fixes an ICE if attempting to INCL or EXCL on an unknown
set. The fix was to correct an error format string. Also included in
the patch are patches to remove unused variables. The patch also
marks a variable as written in BuildAdr.
gcc/m2/ChangeLog:
PR modula2/109423
* gm2-compiler/M2Base.def (Unbounded): Remove.
* gm2-compiler/M2Error.def (ErrorAbort0): Add noreturn
attribute.
* gm2-compiler/M2Quads.mod (BuildInclProcedure): Correct
error format string.
(BuildExceptProcedure): Correct error format string.
(BuildAdrFunction): Call PutWriteQuad when taking the
address of a variable.
* gm2-libs-ch/SysExceptions.c (_M2_SysExceptions_init): Add
parameters.
* gm2-libs-ch/wrapc.c (_M2_wrapc_init): Add parameters.
* gm2-libs/DynamicStrings.mod (DumpStringInfo): Remove t.
(PopAllocationExemption): Remove f.
* gm2-libs/FIO.mod (BufferedWrite): Remove result.
* gm2-libs/FormatStrings.mod (Copy): Remove endpos and
afterperc.
(HandlePercent): Remove result.
* gm2-libs/Indexing.mod (RemoveIndiceFromIndex): Remove k.
* gm2-libs/M2Dependent.mod (CreateModule): Remove p0
and p1.
(DumpModuleData): Remove mptr.
(ConstructModules): Remove nulp.
* gm2-libs/RTExceptions.mod (PopHandler): Remove i.
* gm2-libs/RTint.mod (Listen): Remove b4s, b4m, afs
and afm.
* gm2-libs/SFIO.mod (ReadS): Remove c.
* gm2-libs/StringConvert.mod (doDecimalPlaces): Remove
whole and fraction.
gcc/testsuite/ChangeLog:
* gm2/pim/fail/setunknown.mod: New test.
PR modula2/109423
* gm2/pim/fail/setunknown2.mod: New test.
Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
Arsen Arsenović [Tue, 4 Apr 2023 21:24:52 +0000 (23:24 +0200)]
libstdc++: Fix some freestanding test failures
At some point, <charconv> was added to the non-hosted bit of the C++17
block, which induced failures in many tests.
In addition, some tests also lacked a dg-require-effective-target hosted
tag.
libstdc++-v3/ChangeLog:
* include/precompiled/stdc++.h (C++17): Don't double-include
<charconv>, once with wrong conditions.
* testsuite/18_support/96817.cc: Require hosted.
* testsuite/18_support/bad_exception/59392.cc: Ditto.
* testsuite/20_util/scoped_allocator/108952.cc: Ditto.
* testsuite/20_util/uses_allocator/lwg3527.cc: Ditto.
* testsuite/29_atomics/atomic/operators/pointer_partial_void.cc:
Ditto.
Arsen Arsenović [Tue, 4 Apr 2023 17:25:09 +0000 (19:25 +0200)]
libstdc++: Downgrade DEBUG to ASSERTIONS when !HOSTED
Supporting the debug mode in freestanding is a non-trivial job, so
instead, as a best-effort, enable assertions, which are light and easy.
libstdc++-v3/ChangeLog:
* include/bits/c++config: When __STDC_HOSTED__ is zero,
disable _GLIBCXX_DEBUG and, if it was set, enable
_GLIBCXX_ASSERTIONS.
* testsuite/lib/libstdc++.exp (check_v3_target_debug_mode):
Include <bits/c++config.h> when determining whether debug is
set, in order to inherit the logic from above
Arsen Arsenović [Wed, 8 Mar 2023 16:01:24 +0000 (17:01 +0100)]
libstdc++: Add a test for <version> FTM redefinitions
This test detects redefinitions by compiling stdc++.h and <version>, by
disabling the system_header pragma on the latter, to allow warnings in
it. Thanks Patrick Palka for the suggestion.
libstdc++-v3/ChangeLog:
* testsuite/17_intro/versionconflict.cc: New test.
* include/std/version: Allow disabling the system_header pragma
via _GLIBCXX_TESTING_SYSHDR.
Arsen Arsenović [Wed, 8 Mar 2023 11:04:11 +0000 (12:04 +0100)]
libstdc++: Harmonize <version> and other headers
Due to recent, large changes in libstdc++, the feature test macros
declared in <version> got out of sync with the other headers that
possibly declare them.
libstdc++-v3/ChangeLog:
* include/bits/unique_ptr.h (__cpp_lib_constexpr_memory):
Synchronize the definition block with...
* include/bits/ptr_traits.h (__cpp_lib_constexpr_memory):
... this one here. Also define the 202202L value, rather than
leaving it up to purely unique_ptr.h, so that the value is
synchronized across all headers.
(__gnu_debug::_Safe_iterator_base): Move into new conditional
block.
* include/std/memory (__cpp_lib_atomic_value_initialization):
Define on freestanding under the same conditions as in
atomic_base.h.
* include/std/version (__cpp_lib_robust_nonmodifying_seq_ops):
Also define on freestanding.
(__cpp_lib_to_chars): Ditto.
(__cpp_lib_gcd): Ditto.
(__cpp_lib_gcd_lcm): Ditto.
(__cpp_lib_raw_memory_algorithms): Ditto.
(__cpp_lib_array_constexpr): Ditto.
(__cpp_lib_nonmember_container_access): Ditto.
(__cpp_lib_clamp): Ditto.
(__cpp_lib_constexpr_char_traits): Ditto.
(__cpp_lib_constexpr_string): Ditto.
(__cpp_lib_sample): Ditto.
(__cpp_lib_lcm): Ditto.
(__cpp_lib_constexpr_iterator): Ditto.
(__cpp_lib_constexpr_char_traits): Ditto.
(__cpp_lib_interpolate): Ditto.
(__cpp_lib_constexpr_utility): Ditto.
(__cpp_lib_shift): Ditto.
(__cpp_lib_ranges): Ditto.
(__cpp_lib_move_iterator_concept): Ditto.
(__cpp_lib_constexpr_numeric): Ditto.
(__cpp_lib_constexpr_functional): Ditto.
(__cpp_lib_constexpr_algorithms): Ditto.
(__cpp_lib_constexpr_tuple): Ditto.
(__cpp_lib_constexpr_memory): Ditto.
John David Anglin [Wed, 5 Apr 2023 15:40:52 +0000 (15:40 +0000)]
Fix 22_locale/locale/cons/12658_thread-2.cc on hppa.
2023-04-05 John David Anglin <danglin@gcc.gnu.org>
libstdc++-v3/ChangeLog:
* testsuite/22_locale/locale/cons/12658_thread-2.cc: Double
timeout factor on hppa*-*-*.
Jeff Law [Wed, 5 Apr 2023 15:16:29 +0000 (09:16 -0600)]
[RFA][Bug target/108892 ][13 regression] Force re-recognition after changing RTL structure of an insn
So as mentioned in the PR the underlying issue here is combine changes the form of an existing insn, but fails to force re-recognition. As a result other parts of the compiler blow up.
> /* Temporarily replace the set's source with the
> contents of the REG_EQUAL note. The insn will
> be deleted or recognized by try_combine. */
> rtx orig_src = SET_SRC (set); rtx orig_dest = SET_DEST (set); if (GET_CODE (SET_DEST (set)) == ZERO_EXTRACT)
> SET_DEST (set) = XEXP (SET_DEST (set), 0);
> SET_SRC (set) = note;
> i2mod = temp;
> i2mod_old_rhs = copy_rtx (orig_src);
> i2mod_new_rhs = copy_rtx (note);
> next = try_combine (insn, i2mod, NULL, NULL,
> &new_direct_jump_p, last_combined_insn);
> i2mod = NULL;
> if (next)
> {
> statistics_counter_event (cfun, "insn-with-note combine", 1);
> goto retry;
> } SET_SRC (set) = orig_src;
> SET_DEST (set) = orig_dest;
This code replaces the SET_SRC of an insn in the RTL stream with the contents of a REG_EQUAL note. So given an insn like this:
> (insn 122 117 127 2 (set (reg:DI 157 [ _46 ])
> (ior:DI (reg:DI 200)
> (reg:DI 251))) "j.c":14:5 -1
> (expr_list:REG_EQUAL (const_int
25769803782 [0x600000006])
> (nil)))
It replaces the (ior ...) with a (const_int ...). The resulting insn is passed to try_combine which will try to recognize it, then use it in a combination attempt. Recognition succeeds with the special define_insn_and_split pattern in the risc-v backend resulting in:
> (insn 122 117 127 2 (set (reg:DI 157 [ _46 ])
> (const_int
25769803782 [0x600000006])) "j.c":14:5 177 {*mvconst_internal}
> (expr_list:REG_EQUAL (const_int
25769803782 [0x600000006])
> (nil)))
This is as-expected. Now assume we were unable to combine anything, so try_combine returns NULL_RTX. The quoted code above restores SET_SRC (and SET_DEST) resulting in:
> (insn 122 117 127 2 (set (reg:DI 157 [ _46 ])
> (ior:DI (reg:DI 200)
> (reg:DI 251))) "j.c":14:5 177 {*mvconst_internal}
> (expr_list:REG_EQUAL (const_int
25769803782 [0x600000006])
> (nil)))
But this doesn't get re-recognized and we ICE later in LRA.
The fix is trivial, reset the INSN_CODE to force re-recognition in the case where try_combine fails.
PR target/108892
gcc/
* combine.cc (combine_instructions): Force re-recognition when
after restoring the body of an insn to its original form.
gcc/testsuite/
* gcc.c-torture/compile/pr108892.c: New test.
John David Anglin [Wed, 5 Apr 2023 14:44:54 +0000 (14:44 +0000)]
Add assember CFI directives to millicode division and remainder routines.
The millicode division and remainder routines trap division by zero.
The unwinder needs these directives to unwind divide by zero traps.
2023-04-05 John David Anglin <danglin@gcc.gnu.org>
libgcc/ChangeLog:
PR target/109374
* config/pa/milli64.S (RETURN_COLUMN): Define.
($$divI): Add CFI directives.
($$divU): Likewise.
($$remI): Likewise.
($$remU): Likewise.
Martin Jambor [Wed, 5 Apr 2023 14:36:49 +0000 (16:36 +0200)]
ipa: Avoid another ICE when dealing with type-incompatibilities (PR 108959)
PR 108959 shows one more example where undefined code with type
incompatible accesses to stuff passed in parameters can cause an ICE
because we try to create a VIEW_CONVERT_EXPR of mismatching sizes:
1. IPA-CP tries to push one type from above,
2. IPA-SRA (correctly) decides the parameter is useless because it is
only used to construct an argument to another function which does not
use it and so the formal parameter should be removed,
3. but the code reconciling IPA-CP and IPA-SRA transformations still
wants to perform the IPA-CP and overrides the built-in DCE of
useless statements and tries to stuff constants into them
instead, constants of a type with mismatching type and size.
This patch avoids the situation in IPA-SRA by purging the IPA-CP
results from any "aggregate" constants that are passed in parameters
which are detected to be useless. It also removes IPA value range and
bits information associated with removed parameters stored in the same
structure so that the useless information is not streamed later on.
gcc/ChangeLog:
2023-03-22 Martin Jambor <mjambor@suse.cz>
PR ipa/108959
* ipa-sra.cc (zap_useless_ipcp_results): New function.
(process_isra_node_results): Call it.
gcc/testsuite/ChangeLog:
2023-03-17 Martin Jambor <mjambor@suse.cz>
PR ipa/108959
* gcc.dg/ipa/pr108959.c: New test.
Ju-Zhe Zhong [Wed, 5 Apr 2023 13:46:36 +0000 (07:46 -0600)]
[PATCH] RISC-V: Fix SEW64 of vrsub.vx runtime fail in RV32 system
It's quite obvious that the order of vrsub SEW64 is wrong.
gcc/ChangeLog:
* config/riscv/vector.md: Fix incorrect operand order.
gcc/testsuite/ChangeLog:
* g++.target/riscv/rvv/base/bug-23.C: New test.
Jonathan Wakely [Tue, 4 Apr 2023 19:28:59 +0000 (20:28 +0100)]
libstdc++: Define std::sub_match::swap member function (LWG 3204)
This was approved at the C++ meeting in February.
libstdc++-v3/ChangeLog:
* include/bits/regex.h (sub_match::swap): New function.
* testsuite/28_regex/sub_match/lwg3204.cc: New test.
Juzhe-Zhong [Wed, 5 Apr 2023 01:20:47 +0000 (19:20 -0600)]
[PATCH] RISC-V: Fix PR109399 VSETVL PASS bug
PR 109399
gcc/ChangeLog:
* config/riscv/riscv-vsetvl.cc
(pass_vsetvl::compute_local_backward_infos): Update user vsetvl in local
demand fusion.
gcc/testsuite/ChangeLog:
* gcc.target/riscv/rvv/vsetvl/pr109399.c: New test.
Li Xu [Wed, 5 Apr 2023 01:12:26 +0000 (19:12 -0600)]
RISC-V: Fix typos
gcc/ChangeLog:
* config/riscv/riscv-vector-builtins.def: Fix typo.
* config/riscv/riscv.cc (riscv_dwarf_poly_indeterminate_value): Ditto.
* config/riscv/vector-iterators.md: Ditto.
GCC Administrator [Wed, 5 Apr 2023 00:16:53 +0000 (00:16 +0000)]
Daily bump.
Hans-Peter Nilsson [Tue, 4 Apr 2023 15:45:19 +0000 (17:45 +0200)]
doc: md.texi (Including Patterns): Fix page break
The line-break in the example looked odd, even more so with
a page-break in the middle of it, due to recently added text
in preceding pages.
* doc/md.texi (Including Patterns): Fix page break.
Joseph Myers [Tue, 4 Apr 2023 17:06:15 +0000 (17:06 +0000)]
Regenerate gcc.pot
* gcc.pot: Regenerate.
Harald Anlauf [Mon, 3 Apr 2023 19:34:01 +0000 (21:34 +0200)]
Fortran: reject module variable as character length in PARAMETER [PR104349]
gcc/fortran/ChangeLog:
PR fortran/104349
* expr.cc (check_restricted): Adjust check for valid variables in
restricted expressions: make no exception for module variables.
gcc/testsuite/ChangeLog:
PR fortran/104349
* gfortran.dg/der_charlen_1.f90: Adjust dg-patterns.
* gfortran.dg/pr104349.f90: New test.
Jakub Jelinek [Tue, 4 Apr 2023 14:13:06 +0000 (16:13 +0200)]
range-op-float: Fix reverse ops of comparisons [PR109386]
I've missed one of my recent range-op-float.cc changes (likely the
r13-6967 one) caused
FAIL: libphobos.phobos/std/math/algebraic.d execution test
FAIL: libphobos.phobos_shared/std/math/algebraic.d execution test
regressions, distilled into a C testcase below.
In the testcase, we have
!(u >= v)
condition where both u and v are results of fabs*, which guards
t1 = u u<= __FLT_MAX__;
and
t2 = v u<= __FLT_MAX__;
comparisons. From false u >= v where u and v have [0.0, +Inf] NAN
ranges we (incorrectly deduce that one of them is [nextafterf (0.0, 1.0), +Inf] NAN
and the other is [0.0, nextafterf (+Inf, 0.0)] NAN and from that deduce that
one of the comparisons is always true, because UNLE_EXPR with the maximum
representable number are false only if the value is +Inf and our ranges tell
that is not possible.
The bug is that the u >= v comparison determines a sensible range only when
it is true - we then know neither operand can be NAN and it behaves
correctly. But when the comparison is false, our current code gives
sensible answers only if the other op can't be NAN. If it can be NAN,
whenever it is NAN, the comparison is always false regardless of the other
value, so the other value needs to be VARYING.
Now, foperator_unordered_lt::op1_range etc. had code to deal with that
for op?.known_nan (), but as the testcase shows, it is enough if it may be a
NAN at runtime to make it VARYING.
So, the following patch replaces for all those BRS_FALSE cases of the normal
non-equality comparisons if (opOTHER.known_isnan ()) r.set_varying (type);
to do it also if maybe_isnan ().
For the unordered or ... comparisons, it is similar for BRS_TRUE. Those
comparisons are true whenever either operand is NAN, or if neither is NAN,
the corresponding normal comparison. So, if those comparisons are true
and other operand might be a NAN, we can't tell (VARYING), if it is false,
currently handling is correct.
2023-04-04 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/109386
* range-op-float.cc (foperator_lt::op1_range, foperator_lt::op2_range,
foperator_le::op1_range, foperator_le::op2_range,
foperator_gt::op1_range, foperator_gt::op2_range,
foperator_ge::op1_range, foperator_ge::op2_range): Make r varying for
BRS_FALSE case even if the other op is maybe_isnan, not just
known_isnan.
(foperator_unordered_lt::op1_range, foperator_unordered_lt::op2_range,
foperator_unordered_le::op1_range, foperator_unordered_le::op2_range,
foperator_unordered_gt::op1_range, foperator_unordered_gt::op2_range,
foperator_unordered_ge::op1_range, foperator_unordered_ge::op2_range):
Make r varying for BRS_TRUE case even if the other op is maybe_isnan,
not just known_isnan.
* gcc.c-torture/execute/ieee/pr109386.c: New test.
Marek Polacek [Mon, 13 Mar 2023 22:50:25 +0000 (18:50 -0400)]
sanitizer: missing signed integer overflow errors [PR109107]
Here we're failing to detect a signed overflow with -O because match.pd,
since r8-1516, transforms
c = (a + 1) - (int) (short int) b;
into
c = (int) ((unsigned int) a +
4294946117);
wrongly eliding the overflow. This kind of problems is usually
avoided by using TYPE_OVERFLOW_SANITIZED in the appropriate place.
The first match.pd hunk in the patch fixes it. I've constructed
a testcase for each of the surrounding cases as well. Then I
noticed that fold_binary_loc/associate has the same problem, so I've
added a TYPE_OVERFLOW_SANITIZED there as well (it may be too coarse,
sorry). Then I found yet another problem, but instead of fixing it
now I've opened 109134. I could probably go on and find a dozen more.
PR sanitizer/109107
gcc/ChangeLog:
* fold-const.cc (fold_binary_loc): Use TYPE_OVERFLOW_SANITIZED
when associating.
* match.pd: Use TYPE_OVERFLOW_SANITIZED.
gcc/testsuite/ChangeLog:
* c-c++-common/ubsan/pr109107-1.c: New test.
* c-c++-common/ubsan/pr109107-2.c: New test.
* c-c++-common/ubsan/pr109107-3.c: New test.
* c-c++-common/ubsan/pr109107-4.c: New test.
Stam Markianos-Wright [Tue, 4 Apr 2023 12:06:41 +0000 (13:06 +0100)]
arm: Fix vcreate definition
From the initial merge of the MVE backend, the vcreate
intrinsic has had the vector lanes mixed up, compared
to the intended (as per the ACLE) definition. This is
also a discrepancy with clang:
https://godbolt.org/z/4n93e5aqj
This patches simply switches the operands around and
makes the tests more specific on the input registers
(I do not touch the output Q regs as they vary based
on softfp/hardfp or the input registers when the input
is a constant, since, in that case, a single register
is loaded with a constant and then the same register is
used twice as "vmov q0[2], q0[0], r2, r2" and the reg
num might not always be guaranteed).
gcc/ChangeLog:
* config/arm/mve.md (mve_vcvtq_n_to_f_<supf><mode>): Swap operands.
(mve_vcreateq_f<mode>): Swap operands.
gcc/testsuite/ChangeLog:
* gcc.target/arm/mve/intrinsics/vcreateq_f16.c: Tighten test.
* gcc.target/arm/mve/intrinsics/vcreateq_f32.c: Tighten test.
* gcc.target/arm/mve/intrinsics/vcreateq_s16.c: Tighten test.
* gcc.target/arm/mve/intrinsics/vcreateq_s32.c: Tighten test.
* gcc.target/arm/mve/intrinsics/vcreateq_s64.c: Tighten test.
* gcc.target/arm/mve/intrinsics/vcreateq_s8.c: Tighten test.
* gcc.target/arm/mve/intrinsics/vcreateq_u16.c: Tighten test.
* gcc.target/arm/mve/intrinsics/vcreateq_u32.c: Tighten test.
* gcc.target/arm/mve/intrinsics/vcreateq_u64.c: Tighten test.
* gcc.target/arm/mve/intrinsics/vcreateq_u8.c: Tighten test.
Jonathan Wakely [Tue, 4 Apr 2023 11:04:14 +0000 (12:04 +0100)]
libstdc++: Fix outdated docs about demangling exception messages
The string returned by std::bad_exception::what() hasn't been a mangled
name since PR libstdc++/14493 was fixed for GCC 4.2.0, so remove the
docs showing how to demangle it.
libstdc++-v3/ChangeLog:
* doc/xml/manual/extensions.xml: Remove std::bad_exception from
example program.
* doc/html/manual/ext_demangling.html: Regenerate.
Andrew Stubbs [Mon, 3 Apr 2023 11:16:11 +0000 (12:16 +0100)]
amdgcn: Add 64-bit vector not
gcc/ChangeLog:
* config/gcn/gcn-valu.md (one_cmpl<mode>2<exec>): New.
Jakub Jelinek [Tue, 4 Apr 2023 09:20:28 +0000 (11:20 +0200)]
riscv: Fix bootstrap [PR109384]
The following patch unbreaks riscv bootstrap, where it previously failed
on -Werror=format-diag warning promoted to error.
Ok for trunk?
Or shall it say e.g.
"%<-march=%s%>: %<zfinx%> extension conflicts with %<f>"
?
Or say if the current condition is true, do
const char *ext = "zfinx";
if (subset_list->lookup ("zdinx"))
ext = "zdinx";
else if (subset_list->lookup ("zhinx"))
ext = "zhinx";
else if (subset_list->lookup ("zhinxmin"))
ext = "zhinxmin";
and
"%<-march=%s%>: %qs extension conflicts with %<f>", arch, ext
? Or do similar check for which extension to print against it,
const char *ext = "zfinx";
const char *ext2 = "f";
if (subset_list->lookup ("zdinx"))
{
ext = "zdinx";
if (subset_list->lookup ("d"))
ext2 = "d";
}
else if (subset_list->lookup ("zhinx"))
{
ext = "zhinx";
if (subset_list->lookup ("zfh"))
ext2 = "zfh";
}
else if (subset_list->lookup ("zhinxmin"))
{
ext = "zhinxmin";
if (subset_list->lookup ("zfhmin"))
ext2 = "zfhmin";
}
"%<-march=%s%>: %qs extension conflicts with %qs", arch, ext, ext2
?
2023-04-04 Jakub Jelinek <jakub@redhat.com>
PR target/109384
* common/config/riscv/riscv-common.cc (riscv_subset_list::parse):
Reword diagnostics about zfinx conflict with f, formatting fixes.
* gcc.target/riscv/arch-19.c: Expect a different message about zfinx
vs. f conflict.
Rainer Orth [Tue, 4 Apr 2023 08:27:09 +0000 (10:27 +0200)]
config: -pthread shouldn't link with -lpthread on Solaris
libpthread has been folded into libc since Solaris 10 and replaced by a
filter on libc. Linking with libpthread thus only creates unnecessary
runtime overhead.
This patch thus removes linking with -lpthread if -pthread/-pthreads is
specified, thus getting rid of the libpthread dependency in libatomic,
libgdruntime, libgomp, libgphobos, and libitm.
Bootstrapped without regressions on i386-pc-solaris2.11 and
sparc-sun-solaris2.11 (both Solaris 11.3 and 11.4).
2023-04-03 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
gcc:
* config/sol2.h (LIB_SPEC): Don't link with -lpthread.
Richard Biener [Tue, 28 Mar 2023 08:06:12 +0000 (08:06 +0000)]
tree-optimization/109304 - properly handle instrumented aliases
When adjusting calls to reflect instrumentation we failed to handle
calls to aliases since they appear to have no body. Instead resort
to symtab node availability. The patch also avoids touching
internal function calls in a more obvious way (builtins might
have a body available).
profiledbootstrap & regtest running on x86_64-unknown-linux-gnu.
Honza - does this look OK?
PR tree-optimization/109304
* tree-profile.cc (tree_profiling): Use symtab node
availability to decide whether to skip adjusting calls.
Do not adjust calls to internal functions.
* gcc.dg/pr109304.c: New testcase.
Kewen Lin [Tue, 4 Apr 2023 02:47:54 +0000 (21:47 -0500)]
rs6000: Fix vector_set_var_p9 by considering BE [PR108807]
As PR108807 exposes, the current handling in function
rs6000_expand_vector_set_var_p9 doesn't take care of big
endianness. Currently the function is to rotate the
target vector by moving element to-be-set to element 0,
set element 0 with the given val, then rotate back. To
get the permutation control vector for the rotation, it
makes use of lvsr and lvsl, but the element ordering is
different for BE and LE (like element 0 is the most
significant one on BE while the least significant one on
LE), this patch is to add consideration for BE and make
sure permutation control vectors for rotations are expected.
As tested, it helped to fix the below failures:
FAIL: gcc.target/powerpc/pr79251-run.p9.c execution test
FAIL: gcc.target/powerpc/pr89765-mc.c execution test
FAIL: gcc.target/powerpc/vsx-builtin-10d.c execution test
FAIL: gcc.target/powerpc/vsx-builtin-11d.c execution test
FAIL: gcc.target/powerpc/vsx-builtin-14d.c execution test
FAIL: gcc.target/powerpc/vsx-builtin-16d.c execution test
FAIL: gcc.target/powerpc/vsx-builtin-18d.c execution test
FAIL: gcc.target/powerpc/vsx-builtin-9d.c execution test
PR target/108807
gcc/ChangeLog:
* config/rs6000/rs6000.cc (rs6000_expand_vector_set_var_p9): Fix gen
function for permutation control vector by considering big endianness.
Kewen Lin [Tue, 4 Apr 2023 02:47:44 +0000 (21:47 -0500)]
rs6000: Fix vector parity support [PR108699]
The failures on the original failed case builtin-bitops-1.c
and the associated test case pr108699.c here show that the
current support of parity vector mode is wrong on Power.
The hardware insns vprtyb[wdq] which operate on the least
significant bit of each byte per element, they doesn't match
what RTL opcode parity needs, but the current implementation
expands it with them wrongly.
This patch is to fix the handling with one more insn vpopcntb.
PR target/108699
gcc/ChangeLog:
* config/rs6000/altivec.md (*p9v_parity<mode>2): Rename to ...
(rs6000_vprtyb<mode>2): ... this.
* config/rs6000/rs6000-builtins.def (VPRTYBD): Replace parityv2di2 with
rs6000_vprtybv2di2.
(VPRTYBW): Replace parityv4si2 with rs6000_vprtybv4si2.
(VPRTYBQ): Replace parityv1ti2 with rs6000_vprtybv1ti2.
* config/rs6000/vector.md (parity<mode>2 with VEC_IP): Expand with
popcountv16qi2 and the corresponding rs6000_vprtyb<mode>2.
gcc/testsuite/ChangeLog:
* gcc.target/powerpc/p9-vparity.c: Add scan-assembler-not for vpopcntb
to distinguish parity byte from parity.
* gcc.target/powerpc/pr108699.c: New test.
Jason Merrill [Mon, 3 Apr 2023 22:23:58 +0000 (18:23 -0400)]
c++: friend template matching [PR107484]
Here friend matching tries to find a matching non-template friend and fails,
so we mark the friend as a template specialization to be determined later.
Then cplus_decl_attributes tries again to find a matching function and gets
confused by DECL_TEMPLATE_INSTANTIATION without DECL_TEMPLATE_INFO. But it
doesn't make sense for find_last_decl to be trying to match anything with
DECL_USE_TEMPLATE set; those are matched elsewhere.
PR c++/107484
gcc/cp/ChangeLog:
* decl2.cc (find_last_decl): Return early if DECL_USE_TEMPLATE.
gcc/testsuite/ChangeLog:
* g++.dg/lookup/friend25.C: New test.
Hans-Peter Nilsson [Tue, 14 Mar 2023 01:06:34 +0000 (02:06 +0100)]
doc: md.texi (Insn Splitting): Tweak wording for readability.
I needed to check what was allowed in a define_split, but
had problems understanding what was meant by "Splitting of
jump instruction into sequence that over by another jump
instruction".
* doc/md.texi (Insn Splitting): Tweak wording for readability.
Co-Authored-By: Sandra Loosemore <sandra@codesourcery.com>
GCC Administrator [Tue, 4 Apr 2023 00:16:31 +0000 (00:16 +0000)]
Daily bump.
Patrick Palka [Mon, 3 Apr 2023 22:49:37 +0000 (18:49 -0400)]
c++: ICE with loopy var tmpl auto deduction [PR109300]
Now that we resolve non-dependent variable template-ids ahead of time,
cp_finish_decl needs to handle a new invalid situation: we can end up
trying to instantiate a variable template with deduced type before we
fully parsed its initializer.
PR c++/109300
gcc/cp/ChangeLog:
* decl.cc (cp_finish_decl): Diagnose ordinary auto deduction
with no initializer, instead of asserting.
gcc/testsuite/ChangeLog:
* g++.dg/cpp1y/var-templ79.C: New test.
Joseph Myers [Mon, 3 Apr 2023 22:07:53 +0000 (22:07 +0000)]
Update gcc sv.po
* sv.po: Update.
Gaius Mulley [Mon, 3 Apr 2023 14:04:06 +0000 (15:04 +0100)]
PR modula2/109388 clang warnings related to Modula-2
This patch removes an unused parameter 'module' from
DoVariableDeclaration in M2GCCDeclare.mod. It also removes unused
procedures from PHBuild.bnf.
gcc/m2/ChangeLog:
PR modula2/109388
* gm2-compiler/M2GCCDeclare.mod (DoVariableDeclaration):
Remove second parameter module. Adjust all callers to
remove the second parameter.
* gm2-compiler/PHBuild.bnf (CheckAndInsert): Remove.
(InStopSet): Remove.
(PeepToken): Remove.
(PushQualident): Remove.
(SimpleDes): Remove.
(ActualParameters): Remove.
Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
Martin Jambor [Mon, 3 Apr 2023 13:53:36 +0000 (15:53 +0200)]
ipa: Avoid constructing aggregate jump functions with huge offsets (PR 109303)
We are in the process of changing data structures holding information
about constants passed by reference and in aggregates to use unsigned
int offsets rather than HOST_WIDE_INT (which was selected simply
because that is what fell out of get_ref_base_and_extent at that time)
in order to conserve memory, especially at WPA time.
PR 109303 testcase discovers that we do not properly check that we
only create jump functions with offsets (plus sizes) that fit into the
smaller type. This patch adds the necessary check.
gcc/ChangeLog:
2023-03-30 Martin Jambor <mjambor@suse.cz>
PR ipa/109303
* ipa-prop.cc (determine_known_aggregate_parts): Check that the
offset + size will be representable in unsigned int.
gcc/testsuite/ChangeLog:
2023-03-30 Jakub Jelinek <jakub@redhat.com>
Martin Jambor <mjambor@suse.cz>
PR ipa/109303
* gcc.dg/pr109303.c: New test.