Commit graph

208569 commits

Author SHA1 Message Date
David Malcolm
18aabe7d20 analyzer: handle null "var" in state_change_event::get_desc [PR113509]
Avoid ICE with  -fanalyzer-verbose-state-changes when
region_model::get_representative_tree returns nullptr in
state_change_event::get_desc.

gcc/analyzer/ChangeLog:
	PR analyzer/113509
	* checker-event.cc (state_change_event::get_desc): Don't assume
	"var" is non-NULL.

gcc/testsuite/ChangeLog:
	PR analyzer/113509
	* c-c++-common/analyzer/stdarg-pr113509.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2024-01-30 20:06:31 -05:00
Juzhe-Zhong
9dd10de15b RISC-V: Fix VSETLV PASS compile-time issue
The compile time issue was discovered in SPEC 2017 wrf:

Use time and -ftime-report to analyze the profile data of SPEC 2017 wrf compilation .

Before this patch (Lazy vsetvl):

scheduling                         : 121.89 ( 15%)   0.53 ( 11%) 122.72 ( 15%)    13M (  1%)
machine dep reorg                  : 424.61 ( 53%)   1.84 ( 37%) 427.44 ( 53%)  5290k (  0%)
real    13m27.074s
user    13m19.539s
sys     0m5.180s

Simple vsetvl:

machine dep reorg                  :   0.10 (  0%)   0.00 (  0%)   0.11 (  0%)  4138k (  0%)
real    6m5.780s
user    6m2.396s
sys     0m2.373s

The machine dep reorg is the compile time of VSETVL PASS (424 seconds) which counts 53% of
the compilation time, spends much more time than scheduling.

After investigation, the critical patch of VSETVL pass is compute_lcm_local_properties which
is called every iteration of phase 2 (earliest fusion) and phase 3 (global lcm).

This patch optimized the codes of compute_lcm_local_properties to reduce the compilation time.

After this patch:

scheduling                         : 117.51 ( 27%)   0.21 (  6%) 118.04 ( 27%)    13M (  1%)
machine dep reorg                  :  80.13 ( 18%)   0.91 ( 26%)  81.26 ( 18%)  5290k (  0%)
real    7m25.374s
user    7m20.116s
sys     0m3.795s

The optimization of this patch is very obvious, lazy VSETVL PASS: 424s (53%) -> 80s (18%) which
spend less time than scheduling.

Tested on both RV32 and RV64 no regression.  Ok for trunk ?

	PR target/113495

gcc/ChangeLog:

	* config/riscv/riscv-vsetvl.cc (extract_single_source): Remove.
	(pre_vsetvl::compute_vsetvl_def_data): Fix compile time issue.
	(pre_vsetvl::compute_transparent): New function.
	(pre_vsetvl::compute_lcm_local_properties): Fix compile time time issue.
2024-01-31 08:29:37 +08:00
GCC Administrator
097ddd552d Daily bump. 2024-01-31 00:19:27 +00:00
Fangrui Song
d725010038 i386: Add "Ws" constraint for symbolic address/label reference [PR105576]
Printing the raw symbol is useful in inline asm (e.g. in C++ to get the
mangled name).  Similar constraints are available in other targets (e.g.
"S" for aarch64/riscv, "Cs" for m68k).

There isn't a good way for x86 yet, e.g. "i" doesn't work for
PIC/-mcmodel=large.  This patch adds "Ws".  Here are possible use cases:

```
namespace ns { extern int var; }
asm (".pushsection .xxx,\"aw\"; .dc.a %0; .popsection" :: "Ws"(&var));
asm (".reloc ., BFD_RELOC_NONE, %0" :: "Ws"(&var));
```

gcc/ChangeLog:

	PR target/105576
	* config/i386/constraints.md: Define constraint "Ws".
	* doc/md.texi: Document it.

gcc/testsuite/ChangeLog:

	PR target/105576
	* gcc.target/i386/asm-raw-symbol.c: New testcase.
2024-01-30 15:21:04 -08:00
Marek Polacek
f2061b2a96 c++: avoid -Wdangling-reference for std::span-like classes [PR110358]
Real-world experience shows that -Wdangling-reference triggers for
user-defined std::span-like classes a lot.  We can easily avoid that
by considering classes like

    template<typename T>
    struct Span {
      T* data_;
      std::size len_;
    };

to be std::span-like, and not warning for them.  Unlike the previous
patch, this one considers a non-union class template that has a pointer
data member and a trivial destructor as std::span-like.

	PR c++/110358
	PR c++/109640

gcc/cp/ChangeLog:

	* call.cc (reference_like_class_p): Don't warn for std::span-like
	classes.

gcc/ChangeLog:

	* doc/invoke.texi: Update -Wdangling-reference description.

gcc/testsuite/ChangeLog:

	* g++.dg/warn/Wdangling-reference18.C: New test.
	* g++.dg/warn/Wdangling-reference19.C: New test.
	* g++.dg/warn/Wdangling-reference20.C: New test.
