]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
12 months agoDaily bump.
GCC Administrator [Fri, 2 Aug 2024 00:18:55 +0000 (00:18 +0000)] 
Daily bump.

12 months agolibstdc++: Remove unused helper traits
Jonathan Wakely [Sat, 23 Mar 2024 11:11:17 +0000 (11:11 +0000)] 
libstdc++: Remove unused helper traits

These are not used anywhere, we have more efficient variable templates
for them instead. They're not documented as extensions, and are easy for
users to write if they need them.

libstdc++-v3/ChangeLog:

* include/bits/utility.h (__is_in_place_type): Remove.
* include/std/variant (__is_in_place_tag): Remove.

12 months agolibstdc++: Remove unnecessary uses of <stdint.h>
Jonathan Wakely [Thu, 7 Dec 2023 12:13:59 +0000 (12:13 +0000)] 
libstdc++: Remove unnecessary uses of <stdint.h>

We don't need to include all of <stdint.h> when we only need uintptr_t
from it. By using GCC's internal macro we avoid unnecessarily declaring
everything in <stdint.h>. This helps users to avoid accidentally relying
on those names being declared without explicitly including the header.

libstdc++-v3/ChangeLog:

* include/bits/align.h (align, assume_aligned): Use
__UINTPTR_TYPE__ instead of uintptr_t. Do not include
<stdint.h>.
* include/bits/atomic_base.h (__atomic_ref): Likewise.
* include/bits/atomic_wait.h (__waiter_pool_base::_S_for):
Likewise.
* include/std/atomic: Include <cstdint>.

12 months agolibstdc++: Remove unused parameters from atomic impl details
Jonathan Wakely [Sat, 9 Mar 2024 00:19:11 +0000 (00:19 +0000)] 
libstdc++: Remove unused parameters from atomic impl details

libstdc++-v3/ChangeLog:

* include/bits/atomic_base.h (__atomic_impl::compare_exchange_weak):
Remove unused parameter.
(__atomic_impl::compare_exchange_strong): Likewise.

12 months agolibstdc++: Use memcmp to optimize std::bitset::_M_is_equal() [PR113807]
Jonathan Wakely [Thu, 8 Feb 2024 15:46:08 +0000 (15:46 +0000)] 
libstdc++: Use memcmp to optimize std::bitset::_M_is_equal() [PR113807]

As noted in the PR the compiler doesn't seem able to do this on its own,
so we get better code at all optimization levels by using memcmp.

libstdc++-v3/ChangeLog:

PR libstdc++/113807
* include/std/bitset (bitset::_M_is_equal()): Use memcmp to
optimize operator==.

12 months agolibstdc++: Fix incomplete change to reduce iterations for simulators
Jonathan Wakely [Wed, 31 Jul 2024 21:15:40 +0000 (22:15 +0100)] 
libstdc++: Fix incomplete change to reduce iterations for simulators

This should have been done as part of r13-693-ge3b8b4f7814c54, but I
only added the preprocessor logic and didn't use ARGS in the code.

libstdc++-v3/ChangeLog:

* testsuite/26_numerics/random/discrete_distribution/operators/values.cc:
Use ARGS to limit number of iterations for simulators.

12 months agolibstdc++: Constrain std::basic_string default constructor [PR113841]
Jonathan Wakely [Thu, 7 Mar 2024 16:00:01 +0000 (16:00 +0000)] 
libstdc++: Constrain std::basic_string default constructor [PR113841]

This is needed to avoid errors outside the immediate context when
evaluating is_default_constructible_v<basic_string<C, T, A>> when A is
not default constructible.

This change is not sufficient to solve the problem because there are a
large number of member functions which have a default argument that
constructs an allocator.

libstdc++-v3/ChangeLog:

PR libstdc++/113841
* include/bits/basic_string.h (basic_string::basic_string()):
Constrain so that it's only present if the allocator is default
constructible.
* include/bits/cow_string.h (basic_string::basic_string()):
Likewise.
* testsuite/21_strings/basic_string/cons/113841.cc: New test.

12 months agolibstdc++: Remove noexcept from non-const std::basic_string::data() [PR99942]
Jonathan Wakely [Wed, 27 Mar 2024 11:07:17 +0000 (11:07 +0000)] 
libstdc++: Remove noexcept from non-const std::basic_string::data() [PR99942]

The C++17 non-const overload of data() allows modifying the string
contents directly, so for the COW string we must do a copy-on-write to
unshare it. That means allocating, which can throw, so it shouldn't be
noexcept.

libstdc++-v3/ChangeLog:

PR libstdc++/99942
* include/bits/cow_string.h (data()): Change to noexcept(false).

12 months agoRISC-V: Correct mode_idx attribute for viwalu wx variants [PR116149].
Robin Dapp [Wed, 31 Jul 2024 14:54:03 +0000 (16:54 +0200)] 
RISC-V: Correct mode_idx attribute for viwalu wx variants [PR116149].

In PR116149 we choose a wrong vector length which causes wrong values in
a reduction.  The problem happens in avlprop where we choose the
number of units in the instruction's mode as vector length.  For the
non-scalar variants the respective operand has the correct non-widened
mode.  For the scalar variants, however, the same operand has a scalar
mode which obviously only has one unit.  This makes us choose VL = 1
leaving three elements undisturbed (so potentially -1).  Those end up
in the reduction causing the wrong result.

This patch adjusts the mode_idx just for the scalar variants of the
affected instruction patterns.

gcc/ChangeLog:

PR target/116149

* config/riscv/vector.md: Fix mode_idx attribute of scalar
widen add/sub variants.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/pr116149.c: New test.

12 months agofortran: Fix up pasto in gfc_get_array_descr_info
Jakub Jelinek [Thu, 1 Aug 2024 18:23:15 +0000 (20:23 +0200)] 
fortran: Fix up pasto in gfc_get_array_descr_info

A static analyzer found a pasto in gfc_get_array_descr_info.
The code does
      t = base_decl;
      if (!integer_zerop (dtype_off))
        t = fold_build_pointer_plus (t, dtype_off);
      dtype = TYPE_MAIN_VARIANT (get_dtype_type_node ());
      field = gfc_advance_chain (TYPE_FIELDS (dtype), GFC_DTYPE_RANK);
      rank_off = byte_position (field);
      if (!integer_zerop (dtype_off))
        t = fold_build_pointer_plus (t, rank_off);
i.e. uses the same !integer_zerop check between both, while it should
be checking rank_off in the latter case.
This actually doesn't change anything on the generated code, because
both the dtype_off and rank_off aren't zero,
typedef struct dtype_type
{
  size_t elem_len;
  int version;
  signed char rank;
  signed char type;
  signed short attribute;
}
dtype_type;
struct {
  type *base_addr;
  size_t offset;
  dtype_type dtype;
  index_type span;
  descriptor_dimension dim[];
};
dtype_off is 16 on 64-bit arches and 8 on 32-bit ones and rank_off is
12 on 64-bit arches and 8 on 32-bit arches, so this patch is just to
pacify those static analyzers or be prepared if the ABI changes in the
future.  Because in the current ABI both of those are actually non-zero,
doing
if (!integer_zerop (something)) t = fold_build_pointer_plus (t, something);
actually isn't an optimization, it will consume more compile time.  If
the ABI changes and we forget to readd it, nothing bad happens,
fold_build_pointer_plus handles 0 addends fine, just takes some compile
time to handle that.
I've kept this if (!integer_zerop (data_off)) guard earlier because
data_off is 0 in the current ABI, so it is an optimization there.

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

* trans-types.cc (gfc_get_array_descr_info): Don't test if
!integer_zerop (dtype_off), use fold_build_pointer_plus
unconditionally.

12 months agoRISC-V: Reject 'd' extension with ILP32E ABI
Patrick O'Neill [Tue, 30 Jul 2024 21:28:23 +0000 (14:28 -0700)] 
RISC-V: Reject 'd' extension with ILP32E ABI

Also add a testcase for -mabi=lp64d where 'd' is required.

gcc/ChangeLog:

PR target/116111
* config/riscv/riscv.cc (riscv_option_override): Add error.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/arch-41.c: New test.
* gcc.target/riscv/pr116111.c: New test.

Signed-off-by: Patrick O'Neill <patrick@rivosinc.com>
12 months agolibstdc++: Make dg-error pattern more accurate
Jonathan Wakely [Thu, 1 Aug 2024 04:53:03 +0000 (06:53 +0200)] 
libstdc++: Make dg-error pattern more accurate

Remove useless test variable and use a more accurate dg-error pattern so
that only the ill-formed expression compilation error is considered.

libstdc++-v3/ChangeLog:

* testsuite/23_containers/map/operators/1_neg.cc (test01): Remove test variable
and use 'no match' dg-error patter.
* testsuite/23_containers/set/operators/1_neg.cc (test01): Likewise.

