gccrs: Create new test system for name resolution 2.0
This runs the standard compile/**.rs tests
with name resolution 2.0 enabled. The exclude file
can be used to exclude tests which are not yet working
with name resolution 2.0.
gcc/testsuite/ChangeLog:
* rust/compile/nr2/compile.exp: New test.
* rust/compile/nr2/exclude: New.
gccrs: [gccrs#3141] Fix incorrect handling of overflow in numeric types
Fixes gccrs#3141.
gcc/rust/ChangeLog:
* backend/rust-compile-expr.cc: Fix range checking for both integers and floats.
* hir/tree/rust-hir-expr.h: Add "negative_number" boolean to LiteralExpr class.
gcc/testsuite/ChangeLog:
* rust/compile/issue-3141.rs: New test.
Signed-off-by: Joan Vilardaga <github-91yu@joanvc.cat>
Throw an error when auto-traits used without feature attribute.
gcc/rust/ChangeLog:
* checks/errors/rust-feature-gate.cc (FeatureGate::visit): Emit error
on trait when auto field member true.
* checks/errors/rust-feature-gate.h: add prototype of trait visitor.
* checks/errors/rust-feature.cc (Feature::create): add
optin_builtin_traits in match of feature.
gcc/testsuite/ChangeLog:
* rust/compile/auto_trait_super_trait.rs: Add feature attribute.
* rust/compile/generic_auto_trait.rs: likewise.
* rust/compile/auto_trait.rs: add test for error without
feature attribute
Liam Naddell [Thu, 8 Aug 2024 09:31:58 +0000 (05:31 -0400)]
gccrs: Dynamic dispatch with supertraits
gcc/rust/ChangeLog:
* backend/rust-compile.cc:
Modify compute_address_for_trait_item to support supertraits
* typecheck/rust-tyty.cc:
Remove auto
gcc/testsuite/ChangeLog:
* rust/compile/trait13.rs:
Add test for supertraits of supertraits
* rust/compile/trait14.rs:
Diamond problem with supertraits test
* rust/execute/torture/trait14.rs:
Add test for dynamic dispatch with supertraits
* rust/execute/torture/trait15.rs:
Add test for dynamic dispatch with generics
* rust/execute/torture/trait16.rs:
Add test for dynamic dispatch with lifetime params 1
* rust/execute/torture/trait17.rs:
Add test for dynamic dispatch with lifetime params 2
* rust/execute/torture/trait18.rs:
Add test for default implementations with dynamic dispatch and
supertraits
Kushal Pal [Wed, 28 Aug 2024 06:39:28 +0000 (06:39 +0000)]
gccrs: Used `IndexVec` for place_map
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-bir-dump.cc (Dump::go): Use strong
type instead of size_t.
(Dump::visit_place): Likewise.
(Dump::visit_scope): Likewise.
* checks/errors/borrowck/rust-bir-dump.h (class Dump): Use
IndeVec for place_map.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Kushal Pal [Wed, 28 Aug 2024 06:16:11 +0000 (06:16 +0000)]
gccrs: Use `IndexVec` for bb_fold_map
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-bir-dump.cc (simplify_cfg):
Used `IndexVec` for bb_fold_map.
(Dump::go): Use strong type as index instead of value as now we
are using `IndexVec`.
(Dump::visit): Likewise.
* checks/errors/borrowck/rust-bir-dump.h (class Dump): Use
`IndexVec` for bb_fold_map.
* checks/errors/borrowck/rust-bir-place.h: Add constructor for
`IndexVec` that can reserve size.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Kushal Pal [Mon, 19 Aug 2024 10:06:49 +0000 (10:06 +0000)]
gccrs: Used `IndexVec` for BasicBlocks
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
(ExprStmtBuilder::visit): Use strong type as index and
remove access to numeric value.
* checks/errors/borrowck/rust-bir-builder-internal.h
(struct BuilderContext): Likewise.
* checks/errors/borrowck/rust-bir-dump.cc (simplify_cfg):
Likewise.
(Dump::go): Likewise.
(Dump::visit): Likewise.
* checks/errors/borrowck/rust-bir-fact-collector.h
(class FactCollector): Likewise.
(points): Likewise.
* checks/errors/borrowck/rust-bir.h (struct BasicBlockId): Used
IndexVec for BasicBlocks.
(struct Function): Likewise.
* checks/errors/borrowck/rust-borrow-checker-diagnostics.cc
(BorrowCheckerDiagnostics::get_statement): Change the extracted
index to strong type.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Kushal Pal [Mon, 19 Aug 2024 09:48:49 +0000 (09:48 +0000)]
gccrs: Used `IndexVec` for Loans
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-bir-place.h: Used `IndexVec` with
ScopeId as index.
* checks/errors/borrowck/rust-borrow-checker-diagnostics.cc
(BorrowCheckerDiagnostics::get_loan): Convert Polonius::Loan to
BIR::Loan, so we can use it as index.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Kushal Pal [Mon, 19 Aug 2024 09:28:25 +0000 (09:28 +0000)]
gccrs: Introduce `IndexVec`
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-bir-place.h (struct Loan):
Introduce new class `IndexVec` inspired from IndexVec of rust.
It acts as a wrapper around `std::vector` and lets user specify
a strong type to use as index.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Kushal Pal [Wed, 7 Aug 2024 10:58:17 +0000 (10:58 +0000)]
gccrs: Strong type BasicBlockId
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit):
Use value of BasicBlockId as index.
* checks/errors/borrowck/rust-bir-builder-internal.h (struct BuilderContext):
Likewise.
* checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h:
Initialize with ENTRY_BASIC_BLOCK.
* checks/errors/borrowck/rust-bir-dump.cc (simplify_cfg):
Use value of BasicBlockId as index.
(Dump::go): Likewise.
(Dump::visit): Likewise.
* checks/errors/borrowck/rust-bir-fact-collector.h (class FactCollector):
Initialize with ENTRY_BASIC_BLOCK.
(points): Use value of BasicBlockId as index.
* checks/errors/borrowck/rust-bir.h (struct BasicBlockId):
BasicBlockId is a struct now.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Kushal Pal [Wed, 7 Aug 2024 10:16:24 +0000 (10:16 +0000)]
gccrs: Strong type ScopeId
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
(ExprStmtBuilder::setup_loop): Use value of ScopeId.
(ExprStmtBuilder::visit): Use continue scope id instead of
continue basic block id.
* checks/errors/borrowck/rust-bir-builder-internal.h: Use value
of ScopeId.
* checks/errors/borrowck/rust-bir-dump.cc (Dump::go): Use
ROOT_VALUE instead of hardcoded 0.
(Dump::visit_scope): Use value of ScopeId.
* checks/errors/borrowck/rust-bir-place.h (struct ScopeId):
ScopeId is now a struct.
(std::numeric_limits::max): Set invalid ScopeId.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Kushal Pal [Wed, 7 Aug 2024 08:44:03 +0000 (08:44 +0000)]
gccrs: Strong type LoanId
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-bir-dump.cc (Dump::visit): Use new
API, i.e get_loan_id() instead of get_loan().
* checks/errors/borrowck/rust-bir-fact-collector.h (points): Use
value of LoanId in Polonius facts.
* checks/errors/borrowck/rust-bir-place.h (struct LoanId):
LoanId is a struct now.
* checks/errors/borrowck/rust-bir.h (class AbstractExpr): Use
new API, as we are getting a LoanId and not a loan itself.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Kushal Pal [Thu, 8 Aug 2024 07:12:00 +0000 (07:12 +0000)]
gccrs: Use FreeRegions inplace of `std::vector<FreeRegion>`
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-bir-builder-internal.h: Use
FreeRegions instead of making a temporary vector of FreeRegion.
* checks/errors/borrowck/rust-bir-builder.h: Likewise.
* checks/errors/borrowck/rust-bir-fact-collector.h (class FactCollector):
Likewise.
(points): Likewise.
* checks/errors/borrowck/rust-bir-free-region.h: Remove obsolete
set_from() helpers, add push_back().
* checks/errors/borrowck/rust-bir-place.h: Use FreeRegions
instead of making a temporary vector of Origin.
* typecheck/rust-tyty-variance-analysis-private.h: Change type
of `regions`.
* typecheck/rust-tyty-variance-analysis.cc (CrateCtx::query_type_regions):
Use new type.
(GenericTyPerCrateCtx::query_generic_variance): Likewise.
(TyVisitorCtx::add_constraints_from_generic_args): Likewise.
(FieldVisitorCtx::add_constraints_from_region): Likewise.
(FieldVisitorCtx::add_constrints_from_param): Likewise.
* typecheck/rust-tyty-variance-analysis.h: Likewise.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Kushal Pal [Wed, 7 Aug 2024 05:19:28 +0000 (05:19 +0000)]
gccrs: Strong type FreeRegion
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-bir-builder-internal.h: Use
STATIC_FREE_REGION, use value of FreeRegion for origin.
* checks/errors/borrowck/rust-bir-builder.h: Use free region
value.
* checks/errors/borrowck/rust-bir-dump.cc (Dump::visit_scope):
Likewise.
* checks/errors/borrowck/rust-bir-fact-collector.h (points):
Likewise.
* checks/errors/borrowck/rust-bir-free-region.h (struct FreeRegion):
Make FreeRegion a struct.
* checks/errors/borrowck/rust-bir-place.h: Use FreeRegion
instead of Origin in PlaceDB.
* typecheck/rust-tyty-variance-analysis.cc (FieldVisitorCtx::add_constraints_from_region):
Use value of FreeRegion for origin.
(FieldVisitorCtx::add_constrints_from_param): Likewise.
(Term::make_transform): Likewise.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Kushal Pal [Mon, 5 Aug 2024 10:50:55 +0000 (10:50 +0000)]
gccrs: Strong type PlaceId
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-bir-dump.cc (renumber_places):
Use value of PlaceId as index.
(Dump::visit_place): Likewise.
(Dump::visit_scope): Likewise.
(Dump::go): Refill `place_map` with for loop instead of
using std::iota().
* checks/errors/borrowck/rust-bir-fact-collector.h (points): Use
value as index.
* checks/errors/borrowck/rust-bir-place.h (struct PlaceId):
PlaceId is now a class holding a uint32_t value. Overloaded
comparision operators for easier comparision.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
badumbatish [Thu, 8 Aug 2024 21:22:05 +0000 (14:22 -0700)]
gccrs: Use's array type when constring string tree
gcc/rust/ChangeLog:
* backend/rust-compile-asm.cc (CompileAsm::asm_build_expr):
Use's array type when constring string tree
(CompileAsm::asm_construct_string_tree):
Use's array type when constring string tree
badumbatish [Thu, 1 Aug 2024 23:22:32 +0000 (16:22 -0700)]
gccrs: Perform lowering hir output operand to tree
gcc/rust/ChangeLog:
* backend/rust-compile-asm.cc (CompileAsm::asm_build_expr):
Add debug comment
(CompileAsm::asm_construct_outputs):
Perform lowering hir output operand to tree
* backend/rust-compile-asm.cc (CompileAsm::asm_construct_outputs):
Lower the HIR to tree with CompileExpr
* backend/rust-compile-asm.h: Remove static from method
* expand/rust-macro-builtins-asm.cc (parse_reg_operand):
Remove warnings
(parse_reg_operand_out): Remove warnings
(expand_inline_asm): New function for eventual expansion
(parse_asm): Use expand_inline_asm
gcc/testsuite/ChangeLog:
* rust/execute/torture/inline_asm_mov_x_5.rs: New test.
Raiki Tamura [Fri, 9 Aug 2024 14:56:55 +0000 (23:56 +0900)]
gccrs: Add typecheck for path patterns.
gcc/rust/ChangeLog:
* hir/tree/rust-hir.cc (Item::item_kind_string): New function.
* hir/tree/rust-hir.h: New function.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
Modify to check all arms in match expressions even if some of them
has errors.
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
Add and fix check for path patterns.
gcc/testsuite/ChangeLog:
* rust/compile/issue-2324-2.rs: Fix error message.
* rust/compile/match9.rs: New test.
Arthur Cohen [Wed, 21 Aug 2024 13:42:58 +0000 (15:42 +0200)]
gccrs: feature-gate: Cleanup visitor and constructor
This commit turns a few of the fields into `tl::optional<T>` and cleanups
the constructor with a couple default parameters. We can also reuse the
variable that we are `switch`ing on, instead of repeating the enum variants
each time.
Most importantly, the `FeatureGate` visitor now uses the `DefaultAstVisitor`
correctly, and will now visit nested items. This means that we have to
fix a bunch of the testsuite as some feature attributes were missing.
gcc/rust/ChangeLog:
* checks/errors/rust-feature.cc (Feature::create): Reuse variable,
remove now optional parameters from constructor.
* checks/errors/rust-feature.h: Cleanup class definition.
* checks/errors/rust-feature-gate.cc (FeatureGate::gate): Use optional.
* checks/errors/rust-feature-gate.h: Cleanup visitor implementation.
badumbatish [Mon, 19 Aug 2024 23:39:11 +0000 (16:39 -0700)]
gccrs: Fix the disorder struct and class in inline asm
gcc/rust/ChangeLog:
* ast/rust-ast-full-decls.h (struct InlineAsmOperand):
Change to class
(class InlineAsmOperand): Change from struct
* hir/tree/rust-hir-full-decls.h (struct InlineAsmRegOrRegClass):
Removed from decl, used from AST
(struct AnonConst): new decl from rust-hir-expr.h
(class InlineAsmOperand): new decl from rust-hir-expr.h
Arthur Cohen [Mon, 24 Jun 2024 16:25:15 +0000 (18:25 +0200)]
gccrs: ast: Introduce class hierarchy for lang item paths
Create a base Path class which is derived into two children classes for
regular paths and lang item paths. This allows it to hold either the
segments of a fully formed path, or the node ID of a lang-item path.
This is required in order to create these special paths
which do not have segments, and do not necessarily have a canonical
form - they only depend on where the item was defined.
This method was used only for stripping PathPattern AST nodes during
`cfg-strip`, which seems like a misnomer and makes it a good candidate
for simplification.
gcc/rust/ChangeLog:
* ast/rust-path.h (class PathInExpression): Remove `remove_all_segments`
method, add a `marked_for_strip` flag instead.
Kushal Pal [Mon, 12 Aug 2024 05:48:27 +0000 (05:48 +0000)]
gccrs: Move errors with locations
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-borrow-checker-diagnostics.cc
(BorrowCheckerDiagnostics::report_move_errors): Specify
locations for code causing errors and related moves.
gcc/testsuite/ChangeLog:
* rust/borrowck/test_move.rs: Test rich-errors related to moves.
* rust/borrowck/test_move_conditional.rs: Likewise.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Kushal Pal [Fri, 26 Jul 2024 07:40:58 +0000 (07:40 +0000)]
gccrs: Subset errors with locations
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-borrow-checker-diagnostics.cc
(BorrowCheckerDiagnostics::report_subset_errors): Highlight
lifetime locations while reporting subset errors.
(BorrowCheckerDiagnostics::get_lifetime_param): Helper function
to fetch HIR::Lifetime node from Polonius::Origin.
* checks/errors/borrowck/rust-borrow-checker-diagnostics.h:
Definition of helper function.
gcc/testsuite/ChangeLog:
* rust/borrowck/subset.rs: Better subset errors.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Kushal Pal [Thu, 25 Jul 2024 11:57:35 +0000 (11:57 +0000)]
gccrs: Map locations to placeholder regions
Mapped placeholder regions to their respective HIR nodes so we can fetch
locations during error reporting.
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-bir-builder.h: Map regions to
their respective HIR nodes.
* checks/errors/borrowck/rust-bir.h (struct Function):
Add unordered_map to maintain the mapping.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Liam Naddell [Sat, 3 Aug 2024 05:36:06 +0000 (01:36 -0400)]
gccrs: [gccrs#2324] Add error message for E0532
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-pattern.cc:
Emit E0532 when trying to reference a Tuple or Struct variant
using a non Tuple or Struct pattern.
gcc/testsuite/ChangeLog:
* rust/compile/issue-2324-1.rs:
add test for E0532 with tuple enum variant
* rust/compile/issue-2324-2.rs:
add test for E0532 with struct enum variant
gccrs: Eager expansion for include* gccrs#1805 gccrs#1865
gcc/rust/ChangeLog:
* expand/rust-expand-visitor.h:
remove auto keyword
* expand/rust-macro-builtins-helpers.cc:
allow for changing macro invoc types on eager expansions to
semicoloned macros
* expand/rust-macro-builtins-helpers.h:
add default semicoloned argument
* expand/rust-macro-builtins-include.cc:
allow for eager expansion for include and include_bytes
allow for parsing include invocations as items instead of
expressions, which allows invocations at global scope
* expand/rust-macro-expand.cc:
push Expr type for eager invocations
gcc/testsuite/ChangeLog:
* rust/compile/macros/builtin/include1.rs:
add basic include test at global scope
* rust/compile/macros/builtin/include2.rs:
add basic include test at local scope with expression
* rust/compile/macros/builtin/include3.rs:
add eager expansion test at global scope
* rust/compile/macros/builtin/include4.rs:
add eager expansion test at local scope with expression
* rust/compile/macros/builtin/include_bytes.rs:
add eager expansion test at global scope
* rust/compile/macros/builtin/include_rs:
supporting test file with dummy function
* rust/compile/macros/builtin/include_rs2:
supporting test file with dummy string
* rust/compile/macros/builtin/include_str.rs:
add eager expansion test at global scope
* rust/execute/torture/builtin_macro_include_bytes.rs:
clean up old test logic, add permutations for eager expansion
* rust/execute/torture/builtin_macro_include_str.rs:
add eager expansion permutations
Kushal Pal [Wed, 31 Jul 2024 01:37:54 +0000 (01:37 +0000)]
gccrs: Simplify construction of BIR::Statement
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-bir-builder-internal.h:
Use `make_*` functions to create BIR::Statements.
* checks/errors/borrowck/rust-bir.h: Make a complete constructor
and introduce `make_*` functions to create various
BIR::Statements.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Kushal Pal [Thu, 18 Jul 2024 08:12:49 +0000 (08:12 +0000)]
gccrs: Loan errors with locations
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-borrow-checker-diagnostics.cc
(BorrowCheckerDiagnostics::report_loan_errors): Add label to
where the borrow occurs and where the invalid access occurs.
(BorrowCheckerDiagnostics::get_statement):
Fetch BIR::Statement from Polonius::Point
(BorrowCheckerDiagnostics::get_loan):
Fetch BIR::Loan from Polonius::Loan
* checks/errors/borrowck/rust-borrow-checker-diagnostics.h:
Function definition of helpers.
Kushal Pal [Fri, 19 Jul 2024 07:30:03 +0000 (07:30 +0000)]
gccrs: Add location to BIR::Statement of kind RETURN
This commit adds location_t to BIR::Statement where type is RETURN.
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit):
Add location parameter.
* checks/errors/borrowck/rust-bir-builder.h: Likewise.
* checks/errors/borrowck/rust-bir-builder-internal.h: Add helper
function for pushing return statements.
* checks/errors/borrowck/rust-bir.h: Remove `expr` parameter as
it is only needed for ASSIGNMENT statements, for which we
already have a constructor.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Kushal Pal [Tue, 9 Jul 2024 10:37:27 +0000 (10:37 +0000)]
gccrs: Add location to BIR::Loan
This commit adds location_t to BIR::Loan, this location will point to
location is source code where the borrow occured, this information will
be useful for reporting borrow-checking errors.
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-bir-builder-internal.h:
Fill location for loan.
* checks/errors/borrowck/rust-bir-place.h (struct Loan):
Add location field.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
* hir/rust-ast-lower-expr.cc (from_operand):
Set up the lowering for operand
(ASTLoweringExpr::visit): Likewise
* hir/tree/rust-hir-expr.h (struct InlineAsmRegOrRegClass):
Not necessary, kept from ast
(struct AnonConst): Set up lowering for operand
(class InlineAsmOperand): Likewise, add getters
Kushal Pal [Wed, 31 Jul 2024 10:53:35 +0000 (10:53 +0000)]
gccrs: Improve compressed point bit manipulation
gcc/rust/ChangeLog:
* checks/errors/borrowck/polonius/rust-polonius.h (struct FullPoint):
Added comments and made extraction of statement more verbose for
better understanding.
* checks/errors/borrowck/ffi-polonius/src/lib.rs: Likewise.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
gccrs: Use new constructors and control flow for operand
gcc/rust/ChangeLog:
* ast/rust-expr.h (struct InlineAsmOperand): changed to class
(class InlineAsmOperand): Have appropriate constructor,
and getter
* expand/rust-macro-builtins-asm.cc (parse_reg_operand):
Use the new implement constructors and new control flow.
(parse_reg_operand_in): Likewise
(parse_reg_operand_out): Likewise
(parse_reg_operand_inout): Likewise
(parse_reg_operand_const): Likewise
Arthur Cohen [Fri, 26 Jul 2024 09:04:46 +0000 (11:04 +0200)]
gccrs: ffi-polonius: Remove usage of extern types.
This will allow us to revert our dependency on extern types, which would
help our godbolt build as well as our various builders.
gcc/rust/ChangeLog:
* checks/errors/borrowck/ffi-polonius/src/gccrs_ffi.rs: Remove extern
type feature.
* checks/errors/borrowck/ffi-polonius/src/lib.rs: Define FFIVector
per the nomicon's recommendation
https://doc.rust-lang.org/nomicon/ffi.html#representing-opaque-structs
gcc/rust/ChangeLog:
* ast/rust-ast.cc:
Fix Attribute constructors to copy inner_attribute
* checks/errors/rust-unsafe-checker.cc:
Add pass for #[may_dangle] in safe impl's
* hir/rust-ast-lower-item.cc:
Add support for unsafe impl's
* hir/rust-ast-lower-type.cc:
Lower attributes in impl's from AST to HIR
* hir/rust-hir-dump.cc:
Change single attribute to AttrVec
* hir/tree/rust-hir-item.h:
Add unsafe support to Impl blocks in HIR
* hir/tree/rust-hir.cc:
Change single attribute to AttrVec
* hir/tree/rust-hir.h:
Add has/get_outer_attribute to GenericParam
gcc/testsuite/ChangeLog:
* rust/compile/issue-3045-1.rs:
Add test for #[may_dangle] Generic Type triggering error
* rust/compile/issue-3045-2.rs:
Add test for #[may_dangle] Lifetime triggering error
Antonio Gomes [Fri, 19 Jul 2024 01:50:54 +0000 (22:50 -0300)]
gccrs: Properly striping struct fields when using attrs
gcc/rust/ChangeLog:
* expand/rust-cfg-strip.cc:
Strip struct expr fields and strip fields in struct definition
* expand/rust-cfg-strip.h:
Signatures for new function maybe_strip_struct_expr_fields
gcc/testsuite/ChangeLog:
* rust/compile/macro-issue2983_2984.rs:
Add test to check for correct stripped fields
Signed-off-by: Antonio Gomes <antoniospg100@gmail.com>
Tomasz Kamiński [Wed, 19 Mar 2025 10:42:50 +0000 (11:42 +0100)]
libstdc++: Support maps deduction from_range of tuples.
This implements part of LWG4223 that enables deduction for maps types
(map, unordered_map, flat_map and non-unique equivalent) from
(from_range, rg, ...) arguments, where rg is range of tuple
or other pair-like.
libstdc++-v3/ChangeLog:
* include/bits/ranges_base.h (__detail::__range_key_type):
Replace RV::first_type with tuple_element_t<0, RV>.
(__detail::__range_mapped_type) Replace RV::second_type
with tuple_element_t<1, RV>.
* testsuite/23_containers/flat_map/1.cc: New tests.
* testsuite/23_containers/flat_multimap/1.cc: New tests.
* testsuite/23_containers/map/cons/from_range.cc: New tests.
* testsuite/23_containers/multimap/cons/from_range.cc: New tests.
* testsuite/23_containers/unordered_map/cons/from_range.cc: New tests.
* testsuite/23_containers/unordered_multimap/cons/from_range.cc:
New tests.
Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
Jakub Jelinek [Wed, 19 Mar 2025 13:26:22 +0000 (14:26 +0100)]
i386: Fix up splitters into vptest [PR119357]
The following testcase ICEs, because the splitters into vptest
create an invalid instruction. The operands of all the UNSPEC_PTEST
using instructions use register_operand and vector_operand predicate,
these splitters use vector_operand predicate but create vptest
instruction which has the same argument twice, so one of them needs
to be in a register.
The following patch keeps vector_operand predicate on the splitters
but uses force_reg to force it into a REG if it was a MEM, that results
in better code generation e.g. on the included testcase, as combine
can match those even with MEM.
The difference on the testcase is
- vpxor %xmm0, %xmm0, %xmm0
- vpcmpeqb (%rdi), %xmm0, %xmm0
- vpmovmskb %xmm0, %eax
- cmpl $65535, %eax
+ vmovdqa (%rdi), %xmm0
+ vptest %xmm0, %xmm0
(- for patch which changes the splitters to
s/vector_operand/register_operand/ and + for this patch).
2025-03-19 Jakub Jelinek <jakub@redhat.com>
PR target/119357
* config/i386/sse.md (pmovmskb 0xffff to ptest splitter,
*pmovsk_ptest_<mode>_avx512): Force operands[0] into a REG.
* gcc.target/i386/avx512vlbw-pr119357.c: New test.
Tamar Christina [Wed, 19 Mar 2025 12:58:14 +0000 (12:58 +0000)]
middle-end: update early-break tests for non-load-lanes targets [PR119286]
Broadly speaking, these tests were failing because the BB limitation for SLP'ing
loads in an || in an early break makes the loads end up in different BBs and so
today we can't SLP them. This results in load_lanes being required to vectorize
them because the alternative is loads with permutes which we don't allow.
The original checks were only checking partial vectors, which ended up working
because e.g. Adv. SIMD isn't a partial vector target, so it failed, and SVE was
a partial vector target but also has load lanes so it passes.
GCN however is a partial vector target without load lanes which makes the tests
fail. As we require load_lanes for now, also check for them.
Bootstrapped Regtested on aarch64-none-linux-gnu,
arm-none-linux-gnueabihf, x86_64-pc-linux-gnu
-m32, -m64 and no issues.
Cross checked the failing cases on amdgcn-amdhsa
and all pass now.
gcc/testsuite/ChangeLog:
PR target/119286
* gcc.dg/vect/bb-slp-41.c: Add pragma novector.
* gcc.dg/vect/vect-early-break_133_pfa11.c: Should never vectorize today
as indexes can be out of range.
* gcc.dg/vect/vect-early-break_128.c: Require load_lanes as well.
* gcc.dg/vect/vect-early-break_133_pfa10.c: Likewise.
* gcc.dg/vect/vect-early-break_133_pfa8.c: Likewise.
* gcc.dg/vect/vect-early-break_133_pfa9.c: Likewise.
* gcc.dg/vect/vect-early-break_22.c: Likewise.
* gcc.dg/vect/vect-early-break_26.c: Likewise.
* gcc.dg/vect/vect-early-break_43.c: Likewise.
* gcc.dg/vect/vect-early-break_44.c: Likewise.
* gcc.dg/vect/vect-early-break_6.c: Likewise.
* gcc.dg/vect/vect-early-break_56.c: Expect failures on group misalign.
Tomasz Kamiński [Tue, 18 Mar 2025 15:10:48 +0000 (16:10 +0100)]
libstdc++-v3: Implement allocator-aware from_range_t constructors for unordered containers.
This patch implements part of LWG2713 covering the from_range
constructors, which makes std::ranges::to<std::unordered_set>(alloc)
well-formed. Likewise for rest of unordered containers.
As this consturctors were added to v15, this has no impact
on code that compiled with previous versions.
libstdc++-v3/ChangeLog:
* include/bits/unordered_map.h
(unordered_map(from_range_t, _Rg&&, const allocator_type&))
(unordered_multimap(from_range_t, _Rg&&, const allocator_type&)):
Define.
* include/bits/unordered_set.h
(unordered_set(from_range_t, _Rg&&, const allocator_type&))
(unordered_multiset(from_range_t, _Rg&&, const allocator_type&)):
Define.
* testsuite/23_containers/unordered_map/cons/from_range.cc: New tests.
New tests.
* testsuite/23_containers/unordered_multimap/cons/from_range.cc:
New tests.
* testsuite/23_containers/unordered_multiset/cons/from_range.cc:
New tests.
* testsuite/23_containers/unordered_set/cons/from_range.cc: New tests.
* testsuite/std/ranges/conv/1.cc: New tests.
Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
Tomasz Kamiński [Tue, 18 Mar 2025 16:32:40 +0000 (17:32 +0100)]
libstdc++: Cast difference_type for insert_range unordered non-unique containers [PR119358]
ranges::distance may produce an integer-like class type
(ranges::__detail::__max_diff_type) that is only explicitly convertible to
other integer types, so the result needs to be casted to containers size_type.
PR libstdc++/119358
libstdc++-v3/ChangeLog:
* include/bits/unordered_map.h (unordered_multimap::insert_range):
Cast ranges::distance to size_type before passing to _M_rehash_insert.
* include/bits/unordered_set.h (unordered_multiset::insert_range):
Same as unordered_multimap::insert_range.
* testsuite/23_containers/unordered_multimap/cons/from_range.cc:
New tests.
* testsuite/23_containers/unordered_multiset/cons/from_range.cc:
New tests.
Kyrylo Tkachov [Mon, 17 Mar 2025 15:24:18 +0000 (08:24 -0700)]
aarch64: Add +sve2p1 to -march=armv9.4-a flags
The ArmARM says:
"In an Armv9.4 implementation, if FEAT_SVE2 is implemented, FEAT_SVE2p1
is implemented."
We should enable +sve2p1 as part of -march=armv9.4-a, which this patch does.
This makes gcc consistent with gas.
Bootstrapped and tested on aarch64-none-linux-gnu.
Jakub Jelinek [Wed, 19 Mar 2025 08:34:10 +0000 (09:34 +0100)]
c++: Perform immediate invocation evaluation separately from cp_fold_r [PR118068]
The r14-4140 change moved consteval evaluation from build_over_call to
cp_fold_r.
The following testcase is a regression caused by that change. There
is a cast around immediate invocation, (int) foo (0x23)
where consteval for returns unsigned char. When the consteval call
has been folded early to 0x23 (with unsigned char type), cp_fold sees
(int) 0x23 and folds that to 0x23 with int type.
But when the immediate invocation is handled only during cp_fold_r,
cp_fold_r first calls cp_fold on the NOP_EXPR, which calls cp_fold
on its operand, it is CALL_EXPR, nothing is folded at that point.
Then cp_fold_r continues to walk the NOP_EXPR's operand, sees it is
an immediate function invocation and cp_fold_immediate_r calls
cxx_constant_value on it and replaces the CALL_EXPR with the INTEGER_CST
0x23. Nothing comes back to folding the containing NOP_EXPR though.
Sure, with optimizations enabled some GIMPLE optimization folds that later,
but e.g. with -O0 nothing does that. I think there could be arbitrarily
complex expressions on top of the immediate invocation(s) that used to be
folded by cp_fold before and aren't folded anymore.
One possibility would be to do the immediate invocation evaluation in
cp_fold rather than cp_fold_r (or in addition to cp_fold_r).
The following patch instead first evaluates all immediate invocations and
does cp_fold_r in a separate step. That not only allows the folding of
expressions which contain immediate invocations, but also simplifies some
of the quirks that had to be done when it was in cp_fold_r.
Though, I had to add an extra case to cp_genericize_r RETURN_EXPR handling
to avoid a regression where after emitting errors in RETURN_EXPR argument
we've emitted a -Wreturn-type false positive. Previously we ended up with
RETURN_EXPR with CLEANUP_POINT_EXPR with INIT_EXPR of RESULT_DECL to
error_mark_node, now we fold it more and have RETURN_EXPR with
error_mark_node operand. The former would result during gimplification
into something -Wresult-type was quiet about, the latter doesn't.
BTW, r14-4140 changed behavior on
consteval bool foo (bool x) { if (x) throw 1; return false; }
constexpr void
foo ()
{
if constexpr (false)
{
bool a = foo (true);
}
}
where GCC 13 emitted
error: expression ‘<throw-expression>’ is not a constant expression
error and GCC 14/trunk including the patch below doesn't reject it.
And clang++ trunk rejects it. It isn't immediately clear to me what
is right, if immediate invocations in discarded statements should
be evaluated or not.
2025-03-19 Jakub Jelinek <jakub@redhat.com>
PR target/118068
gcc/cp/
* cp-gimplify.cc (cp_fold_immediate): Use cp_walk_tree rather than
cp_walk_tree_without_duplicates.
(cp_fold_immediate_r): For IF_STMT_CONSTEVAL_P IF_STMT don't walk
into THEN_CLAUSE subtree, only ELSE_CLAUSE. For non-call related
stmts call data->pset.add and if it returns true, don't walk subtrees.
(cp_fold_r): Don't call cp_fold_immediate_r here.
(cp_fold_function): For C++20 or later call cp_walk_tree
with cp_fold_immediate_r callback first before calling cp_walk_tree
with cp_fold_r callback and call data.pset.empty () in between.
(cp_fully_fold_init): Likewise.
(cp_genericize_r) <case RETURN_EXPR>: Suppress -Wreturn-type warning
if RETURN_EXPR has erroneous argument.
gcc/testsuite/
* g++.target/i386/pr118068.C: New test.
Eric Botcazou [Wed, 19 Mar 2025 07:55:04 +0000 (08:55 +0100)]
Fix misoptimization at -O2 in LTO mode
This is a regression in recent releases. The problem is that the IPA mod/ref
pass looks through the (nominal) type of a pointer-to-discriminated-type
parameter in a call to a subprogram in order to see the (actual) type used
for the dereferences of the parameter in the callee, which is a
pointer-to-constrained-subtype.
Historically the discriminated type is marked with the may_alias attribute
because of the symmetric effect for the argument in the caller, so we mark
the constrained subtype with the attribute now for the sake of the callee.
gcc/ada/
* gcc-interface/decl.cc (gnat_to_gnu_entity) <E_Record_Subtype>: Set
the may_alias attribute if a specific GCC type is built.
Martin Uecker [Sat, 1 Mar 2025 20:32:21 +0000 (21:32 +0100)]
c: Fix bug in typedef redefinitions of tagged types [PR118765]
When we redefine a tagged type we incorrectly update TYPE_STUB_DECL
of the previously defined type instead of the new one. Because
TYPE_STUB_DECL is used when determining whether two such types are
the same, this can cause valid typedef redefinitions to be rejected
later. This is only a partial fix for PR118765.
PR c/118765
gcc/c/ChangeLog:
* c-decl.cc (finish_struct,finish_enum): Swap direction when
copying TYPE_STRUB_DECL in redefinitions.
gcc/testsuite/ChangeLog:
* gcc.dg/pr118765.c: New test.
Eric Botcazou [Wed, 19 Mar 2025 07:22:33 +0000 (08:22 +0100)]
Fix spurious visibility error with partially parameterized formal package
This is not a regression but the issue is quite annoying and the fix is
trivial. The problem is that a formal parameter covered by a box in the
formal package is not visible in the instance when it comes after another
formal parameter that is also a formal package.
It comes from a discrepancy internal to Instantiate_Formal_Package, where
a specific construct (the abbreviated instance) built for the nested formal
package discombobulates the processing done for the outer formal package.
gcc/ada/
* gen_il-gen-gen_nodes.adb (N_Formal_Package_Declaration): Use
N_Declaration instead of Node_Kind as ancestor.
* sem_ch12.adb (Get_Formal_Entity): Remove obsolete alternative.
(Instantiate_Formal_Package): Take into account the abbreviated
instances in the main loop running over the actuals of the local
package created for the formal package.
gcc/testsuite/
* gnat.dg/generic_inst14.adb: New test.
* gnat.dg/generic_inst14_pkg.ads: New helper.
* gnat.dg/generic_inst14_pkg-child.ads: Likewise.