]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
4 months agoopenmp: Add OpenMP _BitInt support [PR113409]
Jakub Jelinek [Wed, 17 Jan 2024 09:47:31 +0000 (10:47 +0100)] 
openmp: Add OpenMP _BitInt support [PR113409]

The following patch adds support for _BitInt iterators of OpenMP canonical
loops (with the preexisting limitation that when not using compile time
static scheduling the iterators in the library are at most unsigned long long
or signed long, so one can't in the runtime/dynamic/guided etc. cases iterate
more than what those types can represent, like is the case of e.g. __int128
iterators too) and the testcase also covers linear/reduction clauses for them.

2024-01-17  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/113409
* omp-general.cc (omp_adjust_for_condition): Handle BITINT_TYPE like
INTEGER_TYPE.
(omp_extract_for_data): Use build_bitint_type rather than
build_nonstandard_integer_type if either iter_type or loop->v type
is BITINT_TYPE.
* omp-expand.cc (expand_omp_for_generic,
expand_omp_taskloop_for_outer, expand_omp_taskloop_for_inner): Handle
BITINT_TYPE like INTEGER_TYPE.

* testsuite/libgomp.c/bitint-1.c: New test.

4 months agoSanitizer/MIPS: Use $t9 for preemptible function call
YunQiang Su [Wed, 17 Jan 2024 07:11:33 +0000 (15:11 +0800)] 
Sanitizer/MIPS: Use $t9 for preemptible function call

Currently, almost all of the shared libraries of MIPS, rely on $t9
to get the address of current function, instead of PCREL instructions,
even on MIPSr6. So we have to set $t9 properly.

To get the address of preemptible function, we need the help of GOT.
MIPS/O32 has .cpload, which can help to generate 3 instructions to get GOT.
For __mips64, we can get GOT by:

lui $t8, %hi(%neg(%gp_rel(SANITIZER_STRINGIFY(TRAMPOLINE(func)))))
daddu $t8, $t8, $t9
daddiu $t8, $t8, %hi(%neg(%gp_rel(SANITIZER_STRINGIFY(TRAMPOLINE(func)))))

And then get the address of __interceptor_func, and jump to it

ld $t9, %got_disp(_interceptor" SANITIZER_STRINGIFY(func) ")($t8)
jr $t9

Upstream-Commit: 0a64367a72f1634321f5051221f05f2f364bd882

libsanitizer