12 months agoc++: Fix up error recovery of invalid structured bindings used in conditions [PR116113]
Jakub Jelinek [Thu, 1 Aug 2024 16:49:39 +0000 (18:49 +0200)] 
c++: Fix up error recovery of invalid structured bindings used in conditions [PR116113]

The following testcase ICEs, because for structured binding error recovery
DECL_DECOMP_BASE is kept NULL and the newly added code to pick up saved
value from the base assumes that on structured binding bases the
TARGET_EXPR will be always there (that is the case if there are no errors).

The following patch fixes it by testing DECL_DECOMP_BASE before
dereferencing it, another option would be not to do that if
error_operand_p (cond).

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

PR c++/116113
* semantics.cc (maybe_convert_cond): Check DECL_DECOMP_BASE
is non-NULL before dereferencing it.
(finish_switch_cond): Likewise.

* g++.dg/cpp26/decomp11.C: New test.

12 months agoAArch64: Add Cortex-X925 core definition and cost model
Tamar Christina [Thu, 1 Aug 2024 15:55:10 +0000 (16:55 +0100)] 
AArch64: Add Cortex-X925 core definition and cost model

This adds a cost model and core definition for Cortex-X925.

gcc/ChangeLog:

* config/aarch64/aarch64-cores.def (cortex-x925): New.
* config/aarch64/aarch64-tune.md: Regenerate.
* config/aarch64/tuning_models/cortexx925.h: New file.
* config/aarch64/aarch64.cc: Use it.
* doc/invoke.texi: Document it.

12 months agoAArch64: Update Neoverse N2 cost model to release costs
Tamar Christina [Thu, 1 Aug 2024 15:54:49 +0000 (16:54 +0100)] 
AArch64: Update Neoverse N2 cost model to release costs

This updates the cost for Neoverse N2 to reflect the updated
Software Optimization Guide.

gcc/ChangeLog:

* config/aarch64/tuning_models/neoversen2.h: Update costs.

12 months agoAArch64: Update Generic Armv9-a cost model to release costs
Tamar Christina [Thu, 1 Aug 2024 15:54:31 +0000 (16:54 +0100)] 
AArch64: Update Generic Armv9-a cost model to release costs

this updates the costs for gener-armv9-a based on the updated costs for
Neoverse V2 and Neoverse N2.

gcc/ChangeLog:

* config/aarch64/tuning_models/generic_armv9_a.h: Update costs.

12 months agoAArch64: Add Neoverse N3 and Cortex-A725 core definition and cost model
Tamar Christina [Thu, 1 Aug 2024 15:54:15 +0000 (16:54 +0100)] 
AArch64: Add Neoverse N3 and Cortex-A725 core definition and cost model

This adds a cost model and core definition for Neoverse N3 and Cortex-A725.

It also makes Cortex-A725 use the Neoverse N3 cost model.

gcc/ChangeLog:

* config/aarch64/aarch64-cores.def (neoverse-n3, cortex-a725): New.
* config/aarch64/aarch64-tune.md: Regenerate.
* config/aarch64/tuning_models/neoversen3.h: New file.
* config/aarch64/aarch64.cc: Use it.
* doc/invoke.texi: Document it.

12 months agoAArch64: Add Neoverse V3AE core definition and cost model
Tamar Christina [Thu, 1 Aug 2024 15:53:59 +0000 (16:53 +0100)] 
AArch64: Add Neoverse V3AE core definition and cost model

This adds a cost model and core definition for Neoverse V3AE.

gcc/ChangeLog:

* config/aarch64/aarch64-cores.def (neoverse-v3ae): New.
* config/aarch64/aarch64-tune.md: Regenerate.
* config/aarch64/tuning_models/neoversev3ae.h: New file.
* config/aarch64/aarch64.cc: Use it.
* doc/invoke.texi: Document it.

12 months agoAArch64: Add Neoverse V3 core definition and cost model
Tamar Christina [Thu, 1 Aug 2024 15:53:41 +0000 (16:53 +0100)] 
AArch64: Add Neoverse V3 core definition and cost model

This adds a cost model and core definition for Neoverse V3.

It also makes Cortex-X4 use the Neoverse V3 cost model.

gcc/ChangeLog:

* config/aarch64/aarch64-cores.def (cortex-x4): Update.
(neoverse-v3): New.
* config/aarch64/aarch64-tune.md: Regenerate.
* config/aarch64/tuning_models/neoversev3.h: New file.
* config/aarch64/aarch64.cc: Use it.
* doc/invoke.texi: Document it.

12 months agoAArch64: Update Neoverse V2 cost model to release costs
Tamar Christina [Thu, 1 Aug 2024 15:53:22 +0000 (16:53 +0100)] 
AArch64: Update Neoverse V2 cost model to release costs

This updates the cost for Neoverse V2 to reflect the updated
Software Optimization Guide.

It also makes Cortex-X3 use the Neoverse V2 cost model.

gcc/ChangeLog:

* config/aarch64/aarch64-cores.def (cortex-x3): Use Neoverse-V2 costs.
* config/aarch64/tuning_models/neoversev2.h: Update costs.

12 months agomatch: Fix wrong code due to `(a ? e : f) !=/== (b ? e : f)` patterns [PR116120]
Andrew Pinski [Mon, 29 Jul 2024 21:00:13 +0000 (14:00 -0700)] 
match: Fix wrong code due to `(a ? e : f) !=/== (b ? e : f)` patterns [PR116120]

When this pattern was converted from being only dealing with 0/-1, we missed that if `e == f` is true
then the optimization is wrong and needs an extra check for that.

This changes the patterns to be:
/* (a ? x : y) != (b ? x : y) --> (a^b & (x != y)) ? TRUE  : FALSE */
/* (a ? x : y) == (b ? x : y) --> (a^b & (x != y)) ? FALSE : TRUE  */
/* (a ? x : y) != (b ? y : x) --> (a^b | (x == y)) ? FALSE : TRUE  */
/* (a ? x : y) == (b ? y : x) --> (a^b | (x == y)) ? TRUE  : FALSE */

Also this can't be done if the X can be a NaNs either. Since that changes the value there too.

This still produces better code than the original case and in many cases (x != y) will
still reduce to either false or true.

With this change we also need to make sure `a`, `b` and the resulting types are all
the same for the same reason as the previous patch.

I updated (well added) to the testcases to make sure there are the right amount of
comparisons left.

Changes since v1:
* v2: Fixed the testcase names and fixed dg-run to be `dg-do run`. Added a check for HONORS_NANS too.

Bootstrapped and tested on x86_64-linux-gnu with no regressions.

PR tree-optimization/116120

gcc/ChangeLog:

* match.pd (`(a ? x : y) eq/ne (b ? x : y)`): Add test for `x != y`
in result.
(`(a ? x : y) eq/ne (b ? y : x)`): Add test for `x == y` in result.

gcc/testsuite/ChangeLog:

* g++.dg/tree-ssa/pr111150.C: Add extra checks on the test.
* gcc.dg/tree-ssa/pr111150-1.c: Likewise.
* gcc.dg/tree-ssa/pr111150.c: Likewise.
* g++.dg/torture/pr116120-1.C: New test.
* g++.dg/torture/pr116120-2.C: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
12 months agoada: Fix computation of new size when reallocating unbounded string
Yannick Moy [Wed, 3 Jul 2024 13:23:34 +0000 (15:23 +0200)] 
ada: Fix computation of new size when reallocating unbounded string

The procedure Realloc_For_Chunk which is used to reallocate an unbounded
string when needed may lead in theory to an overflow, due to the use of
variable S_Length denoting the current allocated length instead of
Source.Last denoting the current string length. Now fixed.

This has no effect in practice since the only targets that use this
version of Ada.Strings.Unbounded do not have enough memory to make it
possible to have an overflow here.

gcc/ada/

* libgnat/a-strunb.adb (Realloc_For_Chunk): Fix computation of new
size.

12 months agoada: Update contracts on Strings libraries
Yannick Moy [Fri, 28 Jun 2024 15:31:19 +0000 (17:31 +0200)] 
ada: Update contracts on Strings libraries

The contracts of Ada.Strings.Bounded.To_String and
Ada.Strings.Fixed.Delete are updated to reflect the standard spec and to
allow proof of callers.

gcc/ada/

* libgnat/a-strbou.ads (To_String): Add a postcondition to state
the value of bounds of the returned string, which helps with proof
of callers.
* libgnat/a-strfix.adb (Delete): Fix implementation to produce
correct result in all cases. For example, returned string should
always have a lower bound of 1, which was not respected in one
case. This was not detected by proof, since this code was dead
according to the too strict precondition.
* libgnat/a-strfix.ads (Delete): State the correct precondition
from standard which allows a value of Through beyond the last
valid index, and also restricts values of From from below. Update
the Contract_Cases accordingly to allow new values of parameters.