2024-01-30 13:18:32 -05:00
Takayuki 'January June' Suwa
24d5e0bf19 xtensa: Make full transition to LRA
gcc/ChangeLog:

	* config/xtensa/constraints.md (R, T, U):
	Change define_constraint to define_memory_constraint.
	* config/xtensa/predicates.md (move_operand): Don't check that a
	constant pool operand size is a multiple of UNITS_PER_WORD.
	* config/xtensa/xtensa.cc
	(xtensa_lra_p, TARGET_LRA_P): Remove.
	(xtensa_emit_move_sequence): Remove "if (reload_in_progress)"
	clause as it can no longer be true.
	(fixup_subreg_mem): Drop function.
	(xtensa_output_integer_literal_parts): Consider 16-bit wide
	constants.
	(xtensa_legitimate_constant_p): Add short-circuit path for
	integer load instructions. Don't check that mode size is
	at least UNITS_PER_WORD.
	* config/xtensa/xtensa.md (movsf): Use can_create_pseudo_p()
	rather reload_in_progress and reload_completed.
	(doloop_end): Drop operand 2.
	(movhi_internal): Add alternative loading constant from a
	literal pool.
	(define_split for DI register_operand): Don't limit to
	!TARGET_AUTO_LITPOOLS.
	* config/xtensa/xtensa.opt (mlra): Change to no effect.
2024-01-30 09:42:53 -08:00
Patrick Palka
1a4c47e10e c++: add original testcase [PR67898]
The original testcase from this PR (fixed by r14-8291) seems rather
different from the others, so let's add it to the testsuite.

	PR c++/67898

gcc/testsuite/ChangeLog:

	* g++.dg/cpp0x/temp_default8.C: New test.
2024-01-30 12:30:32 -05:00
Jason Merrill
209fc1e5f6 testsuite: fix anon6 mangling [PR112846]
As with r14-6796-g2fa122cae50cd8, avoid mangling compatibility aliases in
mangling tests, and test the new mangling.

	PR c++/112846

gcc/testsuite/ChangeLog:

	* g++.dg/abi/anon6.C: Specify ABI v18.
	* g++.dg/abi/anon6a.C: New test for ABI v19.
2024-01-30 12:09:47 -05:00
Jason Merrill
dd7aa986fd testsuite: mangle-reparm1a options [PR113451]
When I added -fabi-compat-version=8 to avoid mangling aliases it also
suppressed the -Wabi warning.

	PR c++/113451

gcc/testsuite/ChangeLog:

	* g++.dg/abi/mangle-regparm1a.C: Use -Wabi=0.
2024-01-30 11:40:33 -05:00
Patrick Palka
0857a00fe3 c++: duplicated side effects of xobj arg [PR113640]
We miscompile the below testcase because keep_unused_object_arg thinks
the object argument of an xobj member function is unused, and so it ends
up duplicating the argument's side effects.

	PR c++/113640

gcc/cp/ChangeLog:

	* call.cc (keep_unused_object_arg): Punt for an xobj member
	function.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp23/explicit-obj-lambda14.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
2024-01-30 10:44:56 -05:00
Patrick Palka
af37bef861 c++: unifying integer parm with type-dep arg [PR113644]
Here when trying to unify P=42 A=T::value we ICE due to the latter's
empty type, which same_type_p dislikes.

	PR c++/113644

gcc/cp/ChangeLog:

	* pt.cc (unify) <case INTEGER_CST>: Handle NULL_TREE type.

gcc/testsuite/ChangeLog:

	* g++.dg/template/nontype30.C: New test.
2024-01-30 10:13:41 -05:00
Jonathan Wakely
5525dd754b libstdc++: Fix check in testsuite/std/time/clock/gps/io.cc
The test_format() function contained an incorrect assertion but wasn't
actually being called from main.

libstdc++-v3/ChangeLog:

	* testsuite/std/time/clock/gps/io.cc: Fix expected result in
	assertion and call test_format() from main.
2024-01-30 14:50:07 +00:00
Pan Li
7bfea0aedb RISC-V: Bugfix for vls mode aggregated in GPR calling convention
According to the issue as below.

https://hub.fgit.cf/riscv-non-isa/riscv-elf-psabi-doc/pull/416

When the mode size of vls integer mode is less than 2 * XLEN, we will
take the gpr for both the args and the return values. Instead of the
reference. For example the below code:

typedef short v8hi __attribute__ ((vector_size (16)));

v8hi __attribute__((noinline))
add (v8hi a, v8hi b)
{
  v8hi r = a + b;
  return r;
}

Before this patch:
add:
  vsetivli zero,8,e16,m1,ta,ma
  vle16.v  v1,0(a1) <== arg by reference
  vle16.v  v2,0(a2) <== arg by reference
  vadd.vv  v1,v1,v2
  vse16.v  v1,0(a0) <== return by reference
  ret