* interception/interception.h (substitution_##func_name):
Use macro C_ASM_TAIL_CALL.
* sanitizer_common/sanitizer_asm.h: Define C_ASM_TAIL_CALL
for MIPS with help of t9.

4 months agoRISC-V: Fix asm checks regression due to recent middle-end change
Pan Li [Wed, 17 Jan 2024 08:56:56 +0000 (16:56 +0800)] 
RISC-V: Fix asm checks regression due to recent middle-end change

The recent middle-end change result in some asm check failures.
This patch would like to fix the asm check by adjust the times.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/vls/shift-1.c: Fix asm check
count.
* gcc.target/riscv/rvv/autovec/vls/shift-2.c: Ditto.
* gcc.target/riscv/rvv/autovec/vls/shift-3.c: Ditto.

Signed-off-by: Pan Li <pan2.li@intel.com>
4 months agotree-optimization/113371 - avoid prologue peeling for peeled early exits
Richard Biener [Tue, 16 Jan 2024 12:09:27 +0000 (13:09 +0100)] 
tree-optimization/113371 - avoid prologue peeling for peeled early exits

The following avoids prologue peeling when doing early exit
vectorization with the IV exit before the early exit.  That's because
we it invalidates the invariant that the effective latch of the loop
is empty causing wrong continuation to the main loop.  In particular
this is prone to break virtual SSA form.

PR tree-optimization/113371
* tree-vect-data-refs.cc (vect_enhance_data_refs_alignment):
Do not peel when LOOP_VINFO_EARLY_BREAKS_VECT_PEELED.
* tree-vect-loop-manip.cc (vect_do_peeling): Assert we do
not perform prologue peeling when LOOP_VINFO_EARLY_BREAKS_VECT_PEELED.

* gcc.dg/vect/pr113371.c: New testcase.

4 months agosched-deps.cc (find_modifiable_mems): Avoid exponential behavior [PR96388]
Maxim Kuvyrkov [Sun, 19 Nov 2023 08:43:05 +0000 (08:43 +0000)] 
sched-deps.cc (find_modifiable_mems): Avoid exponential behavior [PR96388]

This patch avoids sched-deps.cc:find_inc() creating exponential number
of dependencies, which become memory and compilation time hogs.
Consider example (simplified from PR96388) ...
===
sp=sp-4 // sp_insnA
mem_insnA1[sp+A1]
...
mem_insnAN[sp+AN]
sp=sp-4 // sp_insnB
mem_insnB1[sp+B1]
...
mem_insnBM[sp+BM]
===

[For simplicity, let's assume find_inc(backwards==true)].
In this example find_modifiable_mems() will arrange for mem_insnA*
to be able to pass sp_insnA, and, while doing this, will create
dependencies between all mem_insnA*s and sp_insnB -- because sp_insnB
is a consumer of sp_insnA.  After this sp_insnB will have N new
backward dependencies.
Then find_modifiable_mems() gets to mem_insnB*s and starts to create
N new dependencies for _every_ mem_insnB*.  This gets us N*M new
dependencies.

In PR96833's testcase N and M are 10k-15k, which causes RAM usage of
30GB and compilation time of 30 minutes, with sched2 accounting for
95% of both metrics.  After this patch the RAM usage is down to 1GB
and compilation time is down to 3-4 minutes, with sched2 no longer
standing out on -ftime-report or memory usage.

gcc/ChangeLog:

PR rtl-optimization/96388
PR rtl-optimization/111554
* sched-deps.cc (find_inc): Avoid exponential behavior.

4 months agoMove docs for -Wuse-after-free and -Wuseless-cast [PR111693]
Sandra Loosemore [Wed, 17 Jan 2024 04:41:52 +0000 (04:41 +0000)] 
Move docs for -Wuse-after-free and -Wuseless-cast [PR111693]

These options were categorized as C++ options, but they apply to all
C-family languages.

gcc/ChangeLog
PR c/111693
* doc/invoke.texi (Option Summary): Move -Wuseless-cast
from C++ Language Options to Warning Options.  Add entry for
-Wuse-after-free.
(C++ Dialect Options): Move -Wuse-after-free and -Wuseless-cast
from here....
(Warning Options): ...to here.  Minor copy-editing to fix typo
and grammar.

4 months agoMIPS: avoid $gp store if global_pointer is not $gp
YunQiang Su [Mon, 15 Jan 2024 01:28:51 +0000 (09:28 +0800)] 
MIPS: avoid $gp store if global_pointer is not $gp

$GP is used for expanding GOT load, but in the afterward passes,
a temporary register is tried to replace $gp.

If sucess, we have no need to store and reload $gp. The example
of failure is that the function calls a preemtive function.

We shouldn't use $GP for any other purpose in the code we generate.
If a user's inline asm code clobbers $GP, it's their duty to save
and restore $GP.

gcc
* config/mips/mips.cc (mips_compute_frame_info): If another
register is used as global_pointer, mark $GP live false.

gcc/testsuite
* gcc.target/mips/mips.exp (mips_option_groups):
Add -mxgot/-mno-xgot options.
* gcc.target/mips/xgot-n32-avoid-gp.c: New test.
* gcc.target/mips/xgot-n32-need-gp.c: New test.

4 months agoTidy documentation for BPF builtins [PR112973]
Sandra Loosemore [Wed, 17 Jan 2024 00:24:36 +0000 (00:24 +0000)] 
Tidy documentation for BPF builtins [PR112973]

gcc/Changelog
PR target/112973
* doc/extend.texi (BPF Built-in Functions): Wrap long lines and
give the section a light copy-editing pass.

4 months agolibstdc++: Implement P2540R1 change to views::cartesian_product()
Patrick Palka [Wed, 17 Jan 2024 02:20:12 +0000 (21:20 -0500)] 
libstdc++: Implement P2540R1 change to views::cartesian_product()

This paper changes the identity element of views::cartesian_product to a
singleton range instead of an empty range.  It was approved alongside
the main cartesian_product paper P2374R4, but unfortunately was overlooked
when implementing the main paper.

libstdc++-v3/ChangeLog:

* include/std/ranges (views::_CartesianProduct::operator()):
Adjust identity case as per P2540R1.
* testsuite/std/ranges/cartesian_product/1.cc (test01):
Adjust expected result of the identity case.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
4 months agoDaily bump.
GCC Administrator [Wed, 17 Jan 2024 00:21:29 +0000 (00:21 +0000)] 
Daily bump.

4 months agoc++: Support thread_local statics in header modules [PR113292]
Nathaniel Shead [Thu, 11 Jan 2024 05:49:39 +0000 (16:49 +1100)] 
c++: Support thread_local statics in header modules [PR113292]

Currently, thread_locals in header modules cause ICEs. This patch makes
the required changes for them to work successfully.

This requires additionally writing the DECL_TLS_MODEL for thread-local
variables to the module interface, and the TLS wrapper function needs to
have its DECL_BEFRIENDING_CLASSES written too as this is used to
retrieve what VAR_DECL it's a wrapper for when emitting a definition at
end of TU processing.

PR c++/113292

gcc/cp/ChangeLog:
* decl2.cc (get_tls_wrapper_fn): Set DECL_CONTEXT.
(c_parse_final_cleanups): Suppress warning for no definition of
TLS wrapper functions in header modules.
* module.cc (trees_out::lang_decl_vals): Write wrapped variable
for TLS wrapper functions.
(trees_in::lang_decl_vals): Read it.
(trees_out::decl_value): Write TLS model for thread-local vars.
(trees_in::decl_value): Read it for new decls. Remember to emit
definitions of TLS wrapper functions later.

gcc/testsuite/ChangeLog:

* g++.dg/modules/pr113292_a.H: New test.
* g++.dg/modules/pr113292_b.C: New test.
* g++.dg/modules/pr113292_c.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
4 months agoc++: Fix ENABLE_SCOPE_CHECKING printing
Nathaniel Shead [Tue, 16 Jan 2024 09:56:46 +0000 (20:56 +1100)] 
c++: Fix ENABLE_SCOPE_CHECKING printing

The lists of scope kinds used by ENABLE_SCOPE_CHECKING don't seem to
have been updated in a long while, causing ICEs and confusing output.
This patch brings the list into line.

Additionally, the comment on 'explicit_spec_p' says that the flag is
only valid if kind is 'sk_template_parms', so we rewrite the condition
to be more obviously correct here.

gcc/cp/ChangeLog:

* name-lookup.h (enum scope_kind): Add 'sk_count'.
* name-lookup.cc (cp_binding_level_descriptor): Add missing
scope kinds. Add assertion that the list is up to date. Fix
handling of explicit_spec_p.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
4 months agoc++: fix xobj diagnostic messages
Marek Polacek [Tue, 16 Jan 2024 21:17:19 +0000 (16:17 -0500)] 
c++: fix xobj diagnostic messages

Diagnostics should start with a lower-case letter.

gcc/cp/ChangeLog:

* decl.cc (grokdeclarator) <case cdk_function>: Tweak diagnostic
messages.

4 months agoc++: fix ICE with xobj in destructor [PR113340]
Marek Polacek [Tue, 16 Jan 2024 20:49:46 +0000 (15:49 -0500)] 
c++: fix ICE with xobj in destructor [PR113340]

Here we crash in maybe_retrofit_in_chrg on an invalid dtor
with explicit this.  Such member functions do not get converted
to METHOD_TYPE.  If a dtor gets parameters, we reset arg_types
to void_list_node in grokdeclarator.  This results in m_r_in_c
receiving:
  void <T8d> (void)
and crashing on
  parms = DECL_CHAIN (DECL_ARGUMENTS (fn));

This patch avoids the ICE by resetting is_xobj_member_function after
emitting the error.  Then m_r_in_c gets
  void S::<T40b> (struct S *)
which does not cause a crash.

PR c++/113340

gcc/cp/ChangeLog:

* decl.cc (grokdeclarator) <case cdk_function>: Clear
is_xobj_member_function in case of an error.

gcc/testsuite/ChangeLog:

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

4 months agoAdd hppa*-*-hpux* to targets which do not support split DWARF
John David Anglin [Tue, 16 Jan 2024 21:13:18 +0000 (21:13 +0000)] 
Add hppa*-*-hpux* to targets which do not support split DWARF

2024-01-16  John David Anglin  <danglin@gcc.gnu.org>

gcc/testsuite/ChangeLog:

* gcc.dg/pr111409.c: Add hppa*-*-hpux* to targets which do
not support split DWARF.

4 months agoc++: reject packs on xobj params [PR113307]
waffl3x [Fri, 12 Jan 2024 07:40:19 +0000 (07:40 +0000)] 
c++: reject packs on xobj params [PR113307]

Reject and diagnose xobj parameters declared as parameter packs.

PR c++/113307

gcc/cp/ChangeLog:

* parser.cc (cp_parser_parameter_declaration): Reject packs
on xobj params.

gcc/testsuite/ChangeLog:

* g++.dg/cpp23/explicit-obj-diagnostics3.C: Add test for
rejection of packs.

Signed-off-by: Waffl3x <waffl3x@protonmail.com>
4 months agoAdd .data.rel.ro.local to read only sections in gcc.dg/array-quals-1.c
John David Anglin [Tue, 16 Jan 2024 21:03:57 +0000 (21:03 +0000)] 
Add .data.rel.ro.local to read only sections in gcc.dg/array-quals-1.c

2024-01-16  John David Anglin  <danglin@gcc.gnu.org>

gcc/testsuite/ChangeLog:

* gcc.dg/array-quals-1.c: Add .data.rel.ro.local to read only
sections.

4 months agoRemove xfail for hppa*-*-hpux* from stdatomic-flag.c and stdatomic-flag-2.c
John David Anglin [Tue, 16 Jan 2024 20:51:26 +0000 (20:51 +0000)] 
Remove xfail for hppa*-*-hpux* from stdatomic-flag.c and stdatomic-flag-2.c

Tests now pass on hppa64-hp-hpux11.11.

2024-01-16  John David Anglin  <danglin@gcc.gnu.org>

gcc/testsuite/ChangeLog:

* gcc.dg/atomic/stdatomic-flag.c: Remove xfail.
* gcc.dg/atomic/stdatomic-flag-2.c: Likewise.

4 months agoxfail scan-tree-dump-not throw in g++.dg/pr99966.C on hppa*64*-*-*
John David Anglin [Tue, 16 Jan 2024 20:38:50 +0000 (20:38 +0000)] 
xfail scan-tree-dump-not throw in g++.dg/pr99966.C on hppa*64*-*-*

2024-01-16  John David Anglin  <danglin@gcc.gnu.org>

gcc/testsuite/ChangeLog:

PR tree-optimization/110794
* g++.dg/pr99966.C: xfail scan-tree-dump-not throw on hppa*64*-*-*.

4 months agoRequire target lto in several tests
John David Anglin [Tue, 16 Jan 2024 20:18:29 +0000 (20:18 +0000)] 
Require target lto in several tests

2024-01-16  John David Anglin  <danglin@gcc.gnu.org>

gcc/testsuite/ChangeLog:

* gcc.dg/c23-tag-alias-2.c: Require target lto.
* gcc.dg/c23-tag-alias-3.c: Likewise.
* gcc.dg/gnu23-tag-alias-3.c: Likewise.
* gcc.dg/scantest-lto.c: Likewise.

4 months agoSkip various cmp-mem-const tests on lp64 hppa*-*-*
John David Anglin [Tue, 16 Jan 2024 20:04:11 +0000 (20:04 +0000)] 
Skip various cmp-mem-const tests on lp64 hppa*-*-*

Prior optimization already reduced the constant.

2024-01-16  John David Anglin  <danglin@gcc.gnu.org>

gcc/testsuite/ChangeLog:

* gcc.dg/cmp-mem-const-3.c: Skip on lp64 hppa*-*-*.
* gcc.dg/cmp-mem-const-4.c: Likewise.
* gcc.dg/cmp-mem-const-5.c: Likewise.
* gcc.dg/cmp-mem-const-6.c: Likewise.

4 months agoxfail all scan-tree-dump-times checks on hppa*64*-*-* in sra-17.c and sra-18.c
John David Anglin [Tue, 16 Jan 2024 19:32:56 +0000 (19:32 +0000)] 
xfail all scan-tree-dump-times checks on hppa*64*-*-* in sra-17.c and sra-18.c

2024-01-64  John David Anglin  <danglin@gcc.gnu.org>

gcc/testsuite/ChangeLog:

PR tree-optimization/91624
* gcc.dg/tree-ssa/sra-17.c: xfail all scan-tree-dump-times
checks on hppa*64*-*-*.
* gcc.dg/tree-ssa/sra-18.c: Likewise.

4 months agoAArch64: Add -mcpu=cobalt-100
Wilco Dijkstra [Tue, 16 Jan 2024 18:14:12 +0000 (18:14 +0000)] 
AArch64: Add -mcpu=cobalt-100

Add support for -mcpu=cobalt-100 (Neoverse N2 with a different implementer ID).

gcc/ChangeLog:
* config/aarch64/aarch64-cores.def (AARCH64_CORE): Add 'cobalt-100' CPU.
* config/aarch64/aarch64-tune.md: Regenerated.
* doc/invoke.texi (-mcpu): Add cobalt-100 core.

4 months agogccrs: Adjust item kind enums for TupleStructItems and TuplePatternItems
Owen Avery [Fri, 6 Oct 2023 13:15:17 +0000 (09:15 -0400)] 
gccrs: Adjust item kind enums for TupleStructItems and TuplePatternItems

gcc/rust/ChangeLog:

* hir/tree/rust-hir-pattern.h
(TupleStructItems::ItemType::RANGE): Rename to...
(TupleStructItems::ItemType::RANGED): ...here.
(TupleStructItems::ItemType::NO_RANGE): Rename to...
(TupleStructItems::ItemType::MULTIPLE): ...here.

(TuplePatternItems::TuplePatternItemType): Rename to...
(TuplePatternItems::ItemType): ...here.

: Handle renames.

* backend/rust-compile-pattern.cc: Likewise.
* typecheck/rust-hir-type-check-pattern.cc: Likewise.
* checks/errors/borrowck/rust-bir-builder-pattern.h: Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Add a new test for float disambiguation
Pierre-Emmanuel Patry [Tue, 31 Oct 2023 14:43:51 +0000 (15:43 +0100)] 
gccrs: Add a new test for float disambiguation

This new regression test highlight the behavior fixed for float
disambiguation with empty floating point.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Fix float lexing and tuple index disambiguation
Pierre-Emmanuel Patry [Tue, 31 Oct 2023 14:23:45 +0000 (15:23 +0100)] 
gccrs: Fix float lexing and tuple index disambiguation

When a float has a floating point but no value after it, a zero was added
this lead to errors when trying to disambiguate a float into a tuple
index.

gcc/rust/ChangeLog:

* lex/rust-lex.cc (Lexer::parse_decimal_int_or_float): Remove
additional zero after empty floating point.
* parse/rust-parse-impl.h (Parser::left_denotation): Handle float with
empty floating point.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: v0-mangle closures
Raiki Tamura [Thu, 12 Oct 2023 08:24:46 +0000 (17:24 +0900)] 
gccrs: v0-mangle closures

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::generate_closure_function):
Fix reference to node.
* backend/rust-mangle.cc (struct V0Path): Modified to accept closures.
(v0_crate_path): Modified to accept closures.
(v0_closure): New function to mangle closures.
(v0_path): Modified to accept closures
* util/rust-mapping-common.h (UNKNOWN_NODEID): Change to UINT32_MAX.
(UNKNOWN_HIRID): Change to UINT32_MAX.

gcc/testsuite/ChangeLog:

* rust/compile/v0-mangle2.rs: New test.

Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
4 months agogccrs: Move default visitor templates to header
Pierre-Emmanuel Patry [Tue, 7 Nov 2023 12:02:20 +0000 (13:02 +0100)] 
gccrs: Move default visitor templates to header

Move default ast visitor template implementation to headers in order to
match the codebase and avoid link errors.

gcc/rust/ChangeLog:

* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Move from here...
* ast/rust-ast-visitor.h: ... to here.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Move templated functions to header file
Pierre-Emmanuel Patry [Tue, 7 Nov 2023 10:37:39 +0000 (11:37 +0100)] 
gccrs: Move templated functions to header file

Templated functions shall remain in header files to stay in line with the
rest of the codebase.

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): Move to header
file.
(TokenCollector::visit_items_joined_by_separator): Likewise.
(TokenCollector::visit_as_line): Likewise.
(TokenCollector::visit_items_as_lines): Likewise.
(TokenCollector::visit_items_as_block): Likewise.
* ast/rust-ast-collector.h: Add implementation.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Rework function special parameters
Pierre-Emmanuel Patry [Sun, 12 Nov 2023 20:44:07 +0000 (21:44 +0100)] 
gccrs: Rework function special parameters