12 months agoada: Accept duplicate SPARK_Mode pragmas in configuration files
Piotr Trojanek [Tue, 2 Jul 2024 13:19:41 +0000 (15:19 +0200)] 
ada: Accept duplicate SPARK_Mode pragmas in configuration files

For consistency, we now accept duplicate SPARK_Mode pragmas in
configuration files just like we accept other duplicate pragas there.

gcc/ada/

* sem_prag.adb (Analyze_Pragma): Don't check for duplicate
SPARK_Mode pragmas in configuration files.

12 months agoada: Crash on access attribute with overloaded prefix denoting reference object
Gary Dismukes [Tue, 2 Jul 2024 00:42:12 +0000 (00:42 +0000)] 
ada: Crash on access attribute with overloaded prefix denoting reference object

The compiler fails to accept an access attribute where the prefix is the name
of an object of a user-defined reference type, and is not prepared to deal
with the possibility of overloaded prefixes other than subprogram cases.
Such a prefix can either represent the reference object directly, or it
can be interpreted as an implicit dereferencing of the object's reference
value, depending on the expected type.  Special handling for this kind of
prefix is added alongside the normal handling for overloaded prefixes of
access attributes.

gcc/ada/

* sem_attr.adb (Resolve_Attribute, Attribute_*Access): Resolve
overloaded prefixes that denote objects of reference types,
determining whether to use the prefix object directly, or expand
it as an explicit dereference.

12 months agoada: Fix oversight in documentation of At_End_Proc
Eric Botcazou [Tue, 2 Jul 2024 17:16:45 +0000 (19:16 +0200)] 
ada: Fix oversight in documentation of At_End_Proc

It is documented for N_Subprogram_Body_Stub instead of N_Subprogram_Body.

gcc/ada/

* sinfo.ads (N_Block_Statement): Move At_End_Proc to the end of
slot list and alphabetize flag list.
(N_Subprogram_Body): Add At_End_Proc.
(N_Package_Body): Move At_End_Proc to the end of slot list.
(N_Subprogram_Body_Stub): Remove At_End_Proc.

12 months agoada: Deconstruct workarounds for quantified expressions in contracts
Piotr Trojanek [Tue, 2 Jul 2024 09:24:56 +0000 (11:24 +0200)] 
ada: Deconstruct workarounds for quantified expressions in contracts

Apparently we can always safely set the type of a loop parameter from
its discrete subtype definition. It looks like the conditional setting
was only necessary when preconditions were expanded into dedicated
procedures, but we no longer use this expansion.

gcc/ada/

* sem_ch5.adb (Analyze_Loop_Parameter_Specification):
Unconditionally set the type of loop parameter.

12 months agoada: Style fixes: remove blank lines following 'begin' keywords
Ghjuvan Lacambre [Tue, 2 Jul 2024 09:26:19 +0000 (11:26 +0200)] 
ada: Style fixes: remove blank lines following 'begin' keywords

The GNAT style guide specifies that there must not be blank lines after
'begin' keywords.

gcc/ada/

* backend_utils.adb (Scan_Common_Back_End_Switch): Remove blank
line.
* errout.adb (Output_JSON_Message): Likewise.
* erroutc.adb (Set_Msg_Char): Likewise.
* exp_aggr.adb (Two_Dim_Packed_Array_Handled): Likewise.
* exp_pakd.adb (Expand_Packed_Address_Reference): Likewise.
(Expand_Packed_Bit_Reference): Likewise.
(Expand_Packed_Boolean_Operator): Likewise.
(Expand_Packed_Element_Reference): Likewise.
(Expand_Packed_Eq): Likewise.
(Expand_Packed_Not): Likewise.
* exp_prag.adb (Build_Dim3_Declaration): Likewise.
* exp_strm.adb (Build_Elementary_Input_Call): Likewise.
* freeze.adb (Find_Aspect_No_Parts): Likewise.
(Get_Aspect_No_Parts_Value): Likewise.
* gen_il-gen.adb (Compile): Likewise.
* gnat1drv.adb (Adjust_Global_Switches): Likewise.
* gnat_cuda.adb (Expand_CUDA_Package): Likewise.
* gnatchop.adb (Read_File): Likewise.
* gnatls.adb (Get_Runtime_Path): Likewise.
* make.adb (Binding_Phase): Likewise.
* par-ch11.adb (P_Exception_Choice): Likewise.
* par-ch5.adb (P_Loop_Parameter_Specification): Likewise.
* par-ch6.adb (Is_Extended): Likewise.
* sem_attr.adb (Check_Dereference): Likewise.
* sem_ch12.adb (Build_Subprogram_Decl_Wrapper): Likewise.
* sem_ch3.adb (Build_Itype_Reference): Likewise.
* sem_prag.adb (Validate_Compile_Time_Warning_Errors): Likewise.
* sem_res.adb (Resolve_Declare_Expression): Likewise.
* sem_util.adb (Build_Default_Subtype): Likewise.
* sprint.adb (Sprint_Paren_Comma_List): Likewise.

12 months agoada: Restrict string interpolation to single string literal
Javier Miranda [Fri, 28 Jun 2024 21:46:12 +0000 (21:46 +0000)] 
ada: Restrict string interpolation to single string literal

gcc/ada/

* par-ch2.adb (P_Interpolated_String_Literal): remove support of
multi-line string literals.
* doc/gnat_rm/gnat_language_extensions.rst: Update documentation.
* gnat_rm.texi: Regenerate.

12 months agoada: Use ?j? in Output_Obsolescent_Entity_Warnings messages
Viljar Indus [Mon, 1 Jul 2024 09:45:26 +0000 (12:45 +0300)] 
ada: Use ?j? in Output_Obsolescent_Entity_Warnings messages

These messages are conditionally activated only when
-gnatwj (Warn_On_Obsolescent_Feature) is activated. They
should use the switch specific insertion character instead.

gcc/ada/

* sem_warn.adb (Output_Obsolescent_Entity_Warnings): use the ?j?
in warning messages.

12 months agoada: Fix crash in quantified expression expansion
Ronan Desplanques [Mon, 1 Jul 2024 08:16:27 +0000 (10:16 +0200)] 
ada: Fix crash in quantified expression expansion

Before this patch, the compiler failed to handle the case where the for loop
created by expansion of a quantified expression required cleanup handlers.

gcc/ada/

* sem_ch5.adb (Analyze_Loop_Parameter_Specification): Fix test for
expanded quantified expression context.
(Is_Expanded_Quantified_Expr): New function.

12 months agoada: Fix bug in resolution of Ghost_Predicate
Bob Duff [Mon, 1 Jul 2024 13:23:17 +0000 (09:23 -0400)] 
ada: Fix bug in resolution of Ghost_Predicate

This patch fixes a failure of name resolution when
a range attribute reference appears in a Ghost_Predicate
and the ghost policy is Ignore.

gcc/ada/

* sem_ch13.adb (Add_Predicate): Remove the premature "return;".
Ghost code needs to be processed by later code in this procedure
even when ignored; otherwise the second pass of name resolution
fails much later. However, protect Set_SCO_Pragma_Enabled and
Add_Condition with "if not Is_Ignored_Ghost_Pragma"; these parts
should not happen if the ghost code is Ignored.
* libgnat/interfac__2020.ads (Unsigned_8): Minor reformatting.
* libgnat/interfac.ads (IEEE_Extended_Float): Minor comment
improvement.

12 months agoada: Define No_Return flag only for subprograms
Eric Botcazou [Mon, 1 Jul 2024 08:25:07 +0000 (10:25 +0200)] 
ada: Define No_Return flag only for subprograms

...instead of defining it for all entities.

gcc/ada/

* einfo.ads (No_Return): Change description and adjust
accordingly.
* gen_il-gen-gen_entities.adb (Entity_Kind): Remove No_Return.
(Subprogram_Kind): Add No_Return.
(Generic_Subprogram_Kind): Likewise.
* sem_ch6.adb (Analyze_Return_Statement): Adjust No_Return test.

12 months agoada: Implement full relaxed finalization semantics for controlled objects
Eric Botcazou [Wed, 26 Jun 2024 16:09:18 +0000 (18:09 +0200)] 
ada: Implement full relaxed finalization semantics for controlled objects

These semantics state that the compiler is permitted to enforce none of
the guarantees specified by the RM 7.6.1(14/1) and following subclauses,
and to instead just let the exception be propagated upward.

