]> gcc.gnu.org Git - gcc.git/log
gcc.git
7 months agosimplify-rtx: Fix up last argument to simplify_gen_unary [PR113656]
Jakub Jelinek [Wed, 31 Jan 2024 09:56:56 +0000 (10:56 +0100)]
simplify-rtx: Fix up last argument to simplify_gen_unary [PR113656]

When simplifying e.g. (float_truncate:SF (float_truncate:DF (reg:XF))
or (float_truncate:SF (float_extend:XF (reg:DF)) etc. into
(float_truncate:SF (reg:XF)) or (float_truncate:SF (reg:DF)) we call
simplify_gen_unary with incorrect op_mode argument, it should be
the argument's mode, but we call it with the outer mode instead.
As these are all floating point operations, the argument always
has non-VOIDmode and so we can just use that mode (as done in similar
simplifications a few lines later), but neither FLOAT_TRUNCATE nor
FLOAT_EXTEND are operations that should have the same modes of operand
and result.  This bug hasn't been a problem for years because normally
op_mode is used only if the mode of op is VOIDmode, otherwise it is
redundant, but r10-2139 added an assertion in some spots that op_mode
is right even in such cases.

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

PR rtl-optimization/113656
* simplify-rtx.cc (simplify_context::simplify_unary_operation_1)
<case FLOAT_TRUNCATE>: Fix up last argument to simplify_gen_unary.

* gcc.target/i386/pr113656.c: New test.

7 months agodwarf2out: Fix ICE on large _BitInt in loc_list_from_tree_1 [PR113637]
Jakub Jelinek [Wed, 31 Jan 2024 09:56:15 +0000 (10:56 +0100)]
dwarf2out: Fix ICE on large _BitInt in loc_list_from_tree_1 [PR113637]

This spot uses SCALAR_INT_TYPE_MODE which obviously ICEs for large/huge
BITINT_TYPE types which have BLKmode.  But such large BITINT_TYPEs certainly
don't fit into DWARF2_ADDR_SIZE either, so we can just assume it would be
false if type has BLKmode.

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

PR debug/113637
* dwarf2out.cc (loc_list_from_tree_1): Assume integral types
with BLKmode are larger than DWARF2_ADDR_SIZE.

* gcc.dg/bitint-80.c: New test.

7 months agolower-bitint: Fix up VIEW_CONVERT_EXPR handling in handle_operand_addr [PR113639]
Jakub Jelinek [Wed, 31 Jan 2024 09:50:33 +0000 (10:50 +0100)]
lower-bitint: Fix up VIEW_CONVERT_EXPR handling in handle_operand_addr [PR113639]

Yet another spot where we need to treat VIEW_CONVERT_EXPR differently
from NOP_EXPR/CONVERT_EXPR.

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

PR tree-optimization/113639
* gimple-lower-bitint.cc (bitint_large_huge::handle_operand_addr):
For VIEW_CONVERT_EXPR set rhs1 to its operand.

* gcc.dg/bitint-79.c: New test.

7 months agolibstdc++: Enable std::text_encoding for darwin and FreeBSD
Jonathan Wakely [Tue, 30 Jan 2024 14:28:09 +0000 (14:28 +0000)]
libstdc++: Enable std::text_encoding for darwin and FreeBSD

The <xlocale.h> header is needed for newlocale and locale_t on these
targets.

libstdc++-v3/ChangeLog:

* acinclude.m4 (GLIBCXX_CHECK_TEXT_ENCODING): Use <xlocale.h> if
needed for newlocale.
* configure: Regenerate.
* src/c++26/text_encoding.cc: Use <xlocale.h>.

Reviewed-by: Iain Sandoe <iain@sandoe.co.uk>
7 months agolibstdc++: Add "ASCII" as an alias for std::text_encoding::id::ASCII
Jonathan Wakely [Tue, 23 Jan 2024 14:57:15 +0000 (14:57 +0000)]
libstdc++: Add "ASCII" as an alias for std::text_encoding::id::ASCII

As noted in LWG 4043, "ASCII" is not an alias for any known registered
character encoding, so std::text_encoding("ASCII").mib() == id::other.
Add the alias "ASCII" to the implementation-defined superset of aliases
for that encoding.

libstdc++-v3/ChangeLog:

* include/bits/text_encoding-data.h: Regenerate.
* scripts/gen_text_encoding_data.py: Add extra_aliases dict
containing "ASCII".
* testsuite/std/text_encoding/cons.cc: Check "ascii" is known.

Co-authored-by: Ewan Higgs <ewan.higgs@gmail.com>
Signed-off-by: Ewan Higgs <ewan.higgs@gmail.com>
7 months agolibstdc++: Add all supported headers to lists in the manual
Jonathan Wakely [Tue, 23 Jan 2024 14:49:51 +0000 (14:49 +0000)]
libstdc++: Add all supported headers to lists in the manual

libstdc++-v3/ChangeLog:

* doc/xml/manual/using.xml: Update tables of supported headers.
* doc/html/*: Regenerate.

7 months agolibstdc++: Fix -Wshift-count-overflow warning in std::bitset
Jonathan Wakely [Sat, 20 Jan 2024 21:09:28 +0000 (21:09 +0000)]
libstdc++: Fix -Wshift-count-overflow warning in std::bitset

This shift only happens if the unsigned long long type is wider than
unsigned long but the compiler warns when it sees the shift, without
caring if it's reachable.

Use the preprocessor to compare the sizes and just reuse _M_to_ulong()
if sizeof(long) == sizeof(long long).

libstdc++-v3/ChangeLog:

* include/std/bitset (_Base_bitset::_M_do_to_ullong): Avoid
-Wshift-count-overflow warning.

7 months agotree-optimization/113670 - gather/scatter to/from hard registers
Richard Biener [Wed, 31 Jan 2024 08:09:50 +0000 (09:09 +0100)]
tree-optimization/113670 - gather/scatter to/from hard registers

The following makes sure we're not taking the address of hard
registers when vectorizing appearant gathers or scatters to/from
them.

PR tree-optimization/113670
* tree-vect-data-refs.cc (vect_check_gather_scatter):
Make sure we can take the address of the reference base.

* gcc.target/i386/pr113670.c: New testcase.

7 months agoAVR: Add AVR64DU and some older devices.
Georg-Johann Lay [Wed, 31 Jan 2024 08:33:37 +0000 (09:33 +0100)]
AVR: Add AVR64DU and some older devices.

gcc/
* config/avr/avr-mcus.def: Add AVR64DU28, AVR64DU32, ATA5787,
ATA5835, ATtiny64AUTO, ATA5700M322.
* doc/avr-mmcu.texi: Rebuild.

7 months agostrub: drop nonaliased parm from build_ref_type_for [PR113394]
Alexandre Oliva [Wed, 31 Jan 2024 03:13:27 +0000 (00:13 -0300)]
strub: drop nonaliased parm from build_ref_type_for [PR113394]

Variant type copies can't have their own alias sets any more, and it's
not like setting them affected the pointed-to objects anyway.

for  gcc/ChangeLog

PR debug/113394
* ipa-strub.cc (build_ref_type_for): Drop nonaliased.  Adjust
caller.

for  gcc/testsuite/ChangeLog

PR debug/113394
* gcc.dg/strub-internal-pr113394.c: New.

7 months ago0From: Alexandre Oliva <oliva@adacore.com>
Alexandre Oliva [Wed, 31 Jan 2024 03:13:36 +0000 (00:13 -0300)]
0From: Alexandre Oliva <oliva@adacore.com>

strub: introduce STACK_ADDRESS_OFFSET

Since STACK_POINTER_OFFSET is not necessarily at the boundary between
caller- and callee-owned stack, as desired by
__builtin_stack_address(), and using it as if it were or not causes
problems, introduce a new macro so that ports can define it suitably,
without modifying STACK_POINTER_OFFSET.

for  gcc/ChangeLog

PR middle-end/112917
PR middle-end/113100
* builtins.cc (expand_builtin_stack_address): Use
STACK_ADDRESS_OFFSET.
* doc/extend.texi (__builtin_stack_address): Adjust.
* config/sparc/sparc.h (STACK_ADDRESS_OFFSET): Define.
* doc/tm.texi.in (STACK_ADDRESS_OFFSET): Document.
* doc/tm.texi: Rebuilt.

7 months agoc: Fix ICEs casting expressions with integer constant operands to bool [PR111059...
Joseph Myers [Wed, 31 Jan 2024 01:24:21 +0000 (01:24 +0000)]
c: Fix ICEs casting expressions with integer constant operands to bool [PR111059, PR111911]

C front-end bugs 111059 and 111911 both report ICEs with conversions
to boolean of expressions with integer constant operands that can
appear in an integer constant expression as long as they are not
evaluated (such as division by zero).

The issue is a nested C_MAYBE_CONST_EXPR, with the inner one generated
in build_binary_op to indicate that a subexpression has been fully
folded and should not be folded again, and the outer one in
build_c_cast to indicate that the expression has integer constant
operands.  To avoid the inner one from build_binary_op,
c_objc_common_truthvalue_conversion should be given an argument
properly marked as having integer constant operands rather than that
information having been removed by the caller - but because c_convert
would then also wrap a C_MAYBE_CONST_EXPR with a NOP_EXPR converting
to boolean, it seems most convenient to have
c_objc_common_truthvalue_conversion produce the NE_EXPR directly in
the desired type (boolean in this case), before generating any
C_MAYBE_CONST_EXPR there, rather than it always producing a comparison
in integer_type_node and doing a conversion to boolean in the caller.

The same issue as in those PRs also applies for conversion to enums
with a boolean fixed underlying type; that case is also fixed and
tests added for it.  Note that not all the tests added failed before
the patch (in particular, the issue was specific to casts and did not
apply for implicit conversions, but some tests of those are added as
well).

Bootstrapped with no regressions for x86_64-pc-linux-gnu.

PR c/111059
PR c/111911

gcc/c/
* c-tree.h (c_objc_common_truthvalue_conversion): Add third
argument.
* c-convert.cc (c_convert): For conversions to boolean, pass third
argument to c_objc_common_truthvalue_conversion rather than
converting here.
* c-typeck.cc (build_c_cast): Ensure arguments with integer
operands are marked as such for conversion to boolean.
(c_objc_common_truthvalue_conversion): Add third argument TYPE.

gcc/testsuite/
* gcc.c-torture/compile/pr111059-1.c,
gcc.c-torture/compile/pr111059-2.c,
gcc.c-torture/compile/pr111059-3.c,
gcc.c-torture/compile/pr111059-4.c,
gcc.c-torture/compile/pr111059-5.c,
gcc.c-torture/compile/pr111059-6.c,
gcc.c-torture/compile/pr111059-7.c,
gcc.c-torture/compile/pr111059-8.c,
gcc.c-torture/compile/pr111059-9.c,
gcc.c-torture/compile/pr111059-10.c,
gcc.c-torture/compile/pr111059-11.c,
gcc.c-torture/compile/pr111059-12.c,
gcc.c-torture/compile/pr111911-1.c,
gcc.c-torture/compile/pr111911-2.c: New tests.

7 months agoanalyzer: handle null "var" in state_change_event::get_desc [PR113509]
David Malcolm [Wed, 31 Jan 2024 01:06:31 +0000 (20:06 -0500)]
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>
7 months agoRISC-V: Fix VSETLV PASS compile-time issue
Juzhe-Zhong [Mon, 29 Jan 2024 11:32:02 +0000 (19:32 +0800)]
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.

7 months agoDaily bump.
GCC Administrator [Wed, 31 Jan 2024 00:19:27 +0000 (00:19 +0000)]
Daily bump.

7 months agoi386: Add "Ws" constraint for symbolic address/label reference [PR105576]
Fangrui Song [Thu, 11 Jan 2024 18:24:25 +0000 (10:24 -0800)]
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.

7 months agoc++: avoid -Wdangling-reference for std::span-like classes [PR110358]
Marek Polacek [Thu, 25 Jan 2024 17:08:14 +0000 (12:08 -0500)]
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.

7 months agoxtensa: Make full transition to LRA
Takayuki 'January June' Suwa [Mon, 8 May 2023 13:38:51 +0000 (22:38 +0900)]
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.

7 months agoc++: add original testcase [PR67898]
Patrick Palka [Tue, 30 Jan 2024 17:30:32 +0000 (12:30 -0500)]
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.

7 months agotestsuite: fix anon6 mangling [PR112846]
Jason Merrill [Tue, 30 Jan 2024 17:07:21 +0000 (12:07 -0500)]
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.

7 months agotestsuite: mangle-reparm1a options [PR113451]
Jason Merrill [Tue, 30 Jan 2024 16:36:53 +0000 (11:36 -0500)]
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.

7 months agoc++: duplicated side effects of xobj arg [PR113640]
Patrick Palka [Tue, 30 Jan 2024 15:44:56 +0000 (10:44 -0500)]
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>
7 months agoc++: unifying integer parm with type-dep arg [PR113644]
Patrick Palka [Tue, 30 Jan 2024 15:13:41 +0000 (10:13 -0500)]
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.

7 months agolibstdc++: Fix check in testsuite/std/time/clock/gps/io.cc
Jonathan Wakely [Mon, 22 Jan 2024 10:48:55 +0000 (10:48 +0000)]
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.

7 months agoRISC-V: Bugfix for vls mode aggregated in GPR calling convention
Pan Li [Tue, 30 Jan 2024 07:42:06 +0000 (15:42 +0800)]
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>
7 months agoanalyzer: fix -Wanalyzer-allocation-size false +ve on Linux kernel's round_up macro...
David Malcolm [Tue, 30 Jan 2024 13:17:47 +0000 (08:17 -0500)]
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>
7 months agoanalyzer: add SARIF property bag to -Wanalyzer-allocation-size
David Malcolm [Tue, 30 Jan 2024 13:17:47 +0000 (08:17 -0500)]
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>
7 months agogccrs: Fix output line ending patterns.
Arthur Cohen [Mon, 22 Jan 2024 13:04:11 +0000 (14:04 +0100)]
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.

7 months agogccrs: Remove TraitImplItem
Owen Avery [Wed, 20 Dec 2023 08:04:36 +0000 (03:04 -0500)]
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>
7 months agogccrs: Add improved error when no fields in initializer
Robert Goss [Sun, 14 Jan 2024 17:34:22 +0000 (17:34 +0000)]
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>
7 months agogccrs: Test: check implemented for lifetime handling
Jakub Dupak [Thu, 18 Jan 2024 13:37:58 +0000 (14:37 +0100)]
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>
7 months agogccrs: AST: Fix for lifetime lowering
Jakub Dupak [Tue, 9 Jan 2024 14:46:41 +0000 (15:46 +0100)]
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>
7 months agogccrs: AST: Fix for lifetime parsing
Jakub Dupak [Tue, 9 Jan 2024 14:45:12 +0000 (15:45 +0100)]
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>
7 months agogccrs: Test: fix missing lifetime in a test
Jakub Dupak [Tue, 9 Jan 2024 14:43:01 +0000 (15:43 +0100)]
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>
7 months agogccrs: Added newline to get more readable lexdump
Kushal Pal [Sat, 30 Dec 2023 04:10:19 +0000 (09:40 +0530)]
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>
7 months agogccrs: Unify storage of associated items in SingleASTNode
Owen Avery [Wed, 20 Dec 2023 07:30:20 +0000 (02:30 -0500)]
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.

7 months agogccrs: Add improved error when a field is redefined in a struct constructor
Robert Goss [Tue, 16 Jan 2024 22:50:51 +0000 (22:50 +0000)]
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>
7 months agogccrs: Handle `async` keyword for regular implementations
Kushal Pal [Sat, 6 Jan 2024 05:59:14 +0000 (11:29 +0530)]
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>
7 months agogccrs: Fix inconsistent formatting
Kushal Pal [Tue, 16 Jan 2024 13:36:35 +0000 (19:06 +0530)]
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>
7 months agogccrs: Handle `async` functions in traits
Kushal Pal [Wed, 3 Jan 2024 10:32:07 +0000 (16:02 +0530)]
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>
7 months agogccrs: Handle newlines during string parsing while lexing
Nirmal Patel [Wed, 27 Dec 2023 22:49:58 +0000 (17:49 -0500)]
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>
7 months agogccrs: TyTy: Refactor FnType deprecated API
Jakub Dupak [Thu, 14 Dec 2023 11:54:11 +0000 (12:54 +0100)]
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>
7 months agogccrs: ast: Lower 'for' lifetimes
Jakub Dupak [Sun, 3 Dec 2023 11:32:55 +0000 (12:32 +0100)]
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>
7 months agogccrs: ast: Infer static lifetime for const and static items
Jakub Dupak [Sun, 3 Dec 2023 11:30:08 +0000 (12:30 +0100)]
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>
7 months agogccrs: ast: Full lifetime elision handling
Jakub Dupak [Sun, 3 Dec 2023 11:28:07 +0000 (12:28 +0100)]
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>
7 months agogccrs: ast: Unify explicitly and implicitly elided lifettimes
Jakub Dupak [Sun, 3 Dec 2023 11:25:23 +0000 (12:25 +0100)]
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>
7 months agogccrs: ast: Fix lifetime type parsing
Jakub Dupak [Sun, 3 Dec 2023 11:23:17 +0000 (12:23 +0100)]
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>
7 months agogccrs: Generate error for `async` trait fucntions
Kushal Pal [Sat, 16 Dec 2023 14:37:23 +0000 (20:07 +0530)]
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>
7 months agogccrs: Handle `async` qualifier inside trait
Kushal Pal [Fri, 15 Dec 2023 19:11:09 +0000 (00:41 +0530)]
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>
7 months agogccrs: split rust-mangle.cc into two files
Raiki Tamura [Tue, 26 Dec 2023 04:08:42 +0000 (13:08 +0900)]
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>
7 months agogccrs: BIR: Cleanup
Jakub Dupak [Mon, 11 Dec 2023 21:09:07 +0000 (22:09 +0100)]
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>
7 months agogccrs: TyTy: SubstitutionRef cast specialization
Jakub Dupak [Mon, 11 Dec 2023 22:11:34 +0000 (23:11 +0100)]
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>
7 months agogccrs: TyTy: Common interface for fucntion-like types
Jakub Dupak [Sun, 3 Dec 2023 10:16:59 +0000 (11:16 +0100)]
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>
7 months agogccrs: TyTy: refactor to new API
Jakub Dupak [Sun, 3 Dec 2023 10:15:06 +0000 (11:15 +0100)]
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>
7 months agogccrs: BIR: Fix missed nodiscard
Jakub Dupak [Mon, 11 Dec 2023 20:52:48 +0000 (21:52 +0100)]
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>
7 months agogccrs: TyTy: Fix missed nodiscard
Jakub Dupak [Sun, 3 Dec 2023 10:13:04 +0000 (11:13 +0100)]
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>
7 months agogccrs: HIR: add missing getters
Jakub Dupak [Sun, 3 Dec 2023 10:07:04 +0000 (11:07 +0100)]
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>
7 months agogccrs: refactor builtins initialization and attributes
Arthur Cohen [Thu, 3 Nov 2022 14:02:37 +0000 (15:02 +0100)]
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>
7 months agogccrs: Change cfg stripper to use default visitor
Pierre-Emmanuel Patry [Thu, 23 Nov 2023 19:22:29 +0000 (20:22 +0100)]
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>
7 months agogccrs: Make expand visitor inherit from default visitor
Pierre-Emmanuel Patry [Mon, 27 Nov 2023 13:12:20 +0000 (14:12 +0100)]
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>
7 months agogccrs: Make default resolver inherit from default visitor
Pierre-Emmanuel Patry [Mon, 27 Nov 2023 16:00:56 +0000 (17:00 +0100)]
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>
7 months agogccrs: Allow enabling lang_items and no_core features
Owen Avery [Sat, 9 Dec 2023 06:22:02 +0000 (01:22 -0500)]
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>
7 months agogccrs: Renamed `WIN64` to `WIN_64`
Kushal Pal [Sat, 9 Dec 2023 06:34:01 +0000 (12:04 +0530)]
gccrs: Renamed `WIN64` to `WIN_64`

Fixes issue #2768

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc (HIRCompileBase::setup_abi_options):
Renamed `WIN64` to `WIN_64`
* util/rust-abi.cc (get_abi_from_string): Likewise
(get_string_from_abi): Likewise
* util/rust-abi.h (enum ABI): Likewise

Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
7 months agogccrs: Generate error for const trait functions
Nobel Singh [Tue, 5 Dec 2023 12:27:29 +0000 (18:12 +0545)]
gccrs: Generate error for const trait functions

Fixes issue #2040

Add check to assure that a function cant be declared const inside trait impl
blocks.

gcc/rust/ChangeLog:

* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add
check for const funtion.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Nobel Singh <nobel2073@gmail.com>
7 months agogccrs: Add a regression test for function body check
Pierre-Emmanuel Patry [Thu, 23 Nov 2023 13:08:50 +0000 (14:08 +0100)]
gccrs: Add a regression test for function body check

Function body check emit an error message when a required function body
is missing.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add validation for functions without body
Pierre-Emmanuel Patry [Wed, 22 Nov 2023 15:37:17 +0000 (16:37 +0100)]
gccrs: Add validation for functions without body

Add checks in the ast validation pass to error out with functions
(either free or associated) without a definition.

gcc/rust/ChangeLog:

* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add
a validation check and emit an error depending on the context.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Make function bodies truly optional
Pierre-Emmanuel Patry [Wed, 22 Nov 2023 14:15:29 +0000 (15:15 +0100)]
gccrs: Make function bodies truly optional

Missing body on a function should be rejected at a later stage in the
compiler, not during parsing.

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): Adapt defintion
getter.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise.
* expand/rust-cfg-strip.cc (CfgStrip::visit): Likewise.
* expand/rust-expand-visitor.cc (ExpandVisitor::visit): Likewise.
* hir/rust-ast-lower-implitem.h: Likewise.
* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Likewise.
* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Likewise.
* resolve/rust-ast-resolve-stmt.h: Likewise.
* resolve/rust-default-resolver.cc (DefaultResolver::visit): Likewise.
* util/rust-attributes.cc (AttributeChecker::visit):  Likewise.
* parse/rust-parse-impl.h: Allow empty function body during parsing.
* ast/rust-ast.cc (Function::Function): Constructor now take an
optional for the body.
(Function::operator=): Adapt to new optional member.
(Function::as_string): Likewise.
* ast/rust-item.h (class Function): Make body optional and do not
rely on nullptr anymore.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add execution test for name resolution 2.0
Pierre-Emmanuel Patry [Thu, 30 Nov 2023 12:27:01 +0000 (13:27 +0100)]
gccrs: Add execution test for name resolution 2.0

We already have some compile tests but it lacked an execution test to
ensure everything compiles correctly to the correct value.

gcc/testsuite/ChangeLog:

* rust/execute/torture/name_resolution.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add multiple regression test in name resolution
Pierre-Emmanuel Patry [Thu, 30 Nov 2023 09:43:36 +0000 (10:43 +0100)]
gccrs: Add multiple regression test in name resolution

Local variables and functions or global variables have different
resolution when binded to a variable. This was not covered before, even
though it was handled by the new name resolution. This commit highlight
this behavior from the new name resolution mechanism.

gcc/testsuite/ChangeLog:

* rust/compile/name_resolution11.rs: New test.
* rust/compile/name_resolution12.rs: New test.
* rust/compile/name_resolution13.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Make early name resolver inherit from default one
Pierre-Emmanuel Patry [Mon, 27 Nov 2023 14:39:24 +0000 (15:39 +0100)]
gccrs: Make early name resolver inherit from default one

Many visit functions in the early name resolver are just plain old
traversal visit functions like the ones from the default visitor.

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver.cc (EarlyNameResolver::resolve_generic_args):
Move function.
(EarlyNameResolver::resolve_qualified_path_type): Likewise.
(EarlyNameResolver::visit): Add a top level visit function for crate
and remove duplicated code.
* resolve/rust-early-name-resolver.h (class EarlyNameResolver): Update
overriden function list.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Change the attribute checker visitor to default one
Pierre-Emmanuel Patry [Fri, 24 Nov 2023 13:09:23 +0000 (14:09 +0100)]
gccrs: Change the attribute checker visitor to default one

Make the attribute checker visitor inherit from the default visitor
in order to keep visit behavior shared.

gcc/rust/ChangeLog:

* util/rust-attributes.cc (AttributeChecker::visit): Add visit function
for crates.
* util/rust-attributes.h (class AttributeChecker): Update function
prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Make feature gate visitor inherit from default one
Pierre-Emmanuel Patry [Fri, 24 Nov 2023 10:17:52 +0000 (11:17 +0100)]
gccrs: Make feature gate visitor inherit from default one

The feature gating behavior may be shortened and kept cleaner using the
default visitor. This means less maintenance on visit functions as the
traversal is shared by multiple visitors.

gcc/rust/ChangeLog:

* checks/errors/rust-feature-gate.cc (FeatureGate::visit): Add a visit
function for the crate level.
(FeatureGate::check): Add call to crate visit.
* checks/errors/rust-feature-gate.h (class FeatureGate): Remove now
useless visit functions (traversal only).

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add regression test for const fn in trait
Pierre-Emmanuel Patry [Wed, 22 Nov 2023 12:22:42 +0000 (13:22 +0100)]
gccrs: Add regression test for const fn in trait

Const fn declaration in trait declarations shall emit an error. This new
test highlight this behavior.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add AST validation check for const in trait
Pierre-Emmanuel Patry [Wed, 22 Nov 2023 12:08:13 +0000 (13:08 +0100)]
gccrs: Add AST validation check for const in trait

Add a new check in AST validation pass that checks that no function
declaration in traits are declared const.

gcc/rust/ChangeLog:

* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add
const check.
* checks/errors/rust-ast-validation.h: Add visit function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add a regression test for async const functions
Pierre-Emmanuel Patry [Wed, 22 Nov 2023 10:12:05 +0000 (11:12 +0100)]
gccrs: Add a regression test for async const functions

Functions that are both async and const shall be rejected during the
AST validation pass. This new test highlight this behavior.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add async const function ast validation pass
Pierre-Emmanuel Patry [Wed, 22 Nov 2023 09:44:08 +0000 (10:44 +0100)]
gccrs: Add async const function ast validation pass

Add a check during AST validation pass to ensure functions are either
const or async but not both.

gcc/rust/ChangeLog:

* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add
async const check.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Allow const and async specifiers in functions
Pierre-Emmanuel Patry [Wed, 22 Nov 2023 09:35:44 +0000 (10:35 +0100)]
gccrs: Allow const and async specifiers in functions

We need to account for const specifiers in async parsing as const
can be used in the syntax before the async keyword.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_vis_item): Allow parsing async
items in const.
(Parser::parse_async_item): Account for const offset during async
lookahead.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Split async and const function qualifiers
Pierre-Emmanuel Patry [Tue, 21 Nov 2023 09:29:35 +0000 (10:29 +0100)]
gccrs: Split async and const function qualifiers

A function cannot be both async and const, however this should not be
handled in the parser but rather at a later stage in the compiler. This
commit change the AsyncConstStatus in the AST and the HIR to allows a
function to be both async and const.

gcc/rust/ChangeLog:

* ast/rust-ast-builder.cc (AstBuilder::fn_qualifiers): Change
constructor to match the new arguments.
* ast/rust-ast-collector.cc (TokenCollector::visit): Change behavior
to handle both const and async specifiers at the same time.
* ast/rust-ast.cc (FunctionQualifiers::as_string): Likewise.
* ast/rust-item.h (class FunctionQualifiers): Remove AsyncConstStatus
and replace it with both Async and Const status. Also change the safety
arguments to use an enum instead of a boolean.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_qualifiers):
Update constructor call.
* hir/tree/rust-hir-item.h: Add Const and Async status, remove
AsyncConstStatus, update the constructor.
* hir/tree/rust-hir.cc (FunctionQualifiers::as_string): Update with
the new status.
* parse/rust-parse-impl.h (Parser::parse_function_qualifiers): Update
constructor call.
* util/rust-common.h (enum Mutability): Make an enum class.
(enum class): Add Async and Const enum class to avoid booleans.
(enum Unsafety): Change to an enum class.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Remove class AST::InherentImplItem
Owen Avery [Tue, 28 Nov 2023 06:07:00 +0000 (01:07 -0500)]
gccrs: Remove class AST::InherentImplItem

gcc/rust/ChangeLog:

* ast/rust-ast-full-decls.h
(class InherentImplItem): Remove.
* ast/rust-ast.h
(class InherentImplItem): Remove.
(class SingleASTNode):
Store pointer to AssociatedItem instead of InherentImplItem.

* ast/rust-ast.cc
(SingleASTNode::SingleASTNode):
Use clone_associated_item instead of clone_inherent_impl_item.
(SingleASTNode::operator=): Likewise.

* ast/rust-item.h
(class InherentImpl):
Use AssociatedItem rather than InherentImplItem.
(class Function): Likewise.
(class ConstantItem): Likewise.
* ast/rust-macro.h
(class MacroInvocation): Likewise.
* expand/rust-expand-visitor.cc
(ExpandVisitor::visit): Likewise.
* parse/rust-parse-impl.h
(Parser::parse_impl): Likewise.
(Parser::parse_inherent_impl_item): Likewise.
(Parser::parse_inherent_impl_function_or_method): Likewise.
* parse/rust-parse.h
(Parser::parse_inherent_impl_item): Likewise.
(Parser::parse_inherent_impl_function_or_method): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
7 months agogccrs: Remove backend dependancy on resolution rib information
Philip Herron [Mon, 2 Oct 2023 17:41:33 +0000 (18:41 +0100)]
gccrs: Remove backend dependancy on resolution rib information

When making more desugaring for the HIR we can need to add new Let bindings
which will require namesolution information but also rib information for
which block the let binding is associated which was very unnessecary. This
patch simply updates the BLOCK_CONTEXT of the current scope as we are
compiling and encounter HIR::LetStmts instead of trying to do it all
upfront which lots of wierd checks

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc (HIRCompileBase::compile_locals_for_block): removed
* backend/rust-compile-base.h: update header
* backend/rust-compile-block.cc (CompileBlock::visit): remove old logic
* backend/rust-compile-expr.cc (CompileExpr::generate_closure_function): likewise
* backend/rust-compile-stmt.cc (CompileStmt::visit): likewise
* backend/rust-compile-var-decl.h: ensure we setup tuple bindings correctly

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
7 months agogccrs: Add a regression test for unsafe module validation
Pierre-Emmanuel Patry [Tue, 21 Nov 2023 18:34:36 +0000 (19:34 +0100)]
gccrs: Add a regression test for unsafe module validation

Add a new test to check for unsafe modules during AST validation pass.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Emit an error on unsafe modules
Pierre-Emmanuel Patry [Tue, 21 Nov 2023 17:51:21 +0000 (18:51 +0100)]
gccrs: Emit an error on unsafe modules

An error should be emitted on unsafe modules during the AST validation
pass as the syntax allows those even though they're not alowed later down
the line.

gcc/rust/ChangeLog:

* ast/rust-item.h: Add safety getter to modules.
* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Check
a module's safety and emit an error when meeting an unsafe module.
* checks/errors/rust-ast-validation.h: Add function prototype.
* parse/rust-parse-impl.h (Parser::parse_module): Move the module locus
to the first token instead of the mod keyword.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Parse module safety
Pierre-Emmanuel Patry [Tue, 21 Nov 2023 17:28:30 +0000 (18:28 +0100)]
gccrs: Parse module safety

Unsafe module are rejected at a later stage but could not be parsed
properly. This commit changes the parser in order to allow unsafe module
in the AST.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_vis_item): Dispatch to parse
module when meeting an unsafe module.
(Parser::parse_module): Set unsafe status when the parser encounter an
unsafe keyword.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add unsafety member to modules
Pierre-Emmanuel Patry [Tue, 21 Nov 2023 16:56:10 +0000 (17:56 +0100)]
gccrs: Add unsafety member to modules

The rust syntax allows unsafe module even if those are rejected at a
later stage.

gcc/rust/ChangeLog:

* ast/rust-item.h: Add safety status to Modules in the AST.
* parse/rust-parse-impl.h (Parser::parse_module): Adapt constructors.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Create base class for TupleStructItems and TuplePatternItems
Owen Avery [Tue, 3 Oct 2023 21:50:14 +0000 (17:50 -0400)]
gccrs: Create base class for TupleStructItems and TuplePatternItems

gcc/rust/ChangeLog:

* hir/tree/rust-hir-pattern.h
(class TupleItems): New.
(class TupleStructItems): Inherit from TupleItems.
(class TuplePatternItems): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
7 months agogccrs: toplevel: Resolve `use` declarations
Arthur Cohen [Wed, 23 Aug 2023 11:51:06 +0000 (13:51 +0200)]
gccrs: toplevel: Resolve `use` declarations

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::insert_or_error_out): New functions.
(TopLevel::handle_use_dec): New function.
(flatten_rebind): Likewise.
(flatten_list): Likewise.
(flatten_glob): Likewise.
(flatten): Likewise.
(TopLevel::visit): Visit various `use` declaration nodes.
* resolve/rust-toplevel-name-resolver-2.0.h: Declare functions and
visitors.

7 months agogccrs: early: Move `use` declaration resolving to TopLevel
Arthur Cohen [Wed, 23 Aug 2023 11:50:54 +0000 (13:50 +0200)]
gccrs: early: Move `use` declaration resolving to TopLevel

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc
(Early::visit): Remove visitors.
* resolve/rust-early-name-resolver-2.0.h: Likewise.

7 months agogccrs: ast: Add NodeId to UseTree base class
Arthur Cohen [Wed, 23 Aug 2023 11:49:24 +0000 (13:49 +0200)]
gccrs: ast: Add NodeId to UseTree base class

gcc/rust/ChangeLog:

* ast/rust-item.h (class UseTree): Add `node_id` member.

7 months agogccrs: toplevel: Add comment about running the collector twice
Arthur Cohen [Tue, 22 Aug 2023 15:29:56 +0000 (17:29 +0200)]
gccrs: toplevel: Add comment about running the collector twice

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::insert_or_error_out): Add documentation comment.
(TopLevel::go): Likewise.

7 months agogccrs: early: Resolve paths properly
Arthur Cohen [Mon, 21 Aug 2023 14:52:48 +0000 (16:52 +0200)]
gccrs: early: Resolve paths properly

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc
(Early::insert_once): New function.
(Early::visit): Likewise.
* resolve/rust-early-name-resolver-2.0.h: Likewise.

7 months agogccrs: late: Start storing mappings properly in the resolver
Arthur Cohen [Tue, 22 Aug 2023 15:29:05 +0000 (17:29 +0200)]
gccrs: late: Start storing mappings properly in the resolver

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Store mappings
after having resolved them.
* resolve/rust-late-name-resolver-2.0.h: Add `TypePath` visitor.

7 months agogccrs: late: Start setting up builtin types
Arthur Cohen [Tue, 22 Aug 2023 14:58:28 +0000 (16:58 +0200)]
gccrs: late: Start setting up builtin types

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc
(Late::setup_builtin_types): New function.
(Late::go): Setup builtin types.
* resolve/rust-late-name-resolver-2.0.h:
* resolve/rust-name-resolution-context.cc
(NameResolutionContext::map_usage): New function.
* resolve/rust-name-resolution-context.h: Likewise.

7 months agogccrs: nr2.0: Store mappings in NameResolutionContext
Arthur Cohen [Tue, 22 Aug 2023 13:40:25 +0000 (15:40 +0200)]
gccrs: nr2.0: Store mappings in NameResolutionContext

gcc/rust/ChangeLog:

* resolve/rust-name-resolution-context.h: Store a reference to the
mappings.
* resolve/rust-name-resolution-context.cc
(NameResolutionContext::NameResolutionContext): Likewise.

7 months agogccrs: toplevel: Use DefaultResolver for Function
Arthur Cohen [Wed, 15 Nov 2023 10:33:25 +0000 (11:33 +0100)]
gccrs: toplevel: Use DefaultResolver for Function

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Use
the DefaultResolver in the toplevel visitor.

7 months agogccrs: nr2.0: Add base for late name resolution
Arthur Cohen [Fri, 23 Jun 2023 14:37:51 +0000 (16:37 +0200)]
gccrs: nr2.0: Add base for late name resolution

gcc/rust/ChangeLog:

* Make-lang.in: Compile late name resolver.
* resolve/rust-late-name-resolver-2.0.cc: New file.
* resolve/rust-late-name-resolver-2.0.h: New file.

7 months agogccrs: ctx: Add Labels ForeverStack to the resolver.
Arthur Cohen [Thu, 17 Aug 2023 12:07:27 +0000 (14:07 +0200)]
gccrs: ctx: Add Labels ForeverStack to the resolver.

Not sure if dealing with "labels" is the proper way of doing so, so we
might eventually change this to use `resolver.values` later on.

gcc/rust/ChangeLog:

* resolve/rust-name-resolution-context.h: Add a Labels stack.

7 months agogccrs: Added support to Parse ASYNC function
M V V S Manoj Kumar [Tue, 21 Nov 2023 16:34:24 +0000 (22:04 +0530)]
gccrs: Added support to Parse ASYNC function

Fixes issue #2650
The parser now parses ASYNC functions. Added ASYNC case to parse_item
Added a new function parse_async_item which is called in
parse_vis_item to handle the ASYNC case. Parse_async_item
also checks the current Rust edition and generates an error if the
edition is 2015

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_item): Likewise.
(Parser::parse_vis_item): Likewise.
(Parser::parse_async_item): Likewise.
* parse/rust-parse.h: Made declaration for parse_async_item.

gcc/testsuite/ChangeLog:

* rust/compile/issue-2650-1.rs: New test.(edition=2018)
* rust/compile/issue-2650-2.rs: New test.(edition=2015)

Signed-off-by: M V V S Manoj Kumar <mvvsmanojkumar@gmail.com>
7 months agogccrs: Introduce a proper keyword list
Pierre-Emmanuel Patry [Thu, 16 Nov 2023 15:20:49 +0000 (16:20 +0100)]
gccrs: Introduce a proper keyword list

The old "keyword" list was used for the lexer, and could therefore not
be used with keyword spanning over multiple tokens as those tokens should
remain lexed as is. Hence the introduction of a new list macro for
keyword exclusive tasks. This also means we can no longer match a token
id for each keyword. The token id map has been renamed to keep it's
properties.

gcc/rust/ChangeLog:

* lex/rust-lex.cc (Lexer::classify_keyword): Update keyword map name.
* lex/rust-token.h (enum PrimitiveCoreType): Remove some deprecated
comments.
* util/rust-keyword-values.cc (get_keywords): Update the keyword map
name.
(RS_TOKEN): Define as empty
(RS_TOKEN_KEYWORD_2015): Add the emission value.
(RS_TOKEN_KEYWORD_2018): Likewise.
* util/rust-keyword-values.h (RS_KEYWORD_LIST): Introduce the keyword
list.
(RS_TOKEN_KEYWORD_2018): Define multiple new keywords.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Replace some weak keyword raw value with constexpr
Pierre-Emmanuel Patry [Thu, 16 Nov 2023 14:18:41 +0000 (15:18 +0100)]
gccrs: Replace some weak keyword raw value with constexpr

Raw values may have typos or contain error, replacing those will
improve the codebase.

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): Replace raw value.
* parse/rust-parse-impl.h (Parser::is_macro_rules_def): Likewise.
(Parser::parse_item): Likewise.
(Parser::parse_vis_item): Likewise.
(Parser::parse_macro_rules_def): Likewise.
(Parser::parse_union): Likewise.
(Parser::parse_trait_impl_item): Likewise.
(Parser::parse_stmt): Likewise.
(Parser::parse_stmt_or_expr): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add a list of weak keyword
Pierre-Emmanuel Patry [Thu, 16 Nov 2023 14:02:11 +0000 (15:02 +0100)]
gccrs: Add a list of weak keyword

Retrieving a weak keyword value is done using raw values. Introducing a
list of weak keywords means this could change.

gcc/rust/ChangeLog:

* util/rust-keyword-values.h (class WeakKeywords): Add new class with
weak keyword constexpr.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
This page took 0.118558 seconds and 5 git commands to generate.