Make self param and variadic param Param, introduce Param class and make
function parameters param too.
Self can now be represented as a standard parameter and is thus no longer
required as a separate function attribute.
Prevent self pointers and allow self in standard functions during parsing
so they could be rejected at a later stage.

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): Add visitor for
VariadicParam and remove Self parameter visitor from Function visit.
* expand/rust-cfg-strip.cc (CfgStrip::maybe_strip_self_param): Remove
function.
(CfgStrip::maybe_strip_trait_method_decl): Remove self parameter visit.
(CfgStrip::maybe_strip_function_params): Handle new function
parameters.
(CfgStrip::visit): Handle VariadicParam, SelfParam and FunctionParam.
* expand/rust-expand-visitor.cc (ExpandVisitor::expand_self_param):
Remove function.
(ExpandVisitor::expand_trait_method_decl): Do not visit self parameter.
(ExpandVisitor::visit): Add visit for VariadicParam, FunctionParam and
SelfParam.
(ExpandVisitor::expand_function_params): Visit parameters instead.
* expand/rust-expand-visitor.h: Update function prototypes.
* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Update visit
with new parameters.
(ResolveTraitItems::visit): Likewise.
* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
Update visit functions with the new visitor functions for VariadicParam
SelfParam and FunctionParam.
* resolve/rust-early-name-resolver.h: Update function prototypes.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Update visitor
according to the new function parameter structures.
* ast/rust-ast-visitor.h: Update prototypes and add visitor virtual
functions for SelfParam, FunctionParam and VariadicParam.
* ast/rust-ast.cc (Function::Function): Move constructor in
implementation instead of header.
(Function::operator=): Likewise.
(Function::as_string): Update function with pointer dereference.
(VariadicParam::as_string): Likewise.
(TraitFunctionDecl::as_string): Likewise.
(TraitMethodDecl::as_string): Likewise.
(FunctionParam::accept_vis): Add function for visitor.
(SelfParam::accept_vis): Likewise.
(VariadicParam::accept_vis): Likewise.
(TraitItemFunc::TraitItemFunc): Move constructor to implementation
file.
(TraitItemFunc::operator=): Likewise.
(TraitItemMethod::TraitItemMethod): Likewise.
(TraitItemMethod::operator=): Likewise.
* ast/rust-item.h (class Function): Remove self optional member.
(class TraitMethodDecl): Likewise.
(class TraitFunctionDecl): Likewise.
(class Param): Add abstract parameter class.
(class SelfParam): Inherit from Param and remove parameter common
members.
(class FunctionParam): Likewise.
(class VariadicParam): Likewise.
(struct Visibility): Move structure declaration.
(class VisItem):  Likewise.
* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add
a self parameter check during AST validation.
* checks/errors/rust-ast-validation.h: Add function prototype.
* expand/rust-derive-clone.cc (DeriveClone::clone_fn): Update function
constructor.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_self): Rework
function for the new parameters.
(ASTLoweringBase::visit): Add visit functions for VariadicParam,
FunctionParam and SelfParam.
* hir/rust-ast-lower-base.h: Update function prototypes.
* parse/rust-parse-impl.h (Parser::parse_function): Update function
according to new function representation.
(Parser::parse_function_param): Return vector of abstract param instead
of FunctionParam.
(Parser::parse_method): Update according to new representation.
(Parser::parse_trait_item): Likewise.
(Parser::parse_self_param): Error out with
self pointers and prevent the lexer from eating regular function
parameters. Update return type.
* parse/rust-parse.h: Update function return types.
* ast/rust-ast-collector.h: Add VariadicParam visit prototype.
* ast/rust-ast.h (struct Visibility): Move struct declaration.
(class VisItem): Likewise.
* ast/rust-expr.h: Update included files.
* checks/errors/rust-feature-gate.h: Add visitor functions for
SelfParam, FunctionParam and VariadicParam.
* expand/rust-cfg-strip.h: Update function prototypes.
* expand/rust-derive.h: Likewise.
* hir/rust-ast-lower-implitem.h: Handle special arguments.
* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Likewise.
* metadata/rust-export-metadata.cc (ExportContext::emit_function):
Likewise.
* resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Add visitor
functions.
* resolve/rust-ast-resolve-base.h: Update prototypes.
* resolve/rust-ast-resolve-stmt.h: Handle new parameter kind.
* resolve/rust-default-resolver.cc (DefaultResolver::visit): Likewise.
* resolve/rust-default-resolver.h: Update prototype.
* util/rust-attributes.cc (AttributeChecker::visit): Add visitor
functions for SelfParam and VariadicParam.
* util/rust-attributes.h: Add visit prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add new test for invalid variadics
Pierre-Emmanuel Patry [Thu, 9 Nov 2023 22:29:05 +0000 (23:29 +0100)] 
gccrs: Add new test for invalid variadics