The guarantees impose a significant overhead in terms of complexity and
run-time performance compared to similar constructs in other languages,
and the goal is to reduce it significantly, if not eliminate it totally:
for example, untagged record types declared with the Finalizable aspect,
the relaxed finalization semantics and inline Initialize/Adjust/Finalize
primitives, and used with abort disabled:

  pragma Restrictions (No_Abort_Statements);
  pragma Restrictions (Max_Asynchronous_Select_Nesting => 0);
  pragma Restrictions (No_Asynchronous_Control);

should behave like simple C++ classes.

The implementation morally boils down to undoing the changes made a few
months ago to the support of finalization for controlled objects, i.e.
to getting rid of the added linked list and the associated indirection
for controlled objects with relaxed finalization semantics.

But, in order to keep a unified processing for both kinds of controlled
objects and not to bring back the issues addressed by the aforementioned
changes, the work is split between the front-end and the code generator:
the front-end drops the linked list and the code generator is in charge
of eliminating the indirection with the help of the optimizer.

gcc/ada/

* doc/gnat_rm/gnat_language_extensions.rst (Generalized
Finalization): Update status.
* einfo.ads (Has_Relaxed_Finalization): Add more details.
* exp_ch4.adb (Process_Transients_In_Expression): Invoke
Make_Finalize_Call_For_Node instead of building the call.
* exp_ch5.adb (Expand_N_Assignment_Statement): Do not set up an
exception handler around the assignment for a controlled type with
relaxed finalization semantics. Streamline the code implementing
the protection against aborts and do not use an At_End handler for
a controlled type with relaxed finalization semantics.
* exp_ch7.ads (Make_Finalize_Call_For_Node): New function.
* exp_ch7.adb (Finalize_Address_For_Node): New function renaming.
(Set_Finalize_Address_For_Node): New procedure renaming.
(Attach_Object_To_Master_Node): Also attach the Finalize_Address
primitive to the Master_Node statically.
(Build_Finalizer): Add Has_Strict_Ctrl_Objs local variable. Insert
back the body of the finalizer at the end of the statement list in
the non-package case and restore the associated support code to
that effect. When all the controlled objects have the relaxed
finalization semantics, do not create a Finalization_Master and
finalize the objects directly instead.
(Processing_Actions): Add Strict parameter and use it to set the
Has_Strict_Ctrl_Objs variable.
(Process_Declarations): Make main loop more robust and adjust
calls to Processing_Actions.
(Make_Finalize_Address_Body): Mark the primitive as inlined if the
type has relaxed finalization semantics.
(Make_Finalize_Call_For_Node): New function.
* sem_ch6.adb (Check_Statement_Sequence): Skip subprogram bodies.
* libgnat/s-finpri.ads (Finalize_Object): Add Finalize_Address
parameter.
(Master_Node): Remove superfluous qualification.
* libgnat/s-finpri.adb (Attach_Object_To_Node): Likewise.
(Finalize_Master): Adjust calls to Finalize_Object.
(Finalize_Object): Add Finalize_Address parameter and assert that
it is equal to the component of the node. Use the Object_Address
component as guard.
(Suppress_Object_Finalize_At_End): Clear Object_Address component.
* gnat_rm.texi: Regenerate.
* gnat_ugn.texi: Regenerate.

12 months agoada: Put back -G for binder
Arnaud Charlet [Fri, 28 Jun 2024 08:35:25 +0000 (08:35 +0000)] 
ada: Put back -G for binder

gcc/ada/

* bindgen.adb (Gen_Main): Put back support for -G
* bindusg.adb (Display): Put back line for -G
* opt.ads (CCG_Mode): Update doc
* switch-b.adb (Scan_Binder_Switches): Put back support for -G

12 months agoada: exp_pakd.adb: disable packed expansions in CodePeer_Mode
Ghjuvan Lacambre [Fri, 28 Jun 2024 08:13:17 +0000 (10:13 +0200)] 
ada: exp_pakd.adb: disable packed expansions in CodePeer_Mode

A previous commit disabled the removal of the Component_Size aspect from
GNAT's tree when in CodePeer_Mode. This effectively resulted in CodePeer
not ignoring Component_Size anymore. As a side effect, GNAT started
expanding packed operations on array types from their high-level
representations to operations operating on bits. It wasn't caught during
the original testing, but this actually confuses CodePeer. We thus need
to disable expansion of packed operations while in CodePeer_Mode.

gcc/ada/

* exp_pakd.adb (Expand_Bit_Packed_Element_Set): Disable expansion
in CodePeerMode.
(Expand_Packed_Address_Reference): Likewise.
(Expand_Packed_Bit_Reference): Likewise.
(Expand_Packed_Boolean_Operator): Likewise.
(Expand_Packed_Element_Reference): Likewise.
(Expand_Packed_Eq): Likewise.
(Expand_Packed_Not): Likewise.

12 months agoada: Check default value aspects before resolving their expressions
Piotr Trojanek [Mon, 24 Jun 2024 13:25:06 +0000 (15:25 +0200)] 
ada: Check default value aspects before resolving their expressions

Check expressions of aspects Default_Value and Default_Component_Value
for references to the annotated types just before resolving these
expressions.

This patch fixes both an asymmetry in processing of those aspects and
adds a missing check in GNATprove on aspect Default_Component_Value.

gcc/ada/

* sem_ch13.adb (Check_Aspect_Too_Late): Move routine to top-level.
(Resolve_Aspect_Expressions): Check aspects Default_Value and
Default_Component_Value before resolving their expressions.

12 months agoada: Fix freezing of Default_Value expressions
Piotr Trojanek [Mon, 24 Jun 2024 11:07:13 +0000 (13:07 +0200)] 
ada: Fix freezing of Default_Value expressions

This patch fixes an infinite loop in freezing that occurred when
expression of the Default_Value aspect includes a declare expression
with an object of the annotated type.

gcc/ada/

* sem_ch13.adb (Check_Aspect_Too_Late): Prevent freezing during
preanalysis.

12 months agoada: Remove Must_Not_Freeze flags from default value expressions
Piotr Trojanek [Fri, 21 Jun 2024 13:27:41 +0000 (15:27 +0200)] 
ada: Remove Must_Not_Freeze flags from default value expressions

This is a code cleanup and apparently has no impact on the behavior.

The Must_Not_Freeze is saved/set/restored by Preanalyze_Spec_Expression,
so it doesn't need to be set before calling that routine and apparently
doesn't need to be set after that calling that routine either.

gcc/ada/

* sem_ch13.adb (Resolve_Aspect_Expression): Don't set
Must_Not_Freeze before preanalyzing spec expressions.

12 months agoada: Change "missing overriding indicator" message from error to warning
Steve Baird [Wed, 26 Jun 2024 20:50:48 +0000 (13:50 -0700)] 
ada: Change "missing overriding indicator" message from error to warning

There is no RM rule requiring an overriding indicator in the case where
this message is generated; such a rule was discussed many years ago in an
AI, but that AI was never approved. So generate a warning message instead
of an error message. And don't even do that if we are in an instance (warning
a user they should change the source of an instance seems unlikely to be
helpful, at least in this case).

gcc/ada/

* sem_disp.adb (Check_Dispatching_Operation): When calling
Error_Msg_NE to generate a "missing overriding indicator" message,
generate a warning message instead of an error message (and update
comment to describe this new behavior).

12 months agoada: Miscomputed bounds for inner null array aggregates
Javier Miranda [Mon, 24 Jun 2024 11:29:57 +0000 (11:29 +0000)] 
ada: Miscomputed bounds for inner null array aggregates

gcc/ada/

* sem_aggr.adb (Collect_Aggr_Bounds): Adjust previous patch to
store the bounds of inner null aggregates in the itype; required
generate the runtime check of ARM 4.3.3(30).

12 months agoada: Followup on previous change for -gnatceg
Arnaud Charlet [Thu, 27 Jun 2024 09:59:27 +0000 (09:59 +0000)] 
ada: Followup on previous change for -gnatceg

gcc/ada/

* osint-c.ads, osint-c.adb (Create_C_File, Close_C_File,
Delete_C_File): Put back, needed by LLVM based CCG.
* exp_unst.adb (Unnest_Subprogram): Complete previous change by
removing now dead code and corresponding ??? comment.

12 months agoada: Missing adjust of controlled component initialized from container aggregate
Gary Dismukes [Wed, 26 Jun 2024 22:00:49 +0000 (22:00 +0000)] 
ada: Missing adjust of controlled component initialized from container aggregate

In the case of controlled components initialized by a container aggregate,
the compiler was suppressing the call to the needed Adjust operation,
because it was suppressed for all aggregates. But container aggregates
aren't built in place, so target adjustment should still be done in that
case.

gcc/ada/

* exp_ch3.adb (Build_Record_Init_Proc.Build_Assignment): Do the
component adjustment in the case of initialization by a container
aggregate.

