Martin Jambor [Tue, 13 Dec 2022 23:33:06 +0000 (00:33 +0100)]
ipa-sra: Forward propagation of sizes which are safe to dereference
The previous patch established a way to propagate information about
parameters from callers to callees (even though then the actual
splitting is done in the opposite direction), this patch adds to that
information about size of the parameters that is known to be safe to
dereference in the callers - the information currently does not come
from actual dereferences but only when we pass a reference to a known
declaration, but we can use e.g. dereferences in BBs dominating the
call, for example too, if we decide it is worth it.
References which look like splitting candidates but are not always
dereferenced are - assuming the dereferences are not improbable - not
discarded straight away but only marked as conditionally
dereferenceable. IPA phase then makes sure that they stay candidates
only if all incoming edges have big enough known-to-be-safe size.
gcc/ChangeLog:
2022-11-11 Martin Jambor <mjambor@suse.cz>
* ipa-sra.cc (isra_param_desc): New fields safe_size,
conditionally_dereferenceable and safe_size_set.
(struct gensum_param_desc): New field conditionally_dereferenceable.
(struct isra_param_flow): Updated comment of field unit_size.
(ipa_sra_function_summaries::duplicate): Copy the new fields.
(isra_call_summary::dump): Dump unit_size when representing safe_size.
(dump_gensum_param_descriptor): Dump new flag.
(dump_isra_param_descriptor): Dump new fields.
(isra_analyze_call): Fill unit_size when it represents known safe
size.
(check_gensum_access): Instead of disqualifying pointers which are not
always dereference, mark them as conditionally dereferencable if loads
are frequent enough.
(process_scan_results): Copy the conditionally_dereferenceable flag.
(isra_write_node_summary): Stream new fields, or assert they are not
initialized yet.
(isra_read_node_info): Stream new fields.
(update_safe_size): New function.
(propagate_param_hints_accross_call): Propagate safe_sizes.
(propagate_hints_to_all_callees): New function.
(adjust_parameter_descriptions): Check conditionally_dereferenceable
candidates, rework dumping.
(ipa_sra_analysis): Move most of hint propagation for one node to
propagate_hints_to_all_callees. Add another loop to stabilize within
SCCs and another one to verify.
gcc/testsuite/ChangeLog:
2022-11-11 Martin Jambor <mjambor@suse.cz>
* gcc.dg/ipa/ipa-sra-26.c: New test.
* gcc.dg/ipa/ipa-sra-27.c: Likewise.
* gcc.dg/ipa/ipa-sra-28.c: Likewise.
Martin Jambor [Tue, 13 Dec 2022 23:33:06 +0000 (00:33 +0100)]
ipa-sra: Be optimistic about Fortran descriptors
Fortran descriptors are structures which are often constructed just
for a particular argument of a particular call where it is passed by
reference. When the called function is under compiler's control, it
can be beneficial to split up the descriptor and pass it in individual
parameters. Unfortunately, currently we allow IPA-SRA to replace a
pointer with a set of replacements which are at most twice as big in
total and for descriptors we'd need to bump that factor to seven.
This patch looks for parameters which are ADDR_EXPRs of local
variables which are written to and passed as arguments by reference
but are never loaded from and marks them with a flag in the call edge
summary. The IPA analysis phase then identifies formal parameters
which are always fed such arguments and then is more lenient when it
comoes to size.
In order not to store to maximums per formal parameter, I calculate
the more lenient one by multiplying the existing one with a new
parameter. If it is preferable to keep the maximums independent, we
can do that. Documentation for the new parameter is missing as I
still need to re-base the patch on a version which has sphinx. I will
write it before committing.
I have disable IPA-SRA in pr48636-2.f90 in order to be able to keep
using its dump-scan expressions. The new testcase is basically a copy
of it with different options and IPA-SRA dump scans.
gcc/ChangeLog:
2022-11-11 Martin Jambor <mjambor@suse.cz>
* ipa-sra.cc (isra_param_desc): New field not_specially_constructed.
(struct isra_param_flow): New field constructed_for_calls.
(isra_call_summary::dump): Dump the new flag.
(loaded_decls): New variable.
(dump_isra_param_descriptor): New parameter hints, dump
not_specially_constructed if it is true.
(dump_isra_param_descriptors): New parameter hints, pass it to
dump_isra_param_descriptor.
(ipa_sra_function_summaries::duplicate): Duplicate new flag.
(create_parameter_descriptors): Adjust comment.
(get_gensum_param_desc): Bail out when decl2desc is NULL.
(scan_expr_access): Add loaded local variables to loaded_decls.
(scan_function): Survive if final_bbs is NULL.
(isra_analyze_call): Compute constructed_for_calls flag.
(process_scan_results): Be optimistic about size limits. Do not dump
computed param hints when dumpint IPA-SRA structures.
(isra_write_edge_summary): Stream constructed_for_calls.
(isra_read_edge_summary): Likewise.
(ipa_sra_dump_all_summaries): New parameter hints, pass it to
dump_isra_param_descriptor.
(flip_all_hints_pessimistic): New function.
(flip_all_param_hints_pessimistic): Likewise.
(propagate_param_hints): Likewise.
(disable_unavailable_parameters): Renamed to
adjust_parameter_descriptions. Expand size limits for parameters
which are specially contstructed by all callers. Check limits again.p
(ipa_sra_analysis): Pass required hints to ipa_sra_dump_all_summaries.
Add hint propagation.
(ipa_sra_summarize_function): Initialize and destory loaded_decls,
rearrange so that scan_function is called even when there are no
candidates.
* params.opt (ipa-sra-ptrwrap-growth-factor): New parameter.
gcc/testsuite/ChangeLog:
2021-11-11 Martin Jambor <mjambor@suse.cz>
* gfortran.dg/pr48636-2.f90: Disable IPA-SRA.
* gfortran.dg/ipa-sra-1.f90: New test.
Martin Jambor [Tue, 13 Dec 2022 23:33:06 +0000 (00:33 +0100)]
ipa-sra: Move caller->callee propagation before callee->caller one
This patch does not do any functional changes, it merely moves
top-down propagation in the IPA-SRA WPA phase before bottom-up one.
This also meant moving some preliminary checks from the latter to the
former - where they need to be in their own loop over each SCC because
the subsequent one looks at callers.
Currently the propagations are independent (top-down is used for
return value rermoval, bottom-up for parameter removal and splitting)
but subsequent patches will introduce flags about parameters which
should be propagated from callers first and used in splitting. I
separated this change to test ir independently and make those
subsequent patches cleaner.
While at it, I also replaced couple of FOR_EACH_VEC_ELT macros with
C++11 style iteration.
gcc/ChangeLog:
2022-11-11 Martin Jambor <mjambor@suse.cz>
* ipa-sra.cc (ipa_sra_analysis): Move top-down analysis before
bottom-up analysis. Replace FOR_EACH_VEC_ELT with C++11 iteration.
gcc/testsuite/ChangeLog:
2021-12-14 Martin Jambor <mjambor@suse.cz>
* gcc.dg/ipa/ipa-sra-25.c: New test
Martin Jambor [Tue, 13 Dec 2022 23:33:06 +0000 (00:33 +0100)]
ipa-sra: Treat REFERENCE_TYPES as always dereferencable
C++ and especially Fortran pass data by references which are not
pointers potentially pointing anywhere and so can be assumed to be
safely dereferencable. This patch teaches IPA-SRA to treat them as
such and avoid the dance we do to prove that we can move loads from
them to the caller.
When we do not know that a dereference will happen all the time, we
need a heuristics so that we do not force memory accesses that normally
happen only rarely. The patch simply uses the (possibly guessed)
profile and checks whether the (expected) number of loads is at least
half of function invocations invocations - the half is now
configurable with a param as requested by Honza.
gcc/ChangeLog:
2022-12-13 Martin Jambor <mjambor@suse.cz>
PR ipa/103585
* params.opt (ipa-sra-deref-prob-threshold): New parameter.
* doc/invoke.texi (ipa-sra-deref-prob-threshold): Document it.
* ipa-sra.cc (struct gensum_param_access): New field load_count.
(struct gensum_param_desc): New field safe_ref, adjusted comments.
(by_ref_count): Renamed to unsafe_by_ref_count, adjusted all uses.
(dump_gensum_access): Dump the new field.
(dump_gensum_param_descriptor): Likewise.
(create_parameter_descriptors): Set safe_ref field, move setting
by_ref forward. Only increment unsafe_by_ref_count for unsafe
by_ref parameters.
(allocate_access): Initialize new field.
(mark_param_dereference): Adjust indentation. Only add data to
bb_dereferences for unsafe by_ref parameters.
(scan_expr_access): For loads, accumulate BB counts.
(dereference_probable_p): New function.
(check_gensum_access): Fix leading comment, add parameter FUN.
Check cumulative counts of loads for safe by_ref accesses instead
of dereferences.
(process_scan_results): Do not propagate dereference distances for
safe by_ref parameters. Pass fun to check_gensum_access. Safe
by_ref params do not need the postdominance check.
gcc/testsuite/ChangeLog:
2022-11-11 Martin Jambor <mjambor@suse.cz>
* g++.dg/ipa/ipa-sra-5.C: New test
Martin Jambor [Tue, 13 Dec 2022 23:33:05 +0000 (00:33 +0100)]
ipa-cp: Leave removal of unused parameters to IPA-SRA
Looking at some benchmarks I have noticed many cases when IPA-CP
cloned a function for all contexts just because it knew that some
parameters were not used at all. Then IPA-SRA looked at the function
and cloned it again to split another parameter or two. The latter
pass is better equipped to detect when parameters can be altogether
removed and so the IPA-CP cloning was for no good reason.
This patch simply alters the IPA-CP not to do that in the situations
where IPA-SRA can (for nodes which can be made local) with additional
dumping requested by Honza.
gcc/ChangeLog:
2022-12-13 Martin Jambor <mjambor@suse.cz>
* ipa-cp.cc (clone_for_param_removal_p): New function.
(estimate_local_effects): Call it before considering cloning
just to remove unused parameters.
Martin Jambor [Tue, 13 Dec 2022 23:33:05 +0000 (00:33 +0100)]
ipa: Better way of applying both IPA-CP and IPA-SRA (PR 103227)
This is basically a better fix for PR 103227. The one currently in
use, rushed in late at stage3, which means that IPA-CP transformation
simply does a replacement of default-definition of IPA-SRA-created
scalar parameters with a constant, meant that IPA-SRA actually often
led to creation of a bunch of unused parameters, which was rather
ironic and sub-optimal.
This patch rips that old way out and makes sure the clash is resolved
at clone-materialization time. What happens is that:
1) IPA-SRA IPA analysis (decision) stage recognizes the clash and does
not create a param adjustment entry for such a scalar component.
2) Clone materialization code checks the IPA-CP transformation
summary and when it realizes that it is removing a parameter that
is a base for a discovered IPA-CP aggregate constant, and:
a) the value is passed by reference, it internally records that any
load of the value is replaced directly with the known constant
value. IPA-SRA will not attempt to split values passed by
reference when there is a write to it so we know such a load
won't be on a a LHS.
b) the value is passed by value, there can be stores to the
corresponding bit of the aggregate and so all accesses are
replaced with a new decl and an assignment of the constant to
this decl is generated at the beginning of the function.
The new testcase contains an xfail as the patch does not fix PR 107640
but it is one that ICEs when one is not careful about remapping
indices of parameters, so I'd like to have it in testsuite/gcc.gd/ipa/
even now.
I don't think that PR 107640 should be attempted through
ipa-param-manipulation replacements because the information is not
really there any more and we'd either need to do the replacements
earlier or dig deep into the clone parent info. Instead, we should
record somewhere that at the beginning of the function the bits of the
global decl have known values and use that in the value numbering.
That way we could one day encode also known constants in globals that
do not come through parameters.
gcc/ChangeLog:
2022-11-11 Martin Jambor <mjambor@suse.cz>
PR ipa/103227
* ipa-param-manipulation.h (class ipa_param_adjustments): Removed
member function get_updated_index_or_split.
(class ipa_param_body_adjustments): New overload of
register_replacement, new member function append_init_stmts, new
member m_split_agg_csts_inits.
* ipa-param-manipulation.cc: Include ipa-prop.h.
(ipa_param_adjustments::get_updated_index_or_split): Removed.
(ipa_param_body_adjustments::register_replacement): New overload, use
it from the older one.
(ipa_param_body_adjustments::common_initialization): Added the
capability to create replacements for conflicting IPA-CP discovered
constants.
(ipa_param_body_adjustments::ipa_param_body_adjustments): Construct
the new member.
(ipa_param_body_adjustments::append_init_stmts): New function.
* ipa-sra.cc: Include ipa-prop.h.
(push_param_adjustments_for_index): Require IPA-CP transformation
summary as a parameter, do not create replacements which are known to
have constant values.
(process_isra_node_results): Find and pass to the above function the
IPA-CP transformation summary.
* ipa-prop.cc (adjust_agg_replacement_values): Remove the
functionality replacing IPA-SRA created scalar parameters with
constants. Simplify, do not require parameter descriptors, do not
return anything.
(ipcp_transform_function): Simplify now that
adjust_agg_replacement_values does not change cfg. Move definition
and initialization of descriptors lower.
* tree-inline.cc (tree_function_versioning): Call append_init_stmts of
param_body_adjs, if there are any.
gcc/testsuite/ChangeLog:
2022-11-11 Martin Jambor <mjambor@suse.cz>
PR ipa/103227
PR ipa/107640
* gcc.dg/ipa/pr107640-2.c: New test.
Martin Jambor [Tue, 13 Dec 2022 23:33:05 +0000 (00:33 +0100)]
ipa-cp: Write transformation summaries of all functions
IPA-CP transformation summary streaming code currently won't stream
out transformations necessary for clones which are only necessary for
materialization of other clones (such as an IPA-CP clone which is then
cloned again by IPA-SRA). However, a follow-up patch for bettor
reconciling IPA-SRA and IPA-CP modifications requires to have that
information at its disposal and so this one reworks the streaming to
write out all non-empty transformation summaries.
In order not to stream transformation summaies into partitions where
the node itself nor any of its clones are materialized, I had to make
sure that clones also get encode_body flag in the encoder (so that it
could be tested) and therefore in turn lto_output understands it needs
to skip clones.
This should actually mean less streaming in typical case because
previously we streamed three zeros for all nodes in a partition with
no useful information associated with them. Currently we don't stream
anything for those.
When reworking the streaming, I also simplified it a little a
converted it writing to nicer C++ vector iterations.
gcc/ChangeLog:
2022-11-25 Martin Jambor <mjambor@suse.cz>
* ipa-prop.cc (useful_ipcp_transformation_info_p): New function.
(write_ipcp_transformation_info): Added a parameter, simplified
given that is known not to be NULL.
(ipcp_write_transformation_summaries): Write out all useful
transformation summaries.
(read_ipcp_transformation_info): Simplify given that some info
will be read.
(read_replacements_section): Remove assert.
* lto-cgraph.cc (add_node_to): Also set encode_body for clones.
* lto-streamer-out.cc (lto_output): Do not output virtual clones.
Jakub Jelinek [Tue, 13 Dec 2022 21:16:34 +0000 (22:16 +0100)]
i386: Fix up *concat*_{5,6,7} patterns [PR108044]
The following patch fixes 2 issues with the *concat<half><mode>3_5 and
*concat<mode><dwi>3_{6,7} patterns.
One is that if the destination is memory rather than register, then
we can't use movabsq and so can't support all the possible immediates.
I see 3 possibilities to fix that. One would be to use
x86_64_hilo_int_operand predicate instead of const_scalar_int_operand
and thus not match it at all during combine in such cases, but that
unnecessarily pessimizes also the case when it is loaded into register
where we can use movabsq.
Another one is what is implemented in the patch, use Wd constraint
for the integer on 64-bit if destination is memory and n otherwise.
Yet another option would be to add match_scratch to the pattern and use
it with =X constraints except for the =o case for 64-bit non-Wd where it
would give a single DImode register (rather than 2).
Another thing is that if one half of the constant is
ix86_endbr_immediate_operand, then for -fcf-protection=branch we
force those constants into memory and that might not work properly
with -fpic. So we should refuse to match with such constants.
OT, seems for movabsq we don't check that and happily allow the endbr
pattern in the immediate.
2022-12-13 Jakub Jelinek <jakub@redhat.com>
PR target/108044
* config/i386/i386.md (*concat<half><mode>3_5, *concat<mode><dwi>3_6,
*concat<mode><dwi>3_7): Split alternative with =ro output constraint
into =r,o,o and use Wd input constraint for the last alternative which
is enabled for TARGET_64BIT. Reject ix86_endbr_immediate_operand
in the input constant.
* gcc.target/i386/pr108044-1.c: New test.
* gcc.target/i386/pr108044-2.c: New test.
* gcc.target/i386/pr108044-3.c: New test.
* gcc.target/i386/pr108044-4.c: New test.
Jakub Jelinek [Tue, 13 Dec 2022 21:15:29 +0000 (22:15 +0100)]
libstdc++: Update backtrace-rename.h
When writing the r13-4629 commit log I've realized that libsanitizer
isn't the only place which nowadays renames libbacktrace symbols,
libstdc++ does that too.
2022-12-13 Jakub Jelinek <jakub@redhat.com>
* src/libbacktrace/backtrace-rename.h (backtrace_uncompress_zstd):
Define.
Steve Kargl [Mon, 12 Dec 2022 20:11:07 +0000 (21:11 +0100)]
Fortran: NULL pointer dereference while parsing a function [PR107423]
gcc/fortran/ChangeLog:
PR fortran/107423
* parse.cc (parse_spec): Avoid NULL pointer dereference when parsing
a function and an error occured.
gcc/testsuite/ChangeLog:
PR fortran/107423
* gfortran.dg/pr107423.f90: New test.
Tamar Christina [Tue, 13 Dec 2022 18:01:15 +0000 (18:01 +0000)]
AArch64: Fix ILP32 tbranch
the baremetal builds are currently broken because the shift ends up in the wrong
representation if the mode is SImode and the shift amount if 31. To fix this
create the rtx constant with an explicit mode so the backend passes know which
representation it needs to take.
gcc/ChangeLog:
* config/aarch64/aarch64.md (tbranch_<code><mode>3): Use gen_int_mode.
Jakub Jelinek [Tue, 13 Dec 2022 15:55:21 +0000 (16:55 +0100)]
vect-patterns: Fix up vect_recog_rotate_pattern [PR108064]
Since vect_recog_rotate_pattern has been extended to work also
on signed types in r13-1100 we miscompile the testcase below.
vect_recog_rotate_pattern actually emits correct scalar code into
the pattern def sequence (in particular cast to utype, doing the
2 shifts in utype so that the right shift is logical and not arithmetic,
or and then cast back to the signed type), but it didn't supply vectype
for most of those pattern statements, which means that the generic handling
fills it up later with the vectype provided by vect_recog_rotate_pattern.
The problem is that it is vectype of the result of the whole pattern,
i.e. vector of signed values in this case, while the conversion to utype,
2 shifts and or (everything with utype lhs in scalar code) should have
uvectype as STMT_VINFO_VECTYPE.
2022-12-13 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/108064
* tree-vect-patterns.cc (vect_recog_rotate_pattern): Pass uvectype
as 4th argument to append_pattern_def_seq for statements with lhs
with utype type.
* gcc.c-torture/execute/pr108064.c: New test.
Richard Biener [Tue, 13 Dec 2022 13:24:02 +0000 (14:24 +0100)]
tree-optimization/105801 - CCP and .DEFERRED_INIT
This makes sure we treat .DEFERRED_INIT as producing UNDEFINED so
we can continue optimizing uninitialized uses the same as without
-ftrivial-auto-var-init=zero. For the testcase this means we
catch the return 1 optimization opportunity at CCP rather than
only at FRE which already does the right thing here.
PR tree-optimization/105801
* tree-ssa-ccp.cc (likely_value): .DEFERRED_INIT produces
UNDEFINED.
* doc/invoke.texi (ftrivial-auto-var-init): Explicitely
mention we treat variables without an initializer as
undefined also for optimization purposes.
* gcc.dg/tree-ssa/ssa-ccp-43.c: New testcase.
Philip Herron [Tue, 23 Aug 2022 15:45:19 +0000 (16:45 +0100)]
gccrs: Add README, CONTRIBUTING and compiler logo
We still need to write out a documentation section, but these READMEs will
help in the meantime.
gcc/rust/
* CONTRIBUTING.md: New.
* README.md: New.
* logo.png: New.
Philip Herron [Tue, 23 Aug 2022 15:39:44 +0000 (16:39 +0100)]
gccrs: Add config-lang.in
This was a copy/paste from gccgo front-end. We do not use any of the
target_libs yet, but we will need these when we support the libpanic crate.
gcc/rust/
* config-lang.in: New.
Arthur Cohen [Mon, 28 Nov 2022 17:22:34 +0000 (18:22 +0100)]
gccrs: Add fatal_error when experimental flag is not present
This commits ports over the flag/env variable checking from #1540 which only
allows compilation using gccrs if a certain flag is specified
gcc/rust/
* lang.opt (-frust-incomplete-and-experimental-compiler-do-not-use):
New.
* rust-session-manager.cc (Session::compile_crate): Check it.
* Make-lang.in (RUST_SELFTEST_FLAGS): Add it.
gcc/testsuite/
* lib/rust.exp (rust_init): Add
'-frust-incomplete-and-experimental-compiler-do-not-use'.
Philip Herron [Tue, 23 Aug 2022 15:39:33 +0000 (16:39 +0100)]
gccrs: Add GCC Rust front-end Make-lang.in
This is the Makefile for our front-end.
gcc/rust/
* Make-lang.in: New.
Philip Herron [Tue, 23 Aug 2022 15:41:00 +0000 (16:41 +0100)]
gccrs: Add lang.opt
We have some Rust-specific language options. Note that -fwrapv is
enabled by default in the code. We are trying to respect options such as
-Wunused-result which we get by porting over C++'s no-discard for Rust's
must-use attribute, so we have enabled these by default directly here.
gcc/rust/
* lang.opt: New.
Philip Herron [Tue, 23 Aug 2022 15:40:07 +0000 (16:40 +0100)]
gccrs: Add lang-spec.h
This specifies the extensions of the Rust language.
gcc/rust/
* lang-specs.h: New.
Philip Herron [Tue, 23 Aug 2022 15:44:42 +0000 (16:44 +0100)]
gccrs: Compiler proper interface kicks off the pipeline
This is a wrapper to get out of C land in the rust-lang.cc and into our
class hierarchy for the rust front-end. We expect that the front-end only
support one source file input as the expansion pass will attempt to resolve
that relative pass and parse accordingly.
The main missing piece here is that we are using saw_errors() to return
early which is unnecessary but as our error handling has been improving
over time we will start to take advantage of error node in our type system
as well as error_mark_node from GCC. The caveat being that our lints/checks
expect no errors and will throw an assertion.
gcc/rust/
* rust-lang.cc: New.
* rust-session-manager.cc: New.
* rust-session-manager.h: New.
Philip Herron [Tue, 23 Aug 2022 15:41:31 +0000 (16:41 +0100)]
gccrs: Add compiler driver
Our compiler driver is fairly simple so far. The key piece to enforce is
that a compilation unit in Rust is the whole crate, so the process for
compiling Rust means pointing the compiler at the main entry point such as
src/lib.rs or src/main.rs where the expansion pass takes over loading the
other source files to include them in the crate.
gcc/rust/
* rustspec.cc: New.
Philip Herron [Wed, 24 Aug 2022 11:08:58 +0000 (12:08 +0100)]
gccrs: These are wrappers ported from reusing gccgo
The wrappers over linemap and location will eventually disappear here but
served as a useful starting point for us. We have wrappers over the
diagnostics system which we might be able to get rid of as well.
gcc/rust/
* rust-diagnostics.cc: New.
* rust-diagnostics.h: New.
* rust-gcc-diagnostics.cc: New.
* rust-linemap.cc: New.
* rust-linemap.h: New.
* rust-location.h: New.
* rust-system.h: New.
Philip Herron [Fri, 21 Oct 2022 12:29:50 +0000 (14:29 +0200)]
gccrs: Add HIR to GCC GENERIC lowering entry point
This patch contains the entry point and utilities used for the lowering
of HIR nodes to `tree`s. It also contains a constant evaluator, ported
over from the C++ frontend.
gcc/rust/
* backend/rust-compile-context.cc: New.
* backend/rust-compile-context.h: New.
* backend/rust-compile.cc: New.
* backend/rust-compile.h: New.
* backend/rust-constexpr.cc: New.
* backend/rust-constexpr.h: New.
Co-authored-by: David Faust <david.faust@oracle.com>
Co-authored-by: Faisal Abbas <90.abbasfaisal@gmail.com>
Signed-off-by: Faisal Abbas <90.abbasfaisal@gmail.com>
Philip Herron [Fri, 21 Oct 2022 12:27:56 +0000 (14:27 +0200)]
gccrs: Add HIR to GCC GENERIC lowering for all nodes
This patch implements the lowering mentioned in the previous patch for all HIR nodes.
gcc/rust/
* backend/rust-compile-block.cc: New.
* backend/rust-compile-block.h: New.
* backend/rust-compile-expr.cc: New.
* backend/rust-compile-expr.h: New.
* backend/rust-compile-extern.h: New.
* backend/rust-compile-fnparam.cc: New.
* backend/rust-compile-fnparam.h: New.
* backend/rust-compile-implitem.cc: New.
* backend/rust-compile-implitem.h: New.
* backend/rust-compile-intrinsic.cc: New.
* backend/rust-compile-intrinsic.h: New.
* backend/rust-compile-item.cc: New.
* backend/rust-compile-item.h: New.
* backend/rust-compile-pattern.cc: New.
* backend/rust-compile-pattern.h: New.
* backend/rust-compile-resolve-path.cc: New.
* backend/rust-compile-resolve-path.h: New.
* backend/rust-compile-stmt.cc: New.
* backend/rust-compile-stmt.h: New.
* backend/rust-compile-struct-field-expr.cc: New.
* backend/rust-compile-struct-field-expr.h: New.
* backend/rust-compile-type.cc: New.
* backend/rust-compile-type.h: New.
* backend/rust-compile-var-decl.h: New.
Co-authored-by: David Faust <david.faust@oracle.com>
Philip Herron [Fri, 21 Oct 2022 12:01:04 +0000 (14:01 +0200)]
gccrs: Add base for HIR to GCC GENERIC lowering
This pass walks the HIR crate and turns them into GCC `tree`s. We do not have
any Rust specific tree's. We are slowly removing the backend abstraction
which was ported over from gccgo in favour of using `tree`s directly.
gcc/rust/
* backend/rust-builtins.h: New.
* backend/rust-compile-base.cc: New.
* backend/rust-compile-base.h: New.
* backend/rust-mangle.cc: New.
* backend/rust-mangle.h: New.
* backend/rust-tree.cc: New.
* backend/rust-tree.h: New.
* rust-backend.h: New.
* rust-gcc.cc: New.
Co-authored-by: David Faust <david.faust@oracle.com>
Philip Herron [Tue, 23 Aug 2022 15:36:29 +0000 (16:36 +0100)]
gccrs: Add metadata output pass
Extern crates statements to tell the front-end to look for another library.
The mechanism here is heavily inspired from gccgo, so when we compile a
library for example we invoke:
gccrs -g -O2 -frust-crate=mylib -c src/lib.rs -o src/mylib.o
All going well this object file will now contain extra data inside
.rust-export section inside the object file which will be preserved inside
archives and shared objects. When we have another application which uses
this library 'mylib'.
extern crate mylib;
use mylib::foo;
fn main() {
foo();
}
We compile using:
gcc -g -O2 -frust-crate=test -c src/main.rs -o src/main.o
When the extern crate line is hit the front-end will look for mylib.o,
libmylib.a, mylib.rox. If it finds a raw object file it will read the
.rust-export section directly from the object for the public metadata
such as public functions, types constants etc. If it fails to find an
object it might find .rox which is the objdump of the .rust-export to a
raw file, it might even find libmylib.a and read the export directly out
of the archive file reusing code from gccgo to do so.
The full compiler pipeline is reused here, so the metatadata is actually
just real rust code. The benifit here is that Rust supports exporting,
macros and generics so this requires the name-resolution and type info
all to be generated and inserted into the apropriate context classes. Since
the metadata is real rust code it means we can reuse the full pipeline to
generate the code as necessary. So for the simple case of a public struct
we simply emit the AST dump of this struct directly into the metadata. If
its a non-generic public function we emit and extern rust abi block for
that function. If its a trait we can simply emit the trait with the public
memebers. Generics are more complicated since we need to emit the function
fully for it to be compiled correctly this still needs tests to be added.
The hardest part is non generic impl blocks which is still a WIP.
To finally link the two crates together you run:
gcc -g -O2 -o rust-program.exe src/main.o src/mylib.o
gcc/rust/
* metadata/rust-export-metadata.cc: New.
* metadata/rust-export-metadata.h: New.
* metadata/rust-extern-crate.cc: New.
* metadata/rust-extern-crate.h: New.
* metadata/rust-import-archive.cc: New.
* metadata/rust-imports.cc: New.
* metadata/rust-imports.h: New.
* rust-object-export.cc: New.
* rust-object-export.h: New.
Philip Herron [Tue, 23 Aug 2022 15:35:44 +0000 (16:35 +0100)]
gccrs: Add unused variable scan
This is a simple walk_tree which acts on the monomorphized code by walking
the compiled translation unit of functions.
gcc/rust/
* checks/lints/rust-lint-unused-var.cc: New.
* checks/lints/rust-lint-unused-var.h: New.
Thomas Young [Tue, 23 Aug 2022 15:34:35 +0000 (16:34 +0100)]
gccrs: Add dead code scan on HIR
In order to find dead code we use a depth first search and keep liveness
variables, after type resolution. In this case, if a function is unused
and it calls another function the 2nd function is now unused since the
caller is not used etc. The algorithm is a depth first search.
gcc/rust/
* checks/lints/rust-lint-marklive-base.h: New.
* checks/lints/rust-lint-marklive.cc: New.
* checks/lints/rust-lint-marklive.h: New.
* checks/lints/rust-lint-scan-deadcode.h: New.
Arthur Cohen [Tue, 23 Aug 2022 15:32:26 +0000 (16:32 +0100)]
gccrs: Add privacy checks
This pass is responsible for resolving the privacy of items and verifying
that access to these items is performed within the limits of that privacy.
By default, items in Rust are private and only public to the current
module and its submodules. However, the user can annotate an item with
various qualifiers such as `pub` to publicly expose an item. Furthermore,
a module path can be given to `pub` to restrict an item's privacy to a
certain module: These paths need to be resolved and later on checked by
the privacy error reporter.
gcc/rust/
* checks/errors/privacy/rust-privacy-check.cc: New.
* checks/errors/privacy/rust-privacy-check.h: New.
* checks/errors/privacy/rust-privacy-common.h: New.
* checks/errors/privacy/rust-privacy-ctx.cc: New.
* checks/errors/privacy/rust-privacy-ctx.h: New.
* checks/errors/privacy/rust-privacy-reporter.cc: New.
* checks/errors/privacy/rust-privacy-reporter.h: New.
* checks/errors/privacy/rust-pub-restricted-visitor.cc: New.
* checks/errors/privacy/rust-pub-restricted-visitor.h: New.
* checks/errors/privacy/rust-reachability.cc: New.
* checks/errors/privacy/rust-reachability.h: New.
* checks/errors/privacy/rust-visibility-resolver.cc: New.
* checks/errors/privacy/rust-visibility-resolver.h: New.
Arthur Cohen [Tue, 23 Aug 2022 15:31:55 +0000 (16:31 +0100)]
gccrs: Add const checker
Similarly to the unsafe checker, constant evaluation can only be performed
in a few contexts and include restrictions on the Rust language. Should
the user fail to uphold those conditions, errors will be reported and the
compilation pipeline interrupted.
These contexts are as follow:
- Array type length expressions
- Array repeat length expressions
- Constants
- Statics
- Enum discriminants
- Const generic arguments
In these contexts, the user is restricted to calling only functions marked
as `const` or perform arithmetic operations only on certain types, among
other restrictions.
gcc/rust/
* checks/errors/rust-const-checker.cc: New.
* checks/errors/rust-const-checker.h: New.
Arthur Cohen [Tue, 23 Aug 2022 15:31:17 +0000 (16:31 +0100)]
gccrs: Add unsafe checks for Rust
The UnsafeChecker visitor verifies that unsafe actions are only performed
in unsafe contexts. Otherwise, an error should be reported to the user and
the compilation pipeline should be halted. These contexts, which include
unsafe blocks or unsafe functions, are allowed to perform more actions
than regular safe Rust code. These actions currently include:
- Dereferencing raw pointers
- Calls to unsafe functions
- Use of inline assembly
- Use of mutable static
- Use of extern static
- Access to a union's field
- Call to functions with #[target(feature)] attribute
- Initializing type with rustc_layout_scalar_valid_range attribute
- Mutation of layout constrained field
- Borrow of layout constrained field
gcc/rust/
* checks/errors/rust-unsafe-checker.cc: New.
* checks/errors/rust-unsafe-checker.h: New.
Philip Herron [Fri, 21 Oct 2022 11:55:28 +0000 (13:55 +0200)]
gccrs: Add remaining type system transformations
This patch implements multiple transformation performed on the HIR
during type-resolution such as type coercion, casts, auto-dereferencement.
gcc/rust/
* typecheck/rust-autoderef.cc: New.
* typecheck/rust-autoderef.h: New.
* typecheck/rust-casts.cc: New.
* typecheck/rust-casts.h: New.
* typecheck/rust-coercion.cc: New.
* typecheck/rust-coercion.h: New.
* typecheck/rust-hir-dot-operator.cc: New.
* typecheck/rust-hir-dot-operator.h: New.
* typecheck/rust-hir-inherent-impl-overlap.h: New.
* typecheck/rust-hir-path-probe.h: New.
* typecheck/rust-hir-trait-ref.h: New.
* typecheck/rust-hir-type-bounds.h: New.
* typecheck/rust-substitution-mapper.cc: New.
* typecheck/rust-substitution-mapper.h: New.
* typecheck/rust-tycheck-dump.h: New.
* typecheck/rust-tyctx.cc: New.
* typecheck/rust-tyty-bounds.cc: New.
* typecheck/rust-tyty-call.cc: New.
* typecheck/rust-tyty-call.h: New.
* typecheck/rust-tyty-cmp.h: New.
* typecheck/rust-tyty-rules.h: New.
Philip Herron [Fri, 21 Oct 2022 11:53:58 +0000 (13:53 +0200)]
gccrs: Add Rust type information
Contains abstractions over Rust's types, used when performing the
HIR's type-resolution.
gcc/rust/
* typecheck/rust-tyty.cc: New.
* typecheck/rust-tyty.h: New.
Philip Herron [Fri, 21 Oct 2022 11:53:14 +0000 (13:53 +0200)]
gccrs: Add type resolution and trait solving pass
This serves to handle parts of the Rust type-system. Namely, the type
resolution (similar to type-checking) and the trait solving algorithms
(which ensure Rust's type contracts are upheld throughout the codebase).
gcc/rust/
* typecheck/rust-hir-trait-resolve.cc: New.
* typecheck/rust-hir-trait-resolve.h: New.
* typecheck/rust-hir-type-check-base.cc: New.
* typecheck/rust-hir-type-check-base.h: New.
* typecheck/rust-hir-type-check-enumitem.cc: New.
* typecheck/rust-hir-type-check-enumitem.h: New.
* typecheck/rust-hir-type-check-expr.cc: New.
* typecheck/rust-hir-type-check-expr.h: New.
* typecheck/rust-hir-type-check-implitem.cc: New.
* typecheck/rust-hir-type-check-implitem.h: New.
* typecheck/rust-hir-type-check-item.cc: New.
* typecheck/rust-hir-type-check-item.h: New.
* typecheck/rust-hir-type-check-path.cc: New.
* typecheck/rust-hir-type-check-pattern.cc: New.
* typecheck/rust-hir-type-check-pattern.h: New.
* typecheck/rust-hir-type-check-stmt.cc: New.
* typecheck/rust-hir-type-check-stmt.h: New.
* typecheck/rust-hir-type-check-struct-field.h: New.
* typecheck/rust-hir-type-check-struct.cc: New.
* typecheck/rust-hir-type-check-toplevel.cc: New.
* typecheck/rust-hir-type-check-toplevel.h: New.
* typecheck/rust-hir-type-check-type.cc: New.
* typecheck/rust-hir-type-check-type.h: New.
* typecheck/rust-hir-type-check-util.cc: New.
* typecheck/rust-hir-type-check-util.h: New.
* typecheck/rust-hir-type-check.cc: New.
* typecheck/rust-hir-type-check.h: New.
* typecheck/rust-tyty-visitor.h: New.
Philip Herron [Tue, 23 Aug 2022 15:29:11 +0000 (16:29 +0100)]
gccrs: Add helpers mappings canonical path and lang items
These are various helper classes used in the compiler pipeline.
gcc/rust/
* util/rust-canonical-path.h: New.
* util/rust-common.h: New.
* util/rust-hir-map.cc: New.
* util/rust-hir-map.h: New.
* util/rust-identifier.h: New.
* util/rust-lang-item.h: New.
* util/rust-mapping-common.h: New.
* util/rust-stacked-contexts.h: New.
Arthur Cohen [Tue, 23 Aug 2022 15:27:23 +0000 (16:27 +0100)]
gccrs: Add attributes checker
The attribute checker is responsible for checking the validity of various
attributes including built-in ones. It is currently unfinished and will
receive some modifications, as well as become the host of some existing
code in the compiler which needs to be refactored. One of its
responsibilities is to make sure that arguments given to built-in
attributes are correct, or contain the correct type of information. This
visitor also checks that an attribute is allowed to be used in the current
particular context.
gcc/rust/
* util/rust-attributes.cc: New.
* util/rust-attributes.h: New.
Arthur Cohen [Tue, 23 Aug 2022 15:26:37 +0000 (16:26 +0100)]
gccrs: Add implementation of Optional
This adds an Optional<T> class to improve error handling.
gcc/rust/
* util/rust-optional-test.cc: New.
* util/rust-optional.h: New.
Arthur Cohen [Tue, 23 Aug 2022 15:26:01 +0000 (16:26 +0100)]
gccrs: Add Base62 implementation
Used for V0 symbol mangling scheme which is still in development.
gcc/rust/
* util/rust-base62.cc: New.
* util/rust-base62.h: New.
Philip Herron [Tue, 23 Aug 2022 15:23:22 +0000 (16:23 +0100)]
gccrs: Add Rust ABI enum helpers
This is a simple helper over an enum of possible ABI options in Rust.
gcc/rust/
* util/rust-abi.cc: New.
* util/rust-abi.h: New.
Philip Herron [Tue, 23 Aug 2022 15:22:47 +0000 (16:22 +0100)]
gccrs: Add port of FNV hash used during legacy symbol mangling
This hash was ported from the Go runtime, as we needed a hash for the legacy
symbol mangling system. All symbols in Rust contain a hash of some
metadata for uniqueness on generic functions.
gcc/rust/
* util/fnv-hash.h: New.
Philip Herron [Tue, 23 Aug 2022 15:22:22 +0000 (16:22 +0100)]
gccrs: Add wrapper for make_unique
This is a wrapper for make_unique. We can likely get rid of this, as there
are other implementations available, or simply keep using the unique_ptr
constructor.
gcc/rust/
* util/rust-make-unique.h: New.
Philip Herron [Tue, 23 Aug 2022 15:20:05 +0000 (16:20 +0100)]
gccrs: Add AST to HIR lowering pass
This performs the lowering of the AST to HIR. The interesting piece here is
that we desugar much of the AST as mentioned in the previous pass, but
crucially, we also strip out all code that is "marked-for-strip" which failed
cfg-expansion from the expansion pass. After this, the HIR includes all code
required to compile for this crate.
gcc/rust/
* hir/rust-ast-lower-base.cc: New.
* hir/rust-ast-lower-base.h: New.
* hir/rust-ast-lower-block.h: New.
* hir/rust-ast-lower-enumitem.h: New.
* hir/rust-ast-lower-expr.h: New.
* hir/rust-ast-lower-extern.h: New.
* hir/rust-ast-lower-implitem.h: New.
* hir/rust-ast-lower-item.cc: New.
* hir/rust-ast-lower-item.h: New.
* hir/rust-ast-lower-pattern.cc: New.
* hir/rust-ast-lower-pattern.h: New.
* hir/rust-ast-lower-stmt.h: New.
* hir/rust-ast-lower-struct-field-expr.h: New.
* hir/rust-ast-lower-type.h: New.
* hir/rust-ast-lower.cc: New.
* hir/rust-ast-lower.h: New.
* hir/rust-hir-dump.cc: New.
* hir/rust-hir-dump.h: New.
Philip Herron [Fri, 21 Oct 2022 11:45:38 +0000 (13:45 +0200)]
gccrs: Add HIR definitions and visitor framework
This patch implements the classes mentioned in the previous HIR patch,
as well as a set of visitor frameworks used in handling that HIR.
gcc/rust/
* hir/tree/rust-hir-full-decls.h: New.
* hir/tree/rust-hir-full-test.cc: New.
* hir/tree/rust-hir-full.h: New.
* hir/tree/rust-hir-visitor.h: New.
* hir/tree/rust-hir.h: New.
Philip Herron [Fri, 21 Oct 2022 11:44:20 +0000 (13:44 +0200)]
gccrs: Add declarations for Rust HIR
This patch contains the declarations needed for our second intermediate
representation, which we will refer to as an HIR.
This gives the front-end a chance to desugar much of the AST, such as:
- Removing distinction between functions and methods
- Removing Macros
- Removing IdentifierExprs
- Removing duplicate attribute structures
gcc/rust/
* hir/tree/rust-hir-expr.h: New.
* hir/tree/rust-hir-item.h: New.
* hir/tree/rust-hir-path.h: New.
* hir/tree/rust-hir-pattern.h: New.
* hir/tree/rust-hir-stmt.h: New.
* hir/tree/rust-hir-type.h: New.
Philip Herron [Tue, 23 Aug 2022 15:19:04 +0000 (16:19 +0100)]
gccrs: Add name resolution pass to the Rust front-end
The name resolution is split into two phases, one toplevel pass which scans
the whole "Crate" which iterates all items and nested items in modules to
generate a context class full of CanonicalPath items. It also generates
a hierarchy of parent->child and child->parent relationships using the AST
NodeId for PathResolution in the second phase.
The second phase drills into each item like functions and creates a stack
of canonical paths for variables etc so that we can store information in
a side table of usage variable 'a' resolves to NodeId '123' which refers
to the NodeId of the "let a;" statement.
gcc/rust/
* resolve/rust-ast-resolve-base.cc: New.
* resolve/rust-ast-resolve-base.h: New.
* resolve/rust-ast-resolve-expr.cc: New.
* resolve/rust-ast-resolve-expr.h: New.
* resolve/rust-ast-resolve-implitem.h: New.
* resolve/rust-ast-resolve-item.cc: New.
* resolve/rust-ast-resolve-item.h: New.
* resolve/rust-ast-resolve-path.cc: New.
* resolve/rust-ast-resolve-path.h: New.
* resolve/rust-ast-resolve-pattern.cc: New.
* resolve/rust-ast-resolve-pattern.h: New.
* resolve/rust-ast-resolve-stmt.cc: New.
* resolve/rust-ast-resolve-stmt.h: New.
* resolve/rust-ast-resolve-struct-expr-field.cc: New.
* resolve/rust-ast-resolve-struct-expr-field.h: New.
* resolve/rust-ast-resolve-toplevel.h: New.
* resolve/rust-ast-resolve-type.cc: New.
* resolve/rust-ast-resolve-type.h: New.
* resolve/rust-ast-resolve.cc: New.
* resolve/rust-ast-resolve.h: New.
* resolve/rust-ast-verify-assignee.h: New.
* resolve/rust-name-resolver.cc: New.
* resolve/rust-name-resolver.h: New.
Arthur Cohen [Tue, 23 Aug 2022 15:15:22 +0000 (16:15 +0100)]
gccrs: Add expansion pass for the Rust front-end
The expansion pass is responsible for two actions on our AST:
1. Expanding macro calls
2. Performing conditional compilation
Calls to macros should be checked and expanded into an AST fragment based on
the context they've been called in. This is similar to token substitution, with
a lot of intricacies and checks being performed. A single invocation can result
in an AST fragment containing multiple statements or multiple expressions,
which need to be handled as well. Furthermore, Rust macros can contain
repetitions relying on Kleine operators, similar to regular expression
patterns, that also need to be expanded properly.
Finally, Rust code can be hidden behind `cfg` directives, which allow the user
to perform conditional compilation. If a `cfg` predicate is not met, the
expression or statement it refers to should be marked for strip and removed
from the AST.
gcc/rust/
* expand/rust-attribute-visitor.cc: New.
* expand/rust-attribute-visitor.h: New.
* expand/rust-macro-builtins.cc: New.
* expand/rust-macro-builtins.h: New.
* expand/rust-macro-expand.cc: New.
* expand/rust-macro-expand.h: New.
* expand/rust-macro-invoc-lexer.cc: New.
* expand/rust-macro-invoc-lexer.h: New.
* expand/rust-macro-substitute-ctx.cc: New.
* expand/rust-macro-substitute-ctx.h: New.
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Co-authored-by: Joel Phillips <simplytheother@gmail.com>
Signed-off-by: Joel Phillips <simplytheother@gmail.com>
Joel Phillips [Fri, 21 Oct 2022 11:39:49 +0000 (13:39 +0200)]
gccrs: Add Parser for Rust front-end pt.2
This patch contains the second half of the templated Rust parser.
gcc/rust/
* parse/rust-parse-impl.h: New, second half.
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Signed-off-by: Joel Phillips <simplytheother@gmail.com>
Joel Phillips [Fri, 21 Oct 2022 11:39:04 +0000 (13:39 +0200)]
gccrs: Add Parser for Rust front-end pt.1
This is a Pratt-style parser for Rust that implements all of the AST. The
rust-parser-impl.h is the implementation of the parser as a template,
allowing it to be given ManagedTokenSource and avoid virtual calls. The
downside is it takes time to compile when used.
see: https://en.wikipedia.org/wiki/Operator-precedence_parser#Pratt_parsing
This patch contains the first half of the templated parser, so as to not
lose patches in the mailing list archives.
gcc/rust/
* parse/rust-cfg-parser.cc: New.
* parse/rust-cfg-parser.h: New.
* parse/rust-parse-impl.h: New.
* parse/rust-parse.cc: New.
* parse/rust-parse.h: New.
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Signed-off-by: Joel Phillips <simplytheother@gmail.com>
Joel Phillips [Tue, 23 Aug 2022 15:11:00 +0000 (16:11 +0100)]
gccrs: Add Lexer for Rust front-end
The lexer is referred to as a ManagedTokenSource within the parser. This
lexer does not currently support Unicode, but serves as a starting point
to do so.
gcc/rust/
* lex/rust-codepoint.h: New.
* lex/rust-lex.cc: New.
* lex/rust-lex.h: New.
* lex/rust-token.cc: New.
* lex/rust-token.h: New.
* rust-buffered-queue.h: New.
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Co-authored-by: Mark Wielaard <mark@klomp.org>
Signed-off-by: Joel Phillips <simplytheother@gmail.com>
Joel Phillips [Fri, 21 Oct 2022 11:35:58 +0000 (13:35 +0200)]
gccrs: Add Rust AST visitors
This patch contains the basic framework of our AST visitors, as well as
one aimed at pretty-printing and exporting these AST nodes.
gcc/rust/
* ast/rust-ast-dump.cc: New.
* ast/rust-ast-dump.h: New.
* ast/rust-ast-visitor.h: New.
* ast/rust-cond-compilation.h: New.
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Signed-off-by: Joel Phillips <simplytheother@gmail.com>
Joel Phillips [Fri, 21 Oct 2022 12:35:54 +0000 (14:35 +0200)]
gccrs: Add full definitions of Rust AST data structures
This adds the proper definitions of our AST nodes split across multiple
files for clarity
gcc/rust/
* ast/rust-expr.h: New.
* ast/rust-macro.h: New.
* ast/rust-path.h: New.
* ast/rust-pattern.h: New.
* ast/rust-stmt.h: New.
* ast/rust-type.h: New.
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Signed-off-by: Joel Phillips <simplytheother@gmail.com>
Joel Phillips [Fri, 21 Oct 2022 12:35:09 +0000 (14:35 +0200)]
gccrs: Add definitions of Rust Items in AST data structures
This adds the proper definitions of our AST Item nodes.
gcc/rust/
* ast/rust-item.h: New.
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Signed-off-by: Joel Phillips <simplytheother@gmail.com>
Joel Phillips [Fri, 21 Oct 2022 11:34:11 +0000 (13:34 +0200)]
gccrs: Add Rust front-end base AST data structures
This is a full C++11 class hierarchy representing the Rust AST. We do not
allow dynamic_cast and so the main mechanism to work with the AST is by
using the visitor interface. Slowly we are adding TREE_CODE style node
types to the AST which will allow for more ways to work with the AST but
for now this is it.
See: https://doc.rust-lang.org/reference/items.html
gcc/rust/
* ast/rust-ast-full-decls.h: New.
* ast/rust-ast-full-test.cc: New.
* ast/rust-ast-full.h: New.
* ast/rust-ast.h: New.
* operator.h: New.
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Signed-off-by: Joel Phillips <simplytheother@gmail.com>
Philip Herron [Tue, 23 Aug 2022 15:04:30 +0000 (16:04 +0100)]
gccrs: Add gcc-check-target check-rust
This allows us to invoke the rust testsuite.
* Makefile.def: Add Rust language.
* Makefile.in: Regenerate via autogen.
Philip Herron [Tue, 23 Aug 2022 15:02:25 +0000 (16:02 +0100)]
gccrs: Add execution test cases
This is similar to the compile/torture/*.rs test cases, but all of these are
dg-execute testcases. They are compiled, linked and executed by default. These
testcases are also compiled with the matrix of torture options.
The only caveat here is that gccrs does not currently support the main shim,
so we have a C-style main function here returning zero which is not proper Rust
code.
gcc/testsuite/
* rust/execute/torture/block_expr1.rs: New.
* rust/execute/torture/builtin_macro_cfg.rs: New.
* rust/execute/torture/builtin_macro_concat.rs: New.
* rust/execute/torture/builtin_macro_env.rs: New.
* rust/execute/torture/builtin_macro_include_bytes.rs: New.
* rust/execute/torture/builtin_macro_include_str.rs: New.
* rust/execute/torture/builtin_macro_line.rs: New.
* rust/execute/torture/builtin_macros1.rs: New.
* rust/execute/torture/builtin_macros3.rs: New.
* rust/execute/torture/cfg1.rs: New.
* rust/execute/torture/cfg2.rs: New.
* rust/execute/torture/cfg3.rs: New.
* rust/execute/torture/cfg4.rs: New.
* rust/execute/torture/cfg5.rs: New.
* rust/execute/torture/coercion1.rs: New.
* rust/execute/torture/coercion2.rs: New.
* rust/execute/torture/const_fold1.rs: New.
* rust/execute/torture/const_fold2.rs: New.
* rust/execute/torture/copy_nonoverlapping1.rs: New.
* rust/execute/torture/empty_main.rs: New.
* rust/execute/torture/execute.exp: New.
* rust/execute/torture/exit_error.rs: New.
* rust/execute/torture/extern_mod4.rs: New.
* rust/execute/torture/func1.rs: New.
* rust/execute/torture/helloworld1.rs: New.
* rust/execute/torture/helloworld2.rs: New.
* rust/execute/torture/include.txt: New.
* rust/execute/torture/index1.rs: New.
* rust/execute/torture/issue-1120.rs: New.
* rust/execute/torture/issue-1133.rs: New.
* rust/execute/torture/issue-1198.rs: New.
* rust/execute/torture/issue-1231.rs: New.
* rust/execute/torture/issue-1232.rs: New.
* rust/execute/torture/issue-1249.rs: New.
* rust/execute/torture/issue-1436.rs: New.
* rust/execute/torture/issue-1496.rs: New.
* rust/execute/torture/issue-647.rs: New.
* rust/execute/torture/issue-845.rs: New.
* rust/execute/torture/issue-851.rs: New.
* rust/execute/torture/issue-858.rs: New.
* rust/execute/torture/issue-976.rs: New.
* rust/execute/torture/issue-995.rs: New.
* rust/execute/torture/macros1.rs: New.
* rust/execute/torture/macros10.rs: New.
* rust/execute/torture/macros11.rs: New.
* rust/execute/torture/macros12.rs: New.
* rust/execute/torture/macros13.rs: New.
* rust/execute/torture/macros14.rs: New.
* rust/execute/torture/macros16.rs: New.
* rust/execute/torture/macros17.rs: New.
* rust/execute/torture/macros18.rs: New.
* rust/execute/torture/macros19.rs: New.
* rust/execute/torture/macros2.rs: New.
* rust/execute/torture/macros20.rs: New.
* rust/execute/torture/macros21.rs: New.
* rust/execute/torture/macros22.rs: New.
* rust/execute/torture/macros23.rs: New.
* rust/execute/torture/macros24.rs: New.
* rust/execute/torture/macros25.rs: New.
* rust/execute/torture/macros26.rs: New.
* rust/execute/torture/macros27.rs: New.
* rust/execute/torture/macros28.rs: New.
* rust/execute/torture/macros29.rs: New.
* rust/execute/torture/macros3.rs: New.
* rust/execute/torture/macros30.rs: New.
* rust/execute/torture/macros31.rs: New.
* rust/execute/torture/macros4.rs: New.
* rust/execute/torture/macros5.rs: New.
* rust/execute/torture/macros6.rs: New.
* rust/execute/torture/macros7.rs: New.
* rust/execute/torture/macros8.rs: New.
* rust/execute/torture/macros9.rs: New.
* rust/execute/torture/match1.rs: New.
* rust/execute/torture/match2.rs: New.
* rust/execute/torture/match3.rs: New.
* rust/execute/torture/match_bool1.rs: New.
* rust/execute/torture/match_byte1.rs: New.
* rust/execute/torture/match_char1.rs: New.
* rust/execute/torture/match_int1.rs: New.
* rust/execute/torture/match_loop1.rs: New.
* rust/execute/torture/match_range1.rs: New.
* rust/execute/torture/match_range2.rs: New.
* rust/execute/torture/match_tuple1.rs: New.
* rust/execute/torture/method1.rs: New.
* rust/execute/torture/method2.rs: New.
* rust/execute/torture/method3.rs: New.
* rust/execute/torture/method4.rs: New.
* rust/execute/torture/mod1.rs: New.
* rust/execute/torture/modules/mod.rs: New.
* rust/execute/torture/operator_overload_1.rs: New.
* rust/execute/torture/operator_overload_10.rs: New.
* rust/execute/torture/operator_overload_11.rs: New.
* rust/execute/torture/operator_overload_12.rs: New.
* rust/execute/torture/operator_overload_2.rs: New.
* rust/execute/torture/operator_overload_3.rs: New.
* rust/execute/torture/operator_overload_4.rs: New.
* rust/execute/torture/operator_overload_5.rs: New.
* rust/execute/torture/operator_overload_6.rs: New.
* rust/execute/torture/operator_overload_7.rs: New.
* rust/execute/torture/operator_overload_8.rs: New.
* rust/execute/torture/operator_overload_9.rs: New.
* rust/execute/torture/slice-magic.rs: New.
* rust/execute/torture/slice-magic2.rs: New.
* rust/execute/torture/slice1.rs: New.
* rust/execute/torture/str-layout1.rs: New.
* rust/execute/torture/str-zero.rs: New.
* rust/execute/torture/trait1.rs: New.
* rust/execute/torture/trait10.rs: New.
* rust/execute/torture/trait11.rs: New.
* rust/execute/torture/trait12.rs: New.
* rust/execute/torture/trait13.rs: New.
* rust/execute/torture/trait2.rs: New.
* rust/execute/torture/trait3.rs: New.
* rust/execute/torture/trait4.rs: New.
* rust/execute/torture/trait5.rs: New.
* rust/execute/torture/trait6.rs: New.
* rust/execute/torture/trait7.rs: New.
* rust/execute/torture/trait8.rs: New.
* rust/execute/torture/trait9.rs: New.
* rust/execute/torture/transmute1.rs: New.
* rust/execute/torture/wrapping_op1.rs: New.
* rust/execute/torture/wrapping_op2.rs: New.
* rust/execute/xfail/macro1.rs: New.
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Co-authored-by: Thomas Schwinge <thomas@codesourcery.com>
Co-authored-by: Mark Wielaard <mark@klomp.org>
Co-authored-by: Marc Poulhiès <dkm@kataplop.net>
Philip Herron [Tue, 23 Aug 2022 15:01:16 +0000 (16:01 +0100)]
gccrs: Add general compilation test cases
This suite of tests has two sections: compile/*.rs and compile/torture/*.rs.
The first section is comprised entirely of dg-compile tests, containing a
mixture of dg-warning and dg-error annotations and some with no annotations,
ensuring the creation of resulting asm output. The second section is the same,
but has tests which are ran with the full torture options, for coverage of test
cases that may have an issue with a specific optimization level.
gcc/testsuite/
* rust/compile/abi-options1.rs: New.
* rust/compile/array3.rs: New.
* rust/compile/array_empty_list.rs: New.
* rust/compile/arrays1.rs: New.
* rust/compile/arrays2.rs: New.
* rust/compile/attr-mismatch-crate-name.rs: New.
* rust/compile/attr_cold.rs: New.
* rust/compile/attr_deprecated.rs: New.
* rust/compile/attr_deprecated_2.rs: New.
* rust/compile/bad-crate-name.rs: New.
* rust/compile/bad=file-name.rs: New.
* rust/compile/bad_as_bool_char.rs: New.
* rust/compile/bad_file_name.txt.rs: New.
* rust/compile/bad_inner_doc.rs: New.
* rust/compile/bad_pub_enumitems.rs: New.
* rust/compile/bad_stmt_enums.rs: New.
* rust/compile/bad_toplevel_enums.rs: New.
* rust/compile/bad_tuple_index.rs: New.
* rust/compile/bad_type1.rs: New.
* rust/compile/bad_type2.rs: New.
* rust/compile/break1.rs: New.
* rust/compile/break2.rs: New.
* rust/compile/builtin_macro_compile_error.rs: New.
* rust/compile/builtin_macro_concat.rs: New.
* rust/compile/builtin_macro_env.rs: New.
* rust/compile/builtin_macro_include_bytes.rs: New.
* rust/compile/builtin_macro_include_str.rs: New.
* rust/compile/builtin_macro_not_found.rs: New.
* rust/compile/bytecharstring.rs: New.
* rust/compile/canonical_paths1.rs: New.
* rust/compile/cast1.rs: New.
* rust/compile/cfg1.rs: New.
* rust/compile/cfg2.rs: New.
* rust/compile/cfg3.rs: New.
* rust/compile/cfg4.rs: New.
* rust/compile/cfg5.rs: New.
* rust/compile/compile.exp: New.
* rust/compile/complex-path1.rs: New.
* rust/compile/const-issue1440.rs: New.
* rust/compile/const1.rs: New.
* rust/compile/const2.rs: New.
* rust/compile/const3.rs: New.
* rust/compile/const_generics_1.rs: New.
* rust/compile/const_generics_2.rs: New.
* rust/compile/const_generics_3.rs: New.
* rust/compile/const_generics_4.rs: New.
* rust/compile/const_generics_5.rs: New.
* rust/compile/const_generics_6.rs: New.
* rust/compile/continue1.rs: New.
* rust/compile/deadcode_err1.rs: New.
* rust/compile/deadcode_err2.rs: New.
* rust/compile/debug-diagnostics-default.rs: New.
* rust/compile/debug-diagnostics-off.rs: New.
* rust/compile/debug-diagnostics-on.rs: New.
* rust/compile/doc_isolated_cr_block_comment.rs: New.
* rust/compile/doc_isolated_cr_inner_block_comment.rs: New.
* rust/compile/doc_isolated_cr_inner_line_comment.rs: New.
* rust/compile/doc_isolated_cr_line_comment.rs: New.
* rust/compile/dup_fields.rs: New.
* rust/compile/empty_comment_before_match.rs: New.
* rust/compile/expected_type_args2.rs: New.
* rust/compile/expected_type_args3.rs: New.
* rust/compile/func1.rs: New.
* rust/compile/func2.rs: New.
* rust/compile/func3.rs: New.
* rust/compile/func4.rs: New.
* rust/compile/func5.rs: New.
* rust/compile/generic-default1.rs: New.
* rust/compile/generics1.rs: New.
* rust/compile/generics10.rs: New.
* rust/compile/generics11.rs: New.
* rust/compile/generics12.rs: New.
* rust/compile/generics13.rs: New.
* rust/compile/generics2.rs: New.
* rust/compile/generics3.rs: New.
* rust/compile/generics4.rs: New.
* rust/compile/generics5.rs: New.
* rust/compile/generics6.rs: New.
* rust/compile/generics7.rs: New.
* rust/compile/generics8.rs: New.
* rust/compile/generics9.rs: New.
* rust/compile/implicit_returns_err1.rs: New.
* rust/compile/implicit_returns_err2.rs: New.
* rust/compile/implicit_returns_err3.rs: New.
* rust/compile/implicit_returns_err4.rs: New.
* rust/compile/infer-crate-name.rs: New.
* rust/compile/inline_1.rs: New.
* rust/compile/inline_2.rs: New.
* rust/compile/issue-1005.rs: New.
* rust/compile/issue-1019.rs: New.
* rust/compile/issue-1023.rs: New.
* rust/compile/issue-1031.rs: New.
* rust/compile/issue-1034.rs: New.
* rust/compile/issue-1089.rs: New.
* rust/compile/issue-1128.rs: New.
* rust/compile/issue-1129-1.rs: New.
* rust/compile/issue-1129-2.rs: New.
* rust/compile/issue-1130.rs: New.
* rust/compile/issue-1131.rs: New.
* rust/compile/issue-1152.rs: New.
* rust/compile/issue-1165.rs: New.
* rust/compile/issue-1173.rs: New.
* rust/compile/issue-1226.rs: New.
* rust/compile/issue-1234.rs: New.
* rust/compile/issue-1235.rs: New.
* rust/compile/issue-1237.rs: New.
* rust/compile/issue-1251.rs: New.
* rust/compile/issue-1271.rs: New.
* rust/compile/issue-1289.rs: New.
* rust/compile/issue-1323-1.rs: New.
* rust/compile/issue-1323-2.rs: New.
* rust/compile/issue-1383.rs: New.
* rust/compile/issue-1393.rs: New.
* rust/compile/issue-1447.rs: New.
* rust/compile/issue-407-2.rs: New.
* rust/compile/issue-407.rs: New.
* rust/compile/issue-557.rs: New.
* rust/compile/issue-635-1.rs: New.
* rust/compile/issue-635-2.rs: New.
* rust/compile/lookup_err1.rs: New.
* rust/compile/macro-issue1053-2.rs: New.
* rust/compile/macro-issue1053.rs: New.
* rust/compile/macro-issue1224.rs: New.
* rust/compile/macro-issue1233.rs: New.
* rust/compile/macro-issue1395-2.rs: New.
* rust/compile/macro-issue1395.rs: New.
* rust/compile/macro-issue1400-2.rs: New.
* rust/compile/macro-issue1400.rs: New.
* rust/compile/macro1.rs: New.
* rust/compile/macro10.rs: New.
* rust/compile/macro11.rs: New.
* rust/compile/macro12.rs: New.
* rust/compile/macro13.rs: New.
* rust/compile/macro14.rs: New.
* rust/compile/macro15.rs: New.
* rust/compile/macro16.rs: New.
* rust/compile/macro17.rs: New.
* rust/compile/macro18.rs: New.
* rust/compile/macro19.rs: New.
* rust/compile/macro2.rs: New.
* rust/compile/macro20.rs: New.
* rust/compile/macro21.rs: New.
* rust/compile/macro22.rs: New.
* rust/compile/macro23.rs: New.
* rust/compile/macro25.rs: New.
* rust/compile/macro26.rs: New.
* rust/compile/macro27.rs: New.
* rust/compile/macro28.rs: New.
* rust/compile/macro29.rs: New.
* rust/compile/macro3.rs: New.
* rust/compile/macro30.rs: New.
* rust/compile/macro31.rs: New.
* rust/compile/macro32.rs: New.
* rust/compile/macro33.rs: New.
* rust/compile/macro34.rs: New.
* rust/compile/macro35.rs: New.
* rust/compile/macro36.rs: New.
* rust/compile/macro37.rs: New.
* rust/compile/macro38.rs: New.
* rust/compile/macro39.rs: New.
* rust/compile/macro4.rs: New.
* rust/compile/macro40.rs: New.
* rust/compile/macro41.rs: New.
* rust/compile/macro42.rs: New.
* rust/compile/macro5.rs: New.
* rust/compile/macro6.rs: New.
* rust/compile/macro7.rs: New.
* rust/compile/macro8.rs: New.
* rust/compile/macro9.rs: New.
* rust/compile/macro_return.rs: New.
* rust/compile/match1.rs: New.
* rust/compile/match2.rs: New.
* rust/compile/match3.rs: New.
* rust/compile/match4.rs: New.
* rust/compile/match5.rs: New.
* rust/compile/match6.rs: New.
* rust/compile/match7.rs: New.
* rust/compile/method1.rs: New.
* rust/compile/method2.rs: New.
* rust/compile/mismatch-crate-name.rs: New.
* rust/compile/missing_middle/both_path.rs: New.
* rust/compile/missing_middle/explicit.not.rs: New.
* rust/compile/missing_middle/inner_path.rs: New.
* rust/compile/missing_middle/other.rs: New.
* rust/compile/missing_middle/outer_path.rs: New.
* rust/compile/missing_middle/sub/mod.rs: New.
* rust/compile/missing_return1.rs: New.
* rust/compile/mod_missing_middle.rs: New.
* rust/compile/never_type_err1.rs: New.
* rust/compile/privacy1.rs: New.
* rust/compile/privacy2.rs: New.
* rust/compile/privacy3.rs: New.
* rust/compile/privacy4.rs: New.
* rust/compile/privacy5.rs: New.
* rust/compile/privacy6.rs: New.
* rust/compile/pub_restricted_1.rs: New.
* rust/compile/pub_restricted_2.rs: New.
* rust/compile/pub_restricted_3.rs: New.
* rust/compile/raw_identifiers_bad_keywords.rs: New.
* rust/compile/raw_identifiers_underscore.rs: New.
* rust/compile/redef_error1.rs: New.
* rust/compile/redef_error2.rs: New.
* rust/compile/redef_error3.rs: New.
* rust/compile/redef_error4.rs: New.
* rust/compile/redef_error5.rs: New.
* rust/compile/redef_error6.rs: New.
* rust/compile/reference1.rs: New.
* rust/compile/self-path1.rs: New.
* rust/compile/self-path2.rs: New.
* rust/compile/shadow1.rs: New.
* rust/compile/specify-crate-name.rs: New.
* rust/compile/static_var1.rs: New.
* rust/compile/stmt_with_block_err1.rs: New.
* rust/compile/struct_align1.rs: New.
* rust/compile/struct_align2.rs: New.
* rust/compile/struct_init1.rs: New.
* rust/compile/struct_pack1.rs: New.
* rust/compile/struct_pack2.rs: New.
* rust/compile/syntax-only.rs: New.
* rust/compile/test_mod.rs: New.
* rust/compile/torture/all_doc_comment_line_blocks.rs: New.
* rust/compile/torture/all_doc_comment_line_blocks_crlf.rs: New.
* rust/compile/torture/arithmetic_expressions1.rs: New.
* rust/compile/torture/array_const_fold_1.rs: New.
* rust/compile/torture/array_const_fold_2.rs: New.
* rust/compile/torture/array_function.rs: New.
* rust/compile/torture/array_type_infer.rs: New.
* rust/compile/torture/array_zero_length.rs: New.
* rust/compile/torture/arrays1.rs: New.
* rust/compile/torture/arrays2.rs: New.
* rust/compile/torture/arrays3.rs: New.
* rust/compile/torture/arrays4.rs: New.
* rust/compile/torture/arrays5.rs: New.
* rust/compile/torture/arrays6.rs: New.
* rust/compile/torture/arrays_index1.rs: New.
* rust/compile/torture/arrays_index2.rs: New.
* rust/compile/torture/arrays_index3.rs: New.
* rust/compile/torture/as_bool_char.rs: New.
* rust/compile/torture/associated_types1.rs: New.
* rust/compile/torture/autoderef1.rs: New.
* rust/compile/torture/block_expr1.rs: New.
* rust/compile/torture/block_expr2.rs: New.
* rust/compile/torture/block_expr3.rs: New.
* rust/compile/torture/block_expr4.rs: New.
* rust/compile/torture/block_expr5.rs: New.
* rust/compile/torture/block_expr_parser_bug.rs: New.
* rust/compile/torture/bom.rs: New.
* rust/compile/torture/bom_comment.rs: New.
* rust/compile/torture/bom_shebang.rs: New.
* rust/compile/torture/bom_whitespace.rs: New.
* rust/compile/torture/bools_eq.rs: New.
* rust/compile/torture/borrow1.rs: New.
* rust/compile/torture/borrow_function.rs: New.
* rust/compile/torture/break_function.rs: New.
* rust/compile/torture/byte_char_str.rs: New.
* rust/compile/torture/byte_str.rs: New.
* rust/compile/torture/cast1.rs: New.
* rust/compile/torture/cast2.rs: New.
* rust/compile/torture/cast3.rs: New.
* rust/compile/torture/cfg_attr.rs: New.
* rust/compile/torture/char1.rs: New.
* rust/compile/torture/check-doc-attr-string.rs: New.
* rust/compile/torture/coercion1.rs: New.
* rust/compile/torture/coercion2.rs: New.
* rust/compile/torture/comparison_expr1.rs: New.
* rust/compile/torture/compile.exp: New.
* rust/compile/torture/compound_assignment_expr1.rs: New.
* rust/compile/torture/conditional.rs: New.
* rust/compile/torture/constant1.rs: New.
* rust/compile/torture/constant2.rs: New.
* rust/compile/torture/constant3.rs: New.
* rust/compile/torture/deadcode1.rs: New.
* rust/compile/torture/deadcode2.rs: New.
* rust/compile/torture/deref1.rs: New.
* rust/compile/torture/deref_function.rs: New.
* rust/compile/torture/doc_comment.rs: New.
* rust/compile/torture/enum1.rs: New.
* rust/compile/torture/extern_mod1.rs: New.
* rust/compile/torture/extern_mod2.rs: New.
* rust/compile/torture/float1.rs: New.
* rust/compile/torture/float_types.rs: New.
* rust/compile/torture/forward_decl_1.rs: New.
* rust/compile/torture/forward_decl_2.rs: New.
* rust/compile/torture/forward_decl_3-unsafe.rs: New.
* rust/compile/torture/forward_decl_3.rs: New.
* rust/compile/torture/forward_decl_4.rs: New.
* rust/compile/torture/forward_decl_5.rs: New.
* rust/compile/torture/func1.rs: New.
* rust/compile/torture/func2.rs: New.
* rust/compile/torture/function_reference1.rs: New.
* rust/compile/torture/function_reference2.rs: New.
* rust/compile/torture/function_reference3.rs: New.
* rust/compile/torture/function_reference4.rs: New.
* rust/compile/torture/generics1.rs: New.
* rust/compile/torture/generics10.rs: New.
* rust/compile/torture/generics11.rs: New.
* rust/compile/torture/generics12.rs: New.
* rust/compile/torture/generics13.rs: New.
* rust/compile/torture/generics14.rs: New.
* rust/compile/torture/generics15.rs: New.
* rust/compile/torture/generics16.rs: New.
* rust/compile/torture/generics17.rs: New.
* rust/compile/torture/generics18.rs: New.
* rust/compile/torture/generics19.rs: New.
* rust/compile/torture/generics2.rs: New.
* rust/compile/torture/generics20.rs: New.
* rust/compile/torture/generics21.rs: New.
* rust/compile/torture/generics22.rs: New.
* rust/compile/torture/generics23.rs: New.
* rust/compile/torture/generics24.rs: New.
* rust/compile/torture/generics25.rs: New.
* rust/compile/torture/generics26.rs: New.
* rust/compile/torture/generics27.rs: New.
* rust/compile/torture/generics28.rs: New.
* rust/compile/torture/generics29.rs: New.
* rust/compile/torture/generics3.rs: New.
* rust/compile/torture/generics30.rs: New.
* rust/compile/torture/generics31.rs: New.
* rust/compile/torture/generics32.rs: New.
* rust/compile/torture/generics4.rs: New.
* rust/compile/torture/generics5.rs: New.
* rust/compile/torture/generics6.rs: New.
* rust/compile/torture/generics7.rs: New.
* rust/compile/torture/generics8.rs: New.
* rust/compile/torture/generics9.rs: New.
* rust/compile/torture/grouped_expr_function.rs: New.
* rust/compile/torture/identifier-missing-impl-1.rs: New.
* rust/compile/torture/if.rs: New.
* rust/compile/torture/if_elif.rs: New.
* rust/compile/torture/if_elif_else_expr1.rs: New.
* rust/compile/torture/if_else.rs: New.
* rust/compile/torture/ifunaryexpr.rs: New.
* rust/compile/torture/impl_block1.rs: New.
* rust/compile/torture/impl_block2.rs: New.
* rust/compile/torture/impl_block3.rs: New.
* rust/compile/torture/impl_block_unused.rs: New.
* rust/compile/torture/implicit_returns1.rs: New.
* rust/compile/torture/infer_type1.rs: New.
* rust/compile/torture/inner_attributes.rs: New.
* rust/compile/torture/integer_inference_var1.rs: New.
* rust/compile/torture/integer_inference_var2.rs: New.
* rust/compile/torture/integer_inference_var3.rs: New.
* rust/compile/torture/integer_inference_var4.rs: New.
* rust/compile/torture/integer_inference_var5.rs: New.
* rust/compile/torture/integer_types.rs: New.
* rust/compile/torture/intrinsics-1.rs: New.
* rust/compile/torture/intrinsics-2.rs: New.
* rust/compile/torture/isolated_cr_block_comment.rs: New.
* rust/compile/torture/isolated_cr_line_comment.rs: New.
* rust/compile/torture/issue-1024.rs: New.
* rust/compile/torture/issue-1075.rs: New.
* rust/compile/torture/issue-1432.rs: New.
* rust/compile/torture/issue-1434.rs: New.
* rust/compile/torture/issue-368.rs: New.
* rust/compile/torture/issue-808.rs: New.
* rust/compile/torture/issue-862.rs: New.
* rust/compile/torture/issue-893-2.rs: New.
* rust/compile/torture/issue-893.rs: New.
* rust/compile/torture/lazybooleanexpr_function.rs: New.
* rust/compile/torture/lifetime1.rs: New.
* rust/compile/torture/literals1.rs: New.
* rust/compile/torture/loop1.rs: New.
* rust/compile/torture/loop2.rs: New.
* rust/compile/torture/loop3.rs: New.
* rust/compile/torture/loop4.rs: New.
* rust/compile/torture/loop5.rs: New.
* rust/compile/torture/loop6.rs: New.
* rust/compile/torture/loop7.rs: New.
* rust/compile/torture/macro-issue1403.rs: New.
* rust/compile/torture/macro-issue1426.rs: New.
* rust/compile/torture/macro_as_expr.rs: New.
* rust/compile/torture/match1.rs: New.
* rust/compile/torture/methods1.rs: New.
* rust/compile/torture/methods2.rs: New.
* rust/compile/torture/methods3.rs: New.
* rust/compile/torture/mod-nameresolve.rs: New.
* rust/compile/torture/mod1.rs: New.
* rust/compile/torture/mod2.rs: New.
* rust/compile/torture/mod3.rs: New.
* rust/compile/torture/modules/mod.rs: New.
* rust/compile/torture/modules/valid_path.rs: New.
* rust/compile/torture/must_use1.rs: New.
* rust/compile/torture/must_use2.rs: New.
* rust/compile/torture/name_resolve1.rs: New.
* rust/compile/torture/negation_function.rs: New.
* rust/compile/torture/nested_fn1.rs: New.
* rust/compile/torture/nested_fn2.rs: New.
* rust/compile/torture/nested_struct1.rs: New.
* rust/compile/torture/never_type1.rs: New.
* rust/compile/torture/not_shebang.rs: New.
* rust/compile/torture/not_shebang_block_comment.rs: New.
* rust/compile/torture/not_shebang_comment.rs: New.
* rust/compile/torture/not_shebang_multiline_comment.rs: New.
* rust/compile/torture/not_shebang_spaces.rs: New.
* rust/compile/torture/parameter_usage1.rs: New.
* rust/compile/torture/parens1.rs: New.
* rust/compile/torture/pointer1.rs: New.
* rust/compile/torture/primconsts.rs: New.
* rust/compile/torture/prims_struct_eq.rs: New.
* rust/compile/torture/range-lang-item1.rs: New.
* rust/compile/torture/raw_identifiers.rs: New.
* rust/compile/torture/raw_identifiers_keywords.rs: New.
* rust/compile/torture/recursive_fn1.rs: New.
* rust/compile/torture/return_function.rs: New.
* rust/compile/torture/scoping1.rs: New.
* rust/compile/torture/self_type1.rs: New.
* rust/compile/torture/shadow1.rs: New.
* rust/compile/torture/shadow2.rs: New.
* rust/compile/torture/shebang.rs: New.
* rust/compile/torture/shebang_plus_attr.rs: New.
* rust/compile/torture/shebang_plus_attr2.rs: New.
* rust/compile/torture/static_function.rs: New.
* rust/compile/torture/static_var1.rs: New.
* rust/compile/torture/stmt_with_block1.rs: New.
* rust/compile/torture/str1.rs: New.
* rust/compile/torture/struct_access1.rs: New.
* rust/compile/torture/struct_base_init_1.rs: New.
* rust/compile/torture/struct_decl.rs: New.
* rust/compile/torture/struct_init.rs: New.
* rust/compile/torture/struct_init_10.rs: New.
* rust/compile/torture/struct_init_11.rs: New.
* rust/compile/torture/struct_init_2.rs: New.
* rust/compile/torture/struct_init_3.rs: New.
* rust/compile/torture/struct_init_4.rs: New.
* rust/compile/torture/struct_init_5.rs: New.
* rust/compile/torture/struct_init_6.rs: New.
* rust/compile/torture/struct_init_7.rs: New.
* rust/compile/torture/struct_init_8.rs: New.
* rust/compile/torture/struct_init_9.rs: New.
* rust/compile/torture/top_attr.rs: New.
* rust/compile/torture/traits1.rs: New.
* rust/compile/torture/traits10.rs: New.
* rust/compile/torture/traits11.rs: New.
* rust/compile/torture/traits12.rs: New.
* rust/compile/torture/traits13.rs: New.
* rust/compile/torture/traits14.rs: New.
* rust/compile/torture/traits15.rs: New.
* rust/compile/torture/traits16.rs: New.
* rust/compile/torture/traits17.rs: New.
* rust/compile/torture/traits18.rs: New.
* rust/compile/torture/traits19.rs: New.
* rust/compile/torture/traits2.rs: New.
* rust/compile/torture/traits3.rs: New.
* rust/compile/torture/traits4.rs: New.
* rust/compile/torture/traits5.rs: New.
* rust/compile/torture/traits6.rs: New.
* rust/compile/torture/traits7.rs: New.
* rust/compile/torture/traits8.rs: New.
* rust/compile/torture/traits9.rs: New.
* rust/compile/torture/transmute-size-check-1.rs: New.
* rust/compile/torture/transmute1.rs: New.
* rust/compile/torture/tuple1.rs: New.
* rust/compile/torture/tuple2.rs: New.
* rust/compile/torture/tuple3.rs: New.
* rust/compile/torture/tuple_enum_variants.rs: New.
* rust/compile/torture/tuple_field_access.rs: New.
* rust/compile/torture/tuple_function.rs: New.
* rust/compile/torture/tuple_index.rs: New.
* rust/compile/torture/tuple_struct1.rs: New.
* rust/compile/torture/tuple_struct2.rs: New.
* rust/compile/torture/tuple_struct_unit.rs: New.
* rust/compile/torture/tuple_struct_unused.rs: New.
* rust/compile/torture/type-alias1.rs: New.
* rust/compile/torture/type-alias2.rs: New.
* rust/compile/torture/type_infer1.rs: New.
* rust/compile/torture/type_infer2.rs: New.
* rust/compile/torture/type_infer3.rs: New.
* rust/compile/torture/type_infer4.rs: New.
* rust/compile/torture/type_infer5.rs: New.
* rust/compile/torture/type_infer6.rs: New.
* rust/compile/torture/unary_operators.rs: New.
* rust/compile/torture/undended-string-1.rs: New.
* rust/compile/torture/undended-string-2.rs: New.
* rust/compile/torture/underscore_id.rs: New.
* rust/compile/torture/union.rs: New.
* rust/compile/torture/union_union.rs: New.
* rust/compile/torture/unit_type1.rs: New.
* rust/compile/torture/unit_type2.rs: New.
* rust/compile/torture/unit_type3.rs: New.
* rust/compile/torture/unit_type4.rs: New.
* rust/compile/torture/unit_type5.rs: New.
* rust/compile/torture/unsafe1.rs: New.
* rust/compile/torture/unsafe2.rs: New.
* rust/compile/torture/unsafe3.rs: New.
* rust/compile/torture/unsafe4.rs: New.
* rust/compile/torture/unused.rs: New.
* rust/compile/torture/unused1.rs: New.
* rust/compile/torture/unused_struct.rs: New.
* rust/compile/torture/unused_struct_field.rs: New.
* rust/compile/torture/usize1.rs: New.
* rust/compile/torture/very-broken-attr-string.rs: New.
* rust/compile/torture/while_function.rs: New.
* rust/compile/traits1.rs: New.
* rust/compile/traits10.rs: New.
* rust/compile/traits11.rs: New.
* rust/compile/traits12.rs: New.
* rust/compile/traits2.rs: New.
* rust/compile/traits3.rs: New.
* rust/compile/traits4.rs: New.
* rust/compile/traits5.rs: New.
* rust/compile/traits6.rs: New.
* rust/compile/traits7.rs: New.
* rust/compile/traits8.rs: New.
* rust/compile/traits9.rs: New.
* rust/compile/tuple1.rs: New.
* rust/compile/tuple_struct1.rs: New.
* rust/compile/tuple_struct2.rs: New.
* rust/compile/tuple_struct3.rs: New.
* rust/compile/type-alias1.rs: New.
* rust/compile/type-bindings1.rs: New.
* rust/compile/unary_negation.rs: New.
* rust/compile/unary_not.rs: New.
* rust/compile/unconstrained_type_param.rs: New.
* rust/compile/unicode_escape.rs: New.
* rust/compile/unsafe1.rs: New.
* rust/compile/unsafe10.rs: New.
* rust/compile/unsafe2.rs: New.
* rust/compile/unsafe3.rs: New.
* rust/compile/unsafe4.rs: New.
* rust/compile/unsafe5.rs: New.
* rust/compile/unsafe6.rs: New.
* rust/compile/unsafe7.rs: New.
* rust/compile/unsafe8.rs: New.
* rust/compile/unsafe9.rs: New.
* rust/compile/unterminated_c_comment.rs: New.
* rust/compile/use_1.rs: New.
* rust/compile/usize1.rs: New.
* rust/compile/xfail/lifetime_param.rs: New.
* rust/compile/xfail/struct_field_vis.rs: New.
* rust/compile/xfail/xfail.exp: New.
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Co-authored-by: Thomas Schwinge <thomas@codesourcery.com>
Co-authored-by: Mark Wielaard <mark@klomp.org>
Co-authored-by: Marc Poulhiès <dkm@kataplop.net>
Philip Herron [Tue, 23 Aug 2022 15:00:51 +0000 (16:00 +0100)]
gccrs: Add link cases testsuite
This testsuite is heavily inspired from the LTO testsuite that uses a
pattern where each file is compiled to an object file and finally linked
together. Since Rust does not have headers/prototypes, we rely on the
ordering here so that all files numbered greater than zero get compiled to
object files first. This leaves the _0 file free to test the 'extern crate' and
'use' keywords to force testing of the compiler to read metadata from the
other 'crates'.
gcc/testsuite/
* rust/link/generic_function_0.rs: New.
* rust/link/generic_function_1.rs: New.
* rust/link/link.exp: New.
* rust/link/simple_function_0.rs: New.
* rust/link/simple_function_1.rs: New.
* rust/link/trait_import_0.rs: New.
* rust/link/trait_import_1.rs: New.
Philip Herron [Tue, 23 Aug 2022 14:59:12 +0000 (15:59 +0100)]
gccrs: Add Debug info testsuite
This testsuite is specifically about testcases which scan the asm debug
info for results.
gcc/testsuite/
* rust/debug/chartype.rs: New.
* rust/debug/custom_link_section.rs: New.
* rust/debug/debug.exp: New.
* rust/debug/i8u8.rs: New.
* rust/debug/lang.rs: New.
* rust/debug/no_mangle.rs: New.
* rust/debug/oldlang.rs: New.
* rust/debug/tuple.rs: New.
* rust/debug/win64-abi.rs: New.
Co-authored-by: Tom Tromey <tom@tromey.com>
Co-authored-by: Mark Wielaard <mark@klomp.org>
Co-authored-by: Marc Poulhiès <dkm@kataplop.net>
Philip Herron [Tue, 23 Aug 2022 14:49:47 +0000 (15:49 +0100)]
gccrs: Add necessary hooks for a Rust front-end testsuite
This copies over code from other front-end testsuites to enable testing
for the rust front-end specifically.
gcc/testsuite/
* lib/rust-dg.exp: New.
* lib/rust.exp: New.
Co-authored-by: Marc Poulhiès <dkm@kataplop.net>
Co-authored-by: Thomas Schwinge <thomas@codesourcery.com>
Tom Tromey [Tue, 23 Aug 2022 14:47:13 +0000 (15:47 +0100)]
Use DW_ATE_UTF for the Rust 'char' type
The Rust 'char' type should use the DWARF DW_ATE_UTF encoding.
gcc/
* dwarf2out.cc (is_rust): New.
(base_type_die): Use DW_ATE_UTF for the Rust 'char' type.
(gen_compile_unit_die): Handle "GNU Rust".
Co-authored-by: Mark Wielaard <mark@klomp.org>
Co-authored-by: Marc Poulhiès <dkm@kataplop.net>
Richard Biener [Mon, 12 Dec 2022 16:52:46 +0000 (17:52 +0100)]
tree-optimization/108076 - if-conversion and forced labels
When doing if-conversion we simply throw away labels without checking
whether they are possibly targets of non-local gotos or have their
address taken. The following rectifies this and refuses to if-convert
such loops.
PR tree-optimization/108076
* tree-if-conv.cc (if_convertible_loop_p_1): Reject blocks
with non-local or forced labels that we later remove
labels from.
* gcc.dg/torture/pr108076.c: New testcase.
Jakub Jelinek [Tue, 13 Dec 2022 09:30:36 +0000 (10:30 +0100)]
libsanitizer: Fix up libbacktrace build after r13-4547 [PR108072]
The r13-4547 commit added new non-static function to libbacktrace:
backtrace_uncompress_zstd but for the libsanitizer use we need to
rename it, so that it is in __asan_* namespace and doesn't clash
with other copies of libbacktrace.
2022-12-13 Jakub Jelinek <jakub@redhat.com>
libsanitizer/
PR sanitizer/108072
* libbacktrace/backtrace-rename.h (backtrace_uncompress_zstd): Define.
Haochen Gui [Tue, 13 Dec 2022 08:45:10 +0000 (16:45 +0800)]
rs6000: enable cbranchcc4
This patch enables "have_cbranchcc4" on rs6000 by defining a
"cbranchcc4" expander. "have_cbrnachcc4" is a flag in ifcvt.cc to
indicate if branching by CC bits is valid or not. With this flag
enabled, some branches can be optimized to conditional moves.
2022-12-07 Haochen Gui <guihaoc@linux.ibm.com>
gcc/
* config/rs6000/rs6000.md (cbranchcc4): New expander.
gcc/testsuite
* gcc.target/powerpc/cbranchcc4-1.c: New.
* gcc.target/powerpc/cbranchcc4-2.c: New.
Haochen Gui [Thu, 8 Dec 2022 05:22:29 +0000 (13:22 +0800)]
optabs: make prepare_cmp_insn goto fail when cbranchcc4 checks unsatisfied
prepare_cmp_insn is a help function to generate comparison rtx.
It should not assume that cbranchcc4 exists and all sub-CC modes
are supported on a target. When the check fails, it could go to
fail and return a NULL rtx as its callers check the return value
for CCmode.
The test case (gcc.target/powerpc/cbranchcc4-1.c) which covers
failure path will be committed with an rs6000 specific patch.
2022-12-05 Haochen Gui <guihaoc@linux.ibm.com>
gcc/
* optabs.cc (prepare_cmp_insn): Return a NULL rtx other than
assertion failure when targets don't have cbranch optab or
predicate check fails.
GCC Administrator [Tue, 13 Dec 2022 00:18:07 +0000 (00:18 +0000)]
Daily bump.
Jason Merrill [Mon, 12 Dec 2022 22:41:39 +0000 (17:41 -0500)]
Revert "c++: build initializer_list<string> in a loop [PR105838]"
This patch broke a couple of different patterns; reverting while I work on a
fix.
PR c++/108701
This reverts commit
bd0485f20f4794f9787237706a6308473a8e9415.
Ian Lance Taylor [Mon, 12 Dec 2022 20:46:40 +0000 (12:46 -0800)]
libgo: bump major version
PR go/108057
The current version is the same as for the previous GCC release,
but there have been minor changes like new type descriptors that
make it impossible to run Go programs built with the previous GCC
release with the current libgo.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/456976
Harald Anlauf [Sun, 11 Dec 2022 22:24:03 +0000 (23:24 +0100)]
Fortran: improve checking of assumed-size array spec [PR102180]
gcc/fortran/ChangeLog:
PR fortran/102180
* array.cc (match_array_element_spec): Add check for bad
assumed-implied-spec.
(gfc_match_array_spec): Reorder logic so that the first bad array
element spec may trigger an error.
gcc/testsuite/ChangeLog:
PR fortran/102180
* gfortran.dg/pr102180.f90: New test.
Iain Buclaw [Sat, 10 Dec 2022 21:11:41 +0000 (22:11 +0100)]
d: Fix undefined reference to nested lambda in template (PR108055)
Sometimes, nested lambdas of templated functions get no code generation
due to them being marked as instantianted outside of all modules being
compiled in the current compilation unit. This despite enclosing
template instances being marked as instantiated inside the current
compilation unit. To fix, all enclosing templates are now checked in
`function_defined_in_root_p'.
Because of this change, `function_needs_inline_definition_p' has also
been fixed up to only check whether the regular function definition
itself is to be emitted in the current compilation unit.
PR d/108055
gcc/d/ChangeLog:
* decl.cc (function_defined_in_root_p): Check all enclosing template
instances for definition in a root module.
(function_needs_inline_definition_p): Replace call to
function_defined_in_root_p with test for outer module `isRoot'.
gcc/testsuite/ChangeLog:
* gdc.dg/torture/imports/pr108055conv.d: New.
* gdc.dg/torture/imports/pr108055spec.d: New.
* gdc.dg/torture/imports/pr108055write.d: New.
* gdc.dg/torture/pr108055.d: New test.
Wilco Dijkstra [Mon, 12 Dec 2022 15:44:03 +0000 (15:44 +0000)]
AArch64: Enable TARGET_CONST_ANCHOR
Enable TARGET_CONST_ANCHOR to allow complex constants to be created via
immediate add/sub. Use a 24-bit range as that enables a 3 or 4-instruction
immediate to be replaced by 2 add/sub instructions. Fix the costing of
add/sub to support 24-bit and 12-bit shifted immediates.
The generated code for the testcase is now the same or better than LLVM.
It also results in a small codesize reduction on SPEC.
gcc/
* config/aarch64/aarch64.cc (aarch64_rtx_costs): Add correct costs
for 24-bit and 12-bit shifted immediate add/sub.
(TARGET_CONST_ANCHOR): Define.
* config/aarch64/predicates.md (aarch64_pluslong_immediate):
Fix range check.
gcc/testsuite/
* gcc.target/aarch64/movk_3.c: New test.
Tamar Christina [Mon, 12 Dec 2022 15:21:39 +0000 (15:21 +0000)]
middle-end: simplify complex if expressions where comparisons are inverse of one another.
This optimizes the following sequence
((a < b) & c) | ((a >= b) & d)
into
(a < b ? c : d) & 1
for scalar and on vector we can omit the & 1.
Also recognizes
(-(a < b) & c) | (-(a >= b) & d)
into
a < b ? c : d
This changes the code generation from
zoo2:
cmp w0, w1
cset w0, lt
cset w1, ge
and w0, w0, w2
and w1, w1, w3
orr w0, w0, w1
ret
into
cmp w0, w1
csel w0, w2, w3, lt
and w0, w0, 1
ret
and significantly reduces the number of selects we have to do in the vector
code.
gcc/ChangeLog:
* match.pd: Add new rule.
gcc/testsuite/ChangeLog:
* gcc.target/aarch64/if-compare_1.c: New test.
* gcc.target/aarch64/if-compare_2.c: New test.
Tamar Christina [Mon, 12 Dec 2022 15:20:30 +0000 (15:20 +0000)]
AArch64: Fix vector re-interpretation between partial SIMD modes
While writing a patch series I started getting incorrect codegen out from
VEC_PERM on partial struct types.
It turns out that this was happening because the TARGET_CAN_CHANGE_MODE_CLASS
implementation has a slight bug in it. The hook only checked for SIMD to
Partial but never Partial to SIMD. This resulted in incorrect subregs to be
generated from the fallback code in VEC_PERM_EXPR expansions.
I have unfortunately not been able to trigger it using a standalone testcase as
the mid-end optimizes away the permute every time I try to describe a permute
that would result in the bug.
The patch now rejects any conversion of partial SIMD struct types, unless they
are both partial structures of the same number of registers or one is a SIMD
type who's size is less than 8 bytes.
gcc/ChangeLog:
* config/aarch64/aarch64.cc (aarch64_can_change_mode_class): Restrict
conversions between partial struct types properly.
Tamar Christina [Mon, 12 Dec 2022 15:18:56 +0000 (15:18 +0000)]
AArch64: Support new tbranch optab.
This implements the new tbranch optab for AArch64.
we cannot emit one big RTL for the final instruction immediately.
The reason that all comparisons in the AArch64 backend expand to separate CC
compares, and separate testing of the operands is for ifcvt.
The separate CC compare is needed so ifcvt can produce csel, cset etc from the
compares. Unlike say combine, ifcvt can not do recog on a parallel with a
clobber. Should we emit the instruction directly then ifcvt will not be able
to say, make a csel, because we have no patterns which handle zero_extract and
compare. (unlike combine ifcvt cannot transform the extract into an AND).
While you could provide various patterns for this (and I did try) you end up
with broken patterns because you can't add the clobber to the CC register. If
you do, ifcvt recog fails.
i.e.
int
f1 (int x)
{
if (x & 1)
return 1;
return x;
}
We lose csel here.
Secondly the reason the compare with an explicit CC mode is needed is so that
ifcvt can transform the operation into a version that doesn't require the flags
to be set. But it only does so if it know the explicit usage of the CC reg.
For instance
int
foo (int a, int b)
{
return ((a & (1 << 25)) ? 5 : 4);
}
Doesn't require a comparison, the optimal form is:
foo(int, int):
ubfx x0, x0, 25, 1
add w0, w0, 4
ret
and no compare is actually needed. If you represent the instruction using an
ANDS instead of a zero_extract then you get close, but you end up with an ands
followed by an add, which is a slower operation.
gcc/ChangeLog:
* config/aarch64/aarch64.md (*tb<optab><mode>1): Rename to...
(*tb<optab><ALLI:mode><GPI:mode>1): ... this.
(tbranch_<code><mode>4): New.
* config/aarch64/iterators.md(ZEROM, zerom): New.
gcc/testsuite/ChangeLog:
* gcc.target/aarch64/tbz_1.c: New test.
Tamar Christina [Mon, 12 Dec 2022 15:16:50 +0000 (15:16 +0000)]
middle-end: Add new tbranch optab to add support for bit-test-and-branch operations
This adds a new test-and-branch optab that can be used to do a conditional test
of a bit and branch. This is similar to the cbranch optab but instead can
test any arbitrary bit inside the register.
This patch recognizes boolean comparisons and single bit mask tests.
gcc/ChangeLog:
* dojump.cc (do_jump): Pass along value.
(do_jump_by_parts_greater_rtx): Likewise.
(do_jump_by_parts_zero_rtx): Likewise.
(do_jump_by_parts_equality_rtx): Likewise.
(do_compare_rtx_and_jump): Likewise.
(do_compare_and_jump): Likewise.
* dojump.h (do_compare_rtx_and_jump): New.
* optabs.cc (emit_cmp_and_jump_insn_1): Refactor to take optab to check.
(validate_test_and_branch): New.
(emit_cmp_and_jump_insns): Optiobally take a value, and when value is
supplied then check if it's suitable for tbranch.
* optabs.def (tbranch_eq$a4, tbranch_ne$a4): New.
* doc/md.texi (tbranch_@var{op}@var{mode}4): Document it.
* optabs.h (emit_cmp_and_jump_insns): New.
* tree.h (tree_zero_one_valued_p): New.
Tamar Christina [Mon, 12 Dec 2022 15:15:07 +0000 (15:15 +0000)]
aarch64: Make existing V2HF be usable.
The backend has an existing V2HFmode that is used by pairwise operations.
This mode was however never made fully functional. Amongst other things it was
never declared as a vector type which made it unusable from the mid-end.
It's also lacking an implementation for load/stores so reload ICEs if this mode
is every used. This finishes the implementation by providing the above.
Note that I have created a new iterator VHSDF_P instead of extending VHSDF
because the previous iterator is used in far more things than just load/stores.
It's also used for instance in intrinsics and extending this would force me to
provide support for mangling the type while we never expose it through
intrinsics.
gcc/ChangeLog:
* config/aarch64/aarch64-simd.md (*aarch64_simd_movv2hf): New.
(mov<mode>, movmisalign<mode>, aarch64_dup_lane<mode>,
aarch64_store_lane0<mode>, aarch64_simd_vec_set<mode>,
@aarch64_simd_vec_copy_lane<mode>, vec_set<mode>,
reduc_<optab>_scal_<mode>, reduc_<fmaxmin>_scal_<mode>,
aarch64_reduc_<optab>_internal<mode>, aarch64_get_lane<mode>,
vec_init<mode><Vel>, vec_extract<mode><Vel>): Support V2HF.
(aarch64_simd_dupv2hf): New.
* config/aarch64/aarch64.cc (aarch64_classify_vector_mode):
Add E_V2HFmode.
* config/aarch64/iterators.md (VHSDF_P): New.
(V2F, VMOVE, nunits, Vtype, Vmtype, Vetype, stype, VEL,
Vel, q, vp): Add V2HF.
* config/arm/types.md (neon_fp_reduc_add_h): New.
gcc/testsuite/ChangeLog:
* gcc.target/aarch64/sve/slp_1.c: Update testcase.
Jonathan Wakely [Mon, 12 Dec 2022 12:51:49 +0000 (12:51 +0000)]
libstdc++: Add a test checking for chrono::duration overflows
This test fails if chrono::days::rep or chrono::years::rep is a 32-bit
type, because a large days or years value silently overflows a 32-bit
integer when converted to seconds. It would be conforming to implement
chrono::days as chrono::duration<int32_t, ratio<86400>>, but would make
this overflow case more likely. Similarly for chrono::years,
chrono::months and chrono::weeks. This test is here to remind us not to
make that change lightly.
libstdc++-v3/ChangeLog:
* testsuite/20_util/duration/arithmetic/overflow_c++20.cc: New
test.
Jonathan Wakely [Mon, 12 Dec 2022 11:40:07 +0000 (11:40 +0000)]
libstdc++: Fix constraint on std::basic_format_string [PR108024]
Also remove some redundant std::move calls for return statements.
libstdc++-v3/ChangeLog:
PR libstdc++/108024
* include/std/format (basic_format_string): Fix constraint.
* testsuite/std/format/format_string.cc: New test.
Jonathan Wakely [Mon, 12 Dec 2022 11:22:45 +0000 (11:22 +0000)]
libstdc++: Change names that clash with Win32 or Clang
Clang now defines an __is_unsigned built-in, and Windows defines an
_Out_ macro. Replace uses of those as identifiers.
There might also be a problem with __is_signed, which we use in several
places.
libstdc++-v3/ChangeLog:
* include/std/chrono (hh_mm_ss): Rename __is_unsigned member to
_S_is_unsigned.
* include/std/format (basic_format_context): Rename _Out_
template parameter to _Out2.
* testsuite/17_intro/names.cc: Add Windows SAL annotation
macros.
Jonathan Wakely [Mon, 12 Dec 2022 12:49:40 +0000 (12:49 +0000)]
libstdc++: Define atomic lock-free type aliases for C++20 [PR98034]
libstdc++-v3/ChangeLog:
PR libstdc++/98034
* include/std/atomic (__cpp_lib_atomic_lock_free_type_aliases):
Define macro.
(atomic_signed_lock_free, atomic_unsigned_lock_free): Define
aliases.
* include/std/version (__cpp_lib_atomic_lock_free_type_aliases):
Define macro.
* testsuite/29_atomics/atomic/lock_free_aliases.cc: New test.
Jonathan Wakely [Fri, 9 Dec 2022 14:59:01 +0000 (14:59 +0000)]
libstdc++: Make operator<< for stacktraces less templated (LWG 3515)
This change was approved for C++23 last month.
libstdc++-v3/ChangeLog:
* include/std/stacktrace (operator<<): Only output to narrow
ostreams (LWG 3515).
* testsuite/19_diagnostics/stacktrace/synopsis.cc:
Martin Liska [Mon, 12 Dec 2022 12:24:25 +0000 (13:24 +0100)]
mklog: do not parse binary file for PR entry
contrib/ChangeLog:
* mklog.py: Do not search PR entry in a file that is binary.
Kyrylo Tkachov [Mon, 12 Dec 2022 11:07:45 +0000 (11:07 +0000)]
aarch64: Add __ARM_FEATURE_PAUTH and __ARM_FEATURE_BTI ACLE defines
Recent ACLE additions specified the __ARM_FEATURE_PAUTH and __ARM_FEATURE_BTI macros [1] that the compiler
should define when the pointer authentication and BTI instructions are available (and don't act as NOPs).
We've received requests to enable them in GCC for aarch64, similar to clang [2].
It's a fairly simple patch and should be non-intrusive at this stage.
Pointer authentication has its own "pauth" feature flag, whereas BTI depends on an architecture level
of Armv8.5-a or later.
Bootstrapped and tested on aarch64-none-linux-gnu.
[1] https://github.com/ARM-software/acle/blob/main/main/acle.md#pointer-authentication
[2] https://reviews.llvm.org/rG7d40baa82b1f272f68de63f3c4f68d970bdcd6ed
gcc/ChangeLog:
* config/aarch64/aarch64-c.cc (aarch64_update_cpp_builtins): Define
__ARM_FEATURE_PAUTH and __ARM_FEATURE_BTI when appropriate.
* config/aarch64/aarch64.h (TARGET_BTI): Define.
gcc/testsuite/ChangeLog:
* gcc.target/aarch64/acle/bti_def.c: New test.
* gcc.target/aarch64/acle/pauth_def.c: New test.
Richard Biener [Mon, 12 Dec 2022 07:56:41 +0000 (08:56 +0100)]
Revert parts of ADDR_EXPR/CONSTRUCTOR treatment change in match.pd
This reverts the part that substitutes from the definition of an
SSA name to the capture, thus ADDR_EXPR@0 eventually yielding
&y_1->a[i_2] instead of _3. That's because I didn't think of
how to deal with substituting @0 in the result pattern. So
the following re-instantiates the SSA def CONSTRUCTOR handling
and in the ADDR_EXPR helpers used by match.pd handles SSA names
defined to ADDR_EXPRs transparently.
* genmatch.cc (dt_simplify::gen): Revert last change.
* match.pd: Revert simplification of CONSTUCTOR leaf handling.
(&x cmp SSA_NAME): Handle ADDR_EXPR in SSA defs.
* fold-const.cc (split_address_to_core_and_offset): Handle
ADDR_EXPRs in SSA defs.
(address_compare): Likewise.
Richard Biener [Mon, 12 Dec 2022 07:13:33 +0000 (08:13 +0100)]
tree-optimization/89317 - another pattern for &p->x != p + 4
As seen in the original testcase for PR89317 we are missing
comparison simplification patterns for &p->x != p + 4. Fixed
by making an existing one apply. To make the pattern apply
during CCP we need to simplify ccp_fold to not use GENERIC
folding of conditions but also use GIMPLE folding.
PR tree-optimization/89317
* tree-ssa-ccp.cc (ccp_fold): Handle GIMPLE_COND via
gimple_fold_stmt_to_constant_1.
* match.pd (&a != &a + c): Apply to pointer_plus with non-ADDR_EXPR
base as well.
* gcc.dg/tree-ssa/pr89317.c: Amend.
GCC Administrator [Mon, 12 Dec 2022 00:22:21 +0000 (00:22 +0000)]
Daily bump.
Steve Kargl [Sat, 10 Dec 2022 21:17:15 +0000 (22:17 +0100)]
Fortran: fix ICE on bad use of statement function [PR107995]
gcc/fortran/ChangeLog:
PR fortran/107995
* interface.cc (gfc_check_dummy_characteristics): Reject statement
function dummy arguments.
gcc/testsuite/ChangeLog:
PR fortran/107995
* gfortran.dg/pr107995.f90: New test.
Iain Buclaw [Sat, 10 Dec 2022 18:12:43 +0000 (19:12 +0100)]
d: Fix internal compiler error: in visit, at d/imports.cc:72 (PR108050)
The visitor for lowering IMPORTED_DECLs did not have an override for
dealing with importing OverloadSet symbols. This has now been
implemented in the code generator.
PR d/108050
gcc/d/ChangeLog:
* decl.cc (DeclVisitor::visit (Import *)): Handle build_import_decl
returning a TREE_LIST.
* imports.cc (ImportVisitor::visit (OverloadSet *)): New override.
gcc/testsuite/ChangeLog:
* gdc.dg/imports/pr108050/mod1.d: New.
* gdc.dg/imports/pr108050/mod2.d: New.
* gdc.dg/imports/pr108050/package.d: New.
* gdc.dg/pr108050.d: New test.
Martin Liska [Sun, 11 Dec 2022 16:18:12 +0000 (17:18 +0100)]
unidiff: use newline='\n' argument
In order to support CR on a line, we need to open files
with newline='\n' as our line endings supposed to be of UNIX style.
contrib/ChangeLog:
* check_GNU_style.py: Use newline=\n.
* check_GNU_style_lib.py: Simplify.
* gcc-changelog/git_commit.py: Fix issues seen
Rust patchset.
* gcc-changelog/git_email.py: Use newline argument.
* gcc-changelog/test_email.py: New test.
* gcc-changelog/test_patches.txt: New test.
* mklog.py: Use newline argument.
Iain Buclaw [Fri, 9 Dec 2022 17:59:38 +0000 (18:59 +0100)]
d: Merge upstream dmd, druntime
c8ae4adb2e, phobos
792c8b7c1.
D front-end changes:
- Import dmd v2.101.0.
- Deprecate the ability to call `__traits(getAttributes)' on
overload sets.
- Deprecate non-empty `for' statement increment clause with no
effect.
- Array literals assigned to `scope' array variables can now be
allocated on the stack.
D runtime changes:
- Import druntime v2.101.0.
Phobos changes:
- Import phobos v2.101.0.
gcc/d/ChangeLog:
* dmd/MERGE: Merge upstream dmd
c8ae4adb2e.
* typeinfo.cc (check_typeinfo_type): Update for new front-end
interface.
(TypeInfoVisitor::visit (TypeInfoStructDeclaration *)): Remove warning
that toHash() must be declared 'nothrow @safe`.
libphobos/ChangeLog:
* libdruntime/MERGE: Merge upstream druntime
c8ae4adb2e.
* src/MERGE: Merge upstream phobos
792c8b7c1.
Iain Buclaw [Sat, 10 Dec 2022 16:17:35 +0000 (17:17 +0100)]
d: Expand bsr intrinsic as `clz(arg) ^ (argsize - 1)'
As well as removing unnecessary casts, this results in less temporaries
being generated during the initial gimple lowering pass. Otherwise the
code generated is identical to the former intrinsic expansion.
gcc/d/ChangeLog:
* intrinsics.cc (expand_intrinsic_bsf): Fix comment.
(expand_intrinsic_bsr): Use BIT_XOR_EXPR instead of MINUS_EXPR.
Richard Biener [Sun, 11 Dec 2022 13:07:34 +0000 (14:07 +0100)]
tree-optimization/89317 - missed folding of (p + 4) - &p->d
The PR notices we fail to simplify
a_4 = &x_3(D)->data;
b_5 = x_3(D) + 16;
_1 = b_5 - a_4;
together with the enabler handling ADDR_EXPR leafs in separate
stmts in match.pd the suggested patterns work.
PR tree-optimization/89317
* match.pd ((p + b) - &p->c -> b - offsetof(c)): New patterns.
* gcc.dg/tree-ssa/pr89317.c: New testcase.
Richard Biener [Sun, 11 Dec 2022 11:32:49 +0000 (12:32 +0100)]
Treat ADDR_EXPR and CONSTRUCTOR as GIMPLE/GENERIC magically
The following allows to match ADDR_EXPR for both the invariant
&a.b case as well as the &p->d case in a separate definition
transparently. This also allows to remove the hack we employ
for CONSTRUCTOR which we handle for example with
(match vec_same_elem_p
CONSTRUCTOR@0
(if (TREE_CODE (@0) == SSA_NAME
&& uniform_vector_p (gimple_assign_rhs1 (SSA_NAME_DEF_STMT (@0))))))
Note CONSTUCTORs always appear as separate definition in GIMPLE,
but I continue to play safe and ADDR_EXPRs are now matched in
both places where previously ADDR_EXPR@0 would have missed
the &p->x case.
This is a prerequesite for the PR89317 fix.
* genmatch.cc (dt_node::gen_kids): Handle ADDR_EXPR in both
the GENERIC and GIMPLE op position.
(dt_simplify::gen): Capture both GENERIC and GIMPLE op
position for ADDR_EXPR and CONSTRUCTOR.
* match.pd: Simplify CONSTRUCTOR leaf handling.
* gcc.dg/tree-ssa/forwprop-3.c: Adjust.
* g++.dg/tree-ssa/pr31146-2.C: Likewise.
Richard Biener [Wed, 7 Dec 2022 13:42:24 +0000 (14:42 +0100)]
tree-optimization/106904 - bogus -Wstringopt-overflow with vectors
The following avoids CSE of &ps->wp to &ps->wp.hwnd confusing
-Wstringopt-overflow by making sure to produce addresses to the
biggest container from vectorization. For this I introduce
strip_zero_offset_components which turns &ps->wp.hwnd into
&(*ps) and use that to base the vector data references on.
That will also work for addresses with variable components,
alternatively emitting pointer arithmetic via calling
get_inner_reference and gimplifying that would be possible
but likely more intrusive.
This is by no means a complete fix for all of those issues
(avoiding ADDR_EXPRs in favor of pointer arithmetic might be).
Other passes will have similar issues.
In theory that might now cause false negatives.
PR tree-optimization/106904
* tree.h (strip_zero_offset_components): Declare.
* tree.cc (strip_zero_offset_components): Define.
* tree-vect-data-refs.cc (vect_create_addr_base_for_vector_ref):
Strip zero offset components before building the address.
* gcc.dg/Wstringop-overflow-pr106904.c: New testcase.
Tobias Burnus [Sun, 11 Dec 2022 10:47:55 +0000 (11:47 +0100)]
fortran/openmp.cc: Remove 's' that slipped in during %<..%> replacement
Seemingly, 's' (in VI that's the 's'ubstitute command) appeared verbatim in
a gfc_error message when to doing the '...' to %<...%> replacements in commit
r13-4590-g84f6f8a2a97f88be01e223c9c9dbab801a4f501f
gcc/fortran/
* openmp.cc (gfc_match_omp_context_selector_specification):
Remove spurious 's' in an error message.
GCC Administrator [Sun, 11 Dec 2022 00:17:43 +0000 (00:17 +0000)]
Daily bump.
Harald Anlauf [Sat, 10 Dec 2022 21:05:15 +0000 (22:05 +0100)]
Fortran: reject bad SIZE argument while simplifying ISHFTC [PR106911]
gcc/fortran/ChangeLog:
PR fortran/106911
* simplify.cc (gfc_simplify_ishftc): If the SIZE argument is known
to be outside the allowed range, terminate simplification.
gcc/testsuite/ChangeLog:
PR fortran/106911
* gfortran.dg/pr106911.f90: New test.
Jakub Jelinek [Sat, 10 Dec 2022 15:50:39 +0000 (16:50 +0100)]
ivopts: Fix IP_END handling for asm goto [PR107997]
The following testcase ICEs, because the latch bb ends with
asm goto which has both fallthrough to the header and one or more labels
in the header too. In that case there is just a single edge out of the
latch block, but still the asm goto is stmt_ends_bb_p statement, yet
ivopts decides to emit an IV bump at the IP_END position and inserts
it into the same bb as the asm goto after it, which then fails verification
(control flow in the middle of bb).
The following patch fixes it by splitting the latch -> header edge in that
case and inserting into the newly created bb, where split_edge ->
redirect_edge_and_branch is able to deal with this case correctly.
2022-12-10 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/107997
* tree-ssa-loop-ivopts.cc: Include cfganal.h.
(create_new_iv) <case IP_END>: If ip_end_pos bb is non-empty and ends
with a stmt which ends bb, instead of adding iv update after it split
the latch edge and insert iterator into the new latch bb.
* gcc.c-torture/compile/pr107997.c: New test.
Tobias Burnus [Sat, 10 Dec 2022 12:42:08 +0000 (13:42 +0100)]
libgomp: Handle OpenMP's reverse offloads
This commit enabled reverse offload for nvptx such that gomp_target_rev
actually gets called. And it fills the latter function to do all of
the following: finding the host function to the device func ptr and
copying the arguments to the host, processing the mapping/firstprivate,
calling the host function, copying back the data and freeing as needed.
The data handling is made easier by assuming that all host variables
either existed before (and are in the mapping) or that those are
devices variables not yet available on the host. Thus, the reverse
mapping can do without refcounts etc. Note that the spec disallows
inside a target region device-affecting constructs other than target
plus ancestor device-modifier and it also limits the clauses permitted
on this construct.
For the function addresses, an additional splay tree is used; for
the lookup of mapped variables, the existing splay-tree is used.
Unfortunately, its data structure requires a full walk of the tree;
Additionally, the just mapped variables are recorded in a separate
data structure an extra lookup. While the lookup is slow, assuming
that only few variables get mapped in each reverse offload construct
and that reverse offload is the exception and not performance critical,
this seems to be acceptable.
libgomp/ChangeLog:
* libgomp.h (struct target_mem_desc): Predeclare; move
below after 'reverse_splay_tree_node' and add rev_array
member.
(struct reverse_splay_tree_key_s, reverse_splay_compare): New.
(reverse_splay_tree_node, reverse_splay_tree,
reverse_splay_tree_key): New typedef.
(struct gomp_device_descr): Add mem_map_rev member.
* oacc-host.c (host_dispatch): NULL init .mem_map_rev.
* plugin/plugin-nvptx.c (GOMP_OFFLOAD_get_num_devices): Claim
support for GOMP_REQUIRES_REVERSE_OFFLOAD.
* splay-tree.h (splay_tree_callback_stop): New typedef; like
splay_tree_callback but returning int not void.
(splay_tree_foreach_lazy): Define; like splay_tree_foreach but
taking splay_tree_callback_stop as argument.
* splay-tree.c (splay_tree_foreach_internal_lazy,
splay_tree_foreach_lazy): New; but early exit if callback returns
nonzero.
* target.c: Instatiate splay_tree_c with splay_tree_prefix 'reverse'.
(gomp_map_lookup_rev): New.
(gomp_load_image_to_device): Handle reverse-offload function
lookup table.
(gomp_unload_image_from_device): Free devicep->mem_map_rev.
(struct gomp_splay_tree_rev_lookup_data, gomp_splay_tree_rev_lookup,
gomp_map_rev_lookup, struct cpy_data, gomp_map_cdata_lookup_int,
gomp_map_cdata_lookup): New auxiliary structs and functions for
gomp_target_rev.
(gomp_target_rev): Implement reverse offloading and its mapping.
(gomp_target_init): Init current_device.mem_map_rev.root.
* testsuite/libgomp.fortran/reverse-offload-2.f90: New test.
* testsuite/libgomp.fortran/reverse-offload-3.f90: New test.
* testsuite/libgomp.fortran/reverse-offload-4.f90: New test.
* testsuite/libgomp.fortran/reverse-offload-5.f90: New test.
* testsuite/libgomp.fortran/reverse-offload-5a.f90: New test without
mapping of on-device allocated variables.
Gaius Mulley [Sat, 10 Dec 2022 09:10:29 +0000 (09:10 +0000)]
Add initial ChangeLogs for modula2.
Add initial ChangeLog file in libgm2 and gcc/m2.
ChangeLog:
* libgm2: (New directory).
* libgm2/ChangeLog: (New file).
gcc/ChangeLog:
* m2: (New directory).
* m2/ChangeLog: (New file).
Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
Thomas Schwinge [Sat, 10 Dec 2022 07:33:22 +0000 (08:33 +0100)]
Add stub 'gcc/rust/ChangeLog'