Highlight invalid variadic filtering through the ast validation checker.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add multiple check on variadics position
Pierre-Emmanuel Patry [Thu, 9 Nov 2023 21:51:31 +0000 (22:51 +0100)] 
gccrs: Add multiple check on variadics position

Variadics are forbidden alone as well as non final position, this should
be checked during ast validation.

gcc/rust/ChangeLog:

* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add
check for additional named argument as well as variadic argument's
position.
* checks/errors/rust-ast-validation.h: Add visit function prototype for
external functions.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add trait context to ContextualASTVisitor
Pierre-Emmanuel Patry [Thu, 9 Nov 2023 18:45:08 +0000 (19:45 +0100)] 
gccrs: Add trait context to ContextualASTVisitor

Some construct are forbidden in trait context (eg. pub, async...) and
we'll need to reject those. To do so we need to identify a trait context.

gcc/rust/ChangeLog:

* ast/rust-ast-visitor.cc (ContextualASTVisitor::visit): Push the new
trait context when visiting a trait.
* ast/rust-ast-visitor.h: Add visit function prototype and TRAIT
context.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add regression test for invalid label name
Pierre-Emmanuel Patry [Thu, 9 Nov 2023 14:45:04 +0000 (15:45 +0100)] 
gccrs: Add regression test for invalid label name

An error message should be emitted when the rust code contains invalid
label name. Add a new test for this behavior.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Change error location for LoopLabel
Pierre-Emmanuel Patry [Thu, 9 Nov 2023 14:30:32 +0000 (15:30 +0100)] 
gccrs: Change error location for LoopLabel

Loop label error reporting during ast validation was done at loop label
level. It lead to some innacurate error reporting in break loop labels
due to the way the label is built.

gcc/rust/ChangeLog:

* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Change
reported error location to the lifetime location.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add validation pass for label name
Pierre-Emmanuel Patry [Wed, 8 Nov 2023 15:50:50 +0000 (16:50 +0100)] 
gccrs: Add validation pass for label name

Prevent from using reserved keyword in label name.

gcc/rust/ChangeLog:

* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Check if there is
a label before visit.
* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Emit an
error when a label has a forbidden name.
* checks/errors/rust-ast-validation.h: Add function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Use a loop label in break expression
Pierre-Emmanuel Patry [Wed, 8 Nov 2023 15:34:19 +0000 (16:34 +0100)] 
gccrs: Use a loop label in break expression

Break expression were using a raw lifetime value instead of a loop label
this behavior would have lead to some errors in ast validation.

gcc/rust/ChangeLog:

* ast/rust-expr.h (class BreakExpr): Change Lifetime to LoopLabel.
* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Lower lifetime
inside the label instead.
* resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Resolve the
inner lifetime.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Use keyword const values instead of raw values
Pierre-Emmanuel Patry [Wed, 8 Nov 2023 14:22:33 +0000 (15:22 +0100)] 
gccrs: Use keyword const values instead of raw values

Change the keyword values from a raw string value to their matching const
value in utils.

gcc/rust/ChangeLog:

* lex/rust-lex.cc (Lexer::parse_raw_identifier): Use const value.
* parse/rust-parse-impl.h (Parser::parse_simple_path_segment):
Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Change keyword set to a map
Pierre-Emmanuel Patry [Wed, 8 Nov 2023 13:54:51 +0000 (14:54 +0100)] 
gccrs: Change keyword set to a map

Some part of the code requires the token id behind a given keyword, a map
keep the "set" aspect whilst providing this additional feature.

gcc/rust/ChangeLog:

* lex/rust-lex.cc (RS_TOKEN): Remove local map.
(RS_TOKEN_KEYWORD): Likewise.
(Lexer::classify_keyword): Change call to utils.
* util/rust-keyword-values.cc (get_keywords): Add init function.
(RS_TOKEN_KEYWORD): Call to X macro.
* util/rust-keyword-values.h: Change from set to a map.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Replace local keyword set with the utils
Pierre-Emmanuel Patry [Wed, 8 Nov 2023 09:57:48 +0000 (10:57 +0100)] 
gccrs: Replace local keyword set with the utils

We don't require that local set anymore.

gcc/rust/ChangeLog:

* checks/errors/rust-ast-validation.cc (RS_TOKEN): Remove locale set.
(RS_TOKEN_KEYWORD): Likewise.
(ASTValidation::visit): Change keyword set call to the one from utils.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add new keyword utility class
Pierre-Emmanuel Patry [Wed, 8 Nov 2023 09:50:00 +0000 (10:50 +0100)] 
gccrs: Add new keyword utility class

Much like attributes values, keywords are known beforehand and never
change. Instead of relying on handcrafted string we could centralize
everything in one place. We may require to check whether a word is a
keyword, which can now be done easily thanks to the keyword set.

gcc/rust/ChangeLog:

* Make-lang.in: Add rust-keyword-values.cc to the list.
* util/rust-keyword-values.cc: New file.
* util/rust-keyword-values.h: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add licence text and change header guard name
Pierre-Emmanuel Patry [Wed, 8 Nov 2023 09:46:22 +0000 (10:46 +0100)] 
gccrs: Add licence text and change header guard name

This file was missing a licence text and it's header guard was not
matching the file name.

gcc/rust/ChangeLog:

* util/rust-attribute-values.h (RUST_ATTRIBUTES_VALUE_H): Remove old
header guard.
(RUST_ATTRIBUTE_VALUES_H): Add new one.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add regression test for lifetime name validation
Pierre-Emmanuel Patry [Tue, 7 Nov 2023 18:13:57 +0000 (19:13 +0100)] 
gccrs: Add regression test for lifetime name validation

Lifetime name are restricted and cannot be keyword, this commit add a
test failing the ast validation pass due to some keyword name.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add lifetime name validation pass
Pierre-Emmanuel Patry [Tue, 7 Nov 2023 17:32:58 +0000 (18:32 +0100)] 
gccrs: Add lifetime name validation pass

Add lifetime name check in ast validation visitor.

gcc/rust/ChangeLog:

* checks/errors/rust-ast-validation.cc (RS_TOKEN): Add keyword set.
(RS_TOKEN_KEYWORD): Likewise.
(ASTValidation::visit): Add validation on lifetime visit.
* checks/errors/rust-ast-validation.h: Add function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Replace AST::Method with existing AST::Function
Owen Avery [Sat, 28 Oct 2023 05:04:19 +0000 (01:04 -0400)] 
gccrs: Replace AST::Method with existing AST::Function

gcc/rust/ChangeLog:

* ast/rust-item.h
(class Method): Remove.
(Function::self_param): New.
(Function::has_self_param): New.
(Function::Function): Initialize self_param.
(Function::operator=): Likewise.
(Function::get_self_param): New.
* ast/rust-ast.cc
(Method::as_string): Remove.
(Method::accept_vis): Remove.

* ast/rust-ast-collector.cc
(TokenCollector::visit):
Remove AST::Method visitor, handle self_param in AST::Function visitor.
* ast/rust-ast-collector.h
(TokenCollector::visit): Remove AST::Method visitor.
* ast/rust-ast-full-decls.h (class Method): Remove.

* ast/rust-ast-visitor.h
(ASTVisitor::visit): Remove AST::Method visitor.
(DefaultASTVisitor::visit): Likewise.
* ast/rust-ast-visitor.cc
(DefaultASTVisitor::visit):
Remove AST::Method visitor, handle self_param in AST::Function visitor.

