Sandra Loosemore [Thu, 18 Jan 2024 00:12:40 +0000 (00:12 +0000)]
Re-alphabetize attribute tables in extend.texi.
These sections used to be alphabetized, but when I was working on the
fix for PR111659 I noticed documentation for some newer attributes had
been inserted at random places in the tables instead of maintaining
alphabetical order. There's no change to content here, just moving
blocks of text around.
gcc/ChangeLog
* doc/extend.texi (Common Function Attributes): Re-alphabetize
the table.
(Common Variable Attributes): Likewise.
(Common Type Attributes): Likewise.
Nathaniel Shead [Sat, 16 Dec 2023 10:34:45 +0000 (21:34 +1100)]
c++: Prevent overwriting arguments when merging duplicates [PR112588]
When merging duplicate instantiations of function templates, currently
read_function_def overwrites the arguments with that of the existing
duplicate. This is problematic, however, since this means that the
PARM_DECLs in the body of the function definition no longer match with
the PARM_DECLs in the argument list, which causes issues when it comes
to generating RTL.
There doesn't seem to be any reason to do this replacement, so this
patch removes that logic.
Sandra Loosemore [Wed, 17 Jan 2024 21:37:19 +0000 (21:37 +0000)]
Clean up documentation for -Wstrict-flex-arrays [PR111659]
gcc/ChangeLog
PR middle-end/111659
* doc/extend.texi (Common Variable Attributes): Fix long lines
in documentation of strict_flex_array + other minor copy-editing.
Add a cross-reference to -Wstrict-flex-arrays.
* doc/invoke.texi (Option Summary): Fix whitespace in tables
before -fstrict-flex-arrays and -Wstrict-flex-arrays.
(C Dialect Options): Combine the docs for the two
-fstrict-flex-arrays forms into a single entry. Note this option
is for C/C++ only. Add a cross-reference to -Wstrict-flex-arrays.
(Warning Options): Note -Wstrict-flex-arrays is for C/C++ only.
Minor copy-editing. Add cross references to the strict_flex_array
attribute and -fstrict-flex-arrays option. Add note that this
option depends on -ftree-vrp.
Andrew Pinski [Tue, 16 Jan 2024 23:37:49 +0000 (15:37 -0800)]
aarch64: Fix aarch64_ldp_reg_operand predicate not to allow all subreg [PR113221]
So the problem here is that aarch64_ldp_reg_operand will all subreg even subreg of lo_sum.
When LRA tries to fix that up, all things break. So the fix is to change the check to only
allow reg and subreg of regs.
Note the tendancy here is to use register_operand but that checks the mode of the register
but we need to allow a mismatch modes for this predicate for now.
Built and tested for aarch64-linux-gnu with no regressions
(Also tested with the LD/ST pair pass back on).
PR target/113221
gcc/ChangeLog:
* config/aarch64/predicates.md (aarch64_ldp_reg_operand): For subreg,
only allow REG operands instead of allowing all.
gcc/testsuite/ChangeLog:
* gcc.c-torture/compile/pr113221-1.c: New test.
Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
Vineet Gupta [Tue, 16 Jan 2024 21:23:42 +0000 (13:23 -0800)]
RISC-V: fix some vsetvl debug info in pass's Phase 2 code [NFC]
When staring at VSETVL pass for PR/113429, spotted some minor
improvements.
1. For readablity, remove some redundant condition check in Phase 2
function earliest_fuse_vsetvl_info ().
2. Add iteration count in debug prints in same function.
gcc/ChangeLog:
* config/riscv/riscv-vsetvl.cc (earliest_fuse_vsetvl_info):
Remove redundant checks in else condition for readablity.
(earliest_fuse_vsetvl_info) Print iteration count in debug
prints.
(earliest_fuse_vsetvl_info) Fix misleading vsetvl info
dump details in certain cases.
Vineet Gupta [Tue, 16 Jan 2024 21:17:27 +0000 (13:17 -0800)]
RISC-V: RVV: add toggle to control vsetvl pass behavior
RVV requires VSET?VL? instructions to dynamically configure VLEN at
runtime. There's a custom pass to do that which has a simple mode
which generates a VSETVL for each V insn and a lazy/optimal mode which
uses LCM dataflow to move VSETVL around, identify/delete the redundant
ones.
Currently simple mode is default for !optimize invocations while lazy
mode being the default.
This patch allows simple mode to be forced via a toggle independent of
the optimization level. A lot of gcc developers are currently doing this
in some form in their local setups, as in the initial phase of autovec
development issues are expected. It makes sense to provide this facility
upstream. It could potentially also be used by distro builder for any
quick workarounds in autovec bugs of future.
gcc/ChangeLog:
* config/riscv/riscv.opt: New -param=vsetvl-strategy.
* config/riscv/riscv-opts.h: New enum vsetvl_strategy_enum.
* config/riscv/riscv-vsetvl.cc
(pre_vsetvl::pre_global_vsetvl_info): Use vsetvl_strategy.
(pass_vsetvl::execute): Use vsetvl_strategy.
Jan Hubicka [Wed, 17 Jan 2024 18:16:47 +0000 (19:16 +0100)]
Remove accidental hack in ipa_polymorphic_call_context::set_by_invariant
I managed to commit a hack setting offset to 0 in
ipa_polymorphic_call_context::set_by_invariant. This makes it to give up on multiple
inheritance, but most likely won't give bad code since the ohter base will be of
different type.
Jan Hubicka [Wed, 17 Jan 2024 18:14:16 +0000 (19:14 +0100)]
Fix handling of X86_TUNE_AVOID_512FMA_CHAINS.
I have noticed quite bad pasto in handling of X86_TUNE_AVOID_512FMA_CHAINS. At the
moment it is ignored, but X86_TUNE_AVOID_256FMA_CHAINS controls 512FMA too.
This patch fixes it, we may want to re-check how that works on AVX512 machines.
gcc/ChangeLog:
* config/i386/i386-options.cc (ix86_option_override_internal): Fix
handling of X86_TUNE_AVOID_512FMA_CHAINS.
testsuite: Reduce gcc.dg/torture/inline-mem-cpy-1.c by 11 for simulators
The test inline-mem-cpy-1.c takes 16 minutes at -O0 for the mmix
simulator on a 3.5 year old laptop and thus always times out, despite
the x 2 timeout (i.e. 10 minutes), and times out at all optimization
levels. For the included file (when run as gcc.dg/memcmp-1.c), the
execution time on the same host is 9 minutes 54 seconds, so just
within 10 minutes timeout limit. Seems pragmatically best to reduce
the torture-test by a factor of about 10, but there's no obvious small
set of entities to scale down to get the intended effect, and
splitting up the test into several tests seem a bit too intrusive.
Instead, introduce pseudo-random machinery to skip all but each
RUN_FRACTION:th iteration, defaulting to no change when RUN_FRACTION
isn't defined. Use 11 for RUN_FRACTION, assuming this prime will lead
to even distribution within nested iterations with loops looking like
(0, 1) : (0, 1). Do this only for the main loop in
test_driver_memcmp; the "outermost" two levels of iterations.
With this, execution time for -O0 as above is down to 1 minute 32
seconds.
* gcc.dg/torture/inline-mem-cpy-1.c: Pass -DRUN_FRACTION=11
when testing in a simulator.
* gcc.dg/memcmp-1.c [RUN_FRACTION]: Add machinery to run only
for each RUN_FRACTION:th iteration.
(main): Call initialize_skip_iteration_count.
(test_driver_memcmp): Check SKIP_ITERATION for each iteration.
Jan Hubicka [Wed, 17 Jan 2024 14:19:32 +0000 (15:19 +0100)]
Fix merging of value predictors
expr_expected_value is doing some guesswork when it is merging two or more
independent value predictions either in PHI node or in binary operation.
Since we do not know how the predictions interact with each other, we can
not really merge the values precisely.
The previous logic merged the prediciton and picked the later predictor
(since predict.def is sorted by reliability). This however leads to troubles
with __builtin_expect_with_probability since it is special cased as a predictor
with custom probabilities. If this predictor is downgraded to something else,
we ICE since we have prediction given by predictor that is not expected
to have customprobability.
This patch fixies it by inventing new predictors PRED_COMBINED_VALUE_PREDICTIONS
and PRED_COMBINED_VALUE_PREDICTIONS_PHI which also allows custom values but
are considered less reliable then __builtin_expect_with_probability (they
are combined by ds theory rather then by first match). This is less likely
going to lead to very stupid decisions if combining does not work as expected.
I also updated the code to be bit more careful about merging values and do not
downgrade the precision when unnecesary (as tested by new testcases).
Bootstrapped/regtested x86_64-linux, will commit it tomorrow if there are
no complains.
2024-01-17 Jan Hubicka <jh@suse.cz>
Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/110852
gcc/ChangeLog:
* predict.cc (expr_expected_value_1): Fix profile merging of PHI and
binary operations
(get_predictor_value): Handle PRED_COMBINED_VALUE_PREDICTIONS and
PRED_COMBINED_VALUE_PREDICTIONS_PHI
* predict.def (PRED_COMBINED_VALUE_PREDICTIONS): New predictor.
(PRED_COMBINED_VALUE_PREDICTIONS_PHI): New predictor.
gcc/testsuite/ChangeLog:
* gcc.dg/predict-18.c: Update template to expect combined value predictor.
* gcc.dg/predict-23.c: New test.
* gcc.dg/tree-ssa/predict-1.c: New test.
* gcc.dg/tree-ssa/predict-2.c: New test.
* gcc.dg/tree-ssa/predict-3.c: New test.
Jakub Jelinek [Wed, 17 Jan 2024 13:43:40 +0000 (14:43 +0100)]
lower-bitint: Avoid overlap between destinations and sources in libgcc calls [PR113421]
The following testcase is miscompiled because the bitint lowering emits a
.MULBITINT (&a, 1024, &a, 1024, &x, 1024);
call. The bug is in the overlap between the destination and source, that is
something the libgcc routines don't handle, they use the source arrays
during the entire algorithms which computes the destination array(s).
For the mapping of SSA_NAMEs to VAR_DECLs the code already supports that
correctly, but the checking whether a load from memory can be used directly
without a temporary even when earlier we decided to merge the
multiplication/division/modulo etc. with a store didn't.
The following patch implements that.
2024-01-17 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/113421
* gimple-lower-bitint.cc (stmt_needs_operand_addr): Adjust function
comment.
(bitint_dom_walker::before_dom_children): Add g temporary to simplify
formatting. Start at vop rather than cvop even if stmt is a store
and needs_operand_addr.
Jakub Jelinek [Wed, 17 Jan 2024 12:57:07 +0000 (13:57 +0100)]
gimple-ssa-warn-access: Cast huge params to sizetype before using them in maybe_check_access_sizes [PR113410]
WHen a VLA is created with some very high precision size expression
(say __int128, or _BitInt(65535) etc.), we cast it to sizetype, because
we can't have arrays longer than what can be expressed in sizetype.
But the maybe_check_access_sizes code when trying to determine ranges
wasn't doing this but was using fixed buffers for the sizes. While
__int128 could still be handled (fit into the buffers), obviously
arbitrary _BitInt parameter ranges can't, they can be in the range of
up to almost 20KB per number. It doesn't make sense to print such
ranges though, no array can be larger than sizetype precision, and
ranger's range_of_expr can handle NOP_EXPRs/CONVERT_EXPRs wrapping a
PARM_DECL just fine, so the following patch just casts the excessively
large counters for the range determination purposes to sizetype.
2024-01-17 Jakub Jelinek <jakub@redhat.com>
PR middle-end/113410
* gimple-ssa-warn-access.cc (pass_waccess::maybe_check_access_sizes):
If access_nelts is integral with larger precision than sizetype,
fold_convert it to sizetype.
Jakub Jelinek [Wed, 17 Jan 2024 12:55:50 +0000 (13:55 +0100)]
lower-bitint: Fix up VIEW_CONVERT_EXPR handling [PR113408]
Unlike NOP_EXPR/CONVERT_EXPR which are GIMPLE_UNARY_RHS, VIEW_CONVERT_EXPR
is GIMPLE_SINGLE_RHS and so gimple_assign_rhs1 contains the operand wrapped
in VIEW_CONVERT_EXPR tree.
So, to handle it like other casts we need to look through it.
2024-01-17 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/113408
* gimple-lower-bitint.cc (bitint_large_huge::handle_stmt): For
VIEW_CONVERT_EXPR, pass TREE_OPERAND (rhs1, 0) rather than rhs1
to handle_cast.
Jakub Jelinek [Wed, 17 Jan 2024 12:54:44 +0000 (13:54 +0100)]
ipa-strub: Fix handling of _BitInt returns [PR113406]
Seems pass_ipa_strub::execute contains a copy of the expand_thunk
code I've changed for _BitInt in r14-6805 PR112941 - larger _BitInts
are aggregate_value_p even when they are is_gimple_reg_type.
2024-01-17 Jakub Jelinek <jakub@redhat.com>
PR middle-end/113406
* ipa-strub.cc (pass_ipa_strub::execute): Check aggregate_value_p
regardless of whether is_gimple_reg_type (restype) or not.
This is another C++26 change, approved in Varna 2023. We require a new
static array of data that is extracted from the IANA Character Sets
database. A new Python script to generate a header from the IANA CSV
file is added.
The text_encoding class is basically just a pointer to an {ID,name} pair
in the static array. The aliases view is also just the same pointer (or
empty), and the view's iterator moves forwards and backwards in the
array while the array elements have the same ID (or to one element
further, for a past-the-end iterator).
Because those iterators refer to a global array that never goes out of
scope, there's no reason they should every produce undefined behaviour
or indeterminate values. They should either have well-defined
behaviour, or abort. The overhead of ensuring those properties is pretty
low, so seems worth it.
This means that an aliases_view iterator should never be able to access
out-of-bounds. A non-value-initialized iterator always points to an
element of the static array even when not dereferenceable (the array has
unreachable entries at the start and end, which means that even a
past-the-end iterator for the last encoding in the array still points to
valid memory). Dereferencing an iterator can always return a valid
array element, or "" for a non-dereferenceable iterator (but doing so
will abort when assertions are enabled). In the language being proposed
for C++26, dereferencing an invalid iterator erroneously returns "".
Attempting to increment/decrement past the last/first element in the
view is erroneously a no-op, so aborts when assertions are enabled, and
doesn't change value otherwise.
Similarly, constructing a std::text_encoding with an invalid id (one
that doesn't have the value of an enumerator) erroneously behaves the
same as constructing with id::unknown, or aborts with assertions
enabled.
libstdc++-v3/ChangeLog:
PR libstdc++/113318
* acinclude.m4 (GLIBCXX_CONFIGURE): Add c++26 directory.
(GLIBCXX_CHECK_TEXT_ENCODING): Define.
* config.h.in: Regenerate.
* configure: Regenerate.
* configure.ac: Use GLIBCXX_CHECK_TEXT_ENCODING.
* include/Makefile.am: Add new headers.
* include/Makefile.in: Regenerate.
* include/bits/locale_classes.h (locale::encoding): Declare new
member function.
* include/bits/unicode.h (__charset_alias_match): New function.
* include/bits/text_encoding-data.h: New file.
* include/bits/version.def (text_encoding): Define.
* include/bits/version.h: Regenerate.
* include/std/text_encoding: New file.
* src/Makefile.am: Add new subdirectory.
* src/Makefile.in: Regenerate.
* src/c++26/Makefile.am: New file.
* src/c++26/Makefile.in: New file.
* src/c++26/text_encoding.cc: New file.
* src/experimental/Makefile.am: Include c++26 convenience
library.
* src/experimental/Makefile.in: Regenerate.
* python/libstdcxx/v6/printers.py (StdTextEncodingPrinter): New
printer.
* scripts/gen_text_encoding_data.py: New file.
* testsuite/22_locale/locale/encoding.cc: New test.
* testsuite/ext/unicode/charset_alias_match.cc: New test.
* testsuite/std/text_encoding/cons.cc: New test.
* testsuite/std/text_encoding/members.cc: New test.
* testsuite/std/text_encoding/requirements.cc: New test.
Reviewed-by: Ulrich Drepper <drepper.fsp@gmail.com> Reviewed-by: Patrick Palka <ppalka@redhat.com>
Jonathan Wakely [Tue, 16 Jan 2024 17:15:26 +0000 (17:15 +0000)]
libstdc++: Do not use CTAD for _Utf32_view alias template
We were relying on P1814R0 (CTAD for alias templates) which isn't
supported by Clang. We can just not use CTAD and provide an explicit
template argument list for _Utf32_view.
Ideally we'd define a deduction guide for _Grapheme_cluster_view that
uses views::all_t to properly convert non-views to views, but all_t is
defined in <ranges> and we don't want to include all of that in
<bits/unicode.h>. So just make it require a view for now, which can be
cheaply copied.
Although it's not needed yet, it would also be more correct to
specialize enable_borrowed_range for the views in <bits/unicode.h>.
libstdc++-v3/ChangeLog:
* include/bits/unicode.h (_Grapheme_cluster_view): Require view.
Do not use CTAD for _Utf32_view.
(__format_width, __truncate): Do not use CTAD.
(enable_borrowed_range<_Utf_view<T, R>>): Define specialization.
(enable_borrowed_range<_Grapheme_cluster_view<R>>): Likewise.
Jakub Jelinek [Wed, 17 Jan 2024 10:21:18 +0000 (11:21 +0100)]
Fix comment typos
When looking at PR113410, I found a comment typo and just searched for
the same typo elsewhere and found some typos in the comments which had
that typo as well.
2024-01-17 Jakub Jelinek <jakub@redhat.com>
* tree-into-ssa.cc (pass_build_ssa::gate): Fix comment typo,
funcions -> functions, and use were instead of was.
* gengtype.cc (dump_typekind): Fix comment typos, funcion -> function
and guaranteee -> guarantee.
* attribs.h (struct attr_access): Fix comment typo funcion -> function.
Jakub Jelinek [Wed, 17 Jan 2024 09:47:31 +0000 (10:47 +0100)]
openmp: Add OpenMP _BitInt support [PR113409]
The following patch adds support for _BitInt iterators of OpenMP canonical
loops (with the preexisting limitation that when not using compile time
static scheduling the iterators in the library are at most unsigned long long
or signed long, so one can't in the runtime/dynamic/guided etc. cases iterate
more than what those types can represent, like is the case of e.g. __int128
iterators too) and the testcase also covers linear/reduction clauses for them.
2024-01-17 Jakub Jelinek <jakub@redhat.com>
PR middle-end/113409
* omp-general.cc (omp_adjust_for_condition): Handle BITINT_TYPE like
INTEGER_TYPE.
(omp_extract_for_data): Use build_bitint_type rather than
build_nonstandard_integer_type if either iter_type or loop->v type
is BITINT_TYPE.
* omp-expand.cc (expand_omp_for_generic,
expand_omp_taskloop_for_outer, expand_omp_taskloop_for_inner): Handle
BITINT_TYPE like INTEGER_TYPE.
YunQiang Su [Wed, 17 Jan 2024 07:11:33 +0000 (15:11 +0800)]
Sanitizer/MIPS: Use $t9 for preemptible function call
Currently, almost all of the shared libraries of MIPS, rely on $t9
to get the address of current function, instead of PCREL instructions,
even on MIPSr6. So we have to set $t9 properly.
To get the address of preemptible function, we need the help of GOT.
MIPS/O32 has .cpload, which can help to generate 3 instructions to get GOT.
For __mips64, we can get GOT by:
* interception/interception.h (substitution_##func_name):
Use macro C_ASM_TAIL_CALL.
* sanitizer_common/sanitizer_asm.h: Define C_ASM_TAIL_CALL
for MIPS with help of t9.
Richard Biener [Tue, 16 Jan 2024 12:09:27 +0000 (13:09 +0100)]
tree-optimization/113371 - avoid prologue peeling for peeled early exits
The following avoids prologue peeling when doing early exit
vectorization with the IV exit before the early exit. That's because
we it invalidates the invariant that the effective latch of the loop
is empty causing wrong continuation to the main loop. In particular
this is prone to break virtual SSA form.
PR tree-optimization/113371
* tree-vect-data-refs.cc (vect_enhance_data_refs_alignment):
Do not peel when LOOP_VINFO_EARLY_BREAKS_VECT_PEELED.
* tree-vect-loop-manip.cc (vect_do_peeling): Assert we do
not perform prologue peeling when LOOP_VINFO_EARLY_BREAKS_VECT_PEELED.
This patch avoids sched-deps.cc:find_inc() creating exponential number
of dependencies, which become memory and compilation time hogs.
Consider example (simplified from PR96388) ...
===
sp=sp-4 // sp_insnA
mem_insnA1[sp+A1]
...
mem_insnAN[sp+AN]
sp=sp-4 // sp_insnB
mem_insnB1[sp+B1]
...
mem_insnBM[sp+BM]
===
[For simplicity, let's assume find_inc(backwards==true)].
In this example find_modifiable_mems() will arrange for mem_insnA*
to be able to pass sp_insnA, and, while doing this, will create
dependencies between all mem_insnA*s and sp_insnB -- because sp_insnB
is a consumer of sp_insnA. After this sp_insnB will have N new
backward dependencies.
Then find_modifiable_mems() gets to mem_insnB*s and starts to create
N new dependencies for _every_ mem_insnB*. This gets us N*M new
dependencies.
In PR96833's testcase N and M are 10k-15k, which causes RAM usage of
30GB and compilation time of 30 minutes, with sched2 accounting for
95% of both metrics. After this patch the RAM usage is down to 1GB
and compilation time is down to 3-4 minutes, with sched2 no longer
standing out on -ftime-report or memory usage.
Sandra Loosemore [Wed, 17 Jan 2024 04:41:52 +0000 (04:41 +0000)]
Move docs for -Wuse-after-free and -Wuseless-cast [PR111693]
These options were categorized as C++ options, but they apply to all
C-family languages.
gcc/ChangeLog
PR c/111693
* doc/invoke.texi (Option Summary): Move -Wuseless-cast
from C++ Language Options to Warning Options. Add entry for
-Wuse-after-free.
(C++ Dialect Options): Move -Wuse-after-free and -Wuseless-cast
from here....
(Warning Options): ...to here. Minor copy-editing to fix typo
and grammar.
Patrick Palka [Wed, 17 Jan 2024 02:20:12 +0000 (21:20 -0500)]
libstdc++: Implement P2540R1 change to views::cartesian_product()
This paper changes the identity element of views::cartesian_product to a
singleton range instead of an empty range. It was approved alongside
the main cartesian_product paper P2374R4, but unfortunately was overlooked
when implementing the main paper.
libstdc++-v3/ChangeLog:
* include/std/ranges (views::_CartesianProduct::operator()):
Adjust identity case as per P2540R1.
* testsuite/std/ranges/cartesian_product/1.cc (test01):
Adjust expected result of the identity case.
Nathaniel Shead [Thu, 11 Jan 2024 05:49:39 +0000 (16:49 +1100)]
c++: Support thread_local statics in header modules [PR113292]
Currently, thread_locals in header modules cause ICEs. This patch makes
the required changes for them to work successfully.
This requires additionally writing the DECL_TLS_MODEL for thread-local
variables to the module interface, and the TLS wrapper function needs to
have its DECL_BEFRIENDING_CLASSES written too as this is used to
retrieve what VAR_DECL it's a wrapper for when emitting a definition at
end of TU processing.
PR c++/113292
gcc/cp/ChangeLog:
* decl2.cc (get_tls_wrapper_fn): Set DECL_CONTEXT.
(c_parse_final_cleanups): Suppress warning for no definition of
TLS wrapper functions in header modules.
* module.cc (trees_out::lang_decl_vals): Write wrapped variable
for TLS wrapper functions.
(trees_in::lang_decl_vals): Read it.
(trees_out::decl_value): Write TLS model for thread-local vars.
(trees_in::decl_value): Read it for new decls. Remember to emit
definitions of TLS wrapper functions later.
gcc/testsuite/ChangeLog:
* g++.dg/modules/pr113292_a.H: New test.
* g++.dg/modules/pr113292_b.C: New test.
* g++.dg/modules/pr113292_c.C: New test.
Nathaniel Shead [Tue, 16 Jan 2024 09:56:46 +0000 (20:56 +1100)]
c++: Fix ENABLE_SCOPE_CHECKING printing
The lists of scope kinds used by ENABLE_SCOPE_CHECKING don't seem to
have been updated in a long while, causing ICEs and confusing output.
This patch brings the list into line.
Additionally, the comment on 'explicit_spec_p' says that the flag is
only valid if kind is 'sk_template_parms', so we rewrite the condition
to be more obviously correct here.
gcc/cp/ChangeLog:
* name-lookup.h (enum scope_kind): Add 'sk_count'.
* name-lookup.cc (cp_binding_level_descriptor): Add missing
scope kinds. Add assertion that the list is up to date. Fix
handling of explicit_spec_p.
Marek Polacek [Tue, 16 Jan 2024 20:49:46 +0000 (15:49 -0500)]
c++: fix ICE with xobj in destructor [PR113340]
Here we crash in maybe_retrofit_in_chrg on an invalid dtor
with explicit this. Such member functions do not get converted
to METHOD_TYPE. If a dtor gets parameters, we reset arg_types
to void_list_node in grokdeclarator. This results in m_r_in_c
receiving:
void <T8d> (void)
and crashing on
parms = DECL_CHAIN (DECL_ARGUMENTS (fn));
This patch avoids the ICE by resetting is_xobj_member_function after
emitting the error. Then m_r_in_c gets
void S::<T40b> (struct S *)
which does not cause a crash.
PR c++/113340
gcc/cp/ChangeLog:
* decl.cc (grokdeclarator) <case cdk_function>: Clear
is_xobj_member_function in case of an error.
gcc/testsuite/ChangeLog:
* g++.dg/cpp23/explicit-obj-diagnostics9.C: New test.
Raiki Tamura [Thu, 12 Oct 2023 08:24:46 +0000 (17:24 +0900)]
gccrs: v0-mangle closures
gcc/rust/ChangeLog:
* backend/rust-compile-expr.cc (CompileExpr::generate_closure_function):
Fix reference to node.
* backend/rust-mangle.cc (struct V0Path): Modified to accept closures.
(v0_crate_path): Modified to accept closures.
(v0_closure): New function to mangle closures.
(v0_path): Modified to accept closures
* util/rust-mapping-common.h (UNKNOWN_NODEID): Change to UINT32_MAX.
(UNKNOWN_HIRID): Change to UINT32_MAX.
Make self param and variadic param Param, introduce Param class and make
function parameters param too.
Self can now be represented as a standard parameter and is thus no longer
required as a separate function attribute.
Prevent self pointers and allow self in standard functions during parsing
so they could be rejected at a later stage.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Add visitor for
VariadicParam and remove Self parameter visitor from Function visit.
* expand/rust-cfg-strip.cc (CfgStrip::maybe_strip_self_param): Remove
function.
(CfgStrip::maybe_strip_trait_method_decl): Remove self parameter visit.
(CfgStrip::maybe_strip_function_params): Handle new function
parameters.
(CfgStrip::visit): Handle VariadicParam, SelfParam and FunctionParam.
* expand/rust-expand-visitor.cc (ExpandVisitor::expand_self_param):
Remove function.
(ExpandVisitor::expand_trait_method_decl): Do not visit self parameter.
(ExpandVisitor::visit): Add visit for VariadicParam, FunctionParam and
SelfParam.
(ExpandVisitor::expand_function_params): Visit parameters instead.
* expand/rust-expand-visitor.h: Update function prototypes.
* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Update visit
with new parameters.
(ResolveTraitItems::visit): Likewise.
* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
Update visit functions with the new visitor functions for VariadicParam
SelfParam and FunctionParam.
* resolve/rust-early-name-resolver.h: Update function prototypes.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Update visitor
according to the new function parameter structures.
* ast/rust-ast-visitor.h: Update prototypes and add visitor virtual
functions for SelfParam, FunctionParam and VariadicParam.
* ast/rust-ast.cc (Function::Function): Move constructor in
implementation instead of header.
(Function::operator=): Likewise.
(Function::as_string): Update function with pointer dereference.
(VariadicParam::as_string): Likewise.
(TraitFunctionDecl::as_string): Likewise.
(TraitMethodDecl::as_string): Likewise.
(FunctionParam::accept_vis): Add function for visitor.
(SelfParam::accept_vis): Likewise.
(VariadicParam::accept_vis): Likewise.
(TraitItemFunc::TraitItemFunc): Move constructor to implementation
file.
(TraitItemFunc::operator=): Likewise.
(TraitItemMethod::TraitItemMethod): Likewise.
(TraitItemMethod::operator=): Likewise.
* ast/rust-item.h (class Function): Remove self optional member.
(class TraitMethodDecl): Likewise.
(class TraitFunctionDecl): Likewise.
(class Param): Add abstract parameter class.
(class SelfParam): Inherit from Param and remove parameter common
members.
(class FunctionParam): Likewise.
(class VariadicParam): Likewise.
(struct Visibility): Move structure declaration.
(class VisItem): Likewise.
* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add
a self parameter check during AST validation.
* checks/errors/rust-ast-validation.h: Add function prototype.
* expand/rust-derive-clone.cc (DeriveClone::clone_fn): Update function
constructor.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_self): Rework
function for the new parameters.
(ASTLoweringBase::visit): Add visit functions for VariadicParam,
FunctionParam and SelfParam.
* hir/rust-ast-lower-base.h: Update function prototypes.
* parse/rust-parse-impl.h (Parser::parse_function): Update function
according to new function representation.
(Parser::parse_function_param): Return vector of abstract param instead
of FunctionParam.
(Parser::parse_method): Update according to new representation.
(Parser::parse_trait_item): Likewise.
(Parser::parse_self_param): Error out with
self pointers and prevent the lexer from eating regular function
parameters. Update return type.
* parse/rust-parse.h: Update function return types.
* ast/rust-ast-collector.h: Add VariadicParam visit prototype.
* ast/rust-ast.h (struct Visibility): Move struct declaration.
(class VisItem): Likewise.
* ast/rust-expr.h: Update included files.
* checks/errors/rust-feature-gate.h: Add visitor functions for
SelfParam, FunctionParam and VariadicParam.
* expand/rust-cfg-strip.h: Update function prototypes.
* expand/rust-derive.h: Likewise.
* hir/rust-ast-lower-implitem.h: Handle special arguments.
* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Likewise.
* metadata/rust-export-metadata.cc (ExportContext::emit_function):
Likewise.
* resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Add visitor
functions.
* resolve/rust-ast-resolve-base.h: Update prototypes.
* resolve/rust-ast-resolve-stmt.h: Handle new parameter kind.
* resolve/rust-default-resolver.cc (DefaultResolver::visit): Likewise.
* resolve/rust-default-resolver.h: Update prototype.
* util/rust-attributes.cc (AttributeChecker::visit): Add visitor
functions for SelfParam and VariadicParam.
* util/rust-attributes.h: Add visit prototypes.
Variadics are forbidden alone as well as non final position, this should
be checked during ast validation.
gcc/rust/ChangeLog:
* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add
check for additional named argument as well as variadic argument's
position.
* checks/errors/rust-ast-validation.h: Add visit function prototype for
external functions.
Some construct are forbidden in trait context (eg. pub, async...) and
we'll need to reject those. To do so we need to identify a trait context.
gcc/rust/ChangeLog:
* ast/rust-ast-visitor.cc (ContextualASTVisitor::visit): Push the new
trait context when visiting a trait.
* ast/rust-ast-visitor.h: Add visit function prototype and TRAIT
context.
Loop label error reporting during ast validation was done at loop label
level. It lead to some innacurate error reporting in break loop labels
due to the way the label is built.
gcc/rust/ChangeLog:
* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Change
reported error location to the lifetime location.
Prevent from using reserved keyword in label name.
gcc/rust/ChangeLog:
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Check if there is
a label before visit.
* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Emit an
error when a label has a forbidden name.
* checks/errors/rust-ast-validation.h: Add function prototype.
Some part of the code requires the token id behind a given keyword, a map
keep the "set" aspect whilst providing this additional feature.
gcc/rust/ChangeLog:
* lex/rust-lex.cc (RS_TOKEN): Remove local map.
(RS_TOKEN_KEYWORD): Likewise.
(Lexer::classify_keyword): Change call to utils.
* util/rust-keyword-values.cc (get_keywords): Add init function.
(RS_TOKEN_KEYWORD): Call to X macro.
* util/rust-keyword-values.h: Change from set to a map.
* checks/errors/rust-ast-validation.cc (RS_TOKEN): Remove locale set.
(RS_TOKEN_KEYWORD): Likewise.
(ASTValidation::visit): Change keyword set call to the one from utils.
Much like attributes values, keywords are known beforehand and never
change. Instead of relying on handcrafted string we could centralize
everything in one place. We may require to check whether a word is a
keyword, which can now be done easily thanks to the keyword set.
gcc/rust/ChangeLog:
* Make-lang.in: Add rust-keyword-values.cc to the list.
* util/rust-keyword-values.cc: New file.
* util/rust-keyword-values.h: New file.
gccrs: Fix multiple issues with variadic representation
The new variadic representation has introduced multiple issues and ICE
into the codebase. Some early passes in the compiler depend on the
parameters all having a type and being an actual parameter.
gcc/rust/ChangeLog:
* ast/rust-ast.cc (ExternalFunctionItem::as_string): Adapt as_string
function to the new ast representation.
(NamedFunctionParam::as_string): Likewise.
* ast/rust-item.h: Add a function to test whether a FunctionParam has
a name pattern.
* expand/rust-cfg-strip.cc (CfgStrip::visit): Adapt cfg strip visitor
for the new variadic arguments.
* hir/rust-ast-lower-extern.h: Adapt lowering to the new variadic
function representation.
* metadata/rust-export-metadata.cc (ExportContext::emit_function):
Change call to constructor.
* parse/rust-parse-impl.h (Parser::parse_named_function_param): Change
NamedFunctionParam parsing to accomodate new variadic representation.
(Parser::parse_external_item): Change external item parsing to use the
new NamedFunctionParam variadics.
* parse/rust-parse.h: Add new parsing function prototypes.
* ast/rust-ast-collector.cc (TokenCollector::visit): Rework token
collection to take into account variadic parameters.
* ast/rust-ast-visitor.cc: Likewise.
* expand/rust-expand-visitor.cc (ExpandVisitor::visit): Change function
bound to avoid getting the type of a variadic parameter.
* resolve/rust-ast-resolve-item.cc (ResolveExternItem::visit):
Likewise.
* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
Likewise.
This was made to align NamedFunctionParam with FunctionParam.
gcc/rust/ChangeLog:
* ast/rust-item.h (class NamedFunctionParam): Add variadic boolean and
another constructor.
* hir/rust-ast-lower-extern.h: Avoid last parameter when variadic.
gccrs: Change FunctionParam to represent variadic params
Variadic were represented at the function level while retaining most
informations of a given parameter.
gcc/rust/ChangeLog:
* ast/rust-item.h (class FunctionParam): Add some informations to
function parameters in order to be able to store variadic argument as
a function parameter.
gccrs: Make use of the Contextual visitor in validation
Use the new contextual ast visitor to reduce the amount of code in the
ast validation visitor.
gcc/rust/ChangeLog:
* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Adapt
the call to the new visit functions.
(ASTValidation::check): Launch the parent class visitor root function.
* checks/errors/rust-ast-validation.h (class ASTValidation): Inherit
from the contextual visitor.
gccrs: Add a new visitor that gathers context information
This visitor is intended to be used by other visitors that require
context at some point for a given item.
gcc/rust/ChangeLog:
* ast/rust-ast-visitor.cc (ContextualASTVisitor::visit): Add multiple
context saving calls.
* ast/rust-ast-visitor.h (class DefaultASTVisitor): Make visit
functions virtual.
(class ContextualASTVisitor): Add a stack like container for the
current context chain.
This will allow us to derive other visitors from it and overload only a
few selected visit methods.
gcc/rust/ChangeLog:
* Make-lang.in: Add the new visitor object file.
* ast/rust-ast-visitor.h (class DefaultASTVisitor): Create the default
visitor class.
* ast/rust-ast.h: Add a new reference getter for visitor pattern.
* ast/rust-ast-visitor.cc: New file.
gccrs: Emit an error on associated const without values
Associated const with no value that are not in trait impl are prohibited.
gcc/rust/ChangeLog:
* checks/errors/rust-ast-validation.cc (ASTValidation::check): Launch
check over the whole given crate.
(ASTValidation::visit): Implement visitor for some members of the ast.
* checks/errors/rust-ast-validation.h: Update some prototype according
to implemented visitor functions. Also add a context tracker.
Add the ast validation and feature gating steps to the compile pipeline.
gcc/rust/ChangeLog:
* lang.opt: Add the new compile options and update the enum values.
* rust-session-manager.h (struct CompileOptions): Add the new steps to
the enumeration.
gccrs: Add more checks for expr value in early visitors
Early passes visitors may encounter constant item without a value, this
is expected as the pass rejecting a constant without an expression is
done later during the ast validation.
The lexer cannot distinguish the difference between a float literal and a
tuple index in some cases. This means we should fix this while parsing
depending on the context.
gcc/rust/ChangeLog:
* expand/rust-macro-invoc-lexer.cc (MacroInvocLexer::split_current_token):
Add implementation for multiple token split.
* expand/rust-macro-invoc-lexer.h: Add function prototype.
* expand/rust-proc-macro-invoc-lexer.cc (ProcMacroInvocLexer::split_current_token):
Add implementation for 2+ token split for procedural macros.
* expand/rust-proc-macro-invoc-lexer.h: Add function prototype.
* lex/rust-lex.cc (Lexer::split_current_token): Add function to split a
token in multiple other tokens.
* lex/rust-lex.h: Add function prototype for split_current_token.
* parse/rust-parse-impl.h (Parser::left_denotation): Handle float tuple
index identified as a float literal.
Multiple references to procedural macro token trees were left as magic
number in the code. This commit introduces some constexpr for those along
some explanation for the selected value.
gcc/rust/ChangeLog:
* backend/rust-compile-base.cc (get_attributes): Add documentation for
indices 3 and 4.
(get_trait_name): Add documentation for index 1.
The compiler cannot infer the array length from the type, we should
therefore hand it the information. The proc macro buffer missed that
information.
gcc/rust/ChangeLog:
* backend/rust-compile.cc (proc_macro_buffer): Update type builder with
array length information.
(proc_macro_array): Update type initializer with array length
information.
gccrs: Put common functions in their own namespace
Half of the functions introduced recently had a similar goal while the
other half had a similar goal too. Introducing some namespace to separate
those will keep the code cleaner and avoid confusion.
* backend/rust-compile-base.h: Make static function address_expression
public.
* backend/rust-compile.cc (CompileCrate::add_proc_macro_symbols): Add
new global variable in export function.
(build_bang_proc_macro): Add a function to build the bang proc macro
structure type.
(build_proc_macro): Add a function to build the proc macro structure
type.
(build_proc_macro_payload): Add a function to build the proc macro
union used in proc macro structures.
(init_derive_proc_macro): Add a function to initialize custom derive
proc macros.
(init_attribute_proc_macro): Add a function to initialize attribute
proc macros.
(init_bang_proc_macro): Add a function to initialize bang proc macros.
(init_proc_macro): Add a function to initialize proc macro structures.
(initialize_proc_macro_array): Add a function to initialize the proc
macro buffer array.
(CompileCrate::add_proc_macro_symbols): Add call to the new functions
to correctly initialize proc macros as well as their entrypoint.