After this patch:
add:
  addi     sp,sp,-32
  sd       a0,0(sp)  <== arg by register a0 - a3
  sd       a1,8(sp)
  sd       a2,16(sp)
  sd       a3,24(sp)
  addi     a5,sp,16
  vsetivli zero,8,e16,m1,ta,ma
  vle16.v  v2,0(sp)
  vle16.v  v1,0(a5)
  vadd.vv  v1,v1,v2
  vse16.v  v1,0(sp)
  ld       a0,0(sp)  <== return by a0 - a1.
  ld       a1,8(sp)
  addi     sp,sp,32
  jr       ra

For vls floating point, we take the same rules as integer and passed by
the gpr or reference.

The riscv regression passed for this patch.

gcc/ChangeLog:

	* config/riscv/riscv.cc (riscv_v_vls_mode_aggregate_gpr_count): New function to
	calculate the gpr count required by vls mode.
	(riscv_v_vls_to_gpr_mode): New function convert vls mode to gpr mode.
	(riscv_pass_vls_aggregate_in_gpr): New function to return the rtx of gpr
	for vls mode.
	(riscv_get_arg_info): Add vls mode handling.
	(riscv_pass_by_reference): Return false if arg info has no zero gpr count.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/vls/def.h: Add new helper macro.
	* gcc.target/riscv/rvv/autovec/vls/calling-convention-1.c: New test.
	* gcc.target/riscv/rvv/autovec/vls/calling-convention-10.c: New test.
	* gcc.target/riscv/rvv/autovec/vls/calling-convention-2.c: New test.
	* gcc.target/riscv/rvv/autovec/vls/calling-convention-3.c: New test.
	* gcc.target/riscv/rvv/autovec/vls/calling-convention-4.c: New test.
	* gcc.target/riscv/rvv/autovec/vls/calling-convention-5.c: New test.
	* gcc.target/riscv/rvv/autovec/vls/calling-convention-6.c: New test.
	* gcc.target/riscv/rvv/autovec/vls/calling-convention-7.c: New test.
	* gcc.target/riscv/rvv/autovec/vls/calling-convention-8.c: New test.
	* gcc.target/riscv/rvv/autovec/vls/calling-convention-9.c: New test.
	* gcc.target/riscv/rvv/autovec/vls/calling-convention-run-1.c: New test.
	* gcc.target/riscv/rvv/autovec/vls/calling-convention-run-2.c: New test.
	* gcc.target/riscv/rvv/autovec/vls/calling-convention-run-3.c: New test.
	* gcc.target/riscv/rvv/autovec/vls/calling-convention-run-4.c: New test.
	* gcc.target/riscv/rvv/autovec/vls/calling-convention-run-5.c: New test.
	* gcc.target/riscv/rvv/autovec/vls/calling-convention-run-6.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
2024-01-30 21:48:28 +08:00
David Malcolm
9f38237666 analyzer: fix -Wanalyzer-allocation-size false +ve on Linux kernel's round_up macro [PR113654]
gcc/analyzer/ChangeLog:
	PR analyzer/113654
	* region-model.cc (is_round_up): New.
	(is_multiple_p): New.
	(is_dubious_capacity): New.
	(region_model::check_region_size): Move usage of size_visitor into
	is_dubious_capacity.

gcc/testsuite/ChangeLog:
	PR analyzer/113654
	* c-c++-common/analyzer/allocation-size-pr113654-1.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2024-01-30 08:17:47 -05:00
David Malcolm
181f753dc4 analyzer: add SARIF property bag to -Wanalyzer-allocation-size
This is useful for debugging the analyzer.

gcc/analyzer/ChangeLog:
	* region-model.cc
	(dubious_allocation_size::dubious_allocation_size): Add
	"capacity_sval" param.  Drop unused ctor.
	(dubious_allocation_size::maybe_add_sarif_properties): New.
	(dubious_allocation_size::m_capacity_sval): New field.
	(region_model::check_region_size): Pass capacity svalue to
	dubious_allocation_size ctor.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2024-01-30 08:17:47 -05:00
Arthur Cohen
2a9881565c gccrs: Fix output line ending patterns.
gcc/testsuite/ChangeLog:

	* rust/execute/torture/builtin_macros1.rs: Fix output pattern.
	* rust/execute/torture/coercion3.rs: Likewise.
	* rust/execute/torture/issue-2080.rs: Likewise.
	* rust/execute/torture/issue-2179.rs: Likewise.
	* rust/execute/torture/issue-2180.rs: Likewise.
	* rust/execute/torture/iter1.rs: Likewise.