* checks/errors/rust-feature-gate.cc
(FeatureGate::visit): Remove AST::Method visitor.
* checks/errors/rust-feature-gate.h
(FeatureGate::visit): Likewise..

* expand/rust-cfg-strip.cc
(CfgStrip::visit):
Remove AST::Method visitor, handle self_param in AST::Function visitor.
* expand/rust-cfg-strip.h
(CfgStrip::visit): Remove AST::Method visitor.

* expand/rust-derive-clone.cc
(DeriveClone::clone_fn): Return AST::Function instead of AST::Method.
* expand/rust-derive.h (DeriveVisitor::visit): Remove AST::Method visitor.

* expand/rust-expand-visitor.cc
(ExpandVisitor::visit):
Remove AST::Method visitor, handle self_param in AST::Function visitor.
* expand/rust-expand-visitor.h:
(ExpandVisitor::visit): Remove AST::Method visitor.

* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise.
* hir/rust-ast-lower-base.h (ASTLoweringBase::visit): Likewise.

* hir/rust-ast-lower-implitem.h
(ASTLowerImplItem::visit):
Remove AST::Method visitor, handle self_param in AST::Function visitor.

* parse/rust-parse-impl.h: Include optional.h.
(Parser::parse_function): Adjust AST::Function construction.
(Parser::parse_inherent_impl_function_or_method):
Construct AST::Function instead of AST::Method,
adjust AST::Function construction.
(Parser::parse_trait_impl_function_or_method): Likewise.
(Parser::parse_method):
Return std::unique_ptr<AST::Function> instead of AST::Method.

* parse/rust-parse.h
(Parser::parse_method): Likewise.

* resolve/rust-ast-resolve-base.cc
(ResolverBase::visit): Remove AST::Method visitor.
* resolve/rust-ast-resolve-base.h
(ResolverBase::visit): Likewise.

* resolve/rust-ast-resolve-implitem.h
(ResolveToplevelImplItem::visit): Likewise.

* resolve/rust-ast-resolve-item.cc
(ResolveItem::visit): Remove AST::Method visitor,
handle self_param in AST::Function visitor.
* resolve/rust-ast-resolve-item.h
(ResolveItem::visit): Remove AST::Method visitor.

* resolve/rust-default-resolver.cc
(DefaultResolver::visit): Remove AST::Method visitor.
* resolve/rust-default-resolver.h
(DefaultResolver::visit): Likewise.

* resolve/rust-early-name-resolver.cc
(EarlyNameResolver::visit): Remove AST::Method visitor,
handle self_param in AST::Function visitor.
* resolve/rust-early-name-resolver.h
(EarlyNameResolver::visit): Remove AST::Method visitor.

* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Likewise.
* resolve/rust-toplevel-name-resolver-2.0.h
(TopLevel::visit): Likewise.

* util/rust-attributes.cc
(AttributeChecker::visit): Likewise.
* util/rust-attributes.h
(AttributeChecker::visit): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Add named variadic argument test
Pierre-Emmanuel Patry [Mon, 6 Nov 2023 10:37:50 +0000 (11:37 +0100)] 
gccrs: Add named variadic argument test

Variadic arguments may have a name or a pattern. This commit provides two
new tests in order to ensure their correct behavior.

gcc/testsuite/ChangeLog:

* rust/compile/pattern_variadic.rs: New test.
* rust/execute/torture/named_variadic.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add a new regression test for named variadics
Pierre-Emmanuel Patry [Mon, 23 Oct 2023 12:02:59 +0000 (14:02 +0200)] 
gccrs: Add a new regression test for named variadics

This test ensure that extern C named variadics are parsed correctly.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Parse named variadic parameters
Pierre-Emmanuel Patry [Mon, 23 Oct 2023 11:41:35 +0000 (13:41 +0200)] 
gccrs: Parse named variadic parameters

Add ability to parse named variadic parameters in extern c functions.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_named_function_param): Add
new parsing ability.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add a new regression test
Pierre-Emmanuel Patry [Mon, 23 Oct 2023 11:22:11 +0000 (13:22 +0200)] 
gccrs: Add a new regression test

This new test highlight the behavior of the new parser and it's ability
to parse variadic rust functions.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Fix multiple issues with variadic representation
Pierre-Emmanuel Patry [Thu, 19 Oct 2023 13:23:26 +0000 (15:23 +0200)] 
gccrs: Fix multiple issues with variadic representation

The new variadic representation has introduced multiple issues and ICE
into the codebase. Some early passes in the compiler depend on the
parameters all having a type and being an actual parameter.

gcc/rust/ChangeLog:

* ast/rust-ast.cc (ExternalFunctionItem::as_string): Adapt as_string
function to the new ast representation.
(NamedFunctionParam::as_string): Likewise.
* ast/rust-item.h: Add a function to test whether a FunctionParam has
a name pattern.
* expand/rust-cfg-strip.cc (CfgStrip::visit): Adapt cfg strip visitor
for the new variadic arguments.
* hir/rust-ast-lower-extern.h: Adapt lowering to the new variadic
function representation.
* metadata/rust-export-metadata.cc (ExportContext::emit_function):
Change call to constructor.
* parse/rust-parse-impl.h (Parser::parse_named_function_param): Change
NamedFunctionParam parsing to accomodate new variadic representation.
(Parser::parse_external_item): Change external item parsing to use the
new NamedFunctionParam variadics.
* parse/rust-parse.h: Add new parsing function prototypes.
* ast/rust-ast-collector.cc (TokenCollector::visit): Rework token
collection to take into account variadic parameters.
* ast/rust-ast-visitor.cc: Likewise.
* expand/rust-expand-visitor.cc (ExpandVisitor::visit): Change function
bound to avoid getting the type of a variadic parameter.
* resolve/rust-ast-resolve-item.cc (ResolveExternItem::visit):
Likewise.
* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Allow variadic NamedFunctionParam
Pierre-Emmanuel Patry [Wed, 18 Oct 2023 13:30:57 +0000 (15:30 +0200)] 
gccrs: Allow variadic NamedFunctionParam

This was made to align NamedFunctionParam with FunctionParam.

gcc/rust/ChangeLog:

* ast/rust-item.h (class NamedFunctionParam): Add variadic boolean and
another constructor.
* hir/rust-ast-lower-extern.h: Avoid last parameter when variadic.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add a function to check if a function is variadic
Pierre-Emmanuel Patry [Wed, 18 Oct 2023 13:04:58 +0000 (15:04 +0200)] 
gccrs: Add a function to check if a function is variadic

This function provides an easy way to check for a function's varidicity.

gcc/rust/ChangeLog:

* ast/rust-item.h: Add a getter to check if a given function is
variadic.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Parse variadic functions
Pierre-Emmanuel Patry [Wed, 18 Oct 2023 12:31:53 +0000 (14:31 +0200)] 
gccrs: Parse variadic functions

Variadic functions were not parsed because it is an unstable feature.
While it is still unstable, it is required in order to parse libcore.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_function_param): Parse
variadic functions.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Change FunctionParam to represent variadic params
Pierre-Emmanuel Patry [Wed, 18 Oct 2023 12:24:31 +0000 (14:24 +0200)] 
gccrs: Change FunctionParam to represent variadic params

Variadic were represented at the function level while retaining most
informations of a given parameter.

gcc/rust/ChangeLog:

* ast/rust-item.h (class FunctionParam): Add some informations to
function parameters in order to be able to store variadic argument as
a function parameter.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add a new test for const without body
Pierre-Emmanuel Patry [Thu, 26 Oct 2023 13:48:52 +0000 (15:48 +0200)] 
gccrs: Add a new test for const without body

This new regression test highlight the fixed behavior for 2709.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Make use of the Contextual visitor in validation
Pierre-Emmanuel Patry [Thu, 26 Oct 2023 11:30:28 +0000 (13:30 +0200)] 
gccrs: Make use of the Contextual visitor in validation

Use the new contextual ast visitor to reduce the amount of code in the
ast validation visitor.

gcc/rust/ChangeLog:

* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Adapt
the call to the new visit functions.
(ASTValidation::check): Launch the parent class visitor root function.
* checks/errors/rust-ast-validation.h (class ASTValidation): Inherit
from the contextual visitor.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add a new visitor that gathers context information
Pierre-Emmanuel Patry [Thu, 26 Oct 2023 11:26:13 +0000 (13:26 +0200)] 
gccrs: Add a new visitor that gathers context information