12 months agoada: Fix internal error on limited aggregate in nested conditional expression
Eric Botcazou [Wed, 26 Jun 2024 17:55:44 +0000 (19:55 +0200)] 
ada: Fix internal error on limited aggregate in nested conditional expression

This is a fallout of an earlier fix to Is_Build_In_Place_Aggregate_Return
that made it take into account intermediate conditional expressions, but
turned out to work only for a single nesting level of them.

The fix reuses the delayed expansion mechanism recently extended to deal
with conditional expressions in a straightforward way.

gcc/ada/

* exp_aggr.adb (Convert_To_Assignments): Set Expansion_Delayed on
intermediate conditional expressions for BIP aggregate returns
too.
* exp_ch4.adb (Expand_N_Case_Expression): Also deal with delayed
expansion in the return case.
(Expand_N_If_Expression): Likewise.

12 months agoada: Operator visibility bug in static expression functions
Steve Baird [Mon, 24 Jun 2024 18:57:59 +0000 (11:57 -0700)] 
ada: Operator visibility bug in static expression functions

In some cases, an expanded name refering to a predefined operator (such as
Some_Package."+") occurring in a static expression function would be
incorrectly rejected with a message saying that the operator is not directly
visible (which, while True, does not make the reference illegal).

gcc/ada/

* sem_ch4.adb (Is_Effectively_Visible_Opertor): Return True if
Checking_Potentially_Static_Expression is True. The accompanying
comment says True is returned "if there is a reason it is ok for
Is_Visible_Operator to return False"; if
Checking_Potentially_Static_Expression is true, that is such a
reason.

12 months agoada: Stop ignoring Component_Size attribute in CodePeer_Mode
Ghjuvan Lacambre [Wed, 26 Jun 2024 14:08:20 +0000 (16:08 +0200)] 
ada: Stop ignoring Component_Size attribute in CodePeer_Mode

This piece of code was introduced in 2011 in order to prevent spurious
false positives from appearing on specific code patterns making use of
Component_Size.
It seems that now this piece of code is causing small false positives
instead of preventing them, so let's remove it.

gcc/ada/

* sem_ch13.adb (Analyze_Attribute_Definition_Clause): Stop
ignoring Component_Size attribute in CodePeer_Mode.

12 months agoada: Fix test for wrapping loop parameter spec
Ronan Desplanques [Mon, 17 Jun 2024 15:55:51 +0000 (17:55 +0200)] 
ada: Fix test for wrapping loop parameter spec

This patches fixes a problem where cleanup statements would be
missing for some cases of loop parameter specifications that allocate
on the secondary stack.

gcc/ada/

* sem_ch5.adb (Prepare_Param_Spec_Loop): Fix criterion for
wrapping loop statements into blocks.

12 months agoada: Remove support for bodies in -gnatceg
Arnaud Charlet [Thu, 13 Jun 2024 07:20:49 +0000 (07:20 +0000)] 
ada: Remove support for bodies in -gnatceg

The support for generating C for Ada code is moved to GNAT LLVM.
Keep support for generating header files from Ada spec files which
is the remaining usage of -gnatceg.

gcc/ada/

* bindgen.adb, bindusg.adb, debug.adb, einfo.ads,
exp_aggr.adb, exp_attr.adb, exp_ch11.adb, exp_ch3.adb,
exp_ch4.adb, exp_ch6.adb, exp_ch7.adb, exp_ch8.adb, exp_dbug.adb,
exp_dbug.ads, exp_intr.adb, exp_unst.adb, exp_util.adb,
exp_util.ads, freeze.adb, gen_il-fields.ads,
gen_il-gen-gen_entities.adb, gnat1drv.adb, inline.adb, opt.ads,
osint-c.adb, osint-c.ads, sem_attr.adb, sem_ch12.adb, sem_ch3.adb,
sem_ch4.adb, sem_ch6.adb, sem_elab.adb, sem_res.adb, sinfo.ads,
snames.ads-tmpl, switch-b.adb, switch-c.adb: Major
clean up to remove C code generation for bodies.

12 months agoada: Allow making empty aggregates positional
Ronan Desplanques [Wed, 19 Jun 2024 07:26:35 +0000 (09:26 +0200)] 
ada: Allow making empty aggregates positional

This patch makes Exp_Aggr.Convert_To_Positional accepts appropriate
empty aggregates. The end goal is to remove violations of the
No_Elaboration_Code restriction in some cases of library-level array
objects.

gcc/ada/

* exp_aggr.adb (Flatten): Do not reject empty aggregates. Adjust
criterion for emitting warning about ineffective others clause.
* sem_aggr.adb (Array_Aggr_Subtype): Fix typo. Add handling of
aggregates that were converted to positional form.
(Resolve_Aggregate): Tweak criterion for transforming into a
string literal.
(Resolve_Array_Aggregate): Tweak criterion for reusing existing
bounds of aggregate.
(Retrieve_Aggregate_Bounds): New procedure.
* sem_util.adb (Has_Static_Empty_Array_Bounds): New function.
* sem_util.ads (Has_Static_Empty_Array_Bounds): Likewise.

12 months agoada: Couple of cleanups in finalization machinery
Eric Botcazou [Mon, 24 Jun 2024 12:46:21 +0000 (14:46 +0200)] 
ada: Couple of cleanups in finalization machinery

This removes a parameter and a variable that are entirely determined by
another parameter and another variable respectively.

gcc/ada/

* exp_ch7.ads (Build_Finalizer): Remove Top_Decls parameter.
* exp_ch7.adb (Build_Finalizer): Likewise. Rename Counter_Val into
Count, replace Has_Ctrl_Objs local variable by expression
function, remove Spec_Decls local variable and do not reset
Finalizer_Decls.
(Expand_Cleanup_Actions): Adjust call to Build_Finalizer.
(Expand_N_Package_Body): Likewise.
(Expand_N_Package_Declaration): Likewise.
* inline.adb (Cleanup_Scopes): Likewise.

12 months agoada: Remove obsolete workaround
Eric Botcazou [Fri, 21 Jun 2024 21:01:11 +0000 (23:01 +0200)] 
ada: Remove obsolete workaround

It is possible to call the "+" operator of System.Storage_Elements directly
as done for example in Expand_Interface_Thunk.

gcc/ada/

* exp_ch7.adb (Make_Address_For_Finalize): Generate a direct call
to the "+" operator of System.Storage_Elements.
(Make_Finalize_Address_Stmts): Likewise.
* rtsfind.ads (RE_Id): Remove RE_Add_Offset_To_Address.
(RE_Unit_Table): Remove entry for RE_Add_Offset_To_Address.
* libgnat/s-finpri.ads (Add_Offset_To_Address): Delete.
* libgnat/s-finpri.adb (Add_Offset_To_Address): Likewise.

12 months agotestsuite: Add filters for default_packed targets [PR116155]
Dimitar Dimitrov [Tue, 30 Jul 2024 20:08:38 +0000 (23:08 +0300)] 
testsuite: Add filters for default_packed targets [PR116155]

A few recent C++ test cases are assuming non-zero structure field
padding.  Consequently they fail for targets defaulting to packed
structure layout.  Fix by adding the necessary DejaGnu filters.

There are no test result changes for x86_64-pc-linux-gnu:
  $ dg-cmp-results.sh -v -v "" pre-g++.sum post-g++.sum
  -> No differences.

The tests for pru-unknown-elf changed from FAIL to UNSUPPORTED.

PR testsuite/116155

gcc/testsuite/ChangeLog:

* g++.dg/abi/nsdmi-aggr1a.C: Disable test for effective
default_packed targets.
* g++.dg/abi/nullptr-align2.C: Ignore warning for default_packed
targets.
* g++.dg/cpp1z/aligned-new9.C: Disable test for effective
default_packed targets.
* g++.dg/cpp2a/bit-cast5.C: Ignore dg-error for default_packed
targets.
* g++.dg/pr53037-1.C: Match any default packing value.
* g++.dg/warn/Wpadded-1.C: Ignore warning for default_packed
targets.

Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
12 months agogccrs: Add a test for inherent impl type name resolve
Pierre-Emmanuel Patry [Thu, 18 Apr 2024 20:39:47 +0000 (22:39 +0200)] 
gccrs: Add a test for inherent impl type name resolve

A previous bug with name resolution 2.0 was caused by an incorrectly
resolved inherent impl name. This test shall highlight the behavior
and prevent regression.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
12 months agogccrs: Visit type during resolution of inherent impl
Pierre-Emmanuel Patry [Thu, 18 Apr 2024 20:30:56 +0000 (22:30 +0200)] 
gccrs: Visit type during resolution of inherent impl

Inherent impl has a type it applies to. This type
was not visited and thus not resolved.

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc (DefaultResolver::visit): Visit
inherent impl type.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
12 months agogccrs: borrowck: Bump copyright notice
Jakub Dupak [Wed, 3 Apr 2024 08:30:15 +0000 (10:30 +0200)] 
gccrs: borrowck: Bump copyright notice