2024-01-30 12:36:52 +01:00
Owen Avery
1740fbe1dd gccrs: Remove TraitImplItem
gcc/rust/ChangeLog:

	* ast/rust-ast-full-decls.h
	(class TraitImplItem): Remove forward declaration.
	(class AssociatedItem): Add forward declaration.
	* ast/rust-ast.h
	(class TraitImplItem): Remove.
	(class TraitItem): Inherit from AssociatedItem.
	(SingleASTNode::take_trait_impl_item):
	Return std::unique_ptr<AssociatedItem> instead of
	std::unique_ptr<TraitImplItem>.
	* ast/rust-item.h
	(class Function): Inherit from AssociatedItem instead of
	TraitImplItem.
	(class TypeAlias): Likewise.
	(class ConstantItem): Likewise.
	(class TraitImpl): Store items as AssociatedItem.
	* expand/rust-derive-clone.cc
	(DeriveClone::clone_fn): Return std::unique_ptr<AssociatedItem>.
	(DeriveClone::clone_impl): Take std::unique_ptr<AssociatedItem>.
	* expand/rust-derive-clone.h
	(DeriveClone::clone_fn): Return std::unique_ptr<AssociatedItem>.
	(DeriveClone::clone_impl): Take std::unique_ptr<AssociatedItem>.
	* expand/rust-expand-visitor.cc
	(ExpandVisitor::visit): Handle changes to
	SingleASTNode::take_trait_impl_item.
	* parse/rust-parse-impl.h
	(Parser::parse_impl): Parse TraitImpl as containing AssociatedItem.
	(Parser::parse_trait_impl_item): Return
	std::unique_ptr<AssociatedItem>.
	(Parser::parse_trait_impl_function_or_method): Likewise.
	* parse/rust-parse.h
	(Parser::parse_trait_impl_item): Return
	std::unique_ptr<AssociatedItem>.
	(Parser::parse_trait_impl_function_or_method): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-01-30 12:36:52 +01:00
Robert Goss
c3ce1d6d87 gccrs: Add improved error when no fields in initializer
If a struct type with a variant that has fields is initialized with some fields the expression  HIR StructExprStructFields is checked that all the fields are assigned. However, if no fields are initialized the HIR StructExprStruct is generated. This doesn't check if the struct is a unit during typechekc and only fails at the compile stage with a ICE.

Add a check at the typecheck stage that makes sure the struct does not have a variant with fields and give an error message based on the rustc one.

We have also updated the message given in the case where one field was present to list the missing fields and match more closely the new message.

gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit) Add additional check
	* typecheck/rust-hir-type-check-struct-field.h: A helper method to make error added
	* typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::resolve) Update message

gcc/testsuite/ChangeLog:

	* rust/compile/missing_constructor_fields.rs: Added case with no initializers

Signed-off-by: Robert Goss <goss.robert@gmail.com>
2024-01-30 12:36:52 +01:00
Jakub Dupak
b49afa9ba4 gccrs: Test: check implemented for lifetime handling
gcc/testsuite/ChangeLog:

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

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-01-30 12:36:52 +01:00
Jakub Dupak
4b13ec24b1 gccrs: AST: Fix for lifetime lowering
gcc/rust/ChangeLog:

	* hir/rust-ast-lower-type.cc (ASTLoweringTypeBounds::visit): fix for lifetimes
	(ASTLowerWhereClauseItem::visit): fix for lifetimes

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-01-30 12:36:52 +01:00
Jakub Dupak
37d4cf4846 gccrs: AST: Fix for lifetime parsing
gcc/rust/ChangeLog:

	* parse/rust-parse-impl.h (Parser::parse_where_clause): fix parsing
	(Parser::parse_where_clause_item): fix parsing
	(Parser::parse_type_bound_where_clause_item): fix parsing
	(Parser::parse_trait_bound): fix parsing
	* parse/rust-parse.h: fix parsing

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-01-30 12:36:52 +01:00
Jakub Dupak
aed23b5711 gccrs: Test: fix missing lifetime in a test
This test did not compile with rustc.

gcc/testsuite/ChangeLog:

	* rust/compile/torture/utf8_identifiers.rs: add mising lifetime

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-01-30 12:36:52 +01:00
Kushal Pal
adb62fe2b4 gccrs: Added newline to get more readable lexdump
Fixes #2783

gcc/rust/ChangeLog:

	* lex/rust-lex.cc (Lexer::dump_and_skip):
	Changed " " to '\n'

Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
2024-01-30 12:36:52 +01:00
Owen Avery
1460044f87 gccrs: Unify storage of associated items in SingleASTNode
gcc/rust/ChangeLog:

	* ast/rust-ast-fragment.cc
	(Fragment::assert_single_fragment): Update.

	* ast/rust-ast.h
	(class TraitImplItem): Move definition before that of TraitItem.
	(class TraitItem):
	Inherit from TraitImplItem instead of AssociatedItem.

	(class SingleASTNode): Unify handling of associated items.
	(SingleASTNode::take_assoc_item): Move from...
	(SingleASTNode::take_impl_item): ...here, but leave stub calling
	take_assoc_item behind.
	(SingleASTNode::take_trait_item):
	Cast associated item to TraitItem.
	(SingleASTNode::take_trait_impl_item):
	Cast associated item to TraitImplItem.

	* ast/rust-ast.cc
	(SingleASTNode::SingleASTNode):
	Unify handling of associated items.
	(SingleASTNode::operator=): Likewise.
	(SingleASTNode::accept_vis): Likewise.
	(SingleASTNode::is_error): Likewise.
	(SingleASTNode::as_string): Likewise.

	* ast/rust-item.h
	(class Function): Remove direct inheritence from AssociatedItem.
	(class ConstantItem): Likewise.
	* ast/rust-macro.h
	(class MacroInvocation):
	Remove direct inheritence from AssociatedItem and TraitImplItem.