This visitor is intended to be used by other visitors that require
context at some point for a given item.

gcc/rust/ChangeLog:

* ast/rust-ast-visitor.cc (ContextualASTVisitor::visit): Add multiple
context saving calls.
* ast/rust-ast-visitor.h (class DefaultASTVisitor): Make visit
functions virtual.
(class ContextualASTVisitor): Add a stack like container for the
current context chain.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add a default AST visitor
Pierre-Emmanuel Patry [Wed, 25 Oct 2023 14:56:09 +0000 (16:56 +0200)] 
gccrs: Add a default AST visitor

This will allow us to derive other visitors from it and overload only a
few selected visit methods.

gcc/rust/ChangeLog:

* Make-lang.in: Add the new visitor object file.
* ast/rust-ast-visitor.h (class DefaultASTVisitor): Create the default
visitor class.
* ast/rust-ast.h: Add a new reference getter for visitor pattern.
* ast/rust-ast-visitor.cc: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add some reference getter
Pierre-Emmanuel Patry [Wed, 25 Oct 2023 14:53:59 +0000 (16:53 +0200)] 
gccrs: Add some reference getter

Visitor pattern requires a getter to children using a mutable reference.

gcc/rust/ChangeLog:

* ast/rust-ast.h: Add some missing mutable reference getters.
* ast/rust-expr.h: Likewise.
* ast/rust-item.h: Likewise.
* ast/rust-path.h: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Small fix to the ast collector visitor
Pierre-Emmanuel Patry [Wed, 25 Oct 2023 14:51:31 +0000 (16:51 +0200)] 
gccrs: Small fix to the ast collector visitor

The parameter type was used instead of the default value.

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): Check for presence
of a type and use the default value instead of the type.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Emit an error on associated const without values
Pierre-Emmanuel Patry [Tue, 24 Oct 2023 15:13:13 +0000 (17:13 +0200)] 
gccrs: Emit an error on associated const without values

Associated const with no value that are not in trait impl are prohibited.

gcc/rust/ChangeLog:

* checks/errors/rust-ast-validation.cc (ASTValidation::check): Launch
check over the whole given crate.
(ASTValidation::visit): Implement visitor for some members of the ast.
* checks/errors/rust-ast-validation.h: Update some prototype according
to implemented visitor functions. Also add a context tracker.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add call to ast validation checker
Pierre-Emmanuel Patry [Tue, 24 Oct 2023 14:46:21 +0000 (16:46 +0200)] 
gccrs: Add call to ast validation checker

Add call to ast validation check, also add appropriate step to this pass
and the feature gating.

gcc/rust/ChangeLog:

* rust-session-manager.cc (Session::compile_crate): Add call to ast
validation.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add two new steps to compile process
Pierre-Emmanuel Patry [Tue, 24 Oct 2023 14:16:34 +0000 (16:16 +0200)] 
gccrs: Add two new steps to compile process

Add the ast validation and feature gating steps to the compile pipeline.

gcc/rust/ChangeLog:

* lang.opt: Add the new compile options and update the enum values.
* rust-session-manager.h (struct CompileOptions): Add the new steps to
the enumeration.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add ast validation checker
Pierre-Emmanuel Patry [Tue, 24 Oct 2023 14:08:00 +0000 (16:08 +0200)] 
gccrs: Add ast validation checker

Add a new visitor to validate a given ast after the expansion pass.

gcc/rust/ChangeLog:

* Make-lang.in: Add the new object file the list.
* checks/errors/rust-ast-validation.cc: New file.
* checks/errors/rust-ast-validation.h: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add more checks for expr value in early visitors
Pierre-Emmanuel Patry [Tue, 24 Oct 2023 14:01:52 +0000 (16:01 +0200)] 
gccrs: Add more checks for expr value in early visitors

Early passes visitors may encounter constant item without a value, this
is expected as the pass rejecting a constant without an expression is
done later during the ast validation.

gcc/rust/ChangeLog:

* expand/rust-cfg-strip.cc (CfgStrip::visit): Add expr value check.
* expand/rust-expand-visitor.cc (ExpandVisitor::visit): Likewise.
* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Move SingleASTNode implementation out of header
Pierre-Emmanuel Patry [Thu, 2 Nov 2023 17:23:03 +0000 (18:23 +0100)] 
gccrs: Move SingleASTNode implementation out of header

Those functions implementation put additional constraints on the headers
which makes the codebase harder to work with.

gcc/rust/ChangeLog:

* ast/rust-ast.h: Move implementation from here...
* ast/rust-ast.cc (SingleASTNode::SingleASTNode): ...to here.
(SingleASTNode::operator=): ...and here...
(SingleASTNode::accept_vis): ...and here...
(SingleASTNode::is_error): ...and here...
(SingleASTNode::as_string): ...also here.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add missing override specifier
Pierre-Emmanuel Patry [Thu, 2 Nov 2023 17:10:32 +0000 (18:10 +0100)] 
gccrs: Add missing override specifier

Some function lacked the override specifier, this made the compiler emit
several warning.

gcc/rust/ChangeLog:

* ast/rust-ast.h: Add override specifier.
* ast/rust-item.h: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add regression test for float literal tuple indices
Pierre-Emmanuel Patry [Tue, 17 Oct 2023 11:40:47 +0000 (13:40 +0200)] 
gccrs: Add regression test for float literal tuple indices

Add a new regression test in order to highlight the fix for #2659.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Fix token lexed as a float literal
Pierre-Emmanuel Patry [Tue, 17 Oct 2023 11:24:54 +0000 (13:24 +0200)] 
gccrs: Fix token lexed as a float literal

The lexer cannot distinguish the difference between a float literal and a
tuple index in some cases. This means we should fix this while parsing
depending on the context.

gcc/rust/ChangeLog:

* expand/rust-macro-invoc-lexer.cc (MacroInvocLexer::split_current_token):
Add implementation for multiple token split.
* expand/rust-macro-invoc-lexer.h: Add function prototype.
* expand/rust-proc-macro-invoc-lexer.cc (ProcMacroInvocLexer::split_current_token):
Add implementation for 2+ token split for procedural macros.
* expand/rust-proc-macro-invoc-lexer.h: Add function prototype.
* lex/rust-lex.cc (Lexer::split_current_token): Add function to split a
token in multiple other tokens.
* lex/rust-lex.h: Add function prototype for split_current_token.
* parse/rust-parse-impl.h (Parser::left_denotation): Handle float tuple
index identified as a float literal.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: HIR: remove obsole double borrow member
Jakub Dupak [Thu, 2 Nov 2023 12:42:48 +0000 (13:42 +0100)] 
gccrs: HIR: remove obsole double borrow member

gcc/rust/ChangeLog:

* hir/rust-hir-dump.cc (Dump::visit): Remove obsolete member.
* hir/tree/rust-hir-expr.h (class BorrowExpr): Remove obsolete member.
* hir/tree/rust-hir.cc (BorrowExpr::as_string): Remove obsolete member.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
4 months agogccrs: HIR: fix typo
Jakub Dupak [Thu, 2 Nov 2023 12:31:17 +0000 (13:31 +0100)] 
gccrs: HIR: fix typo

gcc/rust/ChangeLog:

* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Fix typo.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
4 months agogccrs: Compile pattern match statements into conditional statements
Owen Avery [Mon, 23 Oct 2023 01:44:01 +0000 (21:44 -0400)] 
gccrs: Compile pattern match statements into conditional statements

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc
(patterns_mergeable): Remove.
(struct PatternMerge): Remove.
(sort_tuple_patterns): Remove.
(simplify_tuple_match): Remove.
(CompileExpr::visit): Modify compilation of MatchExpr.

* backend/rust-compile-pattern.cc
(CompilePatternCaseLabelExpr::visit): Replace with...
(CompilePatternCheckExpr::visit): ...this.
* backend/rust-compile-pattern.h
(class CompilePatternCaseLabelExpr): Replace with...
(class CompilePatternCheckExpr): ...this.

* backend/rust-compile-type.cc
(TyTyResolveCompile::get_implicit_enumeral_node_type):
Make enumeral type equivalent to isize.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Document proc macro token tree indices
Pierre-Emmanuel Patry [Mon, 23 Oct 2023 13:00:54 +0000 (15:00 +0200)] 
gccrs: Document proc macro token tree indices