gcc/rust/ChangeLog:

* checks/errors/borrowck/ffi-polonius/src/gccrs_ffi.rs: Bump copyright.
* checks/errors/borrowck/ffi-polonius/src/lib.rs: Bump copyright.
* checks/errors/borrowck/polonius/rust-polonius-ffi.h: Bump copyright.
* checks/errors/borrowck/polonius/rust-polonius.h: Bump copyright.
* checks/errors/borrowck/rust-bir-dump.cc: Bump copyright.
* checks/errors/borrowck/rust-bir-fact-collector.h: Bump copyright.
* checks/errors/borrowck/rust-bir-free-region.h: Bump copyright.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
12 months agogccrs: borrowck: Remove block braces to satisfy GNU style
Jakub Dupak [Mon, 1 Apr 2024 12:06:33 +0000 (14:06 +0200)] 
gccrs: borrowck: Remove block braces to satisfy GNU style

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-dump.cc (renumber_places):
Remove unecessary braces.
(Dump::go): Remove unecessary braces.
(Dump::visit): Remove unecessary braces.
(Dump::visit_scope): Remove unecessary braces.
* checks/errors/borrowck/rust-bir-fact-collector.h (class FactCollector):
Remove unecessary braces.
(points): Remove unecessary braces.
* checks/errors/borrowck/rust-bir-free-region.h: Remove unecessary braces.
* checks/errors/borrowck/rust-bir-place.h: Remove unecessary braces.
* checks/errors/borrowck/rust-borrow-checker.cc (BorrowChecker::go):
Remove unecessary braces.
* checks/errors/borrowck/rust-function-collector.h: Remove unecessary braces.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
12 months agogccrs: borrowck: Fact collector
Jakub Dupak [Tue, 27 Feb 2024 22:19:41 +0000 (23:19 +0100)] 
gccrs: borrowck: Fact collector

This is the main Polonius based logic which creates the information
Polonius needs from BIR. It is largly guessed and rever engineered, so
some aspects are probably wrong.

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-fact-collector.h: New file.
* checks/errors/borrowck/rust-borrow-checker.cc (BorrowChecker::go):
Enable fact collection.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
12 months agogccrs: borrowck: Regions in BIR
Jakub Dupak [Tue, 27 Feb 2024 22:01:14 +0000 (23:01 +0100)] 
gccrs: borrowck: Regions in BIR

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-place.h (struct Lifetime):
Extended regions and loans.
(struct Loan): Representation of loan (result of borrowing)
* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit):
Fix let stmt handling.
* checks/errors/borrowck/rust-bir-builder-pattern.h: improved
pattern translation
* checks/errors/borrowck/rust-bir-builder-internal.h: region binding
* checks/errors/borrowck/rust-bir-builder-expr-stmt.h (class ExprStmtBuilder):
Region support.
(class RenumberCtx): Region support.
* checks/errors/borrowck/rust-bir-builder.h (class Builder): Region support.
* checks/errors/borrowck/rust-bir-dump.cc (get_lifetime_name): Region support.
(renumber_places): Region support.
(Dump::go): Region support.
(Dump::visit): Region support.
(Dump::visit_lifetime): Region support.
(Dump::visit_scope): Region support.
* checks/errors/borrowck/rust-bir.h (class AbstractExpr): Region support.
(struct Function): Region support.
(class BorrowExpr): Region support.
(class CallExpr): Region support.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
12 months agogccrs: borrowck: extract regions from types using VA
Jakub Dupak [Tue, 27 Feb 2024 20:31:07 +0000 (21:31 +0100)] 
gccrs: borrowck: extract regions from types using VA

Biggybag on variance analysis to extract regions of fields from ADT
regions.

gcc/rust/ChangeLog:

* typecheck/rust-tyty-variance-analysis-private.h (class FieldVisitorCtx):
Region extraction.
* typecheck/rust-tyty-variance-analysis.cc (query_field_regions): Region extraction.
(FieldVisitorCtx::collect_regions): Region extraction.
(FieldVisitorCtx::add_constraints_from_ty): Region extraction.
(FieldVisitorCtx::add_constraints_from_region): Region
extraction.
(FieldVisitorCtx::add_constrints_from_param): Region extraction.
* typecheck/rust-tyty-variance-analysis.h (query_field_regions):
Region extraction.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
12 months agogccrs: borrowck: Free region representation
Jakub Dupak [Tue, 27 Feb 2024 20:07:03 +0000 (21:07 +0100)] 
gccrs: borrowck: Free region representation

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-free-region.h: New file.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
12 months agogccrs: borrowck: Polonius FFI
Jakub Dupak [Tue, 27 Feb 2024 19:59:58 +0000 (20:59 +0100)] 
gccrs: borrowck: Polonius FFI

Rust part is not build and not invoked at this point.

gcc/rust/ChangeLog:

* checks/errors/borrowck/ffi-polonius/Cargo.toml: New file.
* checks/errors/borrowck/ffi-polonius/src/gccrs_ffi.rs: New file.
* checks/errors/borrowck/ffi-polonius/src/gccrs_ffi_generated.rs: New file.
* checks/errors/borrowck/ffi-polonius/src/lib.rs: New file.
* checks/errors/borrowck/polonius/rust-polonius-ffi.h: New file.
* checks/errors/borrowck/polonius/rust-polonius.h: New file.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
12 months agogccrs: borrowck: BIR: make BIR visitor const
Jakub Dupak [Tue, 27 Feb 2024 19:22:17 +0000 (20:22 +0100)] 
gccrs: borrowck: BIR: make BIR visitor const

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-dump.cc (Dump::visit): const
visitor
* checks/errors/borrowck/rust-bir-dump.h: const visitor
* checks/errors/borrowck/rust-bir-visitor.h: const visitor
* checks/errors/borrowck/rust-bir.h: const getter

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
12 months agogccrs: borrowck: BIR: emit moves
Jakub Dupak [Fri, 2 Feb 2024 13:47:14 +0000 (14:47 +0100)] 
gccrs: borrowck: BIR: emit moves

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Emit moves.
* checks/errors/borrowck/rust-bir-builder-internal.h: Emit moves.
* checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: Emit moves.
* checks/errors/borrowck/rust-bir-dump.cc (Dump::visit_move_place): Emit moves.
(Dump::visit): Emit moves.
* checks/errors/borrowck/rust-bir-place.h (struct Place): Emit moves.
* checks/errors/borrowck/rust-bir-visitor.h: Emit moves.
* checks/errors/borrowck/rust-bir.h (enum class): Emit moves.
(class AbstractExpr): Emit moves.
(BasicBlock::is_terminated): Emit moves.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
12 months agogccrs: borrowck: BIR: scope handling
Jakub Dupak [Fri, 2 Feb 2024 13:38:59 +0000 (14:38 +0100)] 
gccrs: borrowck: BIR: scope handling

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::setup_loop):
Loop handling.
(ExprStmtBuilder::visit): Handle scopes.
* checks/errors/borrowck/rust-bir-builder-internal.h (struct BuilderContext):
Handle scopes.
* checks/errors/borrowck/rust-bir-dump.cc (Dump::go): Dump scopes.
(Dump::visit): Add scopes dump.
(Dump::indent): Add indentation logic.
(Dump::visit_scope): Dump scope.
* checks/errors/borrowck/rust-bir-dump.h: Dump methods.
* checks/errors/borrowck/rust-bir-place.h (std::numeric_limits::max): Scope constants.
(struct Scope): Scope representation.
(class PlaceDB): Scope tracking.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
12 months agogccrs: borrowck: BIR: Place tree traverse API
Jakub Dupak [Fri, 2 Feb 2024 13:36:26 +0000 (14:36 +0100)] 
gccrs: borrowck: BIR: Place tree traverse API

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-place.h:
Create place tree traverse API.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
12 months agogccrs: borrowck: BIR: use callable API
Jakub Dupak [Fri, 2 Feb 2024 13:33:56 +0000 (14:33 +0100)] 
gccrs: borrowck: BIR: use callable API

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit):
Use callable API

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
12 months agogccrs: borrowck: Unify BIR terminilogy (node->statement)
Jakub Dupak [Sat, 4 Nov 2023 15:52:27 +0000 (16:52 +0100)] 
gccrs: borrowck: Unify BIR terminilogy (node->statement)

gcc/rust/ChangeLog:

* checks/errors/borrowck/bir-design-notes.md (nodes): Rename node to statement.
(Nodes): Rename node to statement.
* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit):
Rename node to statement.
* checks/errors/borrowck/rust-bir-builder-internal.h: Rename node to statement.
* checks/errors/borrowck/rust-bir-builder.h: Rename node to statement.
* checks/errors/borrowck/rust-bir-dump.cc (Dump::go): Rename node to statement.
(Dump::visit): Rename node to statement.
* checks/errors/borrowck/rust-bir-dump.h (class Dump): Rename node to statement.
* checks/errors/borrowck/rust-bir-visitor.h (class Node): Rename node to statement.
(class Statement): Rename node to statement.
* checks/errors/borrowck/rust-bir.h (class Node): Rename node to statement.
(class Statement): Rename node to statement.
(class AbstractExpr): Rename node to statement.
(struct Function): Rename node to statement.
(struct BasicBlock): Rename node to statement.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
12 months agogccrs: borrowck: Use rust-system.h
Jakub Dupak [Fri, 22 Mar 2024 15:24:30 +0000 (16:24 +0100)] 
gccrs: borrowck: Use rust-system.h

Replace direct usage of system headers.

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-dump.cc: Use rust-system.h
* checks/errors/borrowck/rust-bir-dump.h (RUST_BIR_DUMP_H): Use rust-system.h
* checks/errors/borrowck/rust-bir-place.h (RUST_BIR_PLACE_H): Use rust-system.h
* checks/errors/borrowck/rust-function-collector.h: Use rust-system.h
* rust-system.h: Use rust-system.h
* typecheck/rust-hir-type-check.h: Use rust-system.h
* typecheck/rust-tyty-subst.cc: Use rust-system.h
* typecheck/rust-tyty-subst.h: Use rust-system.h
* typecheck/rust-tyty.h: Use rust-system.h

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
12 months agogccrs: unify: Always coerce `!` to the target type.
Arthur Cohen [Wed, 6 Mar 2024 15:19:46 +0000 (16:19 +0100)] 
gccrs: unify: Always coerce `!` to the target type.

Never can... never... exist, so it should always be coerced to the type
it is being matched against. This is useful for breaking off of a loop
from inside a match, or an if condition, for example.

gcc/rust/ChangeLog:

* typecheck/rust-unify.cc (UnifyRules::go): Always unify to `ltype` if
we are matching against a `Never` in `rtype`.
(UnifyRules::expect_never): Always unify to the expected type.

gcc/testsuite/ChangeLog:

* rust/compile/match-never-ltype.rs: New test.
* rust/compile/match-never-rtype.rs: New test.

12 months agogccrs: raw-strings: Remove dg-excess-error directive
Arthur Cohen [Fri, 29 Mar 2024 11:19:10 +0000 (12:19 +0100)] 
gccrs: raw-strings: Remove dg-excess-error directive

The error is actually expected and uses the correct location.

gcc/testsuite/ChangeLog:

* rust/compile/raw-byte-string-loc.rs: Use dg-error instead of
dg-excess-error.
* rust/compile/raw-string-loc.rs: Likewise.

12 months agogccrs: Improve parsing of raw string literals
Owen Avery [Wed, 27 Mar 2024 01:10:05 +0000 (21:10 -0400)] 
gccrs: Improve parsing of raw string literals

gcc/rust/ChangeLog:

* lex/rust-lex.cc
(Lexer::parse_raw_string):
Bring handling of edge cases to par with parse_raw_byte_string.

gcc/testsuite/ChangeLog:

* rust/compile/raw-string-loc.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
12 months agogccrs: Avoid parsing const unsafe/extern functions as async
Owen Avery [Tue, 26 Mar 2024 19:58:48 +0000 (15:58 -0400)] 
gccrs: Avoid parsing const unsafe/extern functions as async

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h
(Parser::parse_vis_item):
Call parse_function instead of parse_async_item when finding
UNSAFE or EXTERN_KW during lookahead.

gcc/testsuite/ChangeLog:

* rust/compile/func-const-unsafe.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
12 months agogccrs: Recognize unstable as a builtin attribute
Owen Avery [Tue, 26 Mar 2024 23:28:53 +0000 (19:28 -0400)] 
gccrs: Recognize unstable as a builtin attribute

gcc/rust/ChangeLog:

* util/rust-attribute-values.h
(Attributes::UNSTABLE): New.
* util/rust-attributes.cc
(__definitions): Add Attributes::UNSTABLE.

gcc/testsuite/ChangeLog:

* rust/compile/unstable-fn.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
12 months agogccrs: Recognize rustc_deprecated as a builtin attribute
Owen Avery [Wed, 27 Mar 2024 01:57:17 +0000 (21:57 -0400)] 
gccrs: Recognize rustc_deprecated as a builtin attribute

gcc/rust/ChangeLog:

* util/rust-attribute-values.h
(Attributes::RUSTC_DEPRECATED): New.
* util/rust-attributes.cc
(__definitions): Add Attributes::RUSTC_DEPRECATED.

gcc/testsuite/ChangeLog:

* rust/compile/deprecated-fn.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
12 months agogccrs: Improve parsing of raw byte string literals
Owen Avery [Wed, 27 Mar 2024 00:16:08 +0000 (20:16 -0400)] 
gccrs: Improve parsing of raw byte string literals

gcc/rust/ChangeLog:

* lex/rust-lex.cc
(Lexer::parse_raw_byte_string):
Bring handling of edge cases to par with parse_byte_string.

gcc/testsuite/ChangeLog:

* rust/compile/raw-byte-string-loc.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
12 months agogccrs: Change dfs function return type to support gcc 4.8
Pierre-Emmanuel Patry [Tue, 26 Mar 2024 15:32:31 +0000 (16:32 +0100)] 
gccrs: Change dfs function return type to support gcc 4.8

GCC 4.8 does not handle pair with references correctly. We need to use a
properly typed struct instead.

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.h: Change dfs function prototype and
declare dfs return type structure.
* resolve/rust-forever-stack.hxx: Adapt dfs function to the new return
type.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
12 months agogccrs: Add globbing name resolution 2.0 test
Pierre-Emmanuel Patry [Tue, 26 Mar 2024 09:58:53 +0000 (10:58 +0100)] 
gccrs: Add globbing name resolution 2.0 test

Add a few test for globbing to highlight function call ambiguities.

gcc/testsuite/ChangeLog:

* rust/compile/name_resolution23.rs: New test.
* rust/compile/name_resolution24.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
12 months agogccrs: nr2.0: Add new test cases.
Arthur Cohen [Wed, 23 Aug 2023 15:19:28 +0000 (17:19 +0200)] 
gccrs: nr2.0: Add new test cases.

gcc/testsuite/ChangeLog:

* rust/compile/name_resolution13.rs: Add new module and remove compile
step.
* rust/compile/name_resolution14.rs: New test.
* rust/compile/name_resolution15.rs: New test.
* rust/compile/name_resolution16.rs: New test.
* rust/compile/name_resolution17.rs: New test.
* rust/compile/name_resolution18.rs: New test.
* rust/compile/name_resolution19.rs: New test.
* rust/compile/name_resolution20.rs: New test.
* rust/compile/name_resolution21.rs: New test.

12 months agogccrs: compile: resolve-path-ref: properly resolve nodeId with nr2.0
Arthur Cohen [Fri, 22 Mar 2024 13:31:24 +0000 (14:31 +0100)] 
gccrs: compile: resolve-path-ref: properly resolve nodeId with nr2.0

gcc/rust/ChangeLog:

* backend/rust-compile-resolve-path.cc: Attempt to resolve names
also using new name resolution context.
* backend/rust-compile-resolve-path.h: Add new declaration.

12 months agogccrs: Fix use rebind name resolution.
Pierre-Emmanuel Patry [Thu, 21 Mar 2024 18:25:52 +0000 (19:25 +0100)] 
gccrs: Fix use rebind name resolution.

Name resolution for rebind were missing.

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::handle_use_glob):
Change function prototype to use a reference instead.
(TopLevel::handle_use_dec): Likewise.
(TopLevel::handle_rebind): Add name resolution on rebind use
declarations.
(flatten_rebind): Change prototype to accept a pair of path/alias.
(flatten_list): Adapt call to flatten_rebind.
(flatten): Adapt call to flatten_rebind.
(flatten_glob): Remove unused part.
(TopLevel::visit): Add rebind resolution.
* resolve/rust-toplevel-name-resolver-2.0.h: Adapt function prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
12 months agogccrs: Add mappings for struct base and struct fields
Pierre-Emmanuel Patry [Thu, 21 Mar 2024 18:16:02 +0000 (19:16 +0100)] 
gccrs: Add mappings for struct base and struct fields

Definition/usage mapping during name resolution was missing.

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add mapping
implementation.
* resolve/rust-late-name-resolver-2.0.h: Add function visitor prototype
override.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
12 months agogccrs: Fix quoted string format
Pierre-Emmanuel Patry [Wed, 13 Mar 2024 16:18:58 +0000 (17:18 +0100)] 
gccrs: Fix quoted string format