2024-01-30 12:36:52 +01:00
Robert Goss
88a27c3bc0 gccrs: Add improved error when a field is redefined in a struct constructor
Fixes #2381

If a struct type is initialized with one of it's fields repeated it will currently issue an error at the use site. However we would like to give the rust error code and (like rustc) show both the specifications for the field to help the user diagnose the issue.

We move the check after the index for the field has been established so we can look up if the field has already been defined and get it's location.

We update the visit method to return if it has handled an error otherwise we then output a second fatal error as not all the field in the specification have been processed.

gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-struct-field.h: Allow visit to return a bool
	* typecheck/rust-hir-type-check-struct.cc: Improve check of repeat fields

gcc/testsuite/ChangeLog:

	* rust/compile/repeated_constructor_fields.rs: Added case with constructor field repeated

Signed-off-by: Robert Goss <goss.robert@gmail.com>
2024-01-30 12:36:51 +01:00
Kushal Pal
7a0c487d2c gccrs: Handle async keyword for regular implementations
Fixes #2788

gcc/rust/ChangeLog:

	* parse/rust-parse-impl.h (Parser::parse_inherent_impl_item):
	Added switch-case for ASYNC token.

gcc/testsuite/ChangeLog:

	* rust/compile/issue-2788.rs: New test.

Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
2024-01-30 12:36:51 +01:00
Kushal Pal
f7c8a712be gccrs: Fix inconsistent formatting
gcc/rust/ChangeLog:

	* checks/errors/rust-ast-validation.cc (ASTValidation::visit):
	Enclose const in single quotes.

gcc/testsuite/ChangeLog:

	* rust/compile/const_trait_fn.rs:
	Enclose const in single quotes.

Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
2024-01-30 12:36:51 +01:00
Kushal Pal
f46fdb6399 gccrs: Handle async functions in traits
Fixes #2785

gcc/rust/ChangeLog:

	* checks/errors/rust-ast-validation.cc (ASTValidation::visit):
	Added check for `async` functions inside trait.
	* parse/rust-parse-impl.h (Parser::parse_trait_item):
	Added switch-case for ASYNC token.

gcc/testsuite/ChangeLog:

	* rust/compile/issue-2785.rs: New test.

Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
2024-01-30 12:36:51 +01:00
Nirmal Patel
8b7d6adbbb gccrs: Handle newlines during string parsing while lexing
If newline strings are encountered while lexing, the lexer now handles
newline characters by incrementing current line number. This provides
correct line number when displaying errors. If the lexer encounters end
of file before string end, then it will use the start of the string as
the location to an report error.

gcc/rust/ChangeLog:
	* lex/rust-lex.cc (Lexer::parse_byte_string): Handle newline
	while parsing byte strings
	(Lexer::parse_string): Handle newline while parsing strings

Signed-off-by: Nirmal Patel <nirmal@nirmal.dev>
2024-01-30 12:36:51 +01:00
Jakub Dupak
14025f7359 gccrs: TyTy: Refactor FnType deprecated API
gcc/rust/ChangeLog:

	* backend/rust-compile-expr.cc (CompileExpr::visit): Use new API.
	* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Use new API.
	* typecheck/rust-tyty-cmp.h: Remove old API.
	* typecheck/rust-tyty.cc (FnPtr::is_equal): Use new API.
	* typecheck/rust-tyty.h: Remove old API.
	* typecheck/rust-unify.cc (UnifyRules::expect_fnptr): Use new API.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-01-30 12:36:51 +01:00
Jakub Dupak
d8e8ad5493 gccrs: ast: Lower 'for' lifetimes
gcc/rust/ChangeLog:

	* hir/rust-ast-lower-type.cc (ASTLoweringType::visit): For lifetimes.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-01-30 12:36:51 +01:00
Jakub Dupak
bc1a47f72d gccrs: ast: Infer static lifetime for const and static items
(probably incomplete propagation)

gcc/rust/ChangeLog:

	* hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_lifetime): Propagate static
	requirement.
	* hir/rust-ast-lower-base.h: Propagate static requirement.
	* hir/rust-ast-lower-implitem.h: Propagate static requirement.
	* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Propagate static requirement.
	* hir/rust-ast-lower-type.cc (ASTLoweringType::translate): Propagate static requirement.
	(ASTLoweringType::visit): Propagate static requirement.
	* hir/rust-ast-lower-type.h: Propagate static requirement.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-01-30 12:36:51 +01:00