Multiple references to procedural macro token trees were left as magic
number in the code. This commit introduces some constexpr for those along
some explanation for the selected value.

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc (get_attributes): Add documentation for
indices 3 and 4.
(get_trait_name): Add documentation for index 1.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Move proc macro builders to their own file
Pierre-Emmanuel Patry [Tue, 17 Oct 2023 14:00:30 +0000 (16:00 +0200)] 
gccrs: Move proc macro builders to their own file

The code to build the required procedural macro symbols is rather long
and could be placed in it's own file.

gcc/rust/ChangeLog:

* Make-lang.in: Add gcc/rust/backend/rust-compile-proc-macro.cc to the
list of file to compile.
* backend/rust-compile.cc (attribute_array): Move to
rust-compile-proc-macro.cc
(derive_proc_macro): Likewise.
(bang_proc_macro): Likewise.
(attribute_proc_macro): Likewise.
(proc_macro_payload): Likewise.
(proc_macro): Likewise.
(proc_macro_buffer): Likewise.
(entrypoint): Likewise.
(proc_macro_array): Likewise.
(CompileCrate::add_proc_macro_symbols): Likewise.
* backend/rust-compile-proc-macro.cc: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add array length to the proc macro buffer
Pierre-Emmanuel Patry [Thu, 5 Oct 2023 10:28:38 +0000 (12:28 +0200)] 
gccrs: Add array length to the proc macro buffer

The compiler cannot infer the array length from the type, we should
therefore hand it the information. The proc macro buffer missed that
information.

gcc/rust/ChangeLog:

* backend/rust-compile.cc (proc_macro_buffer): Update type builder with
array length information.
(proc_macro_array): Update type initializer with array length
information.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Put common functions in their own namespace
Pierre-Emmanuel Patry [Wed, 4 Oct 2023 16:48:04 +0000 (18:48 +0200)] 
gccrs: Put common functions in their own namespace

Half of the functions introduced recently had a similar goal while the
other half had a similar goal too. Introducing some namespace to separate
those will keep the code cleaner and avoid confusion.

gcc/rust/ChangeLog:

* backend/rust-compile.cc (build_attribute_array): Renamed from...
(attribute_array): ...to attribute array.
(build_derive_proc_macro): Likewise from...
(derive_proc_macro): ... to derive_proc_macro.
(build_bang_proc_macro): Likewise from...
(bang_proc_macro): ...to bang_proc_macro.
(build_attribute_proc_macro): Likewise from...
(attribute_proc_macro): ... to attribute_proc_macro.
(build_proc_macro_payload): Likewise from...
(proc_macro_payload): to proc_macro_payload.
(build_proc_macro): Likewise from...
(proc_macro): ...to proc_macro.
(build_proc_macro_buffer): Likewise from...
(proc_macro_buffer): ... to proc_macro_buffer.
(build_entrypoint): Likewise from...
(entrypoint): ...to entrypoint.
(init_derive_proc_macro): Renamed to it's shorter counterpart.
(init_attribute_proc_macro): Likewise.
(init_bang_proc_macro): Likewise.
(init_proc_macro): Likewise.
(initialize_proc_macro_array): Likewise.
(proc_macro_array): Likewise.
(CompileCrate::add_proc_macro_symbols): Update function calls.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add macro buffer global variable export
Pierre-Emmanuel Patry [Wed, 20 Sep 2023 15:39:16 +0000 (17:39 +0200)] 
gccrs: Add macro buffer global variable export

Export a new symbol containing the proc macros.

gcc/rust/ChangeLog:

* backend/rust-compile-base.h: Make static function address_expression
public.
* backend/rust-compile.cc (CompileCrate::add_proc_macro_symbols): Add
new global variable in export function.
(build_bang_proc_macro): Add a function to build the bang proc macro
structure type.
(build_proc_macro): Add a function to build the proc macro structure
type.
(build_proc_macro_payload): Add a function to build the proc macro
union used in proc macro structures.
(init_derive_proc_macro): Add a function to initialize custom derive
proc macros.
(init_attribute_proc_macro): Add a function to initialize attribute
proc macros.
(init_bang_proc_macro): Add a function to initialize bang proc macros.
(init_proc_macro): Add a function to initialize proc macro structures.
(initialize_proc_macro_array): Add a function to initialize the proc
macro buffer array.
(CompileCrate::add_proc_macro_symbols): Add call to the new functions
to correctly initialize proc macros as well as their entrypoint.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add an explicit value to proc macro enum kind
Pierre-Emmanuel Patry [Wed, 27 Sep 2023 14:21:25 +0000 (16:21 +0200)] 
gccrs: Add an explicit value to proc macro enum kind

We'll need this value in the final binary, it should therefore be kept
explicit.

libgrust/ChangeLog:

* libproc_macro_internal/proc_macro.h (enum ProcmacroTag): Add
explicit value for proc macro tag enum.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Change proc macro entrypoint
Pierre-Emmanuel Patry [Wed, 4 Oct 2023 10:01:44 +0000 (12:01 +0200)] 
gccrs: Change proc macro entrypoint

Change proc macro entrypoint from a fixed constant declaration to a
proper generation from the stable crate id. Although the stable crate id
is not in use yet, the mechanism to handle it is.

gcc/rust/ChangeLog:

* expand/rust-proc-macro.cc (CustomDeriveProcMacro::CustomDeriveProcMacro):
Remove constant string declaration.
(load_macros_array): Add call to the new generation function.
(generate_proc_macro_decls_symbol): Add a new function to generate the
entrypoint symbol name from the stable crate id.
(PROC_MACRO_DECLS_FMT_ARGS):
New macro to keep formats arguments in sync between each call.
* expand/rust-proc-macro.h (generate_proc_macro_decls_symbol): Add
function prototype.
* rust-system.h: Include <iomanip>.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add utility function to build proc macro types
Pierre-Emmanuel Patry [Fri, 15 Sep 2023 09:08:13 +0000 (11:08 +0200)] 
gccrs: Add utility function to build proc macro types

Add some utility function to build proc macro entrypoint related types.
Those functions will help generate all required metadata in order for
proc macros to be expanded properly.

gcc/rust/ChangeLog:

* backend/rust-compile.cc (build_attribute_array): Add a function to
build the attribute array type.
(build_derive_proc_macro): Add a function to build the derive proc
macro type.
(build_bang_proc_macro): Add a function to build the bang proc macro
type.
(build_attribute_proc_macro): Add a function to build the attribute
proc macro type.
(build_proc_macro): Add a function to build the proc macro tagged union
type.
(build_proc_macro_buffer): Add a function to build the proc macro
buffer type.
(build_entrypoint): Add a function to build the proc macro entrypoint
type.
* backend/rust-compile.h: Add function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add getters for proc macro mappings
Pierre-Emmanuel Patry [Fri, 8 Sep 2023 09:23:51 +0000 (11:23 +0200)] 
gccrs: Add getters for proc macro mappings

Add three different getters, one for each proc macro type.

gcc/rust/ChangeLog:

* backend/rust-compile-context.h: Add getters.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Collect procedural macros in the crate
Pierre-Emmanuel Patry [Wed, 6 Sep 2023 12:44:20 +0000 (14:44 +0200)] 
gccrs: Collect procedural macros in the crate

Collect informations on procedural macros in the compiled crate. For
attribute and bang procedural macros we only require the final address
as well as the name of the function. Derive procedural macros are a bit
different, we collect the fonction's address through it's fndecl tree as
well as the trait's name and the multiple attributes.

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc (HIRCompileBase::setup_fndecl):
Make the function non static in order to be able to access the
compile context. Also add the whole proc macro infomrmation
collection.
(get_attributes): Add a function to retrieve the different
attributes from a derive procedural macro definition attribute.
(get_trait_name): Add a function to retrieve the trait name from
a derive procedural macro definition attribute.
* backend/rust-compile-base.h: Add function prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Reformat comments
Pierre-Emmanuel Patry [Wed, 6 Sep 2023 12:39:46 +0000 (14:39 +0200)] 
gccrs: Reformat comments

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc (HIRCompileBase::setup_abi_options):
Reformat uncorrectly formatted comments.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add containers for proc macro collection mappings
Pierre-Emmanuel Patry [Wed, 6 Sep 2023 12:34:45 +0000 (14:34 +0200)] 
gccrs: Add containers for proc macro collection mappings

Add one container for each kind of procedural macro mapping. Also add a
new structure to gather informations required for derive procedural
macros. Add different functions to fill those new containers.

gcc/rust/ChangeLog:

* backend/rust-compile-context.h (struct CustomDeriveInfo): Add
new derive procedural macro metadata information holder for
mappings.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add const getter for tokentrees
Pierre-Emmanuel Patry [Wed, 6 Sep 2023 12:09:25 +0000 (14:09 +0200)] 
gccrs: Add const getter for tokentrees

We often need to retrieve the underlying tokentree without modifying it,
this getter will help achieve this.

gcc/rust/ChangeLog:

* ast/rust-ast.h: Add const getter.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Change ABI setup and add gccrs_proc_macro attr
Pierre-Emmanuel Patry [Mon, 4 Sep 2023 12:23:10 +0000 (14:23 +0200)] 
gccrs: Change ABI setup and add gccrs_proc_macro attr

Change the way the ABI is setup on a function to avoid duplicates. ABI
is setup by the setup function only now. Add a new attribute to the
function "gccrs_proc_macro" in order to differentiate it from another
type of function.

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc (handle_proc_macro_common): Add
new attribute "gccrs_proc_macro" to all procedural macro
functions.
(get_abi): Add a function to retrieve the correct ABI depending
on wether the function is a proc macro or not.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Make proc macro definition cdecl
Pierre-Emmanuel Patry [Mon, 4 Sep 2023 11:22:21 +0000 (13:22 +0200)] 
gccrs: Make proc macro definition cdecl

We need to make sure proc macros have the C abi in order to be called by
the compiler with dlopen.

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc (HIRCompileBase::setup_fndecl):
Add proc macro handlers dispatch.
(handle_proc_macro_common): Add a function for common behavior
between all kinds of proc macros.
* backend/rust-compile-base.h: Add function prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: borrowck: Refactor and BIR improvements
Jakub Dupak [Thu, 19 Oct 2023 13:26:35 +0000 (15:26 +0200)] 
gccrs: borrowck: Refactor and BIR improvements

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::setup_loop): Move.
(ExprStmtBuilder::get_label_ctx): Move.
(ExprStmtBuilder::get_unnamed_loop_ctx): Moved.
(ExprStmtBuilder::visit): BIR improvements.
* checks/errors/borrowck/rust-bir-builder-expr-stmt.h: Refactor.
* checks/errors/borrowck/rust-bir-builder-internal.h (class LifetimeResolver):
Refactor.
(struct BuilderContext): Move.Refactor.
(optional_from_ptr): Map on null ptr.
* checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h (class LazyBooleanExprBuilder):
Refactor.
* checks/errors/borrowck/rust-bir-builder-pattern.h: Refactor.
* checks/errors/borrowck/rust-bir-builder-struct.h (class StructBuilder): Refactor.
* checks/errors/borrowck/rust-bir-builder.h: Refactor.
* checks/errors/borrowck/rust-bir-dump.cc (Dump::go): Refactor.
(Dump::visit): Refactor.
(Dump::visit_place): Refactor.
(Dump::visit_move_place): Refactor.
(Dump::visit_lifetime): Refactor.
* checks/errors/borrowck/rust-bir-dump.h: Refactor.
* checks/errors/borrowck/rust-bir-place.h: Refactor.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
4 months agogccrs: borrowck: Dev notes
Jakub Dupak [Tue, 24 Oct 2023 06:32:20 +0000 (08:32 +0200)] 
gccrs: borrowck: Dev notes

gcc/rust/ChangeLog:

* checks/errors/borrowck/dev-notes.md: New file.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
4 months agogccrs: borrowck: Docs
Jakub Dupak [Wed, 18 Oct 2023 21:11:20 +0000 (23:11 +0200)] 
gccrs: borrowck: Docs

gcc/rust/ChangeLog:

* checks/errors/borrowck/bir-design-notes.md: New file.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
4 months agogccrs: borrowck: Make goto explicit.
Jakub Dupak [Thu, 19 Oct 2023 08:47:50 +0000 (10:47 +0200)] 
gccrs: borrowck: Make goto explicit.

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Use goto.
* checks/errors/borrowck/rust-bir-builder-internal.h: Explicit goto.
* checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: Explicit goto.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
4 months agogccrs: borrowck: BIR continue
Jakub Dupak [Wed, 18 Oct 2023 21:01:06 +0000 (23:01 +0200)] 
gccrs: borrowck: BIR continue

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Continue.
(ExprStmtBuilder::setup_loop): Continue.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
4 months agogccrs: borrowck: Dump: handle infinite loops
Jakub Dupak [Thu, 19 Oct 2023 09:04:29 +0000 (11:04 +0200)] 
gccrs: borrowck: Dump: handle infinite loops

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-dump.cc (simplify_cfg): Detech infinite loops.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
4 months agogccrs: borrowck: BIR: handle break
Jakub Dupak [Wed, 18 Oct 2023 20:54:37 +0000 (22:54 +0200)] 
gccrs: borrowck: BIR: handle break

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Push ctx.
(ExprStmtBuilder::setup_loop): Common loop infractructure setup.
* checks/errors/borrowck/rust-bir-builder-expr-stmt.h: Loop ctx.
* checks/errors/borrowck/rust-bir-builder-internal.h (struct BuilderContext): Loop ctx.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
4 months agogccrs: borrowck: Dump improve jumps
Jakub Dupak [Wed, 18 Oct 2023 21:27:48 +0000 (23:27 +0200)] 
gccrs: borrowck: Dump improve jumps

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-dump.cc (Dump::go): Improve jumps dump.
(Dump::visit): Improve jumps dump.
* checks/errors/borrowck/rust-bir-dump.h (class Dump): Improve jumps dump.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
4 months agogccrs: borrowck: Dump: simplify cfg
Jakub Dupak [Wed, 18 Oct 2023 20:50:02 +0000 (22:50 +0200)] 
gccrs: borrowck: Dump: simplify cfg

Add option to simplify cfg for better readability. Off by default.

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-dump.cc (simplify_cfg): Simplify cfg logic.
(Dump::go): Run simplify cfg.
* checks/errors/borrowck/rust-bir-dump.h: Option to simplify cfg.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
4 months agogccrs: borrowck: Dump: proper comma separation
Jakub Dupak [Wed, 18 Oct 2023 20:38:30 +0000 (22:38 +0200)] 
gccrs: borrowck: Dump: proper comma separation

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-dump.cc (Dump::go): Use new print.
(print_comma_separated): Comma separation print.
(Dump::visit): Use new print.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
4 months agogccrs: borrowck: BIR dump
Jakub Dupak [Wed, 18 Oct 2023 20:36:38 +0000 (22:36 +0200)] 
gccrs: borrowck: BIR dump

gcc/rust/ChangeLog:

* Make-lang.in: Build BIR dump.
* checks/errors/borrowck/rust-borrow-checker.cc (mkdir_wrapped): Cross-platform mkdir.
(dump_function_bir): Save dump to file.
(BorrowChecker::go): Run dump during borrowck.
* checks/errors/borrowck/rust-bir-dump.cc: New file.
* checks/errors/borrowck/rust-bir-dump.h: New file.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
4 months agogccrs: borrowck: Create BIR builders (visitors)
Jakub Dupak [Wed, 18 Oct 2023 18:43:17 +0000 (20:43 +0200)] 
gccrs: borrowck: Create BIR builders (visitors)

gcc/rust/ChangeLog:

* Make-lang.in: Compile BIR expr visitor.
* checks/errors/borrowck/rust-borrow-checker.cc (BorrowChecker::go): Use BIR builder.
* rust-session-manager.cc (Session::compile_crate): Run borrow checker.
* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc: New file.
* checks/errors/borrowck/rust-bir-builder-expr-stmt.h: New file.
* checks/errors/borrowck/rust-bir-builder-internal.h: New file.
* checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: New file.
* checks/errors/borrowck/rust-bir-builder-pattern.h: New file.
* checks/errors/borrowck/rust-bir-builder-struct.h: New file.
* checks/errors/borrowck/rust-bir-builder.h: New file.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
4 months agogccrs: borrowck: Create Borrow-checker IR (BIR)
Jakub Dupak [Wed, 18 Oct 2023 17:49:59 +0000 (19:49 +0200)] 
gccrs: borrowck: Create Borrow-checker IR (BIR)

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-borrow-checker.cc: Include to compile new code.
* checks/errors/borrowck/rust-bir-place.h: New file.
* checks/errors/borrowck/rust-bir-visitor.h: New file.
* checks/errors/borrowck/rust-bir.h: New file.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>