platform/upstream/gcc.git
15 months agoPR modula2/109496 Fix constant char parameter passing to an array of char
Gaius Mulley [Thu, 13 Apr 2023 16:02:48 +0000 (17:02 +0100)]
PR modula2/109496 Fix constant char parameter passing to an array of char

This patch fixes PR modula2/109496 and PR modula2/109497.  The fix for
PR modula2/109496 promotes a char constant to a string.  The PR
modula2/109497 allows for constant chars to be added to form a string.
The fixes for both PR's occur in M2GenGCC.mod and M2GCCDeclare.mod
after the resolving of constant declarations.

gcc/m2/ChangeLog:

* gm2-compiler/M2ALU.def (PopChar): New procedure function.
* gm2-compiler/M2ALU.mod (PopChar): New procedure function.
* gm2-compiler/M2GCCDeclare.mod (PromoteToString): Detect
a single constant char and build a C string.
* gm2-compiler/M2GenGCC.mod (IsConstStr): New procedure
function.
(GetStr): New procedure function.
(FoldAdd): Use IsConstStr.
* gm2-compiler/M2Quads.mod: Formatting changes.
* gm2-gcc/m2expr.cc (m2expr_GetCstInteger): New function.
* gm2-gcc/m2expr.def (GetCstInteger): New procedure function.
* gm2-gcc/m2expr.h (m2expr_GetCstInteger): New prototype.

gcc/testsuite/ChangeLog:

PR modula2/109497
* gm2/pim/run/pass/addcharconst.mod: New test.
PR modula2/109496
* gm2/pim/run/pass/singlechar.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
15 months agoaarch64: Don't trust TYPE_ALIGN for pointers [PR108910]
Richard Sandiford [Thu, 13 Apr 2023 15:57:57 +0000 (16:57 +0100)]
aarch64: Don't trust TYPE_ALIGN for pointers [PR108910]

The aarch64 PCS rules ignore user alignment for scalars and
vectors and use the "natural" alignment of the type.  GCC tried
to calculate that natural alignment using:

  TYPE_ALIGN (TYPE_MAIN_VARIANT (type))

But as discussed in the PR, it's possible that the main variant
of a pointer type is an overaligned type (although that's usually
accidental).

This isn't known to be a problem for other types, so this patch
changes the bare minimum.  It might be that we need to ignore
TYPE_ALIGN in other cases too.

gcc/
PR target/108910
* config/aarch64/aarch64.cc (aarch64_function_arg_alignment): Do
not trust TYPE_ALIGN for pointer types; use POINTER_SIZE instead.

gcc/testsuite/
PR target/108910
* gcc.dg/torture/pr108910.c: New test.

15 months agotree-optimization/109491 - ICE in expressions_equal_p
Richard Biener [Thu, 13 Apr 2023 12:09:30 +0000 (14:09 +0200)]
tree-optimization/109491 - ICE in expressions_equal_p

At some point I elided the NULL pointer check in expressions_equal_p
because it shouldn't be necessary not realizing that for example
TARGET_MEM_REF has optional operands we cannot substitute with
something non-NULL with the same semantics.  The following does the
simple thing and restore the check removed in r11-4982.

PR tree-optimization/109491
* tree-ssa-sccvn.cc (expressions_equal_p): Restore the
NULL operands test.

15 months agoDaily bump.
GCC Administrator [Thu, 13 Apr 2023 00:16:48 +0000 (00:16 +0000)]
Daily bump.

15 months agolibstdc++: Document libstdc++exp.a library for -fcontracts
Jonathan Wakely [Wed, 12 Apr 2023 22:23:47 +0000 (23:23 +0100)]
libstdc++: Document libstdc++exp.a library for -fcontracts

libstdc++-v3/ChangeLog:

* doc/xml/manual/using.xml: Document libstdc++exp.a library.
* doc/html/*: Regenerate.

15 months agolibstdc++: Fix some AIX test failures
Jonathan Wakely [Wed, 12 Apr 2023 21:14:05 +0000 (22:14 +0100)]
libstdc++: Fix some AIX test failures

AIX <sys/thread.h> defines struct tstate with non-reserved names, so
adjust the 17_intro/names.cc test. It also defines struct user, which
conflicts with namespace user in some tests.

Replacing the global operator new doesn't work on AIX the same way as it
does for ELF, so skip some tests that depend on replacing it.

Add missing DG directives to synchronized_value test so it doesn't run
for the single-threaded AIX multilib.

libstdc++-v3/ChangeLog:

* testsuite/17_intro/names.cc [_AIX]: Do not define policy.
* testsuite/19_diagnostics/error_code/cons/lwg3629.cc: Rename
namespace to avoid clashing with libc struct.
* testsuite/19_diagnostics/error_condition/cons/lwg3629.cc:
Likewise.
* testsuite/23_containers/unordered_map/96088.cc: Skip on AIX.
* testsuite/23_containers/unordered_multimap/96088.cc: Likewise.
* testsuite/23_containers/unordered_multiset/96088.cc: Likewise.
* testsuite/23_containers/unordered_set/96088.cc: Likewise.
* testsuite/experimental/synchronized_value.cc: Require gthreads
and add missing option for pthreads targets.

15 months agoUpdate gcc de.po
Joseph Myers [Wed, 12 Apr 2023 21:07:51 +0000 (21:07 +0000)]
Update gcc de.po

* de.po: Update.

15 months agolibstdc++: Implement ranges::enumerate_view from P2164R9
Patrick Palka [Wed, 12 Apr 2023 17:24:37 +0000 (13:24 -0400)]
libstdc++: Implement ranges::enumerate_view from P2164R9

libstdc++-v3/ChangeLog:

* include/std/ranges (__cpp_lib_ranges_enumerate): Define
for C++23.
(__detail::__range_with_movable_reference): Likewise.
(enumerate_view): Likewise.
(enumerate_view::_Iterator): Likewise.
(enumerate_view::_Sentinel): Likewise.
(views::__detail::__can_enumerate_view): Likewise.
(views::_Enumerate, views::enumerate): Likewise.
* include/std/version (__cpp_lib_ranges_enumerate): Likewise.
* testsuite/std/ranges/version_c++23.cc: Verify value of
__cpp_lib_ranges_enumerate.
* testsuite/std/ranges/adaptors/enumerate/1.cc: New test.

15 months agolibstdc++: Implement LWG 3904 change to lazy_split_view's iterator
Patrick Palka [Wed, 12 Apr 2023 17:04:36 +0000 (13:04 -0400)]
libstdc++: Implement LWG 3904 change to lazy_split_view's iterator

libstdc++-v3/ChangeLog:

* include/std/ranges (lazy_split_view::_OuterIter::_OuterIter):
Propagate _M_trailing_empty in the const-converting constructor
as per LWG 3904.
* testsuite/std/ranges/adaptors/adjacent/1.cc (test04): Correct
assertion.
* testsuite/std/ranges/adaptors/lazy_split.cc (test12): New test.

15 months agolibstdc++: Ensure headers used by fast_float are included
Patrick Palka [Wed, 12 Apr 2023 16:40:41 +0000 (12:40 -0400)]
libstdc++: Ensure headers used by fast_float are included

This makes floating_from_chars.cc explicitly include all headers
that are used by the original fast_float amalgamation according to
r12-6647-gf5c8b82512f9d3, except:

  1. <cctype> since fast_float doesn't seem to use anything from it
  2. <cinttypes> since fast_float doesn't seem to use anything directly
     from it (this header also pulls in <cstdint>)
  3. <system_error> since std::errc is naturally already available
     from <charconv>

This avoids potential fast_float build failures on platforms for which
some required headers (in particular <cstdint>) end up not getting
transitively included from elsewhere.

libstdc++-v3/ChangeLog:

* src/c++17/floating_from_chars.cc: Include <algorithm>,
<iterator>, <limits> and <cstdint>.

15 months agoUpdate gcc .po files
Joseph Myers [Wed, 12 Apr 2023 16:18:32 +0000 (16:18 +0000)]
Update gcc .po files

* be.po, da.po, de.po, el.po, es.po, fi.po, fr.po, hr.po, id.po,
ja.po, nl.po, ru.po, sr.po, sv.po, tr.po, uk.po, vi.po, zh_CN.po,
zh_TW.po: Update.

15 months agolibstdc++: Fix chunk_by_view when value_type& and reference differ [PR108291]
Patrick Palka [Wed, 12 Apr 2023 16:10:23 +0000 (12:10 -0400)]
libstdc++: Fix chunk_by_view when value_type& and reference differ [PR108291]

PR libstdc++/108291

libstdc++-v3/ChangeLog:

* include/std/ranges (chunk_by_view::_M_find_next): Generalize
parameter types of the lambda wrapper passed to adjacent_find.
(chunk_by_view::_M_find_prev): Likewise.
* testsuite/std/ranges/adaptors/chunk_by/1.cc (test04, test05):
New tests.

15 months agoRISC-V: Fix supporting data type according to RVV ISA. [PR109479]
Ju-Zhe Zhong [Wed, 12 Apr 2023 13:56:05 +0000 (21:56 +0800)]
RISC-V: Fix supporting data type according to RVV ISA. [PR109479]

For vint64m*_t, we should only allow them in zve64* instead of zve32*_zvl64b (>=64b).
Ideally, we should make error message more friendly like Clang.
https://godbolt.org/z/f9GMv4dMo to report the RVV type require extenstion name.
However, I failed to find a way to do that. So current GCC can only report "unknown" type.
And I added comments to remind us doing this in the future.

gcc/ChangeLog:

PR target/109479
* config/riscv/riscv-vector-builtins-types.def (vint8mf8_t): Fix predicate.
(vint16mf4_t): Ditto.
(vint32mf2_t): Ditto.
(vint64m1_t): Ditto.
(vint64m2_t): Ditto.
(vint64m4_t): Ditto.
(vint64m8_t): Ditto.
(vuint8mf8_t): Ditto.
(vuint16mf4_t): Ditto.
(vuint32mf2_t): Ditto.
(vuint64m1_t): Ditto.
(vuint64m2_t): Ditto.
(vuint64m4_t): Ditto.
(vuint64m8_t): Ditto.
(vfloat32mf2_t): Ditto.
(vbool64_t): Ditto.
* config/riscv/riscv-vector-builtins.cc (register_builtin_type): Add comments.
(register_vector_type): Ditto.
(check_required_extensions): Fix condition.
* config/riscv/riscv-vector-builtins.h (RVV_REQUIRE_ZVE64): Remove it.
(RVV_REQUIRE_ELEN_64): New define.
(RVV_REQUIRE_MIN_VLEN_64): Ditto.
* config/riscv/riscv-vector-switch.def (TARGET_VECTOR_FP32): Remove it.
(TARGET_VECTOR_FP64): Ditto.
(ENTRY): Fix predicate.
* config/riscv/vector-iterators.md: Fix predicate.

gcc/testsuite/ChangeLog:

PR target/109479
* gcc.target/riscv/rvv/base/pr109479-1.c: New test.
* gcc.target/riscv/rvv/base/pr109479-2.c: New test.
* gcc.target/riscv/rvv/base/pr109479-3.c: New test.
* gcc.target/riscv/rvv/base/pr109479-4.c: New test.
* gcc.target/riscv/rvv/base/pr109479-5.c: New test.
* gcc.target/riscv/rvv/base/pr109479-6.c: New test.

15 months agoreassoc: Fix up another ICE with returns_twice call [PR109410]
Jakub Jelinek [Wed, 12 Apr 2023 14:55:15 +0000 (16:55 +0200)]
reassoc: Fix up another ICE with returns_twice call [PR109410]

The following testcase ICEs in reassoc, unlike the last case I've fixed
there here SSA_NAME_USED_IN_ABNORMAL_PHI is not the case anywhere.
build_and_add_sum places new statements after the later appearing definition
of an operand but if both operands are default defs or constants, we place
statement at the start of the function.

If the very first statement of a function is a call to returns_twice
function, this doesn't work though, because that call has to be the first
thing in its basic block, so the following patch splits the entry successor
edge such that the new statements are added into a different block from the
returns_twice call.

I think we should in stage1 reconsider such placements, I think it
unnecessarily enlarges the lifetime of the new lhs if its operand(s)
are used more than once in the function.  Unless something sinks those
again.  Would be nice to place it closer to the actual uses (or where
they will be placed).

2023-04-12  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/109410
* tree-ssa-reassoc.cc (build_and_add_sum): Split edge from entry
block if first statement of the function is a call to returns_twice
function.

* gcc.dg/pr109410.c: New test.

15 months agoi386: Fix up z operand modifier diagnostics on inline-asm [PR109458]
Jakub Jelinek [Wed, 12 Apr 2023 14:53:23 +0000 (16:53 +0200)]
i386: Fix up z operand modifier diagnostics on inline-asm [PR109458]

On the following testcase, we emit weird diagnostics.
User used the z modifier, but diagnostics talks about Z instead.
This is because z is implemented by doing some stuff and then falling
through into the Z case.

The following patch adjusts the Z diagnostics, such that it prints whatever
modifier user actually uses in places which could happen with either
modifier.

Furthermore, in case of the non-integer operand used with operand code %<z%>
warning the warning location was incorrect (and of function), so I've used
warning_for_asm to get it a proper location in case it is a user inline-asm.

2023-04-12  Jakub Jelinek  <jakub@redhat.com>

PR target/109458
* config/i386/i386.cc: Include rtl-error.h.
(ix86_print_operand): For z modifier warning, use warning_for_asm
if this_is_asm_operands.  For Z modifier errors, use %c and code
instead of hardcoded Z.

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

15 months agomingw: Support building with older gcc versions
Costas Argyris [Wed, 12 Apr 2023 07:48:18 +0000 (08:48 +0100)]
mingw: Support building with older gcc versions

The $@ argument to the compiler is causing
only a warning in some gcc versions but an
error in others. In any case, $@ was never
necessary so remove it completely, just like
the rules in x-mingw32 where the object file
gets named after the source file.

This fixes both warnings and errors about
sym-mingw32.o appearing in the command line
unnecessarily.

The -nostdlib flag is required along with -r
for older gcc versions that don't apply it
automatically with -r, resulting in main
functions erroneously entering a partial link.

Signed-off-by: Jonathan Yong <10walls@gmail.com>
gcc/ChangeLog:

* config/i386/x-mingw32-utf8: Remove extrataneous $@

15 months agoc++: Fix Solaris bootstraps across midnight
Jakub Jelinek [Wed, 12 Apr 2023 14:22:28 +0000 (16:22 +0200)]
c++: Fix Solaris bootstraps across midnight

When working on the PR109040 fix, I wanted to test it on some
WORD_REGISTER_OPERATIONS target and tried sparc-solaris on GCC Farm.
My bootstrap failed in comparison failure on cp/module.o, because
Solaris date doesn't support the -r option and one stage's cp/module.o
was built before midnight and next stage's cp/module.o after midnight,
so they had different -DMODULE_VERSION= value.

Now, I think the advice (don't bootstrap at midnight) is something
we shouldn't have, so the following patch stores the module version
(still generated through the same way, date -r cp/module.cc
if it works, otherwise just date) into a temporary file, makes sure
that temporary file is updated when cp/module.cc source is updated
and when date -r doesn't work copies file from previous stage
if it is newer than cp/module.cc.

2023-04-12  Jakub Jelinek  <jakub@redhat.com>

* Make-lang.in (s-cp-module-version): New target.
(cp/module.o): Depend on it.
(MODULE_VERSION): Remove variable.
(CFLAGS-cp/module.o): For -DMODULE_VERSION= argument just
cat s-cp-module-version.

15 months agotestsuite: Add testcase for recently fixed PR [PR109462]
Jakub Jelinek [Wed, 12 Apr 2023 13:16:31 +0000 (15:16 +0200)]
testsuite: Add testcase for recently fixed PR [PR109462]

This adds a runtime testcase for just fixed PR.

2023-04-12  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/109462
* g++.dg/opt/pr109462.C: New test.

15 months agoDon't use ANY PHI equivalences in range-on-entry.
Andrew MacLeod [Tue, 11 Apr 2023 21:29:03 +0000 (17:29 -0400)]
Don't use ANY PHI equivalences in range-on-entry.

PR 108139 dissallows PHI equivalencies in the on-entry calculator, but
it was only checking if the equivlaence was a PHI.  In this case, NAME
itself is a PHI with an equivlaence caused by an undefined value, so we
also need to check that case.  Unfortunately this un-fixes 101912.

PR tree-optimization/109462
gcc/
* gimple-range-cache.cc (ranger_cache::fill_block_cache): Don't
check for equivalences if NAME is a phi node.

gcc/testsuite/
* gcc.dg/uninit-pr101912.c: XFAIL the warning.

15 months agolibstdc++: Initialize all members of basic_endpoint union [PR109482]
Jonathan Wakely [Wed, 12 Apr 2023 10:55:24 +0000 (11:55 +0100)]
libstdc++: Initialize all members of basic_endpoint union [PR109482]

On Solaris the in_addr struct contains a union and value-initializing it
does not make the s_addr member active. This means we can't access that
member later during constant evaluation.

Make the constructors explicitly set every member that we might want to
read later in constexpr member functions. This means even the default
constructor can only be constexpr for C++20, because we can't change the
active member of a union in older standards.

libstdc++-v3/ChangeLog:

PR libstdc++/109482
* include/experimental/internet (basic_endpoint::basic_endpoint()):
Ensure that the required union members are active. Only define
as constexpr for C++20 and later.
(basic_endpoint::basic_endpoint(const protocol_type&, port_type)):
Likewise.
* testsuite/experimental/net/internet/endpoint/cons.cc: Only
check constexpr default constructor for C++20 and later.
* testsuite/experimental/net/internet/endpoint/extensible.cc:
Likewise.

15 months agolibstdc++: Update tzdata to 2023c
Jonathan Wakely [Mon, 27 Mar 2023 12:51:25 +0000 (13:51 +0100)]
libstdc++: Update tzdata to 2023c

Import the new 2023c tzdata.zi file.

libstdc++-v3/ChangeLog:

* src/c++20/tzdata.zi: Import new file from 2023c release.

15 months agotree-optimization/109473 - ICE with reduction epilog adjustment op
Richard Biener [Wed, 12 Apr 2023 08:22:08 +0000 (10:22 +0200)]
tree-optimization/109473 - ICE with reduction epilog adjustment op

The following makes sure to carry out the reduction epilog adjustment
in the original computation type which for pointers is an unsigned
integer type.  There's a similar issue with signed vs. unsigned ops
and overflow which is fixed by this as well.

PR tree-optimization/109473
* tree-vect-loop.cc (vect_create_epilog_for_reduction):
Convert scalar result to the computation type before performing
the reduction adjustment.

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

15 months agoFortran: fix functions with entry and pointer/allocatable result [PR104312]
Harald Anlauf [Tue, 11 Apr 2023 19:44:20 +0000 (21:44 +0200)]
Fortran: fix functions with entry and pointer/allocatable result [PR104312]

gcc/fortran/ChangeLog:

PR fortran/104312
* resolve.cc (resolve_entries): Handle functions with ENTRY and
ALLOCATABLE results.
* trans-expr.cc (gfc_conv_procedure_call): Functions with a result
with the POINTER or ALLOCATABLE attribute shall not get any special
treatment with -ff2c, as they cannot be written in Fortran 77.
* trans-types.cc (gfc_return_by_reference): Likewise.
(gfc_get_function_type): Likewise.

gcc/testsuite/ChangeLog:

PR fortran/104312
* gfortran.dg/entry_26.f90: New test.
* gfortran.dg/entry_27.f90: New test.

15 months agoFortran: resolve correct generic with TYPE(C_PTR) arguments [PR61615,PR99982]
Harald Anlauf [Tue, 11 Apr 2023 14:44:32 +0000 (16:44 +0200)]
Fortran: resolve correct generic with TYPE(C_PTR) arguments [PR61615,PR99982]

gcc/fortran/ChangeLog:

PR fortran/61615
PR fortran/99982
* interface.cc (compare_parameter): Enable type and rank checks for
arguments of derived type from the intrinsic module ISO_C_BINDING.

gcc/testsuite/ChangeLog:

PR fortran/61615
PR fortran/99982
* gfortran.dg/interface_49.f90: New test.

15 months agotree-optimization/109469 - SLP with returns-twice region start
Richard Biener [Tue, 11 Apr 2023 14:06:12 +0000 (16:06 +0200)]
tree-optimization/109469 - SLP with returns-twice region start

The following avoids an SLP region starting with a returns-twice
call where we cannot insert stmts at the head.

PR tree-optimization/109469
* tree-vect-slp.cc (vect_slp_function): Skip region starts with
a returns-twice call.

* gcc.dg/torture/pr109469.c: New testcase.

15 months agotree-optimization/109434 - bogus DSE of throwing call LHS
Richard Biener [Tue, 11 Apr 2023 13:06:59 +0000 (15:06 +0200)]
tree-optimization/109434 - bogus DSE of throwing call LHS

The byte tracking of call LHS didn't properly handle possibly
throwing calls correctly which cases bogus DSE and in turn, for the
testcase a bogus uninit diagnostic and (unreliable) wrong-code.

PR tree-optimization/109434
* tree-ssa-dse.cc (initialize_ao_ref_for_dse): Properly
handle possibly throwing calls when processing the LHS
and may-defs are not OK.

* g++.dg/opt/pr109434.C: New testcase.

15 months agotestsuite: Adjust powerpc pr83677.c for BE [PR108815]
Kewen Lin [Wed, 12 Apr 2023 02:51:40 +0000 (21:51 -0500)]
testsuite: Adjust powerpc pr83677.c for BE [PR108815]

The test case gcc.target/powerpc/pr83677.c was written for
LE environment, this patch is to make it work on BE as well.

PR testsuite/108815

gcc/testsuite/ChangeLog:

* gcc.target/powerpc/pr83677.c (v_expand_u8, v_expand_u16,
v_load_deinterleave_f32, v_store_interleave_f32): Adjust some code by
considering BE.

15 months agoUpdate gcc sv.po
Joseph Myers [Wed, 12 Apr 2023 00:21:00 +0000 (00:21 +0000)]
Update gcc sv.po

* sv.po: Update.

15 months agoDaily bump.
GCC Administrator [Wed, 12 Apr 2023 00:16:46 +0000 (00:16 +0000)]
Daily bump.

15 months agoRISC-V: avoid splitting small constant in <or_optab>i<mode>_extrabit pattern
Lin Sinan [Tue, 11 Apr 2023 16:23:19 +0000 (10:23 -0600)]
RISC-V: avoid splitting small constant in <or_optab>i<mode>_extrabit pattern

there is no need to split an xori/ori with an small constant. take the test
case `int foo(int idx) { return idx|3; }` as an example,

rv64im_zba generates:
        ori     a0,a0,3
        ret
but, rv64im_zba_zbs generates:
        ori     a0,a0,1
        ori     a0,a0,2
        ret

with this change, insn `ori r2,r1,3` will not be splitted in zbs.

gcc/
* config/riscv/predicates.md (uimm_extra_bit_or_twobits): Adjust
predicate to avoid splitting arith constants.

gcc/testsuite

* gcc.target/riscv/zbs-extra-bit-or-twobits.c: New test.

15 months agoRISC-V: Fix regression of -fzero-call-used-regs=all [PR109104]
Yanzhang Wang [Tue, 11 Apr 2023 11:37:48 +0000 (19:37 +0800)]
RISC-V: Fix regression of -fzero-call-used-regs=all [PR109104]

This patch registers a riscv specific function to
TARGET_ZERO_CALL_USED_REGS instead of default in targhooks.cc. It will
clean gpr and vector relevant registers.

gcc/ChangeLog:

PR target/109104
* config/riscv/riscv-protos.h (emit_hard_vlmax_vsetvl): New.
* config/riscv/riscv-v.cc (emit_hard_vlmax_vsetvl): New.
(emit_vlmax_vsetvl): Use emit_hard_vlmax_vsetvl.
* config/riscv/riscv.cc (vector_zero_call_used_regs): New.
(riscv_zero_call_used_regs): New.
(TARGET_ZERO_CALL_USED_REGS): New.

gcc/testsuite/ChangeLog:

PR target/109104
* gcc.target/riscv/zero-scratch-regs-1.c: New test.
* gcc.target/riscv/zero-scratch-regs-2.c: New test.
* gcc.target/riscv/zero-scratch-regs-3.c: New test.

Signed-off-by: Yanzhang Wang <yanzhang.wang@intel.com>
Co-authored-by: Pan Li <pan2.li@intel.com>
Co-authored-by: Ju-Zhe Zhong <juzhe.zhong@rivai.ai>
Co-authored-by: Kito Cheng <kito.cheng@sifive.com>
15 months agogfortran.dg/gomp/affinity-clause-1.f90: Fix scan-tree-dump
Tobias Burnus [Tue, 11 Apr 2023 11:15:39 +0000 (13:15 +0200)]
gfortran.dg/gomp/affinity-clause-1.f90: Fix scan-tree-dump

Commit r13-7120-g46fe32cb4d887d44a62f9c4ff2a72532d4eb5a19 added the
missing hyphen to 'dg-final', which exposed an -m32 pattern mismatch.

gcc/testsuite/

* gfortran.dg/gomp/affinity-clause-1.f90: Update scan-tree pattern
for -m32.

15 months agodriver: drop flag_var_tracking_assignments flag
Martin Liska [Fri, 31 Mar 2023 12:28:15 +0000 (14:28 +0200)]
driver: drop flag_var_tracking_assignments flag

The revision r13-259-g76db543db88727 moved a condition from one
file to another, but now we do not drop x_flag_var_tracking_assignments
as it was done before the mentioned revision.

PR driver/108241

gcc/ChangeLog:

* opts.cc (finish_options): Drop also
x_flag_var_tracking_assignments.

gcc/testsuite/ChangeLog:

* gcc.dg/pr108241.c: New test.
* gcc.dg/pr79570.c: Add also -g option.

15 months agoif-conv: Restore MASK_CALL conversion [PR108888]
Andre Vieira [Tue, 11 Apr 2023 09:07:43 +0000 (10:07 +0100)]
if-conv: Restore MASK_CALL conversion [PR108888]

The original patch to fix this PR broke the if-conversion of calls into
IFN_MASK_CALL.  This patch restores that original behaviour and makes sure the
tests added earlier specifically test inbranch SIMD clones.

gcc/ChangeLog:

PR tree-optimization/108888
* tree-if-conv.cc (predicate_statements): Fix gimple call check.

gcc/testsuite/ChangeLog:

* gcc.dg/vect/vect-simd-clone-16.c: Make simd clone inbranch only.
* gcc.dg/vect/vect-simd-clone-17.c: Likewise.
* gcc.dg/vect/vect-simd-clone-18.c: Likewise.

15 months agors6000: correct vector sign extend builtins on Big Endian
Haochen Gui [Tue, 11 Apr 2023 00:55:56 +0000 (08:55 +0800)]
rs6000: correct vector sign extend builtins on Big Endian

gcc/
PR target/108812
* config/rs6000/vsx.md (vsx_sign_extend_qi_<mode>): Rename to...
(vsx_sign_extend_v16qi_<mode>): ... this.
(vsx_sign_extend_hi_<mode>): Rename to...
(vsx_sign_extend_v8hi_<mode>): ... this.
(vsx_sign_extend_si_v2di): Rename to...
(vsx_sign_extend_v4si_v2di): ... this.
(vsignextend_qi_<mode>): Remove.
(vsignextend_hi_<mode>): Remove.
(vsignextend_si_v2di): Remove.
(vsignextend_v2di_v1ti): Remove.
(*xxspltib_<mode>_split): Replace gen_vsx_sign_extend_qi_v2di with
gen_vsx_sign_extend_v16qi_v2di and gen_vsx_sign_extend_qi_v4si
with gen_vsx_sign_extend_v16qi_v4si.
* config/rs6000/rs6000.md (split for DI constant generation):
Replace gen_vsx_sign_extend_qi_si with gen_vsx_sign_extend_v16qi_si.
(split for HSDI constant generation): Replace gen_vsx_sign_extend_qi_di
with gen_vsx_sign_extend_v16qi_di and gen_vsx_sign_extend_qi_si
with gen_vsx_sign_extend_v16qi_si.
* config/rs6000/rs6000-builtins.def (__builtin_altivec_vsignextsb2d):
Set bif-pattern to vsx_sign_extend_v16qi_v2di.
(__builtin_altivec_vsignextsb2w): Set bif-pattern to
vsx_sign_extend_v16qi_v4si.
(__builtin_altivec_visgnextsh2d): Set bif-pattern to
vsx_sign_extend_v8hi_v2di.
(__builtin_altivec_vsignextsh2w): Set bif-pattern to
vsx_sign_extend_v8hi_v4si.
(__builtin_altivec_vsignextsw2d): Set bif-pattern to
vsx_sign_extend_si_v2di.
(__builtin_altivec_vsignext): Set bif-pattern to
vsx_sign_extend_v2di_v1ti.
* config/rs6000/rs6000-builtin.cc (lxvrse_expand_builtin): Replace
gen_vsx_sign_extend_qi_v2di with gen_vsx_sign_extend_v16qi_v2di,
gen_vsx_sign_extend_hi_v2di with gen_vsx_sign_extend_v8hi_v2di and
gen_vsx_sign_extend_si_v2di with gen_vsx_sign_extend_v4si_v2di.

gcc/testsuite/
PR target/108812
* gcc.target/powerpc/p9-sign_extend-runnable.c: Set corresponding
expected vectors for Big Endian.
* gcc.target/powerpc/int_128bit-runnable.c: Likewise.

15 months agoDaily bump.
GCC Administrator [Tue, 11 Apr 2023 00:16:33 +0000 (00:16 +0000)]
Daily bump.

15 months agoDo not generate vmaddfp and vnmsubfp
Michael Meissner [Mon, 10 Apr 2023 03:32:27 +0000 (23:32 -0400)]
Do not generate vmaddfp and vnmsubfp

This is version 3 of the patch.  This is essentially version 1 with the removal
of changes to altivec.md, and cleanup of the comments.

Version 2 generated the vmaddfp and vnmsubfp instructions if -Ofast was used,
and those changes are deleted in this patch.

The Altivec instructions vmaddfp and vnmsubfp have different rounding behaviors
than the VSX xvmaddsp and xvnmsubsp instructions due to VSCR[NJ] and other
corner cases.  In particular, generating these instructions seems to break
Eigen on big endian systems.

2023-04-09   Michael Meissner  <meissner@linux.ibm.com>

gcc/

PR target/70243
* config/rs6000/vsx.md (vsx_fmav4sf4): Do not generate vmaddfp.
(vsx_nfmsv4sf4): Do not generate vnmsubfp.

gcc/testsuite/

PR target/70243
* gcc.target/powerpc/pr70243.c: New test.

15 months agoi386: Add AMX-COMPLEX to Granite Rapids
Haochen Jiang [Fri, 31 Mar 2023 02:49:14 +0000 (10:49 +0800)]
i386: Add AMX-COMPLEX to Granite Rapids

gcc/Changelog:

* config/i386/i386.h (PTA_GRANITERAPIDS): Add PTA_AMX_COMPLEX.

15 months agoSupport Intel AMX-COMPLEX
Haochen Jiang [Wed, 31 May 2023 02:45:00 +0000 (10:45 +0800)]
Support Intel AMX-COMPLEX

gcc/ChangeLog:

* common/config/i386/cpuinfo.h (get_available_features):
Detect AMX-COMPLEX.
* common/config/i386/i386-common.cc
(OPTION_MASK_ISA2_AMX_COMPLEX_SET,
OPTION_MASK_ISA2_AMX_COMPLEX_UNSET): New.
(ix86_handle_option): Handle -mamx-complex.
* common/config/i386/i386-cpuinfo.h (enum processor_features):
Add FEATURE_AMX_COMPLEX.
* common/config/i386/i386-isas.h: Add ISA_NAME_TABLE_ENTRY for
amx-complex.
* config.gcc: Add amxcomplexintrin.h.
* config/i386/cpuid.h (bit_AMX_COMPLEX): New.
* config/i386/i386-c.cc (ix86_target_macros_internal): Define
__AMX_COMPLEX__.
* config/i386/i386-isa.def (AMX_COMPLEX): Add DEF_PTA(AMX_COMPLEX).
* config/i386/i386-options.cc (ix86_valid_target_attribute_inner_p):
Handle amx-complex.
* config/i386/i386.opt: Add option -mamx-complex.
* config/i386/immintrin.h: Include amxcomplexintrin.h.
* doc/extend.texi: Document amx-complex.
* doc/invoke.texi: Document -mamx-complex.
* doc/sourcebuild.texi: Document target amx-complex.
* config/i386/amxcomplexintrin.h: New file.

gcc/testsuite/ChangeLog:

* g++.dg/other/i386-2.C: Add -mamx-complex.
* g++.dg/other/i386-3.C: Ditto.
* gcc.target/i386/amx-check.h: Add cpu check for AMX-COMPLEX.
* gcc.target/i386/amx-helper.h: Add amx-complex support.
* gcc.target/i386/funcspec-56.inc: Add new target attribute.
* gcc.target/i386/sse-12.c: Add -mamx-complex.
* gcc.target/i386/sse-13.c: Ditto.
* gcc.target/i386/sse-14.c: Ditto.
* gcc.target/i386/sse-22.c: Add amx-complex.
* gcc.target/i386/sse-23.c: Ditto.
* lib/target-supports.exp (check_effective_target_amx_complex): New.
* gcc.target/i386/amxcomplex-asmatt-1.c: New test.
* gcc.target/i386/amxcomplex-asmintel-1.c: Ditto.
* gcc.target/i386/amxcomplex-cmmimfp16ps-2.c: Ditto.
* gcc.target/i386/amxcomplex-cmmrlfp16ps-2.c: Ditto.

15 months agoDaily bump.
GCC Administrator [Mon, 10 Apr 2023 00:16:39 +0000 (00:16 +0000)]
Daily bump.

15 months agoc++, coroutines: Fix block nests when the function has no top-level bind.
Iain Sandoe [Sat, 1 Apr 2023 16:23:51 +0000 (21:53 +0530)]
c++, coroutines: Fix block nests when the function has no top-level bind.

When the function contains no local vars and also no nested scopes, there
is no top-level bind expression.  Because the rewritten coroutine body will
require both local vars and contain nested scopes, we add a bind expression
to such functions.  When this was done the necessary scope blocks were
omitted which leads to disconnected function content.

Fixed by adding a new block to the added bind expression.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
gcc/cp/ChangeLog:

* coroutines.cc (coro_rewrite_function_body): Ensure that added
bind expressions have scope blocks.

15 months agoDaily bump.
GCC Administrator [Sun, 9 Apr 2023 00:16:37 +0000 (00:16 +0000)]
Daily bump.

15 months agoPR tree-optimization/109392
Jakub Jelinek [Sat, 8 Apr 2023 18:21:42 +0000 (12:21 -0600)]
PR tree-optimization/109392

If we have an object with SSA_NAME_OCCURS_IN_ABNORMAL_PHI, then
maybe_push_res_to_seq may fail.  Directly build the extraction
for that case.

PR tree-optimization/109392

gcc/
* tree-vect-generic.cc (tree_vec_extract): Handle failure
of maybe_push_res_to_seq better.

gcc/testsuite/

* gcc.dg/pr109392.c: New test.

15 months agoxfail gcc.dg/long_branch.c on hppa.
John David Anglin [Sat, 8 Apr 2023 17:25:25 +0000 (17:25 +0000)]
xfail gcc.dg/long_branch.c on hppa.

2023-04-08  John David Anglin  <danglin@gcc.gnu.org>

gcc/testsuite/ChangeLog:

* gcc.dg/pr84877.c: xfail on hppa*-*-*.

15 months agoFix gcc.dg/long_branch.c on hppa.
John David Anglin [Sat, 8 Apr 2023 16:01:26 +0000 (16:01 +0000)]
Fix gcc.dg/long_branch.c on hppa.

2023-04-08  John David Anglin  <danglin@gcc.gnu.org>

gcc/testsuite/ChangeLog:

* gcc.dg/long_branch.c: Use timeout factor 2.0 on hppa*-*-*.

15 months agoPR target/109402: v850 (not v850e) variant of __muldi3() moves sp in reversed directi...
Tetsuma Hoshino [Sat, 8 Apr 2023 14:19:53 +0000 (08:19 -0600)]
PR target/109402: v850 (not v850e) variant of __muldi3() moves sp in reversed direction [PR109402]

muldi3 will deallocate stack space after the call to __save_r26_r31,
then re-allocate the space a short while later.  If an interrupt
occurs in that window, it can clobber items on the stack.

PR target/109402

libgcc/
* config/v850/lib1funcs.S (___muldi3): Remove unnecessary
stack manipulations.

15 months agoriscv: Fix genrvv-type-indexer dependencies
Jakub Jelinek [Sat, 8 Apr 2023 10:05:04 +0000 (12:05 +0200)]
riscv: Fix genrvv-type-indexer dependencies

I've noticed
make: Circular build/genrvv-type-indexer.o <- gtype-desc.h dependency dropped.

The following patch fixes that.  The RTL_BASE_H variable includes a lot of
headers which the generator doesn't include, including gtype-desc.h.
I've preprocessed it and checked all gcc/libiberty headers against what is
included in the other dependency variables and here is what I found:
1) coretypes.h includes align.h, poly-int.h and poly-int-types.h which
   weren't listed (most of dependencies are thankfully done automatically,
   so it isn't that big deal except for these generators and the like)
2) system.h includes filenames.h (already listed) but filenames.h includes
   hashtab.h; instead of adding FILENAMES_H I've just added the dependency
   to SYSTEM_H
3) $(RTL_BASE_H) wasn't really needed at all and insn-modes.h is already
   included in $(CORETYPES_H)

2023-04-08  Jakub Jelinek  <jakub@redhat.com>

* Makefile.in (CORETYPES_H): Depend on align.h, poly-int.h and
poly-int-types.h.
(SYSTEM_H): Depend on $(HASHTAB_H).
* config/riscv/t-riscv (build/genrvv-type-indexer.o): Remove unused
dependency on $(RTL_BASE_H), remove redundant dependency on
insn-modes.h.

15 months agoFortran: Fix some of the bugs in associate [PR87477]
Paul Thomas [Sat, 8 Apr 2023 08:04:13 +0000 (09:04 +0100)]
Fortran: Fix some of the bugs in associate [PR87477]

2023-04-08  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
PR fortran/87477
* iresolve.cc (gfc_resolve_adjustl, gfc_resolve_adjustr): if
string length is deferred use the string typespec for result.
* resolve.cc (resolve_assoc_var): Handle parentheses around the
target expression.
(resolve_block_construct): Remove unnecessary static decls.
* trans-array.cc (gfc_conv_expr_descriptor): Guard string len
expression in condition. Improve handling of string length and
span, especially for substrings of the descriptor.
(duplicate_allocatable): Make element type more explicit with
'eltype'.
* trans-decl.cc (gfc_get_symbol_decl): Emit a fatal error with
appropriate message instead of ICE if symbol type is unknown.
(gfc_generate_function_code): Set current locus to proc_sym
declared_at.
* trans-expr.cc (gfc_get_expr_charlen): Retain last charlen in
'previous' and use if end expression in substring reference is
null.
(gfc_conv_string_length): Use gfc_conv_expr_descriptor if
'expr_flat' is an array. Add post block to catch deallocation
of temporaries.
(gfc_conv_procedure_call): Assign the parmse string length to
the expression string length, if it is deferred.
(gfc_trans_alloc_subarray_assign): If this is a deferred string
length component, store the string length in the hidden comp.
Update the typespec length accordingly. Generate a new type
spec for the call to gfc_duplicate-allocatable in this case.
* trans-io.cc (gfc_trans_transfer): Scalarize transfer of
deferred character array components.

gcc/testsuite/
PR fortran/87477
* gfortran.dg/associate_47.f90 : Enable substring test.
* gfortran.dg/associate_51.f90 : Update an error message.
* gfortran.dg/goacc/array-with-dt-2.f90 : Add span to
uninitialzed dg-warnings.

PR fortran/85686
PR fortran/88247
PR fortran/91941
PR fortran/92779
PR fortran/93339
PR fortran/93813
PR fortran/100948
PR fortran/102106
* gfortran.dg/associate_60.f90 : New test

PR fortran/98408
* gfortran.dg/pr98408.f90 : New test

PR fortran/105205
* gfortran.dg/pr105205.f90 : New test

PR fortran/106918
* gfortran.dg/pr106918.f90 : New test

15 months agoFortran: Fix dg directives and remove trailing whitespaces in testsuite
Paul Thomas [Sat, 8 Apr 2023 06:49:13 +0000 (07:49 +0100)]
Fortran: Fix dg directives and remove trailing whitespaces in testsuite

2023-04-08   Paul Thomas  <pault@gcc.gnu.org>

* gfortran.dg/c-interop/allocatable-optional-pointer.f90 : Fix
dg directive and remove trailing whitespace.
* gfortran.dg/c-interop/c407a-1.f90 : ditto
* gfortran.dg/c-interop/c407b-1.f90 : ditto
* gfortran.dg/c-interop/c407b-2.f90 : ditto
* gfortran.dg/c-interop/c407c-1.f90 : ditto
* gfortran.dg/c-interop/c535a-1.f90 : ditto
* gfortran.dg/c-interop/c535a-2.f90 : ditto
* gfortran.dg/c-interop/c535b-1.f90 : ditto
* gfortran.dg/c-interop/c535b-2.f90 : ditto
* gfortran.dg/c-interop/c535b-3.f90 : ditto
* gfortran.dg/c-interop/c535c-1.f90 : ditto
* gfortran.dg/c-interop/c535c-2.f90 : ditto
* gfortran.dg/c-interop/deferred-character-1.f90 : ditto
* gfortran.dg/c-interop/removed-restrictions-1.f90 : ditto
* gfortran.dg/c-interop/removed-restrictions-2.f90 : ditto
* gfortran.dg/c-interop/removed-restrictions-4.f90 : ditto
* gfortran.dg/c-interop/tkr.f90 : ditto
* gfortran.dg/class_result_10.f90 : ditto
* gfortran.dg/dtio_35.f90 : ditto
* gfortran.dg/gomp/affinity-clause-1.f90 : ditto
* gfortran.dg/pr103258.f90 : ditto
* gfortran.dg/pr59107.f90 : ditto
* gfortran.dg/pr93835.f08 : ditto

15 months agoDaily bump.
GCC Administrator [Sat, 8 Apr 2023 00:16:33 +0000 (00:16 +0000)]
Daily bump.

15 months agomime: remove test ordering dependency
Ian Lance Taylor [Fri, 7 Apr 2023 20:27:04 +0000 (13:27 -0700)]
mime: remove test ordering dependency

Backport CL 421442 from upstream.

Original description:

Arrange for tests that call setMimeInit to fully restore the old values,
by clearing the sync.Once that controls initialization.

Once we've done that, call initMime in initMimeUnixTest because
otherwise the test types loaded there will be cleared by the call to
initMime that previously was not being done.

For golang/go#51648

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/483117

15 months ago[testsuite] [ppc] skip ppc-fortran if fortran is disabled
Alexandre Oliva [Fri, 7 Apr 2023 04:04:32 +0000 (01:04 -0300)]
[testsuite] [ppc] skip ppc-fortran if fortran is disabled

Skip ppc-fortran.exp if a trivial fortran program cannot be compiled.

for  gcc/testsuite/ChangeLog

* gcc.target/powerpc/ppc-fortran/ppc-fortran.exp: Test for
fortran compiler, skip if missing.

15 months agoDaily bump.
GCC Administrator [Fri, 7 Apr 2023 00:17:36 +0000 (00:17 +0000)]
Daily bump.

15 months agoarm: remove unused variables from test
Stam Markianos-Wright [Thu, 6 Apr 2023 17:57:08 +0000 (18:57 +0100)]
arm: remove unused variables from test

This is just a minor issue I found with a previous test
of mine that caused it to fail in C++ mode due to these
unused const variables being uninitialised. I forgot to
remove these after removing some test cases that did use
them. I removed the test cases, because I came to the
conclusion that the const-ness of the immediate was
irrelevant to the test itself.
Removing the variables now makes the test PASS for C++.

gcc/testsuite/ChangeLog:

* gcc.target/arm/mve/intrinsics/mve_intrinsic_type_overloads-fp.c: Remove unused variables.
* gcc.target/arm/mve/intrinsics/mve_intrinsic_type_overloads-int.c: Remove unused variables.

15 months agoarm: mve: fix auto-inc generation [PR107674]
Richard Earnshaw [Thu, 6 Apr 2023 13:44:30 +0000 (14:44 +0100)]
arm: mve: fix auto-inc generation [PR107674]

My change r13-416-g485a0ae0982abe caused the compiler to stop
generating auto-inc operations on mve loads and stores.  The fix
is to check whether there is a replacement register available
when in strict mode and the register is still a pseudo.

gcc:

PR target/107674
* config/arm/arm.cc (arm_effective_regno): New function.
(mve_vector_mem_operand): Use it.

15 months agoCheck if dependency is valid before using in may_recompute_p.
Andrew MacLeod [Wed, 5 Apr 2023 19:59:38 +0000 (15:59 -0400)]
Check if dependency is valid before using in may_recompute_p.

When the IL is rewritten after a statement has been processed and
dependencies cached, its possible that an ssa-name in the dependency
cache is no longer in the IL.  Check this before trying to recompute.

PR tree-optimization/109417
gcc/
* gimple-range-gori.cc (gori_compute::may_recompute_p): Check if
dependency is in SSA_NAME_FREE_LIST.

gcc/testsuite/
* gcc.dg/pr109417.c: New.

15 months agogccrs: Fix issue with parsing unsafe block expression statements
Owen Avery [Fri, 27 Jan 2023 03:59:49 +0000 (22:59 -0500)]
gccrs: Fix issue with parsing unsafe block expression statements

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h
(Parser::parse_stmt): Handle unsafe expression statements.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
15 months agogccrs: Address unsafe with/without block handling ambiguity
Owen Avery [Fri, 27 Jan 2023 03:48:45 +0000 (22:48 -0500)]
gccrs: Address unsafe with/without block handling ambiguity

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h
(Parser::parse_expr_stmt): Remove hypothetical unsafe + expr_stmt_without_block handling.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
15 months agogccrs: Added AST Node AST::InlineAsm
M V V S Manoj Kumar [Fri, 17 Feb 2023 18:09:56 +0000 (23:39 +0530)]
gccrs: Added AST Node AST::InlineAsm

Addresses #1567
Created a AST node InlineAsm similar to the one found in rustc.
As there is no Symbol struct/class in gccrs I have made every instance
of Symbol a string.

gcc/rust/ChangeLog:

* ast/rust-ast-full-decls.h (class InlineAsm):Added class declaration.
* ast/rust-expr.h (class InlineAsm):Added class definition.

Signed-off-by: M V V S Manoj Kumar <mvvsmanojkumar@gmail.com>
15 months agogccrs: diagnostic: Refactor Error class
Arthur Cohen [Wed, 15 Feb 2023 15:56:07 +0000 (16:56 +0100)]
gccrs: diagnostic: Refactor Error class

The class now allows for more variants including a `Hint` one which
then gets emitted by calling `rust_inform`. This allows us to display
hints/tips/notes in backtracking contexts such as the parser.

gcc/rust/ChangeLog:

* rust-diagnostics.h (struct Error): Add new Kind enum and various new
static constructors to allow for hints as well.
* rust-diagnostics.cc (Error::Error): Use new `kind` field properly.
* checks/errors/privacy/rust-visibility-resolver.cc
(VisibilityResolver::resolve_module_path): Use new Error API.
* expand/rust-macro-builtins.cc (MacroBuiltin::include_handler): Likewise.
* expand/rust-macro-expand.cc (parse_many): Likewise.
(transcribe_type): Likewise.
* parse/rust-parse-impl.h (Parser::parse_crate): Likewise.
* rust-session-manager.cc (Session::handle_crate_name): Likewise.
* ast/rust-ast.cc (Module::load_items): Likewise.

15 months agogccrs: ast: Refactor TraitItem to keep Location info
Arthur Cohen [Wed, 15 Feb 2023 16:10:54 +0000 (17:10 +0100)]
gccrs: ast: Refactor TraitItem to keep Location info

gcc/rust/ChangeLog:

* ast/rust-ast.h: Keep location in TraitItem base class
* ast/rust-item.h (class TraitItemFunc): Use base class location instead.
(class TraitItemMethod): Likewise.
(class TraitItemConst): Likewise.
(class TraitItemType): Likewise.
* ast/rust-macro.h: Likewise.

15 months agogccrs: add test case to show our query-type system is working
Philip Herron [Thu, 16 Feb 2023 16:14:23 +0000 (16:14 +0000)]
gccrs: add test case to show our query-type system is working

Fixes #1361

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/testsuite/ChangeLog:

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

15 months agogccrs: rename rust-hir-full-tests.cc
SainiAditya1 [Mon, 30 Jan 2023 17:07:08 +0000 (22:37 +0530)]
gccrs: rename rust-hir-full-tests.cc

gcc/rust/Changelog:

* hir/tree/rust-hir-full-test.cc: Moved to...
* hir/tree/rust-hir.cc: ...here.
* Make-lang.in: Rename rust-hir-full-test.

Signed-off-by: SainiAditya1 <Adityasaini10012001@outlook.com>
15 months agogccrs: Fix up DejaGnu directives in 'rust/compile/issue-1830_{bytes,str}.rs' test...
Thomas Schwinge [Tue, 14 Feb 2023 23:28:35 +0000 (00:28 +0100)]
gccrs: Fix up DejaGnu directives in 'rust/compile/issue-1830_{bytes,str}.rs' test cases [#1838]

'dg-excess-errors' "indicates that the test is expected to fail due to compiler
messages that are not handled by 'dg-error', [etc.]".  It's argument doesn't
specify the message to match but just just a comment.  Here, however, we'd like
to match specific compiler messages, so we should use 'dg-error', etc.  Use the
magic line number zero as the compiler error diagnostic doesn't tell which line
the error occurred on (separate issue to resolve).  This gives us:

    -XFAIL: rust/compile/issue-1830_str.rs (test for excess errors)
    +PASS: rust/compile/issue-1830_bytes.rs  at line 8 (test for errors, line )
    +PASS: rust/compile/issue-1830_bytes.rs (test for excess errors)
    -XFAIL: rust/compile/issue-1830_bytes.rs (test for excess errors)
    +PASS: rust/compile/issue-1830_str.rs  at line 8 (test for errors, line )
    +PASS: rust/compile/issue-1830_str.rs (test for excess errors)

Fix-up for recent GCC/Rust master branch #1838
commit cf9ed4001eec6a22686d19a13f7de8ac94f9cb2a
"testsuite: Add empty string macro test".

gcc/testsuite/
* rust/compile/issue-1830_bytes.rs: Fix up DejaGnu directives.
* rust/compile/issue-1830_str.rs: Likewise.

15 months agogccrs: Add AST::AltPattern class
Owen Avery [Tue, 14 Feb 2023 22:28:35 +0000 (17:28 -0500)]
gccrs: Add AST::AltPattern class

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc
(Dump::visit): Add AltPattern visitor.
* ast/rust-ast-dump.h:
(Dump::visit): Add AltPattern visitor.
* ast/rust-ast-full-decls.h
(class AltPattern): Add declaration.
* ast/rust-ast-visitor.h:
(ASTVisitor::visit): Add AltPattern visitor.
* ast/rust-ast.cc
(AltPattern::as_string): Add definition.
(AltPattern::accept_vis): Add definition.
* ast/rust-pattern.h
(class AltPattern): Add declaration.
* checks/errors/rust-feature-gate.h:
(FeatureGate::visit) Add AltPattern visitor
* expand/rust-attribute-visitor.cc
(AttrVisitor::visit): Add AltPattern visitor.
* expand/rust-attribute-visitor.h:
(AttrVisitor::visit): Add AltPattern visitor.
* hir/rust-ast-lower-base.cc
(ASTLoweringBase::visit): Add AltPattern visitor.
* hir/rust-ast-lower-base.h:
(ASTLoweringBase::visit): Add AltPattern visitor.
* resolve/rust-ast-resolve-base.cc
(ResolverBase::visit): Add AltPattern visitor.
* resolve/rust-ast-resolve-base.h:
(ResolverBase::visit): Add AltPattern visitor.
* resolve/rust-early-name-resolver.cc
(EarlyNameResolver::visit): Add AltPattern visitor.
* resolve/rust-early-name-resolver.h:
(EarlyNameResolver::visit): Add AltPattern visitor.
* util/rust-attributes.cc
(AttributeChecker::visit): Add AltPattern visitor.
* util/rust-attributes.h:
(AttributeChecker::visit): Add AltPattern visitor.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
15 months agogccrs: Fix formatting
Owen Avery [Wed, 15 Feb 2023 15:04:32 +0000 (10:04 -0500)]
gccrs: Fix formatting

gcc/rust/ChangeLog:

* ast/rust-pattern.h: Fix formatting.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
15 months agogccrs: builtins: Return empty list of tokens instead of nullptr
Arthur Cohen [Wed, 15 Feb 2023 09:52:28 +0000 (10:52 +0100)]
gccrs: builtins: Return empty list of tokens instead of nullptr

gcc/rust/ChangeLog:

* expand/rust-macro-builtins.cc (MacroBuiltin::include_handler): Do not
return nullptr token in expansion of `include!()`

gcc/testsuite/ChangeLog:

* rust/compile/empty.in: New test.
* rust/compile/include_empty.rs: New test.

15 months agogccrs: Add trailing newline
Owen Avery [Tue, 14 Feb 2023 23:47:53 +0000 (18:47 -0500)]
gccrs: Add trailing newline

gcc/rust/ChangeLog:

* checks/errors/rust-feature-gate.h: Add trailing newline before EOF.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
15 months agogccrs: Fix regression in testcase
Philip Herron [Mon, 13 Feb 2023 22:22:06 +0000 (22:22 +0000)]
gccrs: Fix regression in testcase

Fixes #776

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/testsuite/ChangeLog:

* rust/compile/torture/traits10.rs: Fix test-case

15 months agogccrs: Support for Sized builtin marker trait
Philip Herron [Mon, 13 Feb 2023 17:51:19 +0000 (17:51 +0000)]
gccrs: Support for Sized builtin marker trait

When implementing general bounds checking as part of unify calls, we did
not check associated types on bounds which lead to alot of missed error
checking. This now recursively checks the bounds and the associated types
with a decent error message. This also required us to implement the Sized
marker trait to keep existing test-cases happy.

Fixes #1725

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-reference.cc (TraitReference::clear_associated_types): make const
(TraitReference::clear_associated_type_projections): new interface
* typecheck/rust-hir-trait-reference.h:
* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): refactor
(TraitItemReference::associated_type_reset): reset projections
* typecheck/rust-hir-type-bounds.h:
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): fix bounds
* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::TypeBoundsProbe): refactor into cc file
(TypeBoundsProbe::Probe): refactor
(TypeBoundsProbe::is_bound_satisfied_for_type): likewise
(TypeBoundsProbe::assemble_sized_builtin): add builtin for Sized
(TypeCheckBase::get_predicate_from_bound): refactor
(TypeBoundPredicate::lookup_associated_type): refactor
* typecheck/rust-tyty-subst.cc (SubstitutionRef::lookup_associated_impl)
(SubstitutionRef::prepare_higher_ranked_bounds): new interface to clear hanging bounds
(SubstitutionRef::monomorphize): refactor
* typecheck/rust-tyty-subst.h:
* typecheck/rust-tyty.cc (BaseType::get_locus): helper
(BaseType::satisfies_bound): ensure bounds are satisfied and assoicated types
(ParamType::ParamType): new field in constructor
(ParamType::clone): update clone
(ParamType::set_implicit_self_trait): new interface
(ParamType::is_implicit_self_trait): likewise
* typecheck/rust-tyty.h: cleanup
* util/rust-hir-map.cc (Mappings::Mappings): builtin marker
(Mappings::~Mappings): delete marker
(Mappings::lookup_builtin_marker): lookup
* util/rust-hir-map.h: update header

gcc/testsuite/ChangeLog:

* rust/compile/issue-1725-1.rs: New test.
* rust/compile/issue-1725-2.rs: New test.

15 months agogccrs: Add new virtual function HIR::ImplItem::get_impl_item_name
Philip Herron [Mon, 6 Feb 2023 17:48:06 +0000 (17:48 +0000)]
gccrs: Add new virtual function HIR::ImplItem::get_impl_item_name

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* hir/tree/rust-hir-item.h: implement virtual function
* hir/tree/rust-hir.h: add virtual function

15 months agogccrs: Extract query_type from TypeCheckBase to be a simple extern
Philip Herron [Mon, 6 Feb 2023 17:46:07 +0000 (17:46 +0000)]
gccrs: Extract query_type from TypeCheckBase to be a simple extern

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* Make-lang.in: add new dependancy
* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::query_type): refactor
* typecheck/rust-hir-type-check-base.h: refactor
* typecheck/rust-hir-type-check.h (RUST_HIR_TYPE_CHECK): refactor
* typecheck/rust-type-util.cc: New file.
* typecheck/rust-type-util.h: New file.

15 months agogccrs: Implemented UTF-8 checking for include_str!()
Owen Avery [Sun, 8 Jan 2023 22:19:12 +0000 (17:19 -0500)]
gccrs: Implemented UTF-8 checking for include_str!()

gcc/rust/ChangeLog:

* expand/rust-macro-builtins.cc
(MacroBuiltin::include_str_handler): Add check for valid UTF-8.

gcc/testsuite/ChangeLog:

* rust/compile/builtin_macro_include_str.rs:
Include test of invalid UTF-8.
* rust/compile/invalid_utf8: File with invalid UTF-8.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
15 months agogccrs: Add support for parsing empty tuple patterns.
Owen Avery [Tue, 14 Feb 2023 01:32:51 +0000 (20:32 -0500)]
gccrs: Add support for parsing empty tuple patterns.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h
(Parser::parse_grouped_or_tuple_pattern): Add support for empty tuple patterns.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
15 months agogccrs: testsuite: Add empty string macro test
Pierre-Emmanuel Patry [Thu, 9 Feb 2023 17:24:42 +0000 (18:24 +0100)]
gccrs: testsuite: Add empty string macro test

Add two new tests with empty string for include_str and include_bytes
macros.

gcc/testsuite/ChangeLog:

* rust/compile/issue-1830_bytes.rs: New test.
* rust/compile/issue-1830_str.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
15 months agogccrs: lex: Prevent directories in RAIIFile
Pierre-Emmanuel Patry [Thu, 9 Feb 2023 09:47:15 +0000 (10:47 +0100)]
gccrs: lex: Prevent directories in RAIIFile

RAIIFile constructor was accepting directory filename. This lead to
unattended directory opening in some part of the code (load_file_bytes)
wich resulted in ice. Since RAIIFile are used for the lexer, removing
the ability to open directories with RAIIFile fixes those issues and
prevent future mistakes.

gcc/rust/ChangeLog:

* lex/rust-lex.h: Add file type check.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
15 months agogccrs: Simplify WildcardPattern let statement handling
Owen Avery [Fri, 3 Feb 2023 15:19:32 +0000 (10:19 -0500)]
gccrs: Simplify WildcardPattern let statement handling

gcc/rust/ChangeLog:

* backend/rust-compile-pattern.cc
(CompilePatternLet::visit): Simplify WildcardPattern compilation for let statements.
* backend/rust-compile-var-decl.h:
(CompileVarDecl::visit): Remove variable declaration for WildcardPattern.
* resolve/rust-ast-resolve-pattern.h:
(PatternDeclaration::visit): Remove name resolution for WildcardPattern.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
15 months agogccrs: Add test
Owen Avery [Mon, 13 Feb 2023 16:29:07 +0000 (11:29 -0500)]
gccrs: Add test

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
15 months agogccrs: Add variadic argument type checking
Owen Avery [Fri, 10 Feb 2023 15:19:24 +0000 (10:19 -0500)]
gccrs: Add variadic argument type checking

gcc/rust/ChangeLog:

* typecheck/rust-tyty-call.cc
(TypeCheckCallExpr::visit): Add variadic argument type checking.
(TypeCheckCallExpr::visit): Fix comment spelling ("varadic").

gcc/testsuite/ChangeLog:

* rust/execute/torture/overflow1.rs: Fix test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
15 months agogccrs: Add feature gate for "rust-intrinsic".
mxlol233 [Sun, 5 Feb 2023 13:17:34 +0000 (21:17 +0800)]
gccrs: Add feature gate for "rust-intrinsic".

This commit implemented a feature gate to check `intrinsics`.

gcc/rust/ChangeLog:

* checks/errors/rust-feature-gate.cc: Add implementation for
`void FeatureGate::visit (AST::ExternBlock &block)`. Add `valid_feature`
construction process in `FeatureGate::check`.
* checks/errors/rust-feature-gate.h: Add declaration for
`void FeatureGate::visit (AST::ExternBlock &block)`. Add private
variable `valid_feature`.
* checks/errors/rust-feature.h: Change `issue` to `m_issue`.

gcc/testsuite/ChangeLog:

* rust/compile/const-issue1440.rs: Add crate feature: `intrinsics`.
* rust/compile/feature_intrinsics.rs: New file.
* rust/compile/issue-1031.rs: Add crate feature: `intrinsics`.
* rust/compile/issue-1130.rs: Add crate feature: `intrinsics`.
* rust/compile/issue-1131.rs: Add crate feature: `intrinsics`.
* rust/compile/issue-1237.rs: Add crate feature: `intrinsics`.
* rust/compile/issue-1289.rs: Add crate feature: `intrinsics`.
* rust/compile/rust-const-blog-issue.rs: Add crate feature: `intrinsics`.
* rust/compile/torture/intrinsics-3.rs: Add crate feature: `intrinsics`.
* rust/compile/torture/intrinsics-4.rs: Add crate feature: `intrinsics`.
* rust/compile/torture/intrinsics-5.rs: Add crate feature: `intrinsics`.
* rust/compile/torture/intrinsics-6.rs: Add crate feature: `intrinsics`.
* rust/compile/torture/intrinsics-7.rs: Add crate feature: `intrinsics`.
* rust/compile/torture/issue-1024.rs: Add crate feature: `intrinsics`.
* rust/compile/torture/issue-1075.rs: Add crate feature: `intrinsics`.
* rust/compile/torture/issue-1432.rs: Add crate feature: `intrinsics`.
* rust/compile/unsafe10.rs: Add crate feature: `intrinsics`.
* rust/execute/torture/atomic_load.rs: Add crate feature: `intrinsics`.
* rust/execute/torture/atomic_store.rs: Add crate feature: `intrinsics`.
* rust/execute/torture/copy_nonoverlapping1.rs: Add crate feature:
`intrinsics`.
* rust/execute/torture/issue-1120.rs: Add crate feature: `intrinsics`.
* rust/execute/torture/issue-1133.rs: Add crate feature: `intrinsics`.
* rust/execute/torture/issue-1232.rs: Add crate feature: `intrinsics`.
* rust/execute/torture/slice-magic.rs: Add crate feature: `intrinsics`.
* rust/execute/torture/slice-magic2.rs: Add crate feature: `intrinsics`.
* rust/execute/torture/str-layout1.rs: Add crate feature: `intrinsics`.
* rust/execute/torture/transmute1.rs: Add crate feature: `intrinsics`.
* rust/execute/torture/wrapping_op1.rs: Add crate feature: `intrinsics`.
* rust/execute/torture/wrapping_op2.rs: Add crate feature: `intrinsics`.

Signed-off-by: Xiao Ma <mxlol233@outlook.com>
15 months agogccrs: Update copyright years.
Thomas Schwinge [Mon, 27 Feb 2023 12:53:50 +0000 (13:53 +0100)]
gccrs: Update copyright years.

gcc/rust/ChangeLog:

* ast/rust-ast-fragment.cc: Update copyright years.
* ast/rust-ast-fragment.h: Likewise.
* ast/rust-macro.cc: Likewise.
* checks/errors/rust-feature-gate.cc: Likewise.
* checks/errors/rust-feature-gate.h: Likewise.
* checks/errors/rust-feature.cc: Likewise.
* checks/errors/rust-feature.h: Likewise.
* hir/rust-ast-lower-expr.cc: Likewise.
* hir/rust-ast-lower-type.cc: Likewise.
* resolve/rust-early-name-resolver.cc: Likewise.
* resolve/rust-early-name-resolver.h: Likewise.
* rust-gcc.h: Likewise.
* typecheck/rust-hir-path-probe.cc: Likewise.
* typecheck/rust-hir-trait-reference.cc: Likewise.
* typecheck/rust-tyty-bounds.h: Likewise.
* typecheck/rust-tyty-subst.cc: Likewise.
* typecheck/rust-tyty-subst.h: Likewise.
* typecheck/rust-tyty-util.cc: Likewise.
* typecheck/rust-tyty-util.h: Likewise.
* typecheck/rust-unify.cc: Likewise.
* typecheck/rust-unify.h: Likewise.
* util/rust-inline-visitor.h: Likewise.

15 months agogccrs: cli: Update safety warning message
Pierre-Emmanuel Patry [Thu, 9 Feb 2023 10:32:50 +0000 (11:32 +0100)]
gccrs: cli: Update safety warning message

The compiler's warning message about the safety flag did not match
cargo-gccrs environment variable name anymore.

gcc/rust/ChangeLog:

* rust-session-manager.cc (Session::compile_crate): Update the
environment variable name.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
15 months agogccrs: typecheck: Refactor rust-hir-trait-reference.h
Pierre-Emmanuel Patry [Wed, 8 Feb 2023 15:19:41 +0000 (16:19 +0100)]
gccrs: typecheck: Refactor rust-hir-trait-reference.h

Move function body to their own cc file instead of keeping them in the
header file.

gcc/rust/ChangeLog:

* Make-lang.in: Add `rust-hir-trait-reference.o`.
* typecheck/rust-hir-trait-reference.h: Remove multiple function body.
* typecheck/rust-hir-trait-reference.cc: Add multiple function body.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
15 months agogccrs: expander: Add documentation for `expand_eager_invocations`
Arthur Cohen [Wed, 8 Feb 2023 11:23:06 +0000 (12:23 +0100)]
gccrs: expander: Add documentation for `expand_eager_invocations`

gcc/rust/ChangeLog:

* expand/rust-macro-expand.cc (MacroExpander::expand_eager_invocations):
Add documentation explaining the algorithm.

15 months agogccrs: macros: Perform macro expansion in a fixed-point fashion.
Arthur Cohen [Wed, 18 Jan 2023 11:23:03 +0000 (12:23 +0100)]
gccrs: macros: Perform macro expansion in a fixed-point fashion.

This commit changes our macro expansion system from an eager and recursive
macro expansion to a fixed-point like system. Instead of, when seeing
a macro invocation, expanding it and all of the macros within it, we
now perform multiple passes of expansion on the entire crate.

This, however, leads to a problem. Rust macros are expanded lazily, but
Rust builtin macros should be expanded eagerly. Due to this, we must
work around the lazy expansion in builtin macros and perform eager
expansion for each pass of the fixed-point, before finally expanding
the builtin when there are no longer any inner macro invocations.

To perform proper macro scoping, the ENR now keeps track of the current
scope (`current_scope` member) and resolves macros accordingly.

This is done through the use of the `scoped` method, which creates a new
scope, runs a specified lambda and then exits the scope. This prevents
pushing/popping errors that we've seen happen already in similar
contexts.

We might think about generalizing it to other classes, providing a
`Scoped<EntryFn, ExitFn>` class or similar

gcc/rust/ChangeLog:

* ast/rust-macro.cc: New file.
* Make-lang.in: Add `rust-macro.o` object
* ast/rust-ast-fragment.cc (Fragment::Fragment): Change API around
the construction of AST fragments.
(Fragment::operator=): Correct `Fragment::operator=` to take into
account the fragment tokens.
(Fragment::create_error): Use new constructor.
(Fragment::complete): Remove in favor of new constructor.
(Fragment::unexpanded): Remove as that Fragment type is no longer used
or possible.
(Fragment::get_tokens): Add helper to access a fragment's tokens.
* ast/rust-ast-fragment.h (enum class): Remove `FragmentKind::Unused`
* ast/rust-ast.cc (MacroInvocation::as_string): Display
builtin macro invocations properly.
* ast/rust-ast.h: Fix `DelimTokenTree` class copy constructors and
handling of its token vector.
* ast/rust-macro.h (class MacroMatcher): Format.
(class MetaItemSeq): Likewise.
(builtin_macro_from_string): Get a `BuiltinMacroKind` from a given
string, i.e the name of the macro (`assert!`, `cfg!` and so on).
* expand/rust-attribute-visitor.cc (AttrVisitor::visit): Do not expand
macros recursively anymore.
(AttrVisitor::maybe_expand_expr): Likewise.
(AttrVisitor::maybe_expand_type): Likewise.
* expand/rust-attribute-visitor.h: Likewise, and remove
`expand_macro_fragment_recursively` function.
* expand/rust-macro-builtins.cc (make_token): Add shorthand for
returning `std::unique_ptr<AST::Token>`s.
(make_macro_invocation): Add shorthand for returning fragments
containing builtin macro invocations.
(try_expand_macro_expression): Do not expand macros recursively.
(try_expand_single_string_literal): Likewise.
(try_expand_many_expr): Likewise.
(parse_single_string_literal): Error out more appropriately.
(MacroBuiltin::compile_error_handler): Add explanation for eager
invocation
(MacroBuiltin::file_handler): Return the proper tokens associated with
macro invocation, and builtin macros in the case of necessary eager
expansion.
(MacroBuiltin::column_handler): Likewise.
(MacroBuiltin::include_bytes_handler): Likewise.
(MacroBuiltin::include_str_handler): Likewise.
(MacroBuiltin::concat_handler): Likewise.
(MacroBuiltin::env_handler): Likewise.
(MacroBuiltin::cfg_handler): Likewise.
(MacroBuiltin::include_handler): Likewise.
(MacroBuiltin::line_handler): Likewise.
* expand/rust-macro-expand.cc (MacroExpander::expand_eager_invocations):
Add function to expand eager invocations *once* in the fixed point
pipeline.
(MacroExpander::expand_invoc): Call into `expand_eager_invocations` for
builtin macro invocations.
(MacroExpander::expand_crate): Use new `AttrVisitor` API.
(parse_many): Return tokens in `AST::Fragment`.
(transcribe_expression): Likewise.
(transcribe_type): Likewise.
* expand/rust-macro-expand.h (struct MacroExpander): Add `has_changed`
flag for fixed point checking.
* resolve/rust-early-name-resolver.cc (EarlyNameResolver::EarlyNameResolver):
Keep track of the current macro scope.
(EarlyNameResolver::go): Use `scoped` API.
(EarlyNameResolver::visit): Likewise.
* resolve/rust-early-name-resolver.h: Add `scoped` API.
* rust-session-manager.cc (Session::expansion): Perform macro expansion
in a fixed-point fashion.

gcc/testsuite/ChangeLog:

* rust/compile/macro17.rs: Fix testsuite for new recursion errors.
* rust/compile/macro44.rs: Fix invalid testcase assertions.
* rust/compile/builtin_macro_recurse.rs: Fix invalid test.
* rust/compile/builtin_macro_recurse2.rs: New test.
* rust/compile/macro46.rs: New test.

15 months agogccrs: expansion: Add `get_token_slice` to `MacroInvocLexer` class
Arthur Cohen [Tue, 17 Jan 2023 15:44:23 +0000 (16:44 +0100)]
gccrs: expansion: Add `get_token_slice` to `MacroInvocLexer` class

gcc/rust/ChangeLog:

* expand/rust-macro-invoc-lexer.cc (MacroInvocLexer::get_token_slice):
Add API to retrieve token slices when lexing macro expansions.
* expand/rust-macro-invoc-lexer.h: Declare `get_token_slice`.

15 months agogccrs: parser: Expose parse_macro_invocation as public API
Arthur Cohen [Fri, 13 Jan 2023 11:16:49 +0000 (12:16 +0100)]
gccrs: parser: Expose parse_macro_invocation as public API

gcc/rust/ChangeLog:

* parse/rust-parse.h: Move `parse_macro_invocation` to public API.

15 months agogccrs: rust-item: include rust-expr.h
Arthur Cohen [Tue, 17 Jan 2023 14:53:00 +0000 (15:53 +0100)]
gccrs: rust-item: include rust-expr.h

gcc/rust/ChangeLog:

* ast/rust-item.h (class BlockExpr): Remove forward declaration of
class `BlockExpr`.

15 months agogccrs: Add support for TuplePattern in let statements
Owen Avery [Sat, 4 Feb 2023 05:02:22 +0000 (00:02 -0500)]
gccrs: Add support for TuplePattern in let statements

gcc/rust/ChangeLog:

* hir/tree/rust-hir-pattern.h
(TuplePatternItemsRanged::get_lower_patterns): Add method.
(TuplePatternItemsRanged::get_upper_patterns): Add method.
* backend/rust-compile-pattern.cc
(CompilePatternLet::visit): Implement TuplePattern visitor.
* backend/rust-compile-pattern.h
(CompilePatternLet::visit): Move TuplePattern visitor out of header file.

gcc/testsuite/ChangeLog:

* rust/execute/torture/let-pattern-1.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
15 months agogccrs: Add general TypeBounds checks
Philip Herron [Sat, 4 Feb 2023 22:53:48 +0000 (22:53 +0000)]
gccrs: Add general TypeBounds checks

Existing tests are updated to use libcore copy and clone implementation.

Addresses #1725

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-unify.cc (UnifyRules::go): ensure the bounds are checked

gcc/testsuite/ChangeLog:

* rust/compile/torture/intrinsics-4.rs: implement Copy trait
* rust/compile/torture/intrinsics-5.rs: likewise
* rust/execute/torture/atomic_load.rs: likewise
* rust/execute/torture/atomic_store.rs: likewise
* rust/bounds1.rs: New test.

15 months agogccrs: Remove bad error message on checking function arguments
Philip Herron [Sat, 4 Feb 2023 23:02:31 +0000 (23:02 +0000)]
gccrs: Remove bad error message on checking function arguments

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): remove error message

gcc/testsuite/ChangeLog:

* rust/compile/func3.rs: update test case

15 months agogccrs: Fix higher ranked trait bounds computation of self
Philip Herron [Tue, 31 Jan 2023 18:52:33 +0000 (18:52 +0000)]
gccrs: Fix higher ranked trait bounds computation of self

This updates the higher ranked trait bounds computation to handle ambigious
cases. When we have a slice for example:

  let slice = &a[1..3];

This works by reusing the Index operator overload from libcore, so when the
index range of 1..3 is computed, the type system needs to compute what the
types of index are; this works by integer inference variables
Range<<integer>> that need to be unified with the impl Index for
Range<Usize> which computes the real type of usize for the index. This is
fine but what happens when we have the Copy and Clone traits bounds which
have implementations for all the primitive types i8, i16, i32, i64...
which is valid for any integer inference variable so the code prior to this
patch would have grabbed the first impl it would have found and used it
which is incorrect. When we have integer or float inference variables we
need to look for their respective defaults or emit an ambigious type bound
error.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-reference.h: add const infterface
* typecheck/rust-tyty-subst.cc (SubstitutionParamMapping::get_generic_param): make const
(SubstitutionRef::monomorphize): fix issue
* typecheck/rust-tyty-subst.h: constify interface

15 months agogccrs: Add missing Sized, Copy and Clone lang item mappings
Philip Herron [Tue, 31 Jan 2023 14:39:29 +0000 (14:39 +0000)]
gccrs: Add missing Sized, Copy and Clone lang item mappings

We need these lang items to be defined and later down the line the mappings
will be used to implement proper copy and clone logic.

Fixes #1786

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* util/rust-lang-item.h:

gcc/testsuite/ChangeLog:

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

15 months agogccrs: Fix nullptr dereference
Philip Herron [Tue, 31 Jan 2023 14:27:49 +0000 (14:27 +0000)]
gccrs: Fix nullptr dereference

When we check if this is concrete the guard checks to ensure the argument
is non null but the check here is wrongly returning early when the check
is non null meaning when it is null and therefore not concrete it will
end up doing a null dereference.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-tyty-subst.cc (SubstitutionArg::is_conrete): fix check

15 months agogccrs: Refactor the type unification code
Philip Herron [Mon, 30 Jan 2023 18:19:07 +0000 (18:19 +0000)]
gccrs: Refactor the type unification code

This refactors the unification systems to be a consistent interface using
switch statements and simple functions instead of the old clunky visitor
system. This is more maintainable as it is harder to miss cases when we
can take advantages of switch statements.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* Make-lang.in: update names
* backend/rust-compile-expr.cc (CompileExpr::resolve_method_address):
update to use new interface
* typecheck/rust-coercion.cc (TypeCoercionRules::coerce_borrowed_pointer): likewise
* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::unify_site): likewise
* typecheck/rust-tyty.cc (BaseType::destructure): likewise
(InferType::unify): removed old unify interface
(ErrorType::unify): likewise
(ADTType::unify): likewise
(TupleType::unify): likewise
(FnType::unify): likewise
(FnPtr::unify): likewise
(ClosureType::unify): likewise
(ArrayType::unify): likewise
(SliceType::unify): likewise
(BoolType::unify): likewise
(IntType::unify): likewise
(UintType::unify): likewise
(FloatType::unify): likewise
(USizeType::unify): likewise
(ISizeType::unify): likewise
(CharType::unify): likewise
(ReferenceType::unify): likewise
(PointerType::unify): likewise
(ParamType::unify): likewise
(StrType::unify): likewise
(NeverType::unify): likewise
(PlaceholderType::unify): likewise
(ProjectionType::unify): likewise
(DynamicObjectType::unify): likewise
* typecheck/rust-tyty.h: update destructure interface
* typecheck/rust-tyty-rules.h: Removed.
* typecheck/rust-unify.cc: New file.
* typecheck/rust-unify.h: New file.

gcc/testsuite/ChangeLog:

* rust/compile/never_type_err1.rs: Moved to...
* rust/compile/never_type1.rs: ...here. It now works

15 months agogccrs: Remove monomorphization hack to setup possible associated types
Philip Herron [Fri, 27 Jan 2023 15:38:58 +0000 (15:38 +0000)]
gccrs: Remove monomorphization hack to setup possible associated types

During CallExpr argument type checking we may be calling a default
implementation of a trait function this will require any possible
associated types to be resolved and setup. This monomoprhization call does
this but it will premtivly do extra unification of types which will throw
off type checking later on. This fix is required for my work into type
bounds checking.

Fixes #1773

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-reference.h: change interface to return self
* typecheck/rust-hir-trait-resolve.cc: likewise
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_segments): likewise
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): remove monomorphization hack

gcc/testsuite/ChangeLog:

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

15 months agogccrs: Add missing param subst callback
Philip Herron [Fri, 27 Jan 2023 18:49:53 +0000 (18:49 +0000)]
gccrs: Add missing param subst callback

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-tyty-subst.cc: add missing callback

15 months agogccrs: Clear the substitution callbacks when copying ArgumentMappings
Philip Herron [Fri, 27 Jan 2023 18:31:11 +0000 (18:31 +0000)]
gccrs: Clear the substitution callbacks when copying ArgumentMappings

When we set the callback on substitutions this is not safe to be copied
around since we store the used argument mappings and can reuse them in
different contexts. This clears the callback on copy's to make it safer.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-tyty-subst.cc: update copy constructors

15 months agogccrs: Refactor handle_substitutions to take a reference
Philip Herron [Fri, 27 Jan 2023 18:28:06 +0000 (18:28 +0000)]
gccrs: Refactor handle_substitutions to take a reference

This patch changes the recusive substitution code to take a reference
instead of a copy. This is important as the callback field is going to be
made non-copyable in a future patch and this pipeline is for recursive
substitutions so its ok to reuse the same mappings here.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-tyty-bounds.cc: refactor to take a reference
* typecheck/rust-tyty-subst.cc: likewise
(SubstitutionRef::get_substitution_arguments): likewise
(SubstitutionRef::infer_substitions): likewise
* typecheck/rust-tyty-subst.h: likewise
* typecheck/rust-tyty.cc (ADTType::handle_substitions): likewise
(TupleType::handle_substitions): likewise
(FnType::handle_substitions): likewise
(ClosureType::handle_substitions): likewise
(ArrayType::handle_substitions): likewise
(SliceType::handle_substitions): likewise
(ReferenceType::handle_substitions): likewise
(PointerType::handle_substitions): likewise
(ParamType::handle_substitions): likewise
(ProjectionType::handle_substitions): likewise
* typecheck/rust-tyty.h: likewise

15 months agogccrs: Rename header rust-hir-trait-ref.h to rust-hir-trait-reference.h
Philip Herron [Tue, 17 Jan 2023 22:45:52 +0000 (22:45 +0000)]
gccrs: Rename header rust-hir-trait-ref.h to rust-hir-trait-reference.h

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-ref.h: Moved to...
* typecheck/rust-hir-trait-reference.h: ...here.
* typecheck/rust-hir-trait-resolve.cc: refactor
* typecheck/rust-hir-trait-resolve.h (RUST_HIR_TRAIT_RESOLVE_H): likewise
* typecheck/rust-hir-type-check.h: likewise
* typecheck/rust-tyty.cc: likewise