Jakub Dupak
6def638e66 gccrs: ast: Full lifetime elision handling
gcc/rust/ChangeLog:

	* parse/rust-parse-impl.h (Parser::parse_generic_param): Lifetime elision control.
	(Parser::parse_lifetime_where_clause_item): Lifetime elision control.
	(Parser::parse_type_param_bound): Lifetime elision control.
	(Parser::parse_lifetime_bounds): Lifetime elision control.
	(Parser::parse_lifetime): Lifetime elision control.
	(Parser::parse_path_generic_args): Lifetime elision control.
	(Parser::parse_self_param): Lifetime elision control.
	(Parser::parse_break_expr): Lifetime elision control.
	(Parser::parse_continue_expr): Lifetime elision control.
	(Parser::parse_reference_type_inner): Lifetime elision control.
	* parse/rust-parse.h: Lifetime elision control.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-01-30 12:36:51 +01:00
Jakub Dupak
50f3059268 gccrs: ast: Unify explicitly and implicitly elided lifettimes
gcc/rust/ChangeLog:

	* ast/rust-ast.h: Elided lifetime static constructor
	* ast/rust-type.h: Default lifetime to elided.
	* parse/rust-parse-impl.h (Parser::parse_lifetime_param): Use elided lifetime.
	(Parser::parse_lifetime): Use elided lifetime/
	(Parser::lifetime_from_token): Use elided lifetime.
	(Parser::parse_self_param): Use elided lifetime.
	(Parser::parse_reference_type_inner): Use elided lifetime.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-01-30 12:36:50 +01:00
Jakub Dupak
c936a63cb7 gccrs: ast: Fix lifetime type parsing
There was a mismatch whether lifetime 'static is parsed as "static"
or "'static".

gcc/rust/ChangeLog:

	* parse/rust-parse-impl.h (Parser::lifetime_from_token): Fix matched pattern.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-01-30 12:36:50 +01:00
Kushal Pal
81fcf1087c gccrs: Generate error for async trait fucntions
Fixes #2767

gcc/rust/ChangeLog:

	* checks/errors/rust-ast-validation.cc (ASTValidation::visit):
	Added check for `async` function inside trait.

gcc/testsuite/ChangeLog:

	* rust/compile/issue-2767.rs: New test.

Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
2024-01-30 12:36:50 +01:00
Kushal Pal
bffceda8b9 gccrs: Handle async qualifier inside trait
Fixes #2778

gcc/rust/ChangeLog:

	* parse/rust-parse-impl.h (Parser::parse_trait_impl_item):
	Handled `async` items

Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
2024-01-30 12:36:50 +01:00
Raiki Tamura
7b80033eae gccrs: split rust-mangle.cc into two files
gcc/rust/ChangeLog:

	* Make-lang.in: Add .o files
	* backend/rust-mangle.cc (struct V0Path): moved to splitted files
	(v0_path): Likewise.
	(legacy_mangle_name): Likewise.
	(legacy_mangle_canonical_path): Likewise.
	(legacy_hash): Likewise.
	(v0_tuple_prefix): Likewise.
	(v0_numeric_prefix): Likewise.
	(v0_simple_type_prefix): Likewise.
	(v0_complex_type_prefix): Likewise.
	(v0_integer_62): Likewise.
	(v0_opt_integer_62): Likewise.
	(v0_disambiguator): Likewise.
	(v0_type_prefix): Likewise.
	(v0_generic_args): Likewise.
	(v0_identifier): Likewise.
	(v0_type_path): Likewise.
	(v0_function_path): Likewise.
	(v0_scope_path): Likewise.
	(v0_crate_path): Likewise.
	(v0_inherent_or_trait_impl_path): Likewise.
	(v0_closure): Likewise.
	(legacy_mangle_item): Likewise.
	(v0_mangle_item): Likewise.
	* backend/rust-mangle.h (legacy_mangle_item): Likewise.
	(v0_mangle_item): Likewise.
	* backend/rust-mangle-legacy.cc: New file.
	* backend/rust-mangle-v0.cc: New file.

Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
2024-01-30 12:36:50 +01:00
Jakub Dupak
c54326a867 gccrs: BIR: Cleanup
gcc/rust/ChangeLog:

	* checks/errors/borrowck/rust-bir-place.h: Cleanup.
	* checks/errors/borrowck/rust-borrow-checker.h: Cleanup.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-01-30 12:36:50 +01:00
Jakub Dupak
75e6d0cf41 gccrs: TyTy: SubstitutionRef cast specialization
Allows skipping parent check when casting.

gcc/rust/ChangeLog:

	* typecheck/rust-tyty.h (BaseType::is): Cast API.
	(SubstitutionRef>): Cast API.
	(BaseType::as): Cast API.
	(BaseType::try_as): Cast API.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-01-30 12:36:50 +01:00