This format dialog triggered a warning.

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::handle_use_dec):
Replace the string format %<%s%> with the proper %qs format.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
12 months agogccrs: Prevent getting immutable context with classic nr
Pierre-Emmanuel Patry [Wed, 13 Mar 2024 15:44:00 +0000 (16:44 +0100)] 
gccrs: Prevent getting immutable context with classic nr

Immutable name resolution context is not initialized when the classic
name resolution is in use. It can therefore not be used, the getter would
error out.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_root_path):
Only get immutable name resolution context when name resolution 2.0 is
used.
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path):
Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
12 months agogccrs: Update assignment operator with cratenum
Pierre-Emmanuel Patry [Wed, 13 Mar 2024 15:21:44 +0000 (16:21 +0100)] 
gccrs: Update assignment operator with cratenum

Crate number was not assigned with the other fields in the assignment
operator overload of a CannonicalPath.

gcc/rust/ChangeLog:

* util/rust-canonical-path.h: Also assign crate number.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
12 months agogccrs: Reinject Self parameter in new resolver
Pierre-Emmanuel Patry [Wed, 7 Feb 2024 11:51:28 +0000 (12:51 +0100)] 
gccrs: Reinject Self parameter in new resolver

The old resolver injected a Self generic parameter in order to help the
trait solver. This is clearly sketchy at best and should be fixed in
the future.

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Add
Self generic parameter injection and a warning.
* resolve/rust-toplevel-name-resolver-2.0.h: Add function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
12 months agogccrs: Use new name resolver to compile constant items
Pierre-Emmanuel Patry [Tue, 6 Feb 2024 16:21:45 +0000 (17:21 +0100)] 
gccrs: Use new name resolver to compile constant items

Constant items were handled only by the old resolver, this lead to an
ICE when using the new resolver on some rust code containing a constant
item as the new and the old resolver cannot be used at the same time.

gcc/rust/ChangeLog:

* backend/rust-compile-item.cc (CompileItem::visit): Check the resolver
flag and use the new one when required.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
12 months agogccrs: Remove unsafe block empty visit function
Pierre-Emmanuel Patry [Tue, 6 Feb 2024 14:13:17 +0000 (15:13 +0100)] 
gccrs: Remove unsafe block empty visit function

We need to visit subcomponents in unsafe elements, this means we can
leverage the default ast visitor's code instead of duplicating it.

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc (DefaultResolver::visit): Remove
empty visit function.
* resolve/rust-default-resolver.h: Remove function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
12 months agogccrs: Remove extern block scoping
Pierre-Emmanuel Patry [Tue, 6 Feb 2024 14:10:44 +0000 (15:10 +0100)] 
gccrs: Remove extern block scoping

Remove extern block scoping visit function, use the default visitor visit
function instead. We do not need scoping for extern block as their
element shall be visible from the extern block scope.

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc (DefaultResolver::visit): Remove
visitor implementation and scoping.
* resolve/rust-default-resolver.h: Remove function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
12 months agogccrs: Add constant identifiers to the value namespace
Pierre-Emmanuel Patry [Wed, 24 Jan 2024 16:11:59 +0000 (17:11 +0100)] 
gccrs: Add constant identifiers to the value namespace

Constants could not be resolved without their identifier in the right
scope.

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Add
constant identifiers to the resolver.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
12 months agogccrs: Struct are types, not values
Pierre-Emmanuel Patry [Wed, 24 Jan 2024 16:10:42 +0000 (17:10 +0100)] 
gccrs: Struct are types, not values

We shall search in the right namespace. The correct namespace for struct
is type namespace.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): Change
search location for struct types.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
12 months agogccrs: Change enum namespace from value to type
Pierre-Emmanuel Patry [Wed, 24 Jan 2024 16:08:05 +0000 (17:08 +0100)] 
gccrs: Change enum namespace from value to type

The enum type shall be in type namespace, not value namespace.

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc (GlobbingVisitor::visit):
Change enum type namespace.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
12 months agogccrs: Add tuple struct to the type namespace
Pierre-Emmanuel Patry [Wed, 24 Jan 2024 16:06:56 +0000 (17:06 +0100)] 
gccrs: Add tuple struct to the type namespace

Only tuple struct constructor was added to the resolver.

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc (GlobbingVisitor::visit):
Add tuple struct type to the resolver's context.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
12 months agogccrs: Unit struct constructor shall be resolved
Pierre-Emmanuel Patry [Wed, 24 Jan 2024 16:04:51 +0000 (17:04 +0100)] 
gccrs: Unit struct constructor shall be resolved

Unit struct have a special constructor that should be added to the struct
namespace in order to be resolved later when called. As it is a function
it should be added in the value namespace.

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc (GlobbingVisitor::visit):
Add the struct constructor when the struct is a unit.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
12 months agogccrs: Values shall be inserted in the value namespace
Pierre-Emmanuel Patry [Wed, 24 Jan 2024 16:00:29 +0000 (17:00 +0100)] 
gccrs: Values shall be inserted in the value namespace

Values were inserted in the label namespace instead of the value
namespace this lead to several bugs.

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Change the
namespace for values from "label" to "values".

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
12 months agogccrs: Raw pointer type visitor didn't require overload
Pierre-Emmanuel Patry [Wed, 24 Jan 2024 15:57:37 +0000 (16:57 +0100)] 
gccrs: Raw pointer type visitor didn't require overload

This overload did not dispatch the visitor to sub members of a raw
pointer like the default one. It is therefore useless as pointed type
shall be visited to be resolved correctly.

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc (DefaultResolver::visit): Remove
function implementation.
* resolve/rust-default-resolver.h: Remove function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
12 months agogccrs: Visit constant item type in default resolver
Pierre-Emmanuel Patry [Wed, 24 Jan 2024 15:50:27 +0000 (16:50 +0100)] 
gccrs: Visit constant item type in default resolver

The type of constant item expression was not properly visited in the
default resolver.

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc (DefaultResolver::visit): Visit
constant item's types.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
12 months agogccrs: Visit function return type in default resolver
Pierre-Emmanuel Patry [Wed, 24 Jan 2024 15:47:50 +0000 (16:47 +0100)] 
gccrs: Visit function return type in default resolver

Function return type was not properly visited in the default resolver
visitor pattern.

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc (DefaultResolver::visit): Visit
function return type.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
12 months agogccrs: Change error message to match test
Pierre-Emmanuel Patry [Wed, 17 Jan 2024 12:53:21 +0000 (13:53 +0100)] 
gccrs: Change error message to match test

Error message did not match the test from the previous name resolver when
a given path cannot be resolved.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_root_path):
Change error message to match old resolver and test case.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
12 months agogccrs: Add tuple struct constructor to value namespace
Pierre-Emmanuel Patry [Wed, 17 Jan 2024 12:02:51 +0000 (13:02 +0100)] 
gccrs: Add tuple struct constructor to value namespace

A tuple struct constructor should be inserted in the value namespace
during name resolution in order to reject multiple definitions of the
function.

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Add
the struct constructor to the value namespace.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
12 months agogccrs: Add support for ambiguous use declarations
Pierre-Emmanuel Patry [Tue, 16 Jan 2024 12:55:02 +0000 (13:55 +0100)] 
gccrs: Add support for ambiguous use declarations

Glob use declarations may lead to ambiguous situation where two
definitions with the same name are imported in a given scope. The
compiler now handles shadowable items inserted after non shadowable
items. An error is now thrown when multiple shadowable items are imported
and used in the same rib.

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc (Early::visit): Adapt
resolved type to the new API.
(Early::visit_attributes): Retrieve the node id from the definition.
* resolve/rust-forever-stack.h: Change the return type of getter
functions. Those functions now return a definition type instead of a
node id.
* resolve/rust-forever-stack.hxx: Change member function implementation
in the forever stack to accomodate it's API changes.
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Use internal
node id. Emit an error when resolving multiple ambiguous values.
* resolve/rust-rib.cc (Rib::Definition::Definition): Add a default
constructor.
(Rib::Definition::is_ambiguous): Add a new function to determine
whether a function definition is ambiguous or not.
(Rib::Definition::to_string): Add a member function to convert a given
definition to a string.
(Rib::insert): Add new rules for value insertion in a rib. Insertion
order does not impact the result anymore: inserting a shadowable value
after a non shadowable one does not trigger an error anymore. All
shadowable values inserted in a rib are kepts until being replaced by a
non shadowable one.
(Rib::get): Return a definition instead of a node id.
* resolve/rust-rib.h: Update function prototypes.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::handle_use_glob):
Update return value container to match the new function's prototype.
(TopLevel::handle_use_dec): Likewise.
(flatten_glob): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>