Jakub Dupak
44c58e2972 gccrs: TyTy: Common interface for fucntion-like types
gcc/rust/ChangeLog:

	* typecheck/rust-tyty.h (class ClosureType): Inherit interface.
	(class FnPtr): Inherit interface.
	(class FnType): Inherit interface.
	(class CallableTypeInterface): New interface.
	(BaseType::is): Detect interface members API.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-01-30 12:36:50 +01:00
Jakub Dupak
7eaef4f5b1 gccrs: TyTy: refactor to new API
gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path): Refactor.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-01-30 12:36:50 +01:00
Jakub Dupak
35d5f82eae gccrs: BIR: Fix missed nodiscard
gcc/rust/ChangeLog:

	* checks/errors/borrowck/rust-bir-builder-internal.h: Replace nodiscard.
	* checks/errors/borrowck/rust-bir-place.h: Replace nodiscard.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-01-30 12:36:50 +01:00
Jakub Dupak
ed198edc9b gccrs: TyTy: Fix missed nodiscard
gcc/rust/ChangeLog:

	* typecheck/rust-tyty.h: Fix nodiscard to warn unused.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-01-30 12:36:49 +01:00
Jakub Dupak
cc9465332e gccrs: HIR: add missing getters
gcc/rust/ChangeLog:

	* hir/tree/rust-hir-item.h: Ad lifetime getter.
	* hir/tree/rust-hir-path.h: Make getter const ref.
	* hir/tree/rust-hir.h: Const ref and new getter.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-01-30 12:36:49 +01:00
Arthur Cohen
5bcfcfe985 gccrs: refactor builtins initialization and attributes
This commit performs builtin initialization in a more "GCC-y" way,
similarly to what the D frontend is doing. This way, we no longer have
to worry about invalid attributes or types when initializing them by
hand.

Also add attributes support through LANG_HOOKS_COMMON_ATTRIBUTE_TABLE
lang hook.

Most of these changes are based on D frontend.

gcc/rust/ChangeLog:

	* Make-lang.in (GRS_OBJS): Add rust-attribs.o.
	* backend/rust-builtins.cc (builtin_const, builtin_noreturn)
	(builtin_novops): Remove.
	(BuiltinsContext::lookup_simple_builtin): Adjust.
	(BuiltinsContext::setup_overflow_fns): Remove.
	(BuiltinsContext::define_function_type): Set builtin type to
	errormark so the builtin is considered unavailable.
	(BuiltinsContext::setup_math_fns): Remove.
	(BuiltinsContext::setup_atomic_fns): Remove.
	(build_c_type_nodes): Refactor based on D frontend.
	(BuiltinsContext::define_builtin_types): Likewise.
	(DEF_PRIMITIVE_TYPE): New.
	(DEF_FUNCTION_TYPE_0): New.
	(DEF_FUNCTION_TYPE_1): New.
	(DEF_FUNCTION_TYPE_2): New.
	(DEF_FUNCTION_TYPE_3): New.
	(DEF_FUNCTION_TYPE_4): New.
	(DEF_FUNCTION_TYPE_5): New.
	(DEF_FUNCTION_TYPE_6): New.
	(DEF_FUNCTION_TYPE_7): New.
	(DEF_FUNCTION_TYPE_8): New.
	(DEF_FUNCTION_TYPE_9): New.
	(DEF_FUNCTION_TYPE_10): New.
	(DEF_FUNCTION_TYPE_11): New.
	(DEF_FUNCTION_TYPE_VAR_0): New.
	(DEF_FUNCTION_TYPE_VAR_1): New.
	(DEF_FUNCTION_TYPE_VAR_2): New.
	(DEF_FUNCTION_TYPE_VAR_3): New.
	(DEF_FUNCTION_TYPE_VAR_4): New.
	(DEF_FUNCTION_TYPE_VAR_5): New.
	(DEF_FUNCTION_TYPE_VAR_6): New.
	(DEF_FUNCTION_TYPE_VAR_7): New.
	(DEF_FUNCTION_TYPE_VAR_11): New.
	(DEF_POINTER_TYPE): New.
	(BuiltinsContext::setup): Adjust.
	(BuiltinsContext::define_builtin_attributes): New.
	(DEF_ATTR_NULL_TREE): New.
	(DEF_ATTR_INT): New.
	(DEF_ATTR_STRING): New.
	(DEF_ATTR_IDENT): New.
	(DEF_ATTR_TREE_LIST): New.
	(handle_flags): Remove.
	(BuiltinsContext::define_builtins): New.
	(DEF_BUILTIN): New.
	(BuiltinsContext::define_builtin): Remove.
	(BuiltinsContext::register_rust_mappings): New. Add all missing
	builtins.
	(BuiltinsContext::lookup_gcc_builtin): Adjust.
	* backend/rust-builtins.h (DEF_PRIMITIVE_TYPE): New.
	(DEF_FUNCTION_TYPE_0): New.
	(DEF_FUNCTION_TYPE_1): New.
	(DEF_FUNCTION_TYPE_2): New.
	(DEF_FUNCTION_TYPE_3): New.
	(DEF_FUNCTION_TYPE_4): New.
	(DEF_FUNCTION_TYPE_5): New.
	(DEF_FUNCTION_TYPE_6): New.
	(DEF_FUNCTION_TYPE_7): New.
	(DEF_FUNCTION_TYPE_8): New.
	(DEF_FUNCTION_TYPE_9): New.
	(DEF_FUNCTION_TYPE_10): New.
	(DEF_FUNCTION_TYPE_11): New.
	(DEF_FUNCTION_TYPE_VAR_0): New.
	(DEF_FUNCTION_TYPE_VAR_1): New.
	(DEF_FUNCTION_TYPE_VAR_2): New.
	(DEF_FUNCTION_TYPE_VAR_3): New.
	(DEF_FUNCTION_TYPE_VAR_4): New.
	(DEF_FUNCTION_TYPE_VAR_5): New.
	(DEF_FUNCTION_TYPE_VAR_6): New.
	(DEF_FUNCTION_TYPE_VAR_7): New.
	(DEF_FUNCTION_TYPE_VAR_11): New.
	(DEF_POINTER_TYPE): New.
	(DEF_ATTR_NULL_TREE): New.
	(DEF_ATTR_INT): New.
	(DEF_ATTR_STRING): New.
	(DEF_ATTR_IDENT): New.
	(DEF_ATTR_TREE_LIST): New.
	* backend/rust-compile-intrinsic.cc (Intrinsics::compile): Add
	comment.
	(op_with_overflow_inner): Adjust.
	(copy_handler_inner): Adjust.
	(prefetch_data_handler): Adjust.
	(build_atomic_builtin_name): Adjust.
	(atomic_load_handler_inner): Adjust.
	(uninit_handler): Adjust.
	(move_val_init_handler): Adjust.
	(expect_handler_inner): Adjust.
	* rust-gcc.cc (fetch_overflow_builtins): Adjust.
	* rust-lang.cc (rust_localize_identifier): Adjust.
	(LANG_HOOKS_COMMON_ATTRIBUTE_TABLE): New.
	* rust-attribs.cc: New file.

gcc/testsuite/ChangeLog:

	* rust/compile/torture/intrinsics-4.rs: Adjust.
	* rust/compile/torture/intrinsics-math.rs: Adjust.
	* rust/execute/torture/atomic_load.rs: Adjust.
	* rust/execute/torture/atomic_store.rs: Adjust.
	* rust/compile/torture/intrinsics-1.rs: Removed.
	* rust/compile/torture/builtin_abort.rs: New test.
	* rust/execute/torture/builtin_abort.rs: New test.

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2024-01-30 12:36:49 +01:00
Pierre-Emmanuel Patry
5ee51aa3e5 gccrs: Change cfg stripper to use default visitor
Cfg visitor used it's own visit patterns, this made the code longer than
required.

gcc/rust/ChangeLog:

	* expand/rust-cfg-strip.cc (CfgStrip::visit): Change calls from visitor
	to default visitor.
	(CfgStrip::go): Add call to visit crate.
	* expand/rust-cfg-strip.h (class CfgStrip): Update prototypes and
	remove empty ones.
	* ast/rust-ast-visitor.cc: add WhereClause condition check.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-30 12:36:49 +01:00
Pierre-Emmanuel Patry
65fb288e0d gccrs: Make expand visitor inherit from default visitor
Many visit functions in the expand visitor simply visit their components
like the default visitor. Making the expand visitor inherit from the
default visitor allows us to keep all visitor in sync without having to
change every visitor.

gcc/rust/ChangeLog:

	* expand/rust-expand-visitor.cc (ExpandVisitor::go): Add call to visit
	on the crate.
	(ExpandVisitor::visit): Remove some visit functions in favor of their
	default visitor counterpart.
	* expand/rust-expand-visitor.h (class ExpandVisitor): Inherit from
	default visitor and remove now useless function prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-30 12:36:49 +01:00
Pierre-Emmanuel Patry
b3b5115533 gccrs: Make default resolver inherit from default visitor
The default resolver put some scope in place but mostly has traversal
functions similar to the default ast visitor, making it inherit from the
default visitor allows us to avoid code duplication.

gcc/rust/ChangeLog:

	* resolve/rust-default-resolver.cc (DefaultResolver::visit): Remove
	duplicated functions.
	* resolve/rust-default-resolver.h (class DefaultResolver): Make the
	default resolver inherit from the default visitor.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-30 12:36:49 +01:00
Owen Avery
bdbc24c36c gccrs: Allow enabling lang_items and no_core features
gcc/rust/ChangeLog:

	* checks/errors/rust-feature.cc
	(Feature::name_hash_map):
	Add entries for Name::LANG_ITEMS and Name::NO_CORE.
	* checks/errors/rust-feature.h
	(Feature::Name::LANG_ITEMS): New.
	(Feature::Name::NO_CORE): New.

gcc/testsuite/ChangeLog:

	* rust/compile/sized-stub.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-01-30 12:36:49 +01:00