summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2022-12-15PR-108123 Rebuilt gcc/m2/gm2config.h.indevel/modula-2Gaius Mulley
Rebuilt the file gcc/m2/gm2config.h.in using autoheader-2.69. gcc/m2/ChangeLog: * gm2config.h.in: Rebuilt. Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
2022-12-14Add modula-2 into doc/install.texi and doc/sourcebuild.texi.Gaius Mulley
Add modula-2 into doc/install.texi and doc/sourcebuild.texi. gcc/ChangeLog: * doc/install.texi: Add m2 as a language. (--disable-libgm2) Documented. Add make check-m2 to testing selected tests. * doc/sourcebuild.texi (GM2): New prerequisite item. (Python3 modules) New item. (libgm2) Added. (gcc/m2) Added. Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
2022-12-14Merge branch 'master' into devel/modula-2.Gaius Mulley
2022-12-14Move hand built ChangeLogs out of the way premerge.Gaius Mulley
Move hand built ChangeLogs out of the way premerge. libgm2/ChangeLog: * ChangeLog-2022: (New file). gcc/m2/ChangeLog: * ChangeLog-2022: (New file). Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
2022-12-14Add list of potential target datatype comments to SYSTEM.defGaius Mulley
Add list of potential target datatype comments to all SYSTEM.def files to improve usefulness of target independent documentation. gcc/m2/ChangeLog: * gm2-libs-coroutines/SYSTEM.def: Added list of data types. * gm2-libs-iso/SYSTEM.def: Added list of data types. * gm2-libs/SYSTEM.def: Added list of data types. * target-independent/SYSTEM-iso.texi: Rebuilt. * target-independent/SYSTEM-pim.texi: Rebuilt. * target-independent/gm2-libs.texi: Rebuilt. Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
2022-12-14rust: Fix up aarch64-linux bootstrap [PR106072]Jakub Jelinek
Bootstrap fails on aarch64-linux and some other arches with: .../gcc/rust/parse/rust-parse-impl.h: In member function ‘Rust::AST::ClosureParam Rust::Parser<ManagedTokenSource>::parse_closure_param() [with ManagedTokenSource = Rust::Lexer]’: .../gcc/rust/parse/rust-parse-impl.h:8916:49: error: ‘this’ pointer is null [-Werror=nonnull] The problem is that while say on x86_64-linux the side-effects in the arguments are evaluated from last argument to first, on aarch64-linux it is the other way around, from first to last. The C++ I believe even in C++17 makes the evaluation of those side-effects unordered (indeterminately sequenced with no interleaving), so that is fine. But, when the call in return statement is evaluated from first to last, std::move (pattern) happens before pattern->get_locus () and the former will make pattern (std::unique_ptr) a wrapper object around nullptr, so dereferencing it later to call get_locus () on it is invalid. 2022-12-14 Jakub Jelinek <jakub@redhat.com> PR rust/106072 * parse/rust-parse-impl.h (parse_closure_param): Store pattern->get_locus () in a temporary before std::move (pattern) is invoked.
2022-12-14mklog: do not depend on recent unidiff versionMartin Liska
contrib/ChangeLog: * mklog.py: Check for number of hunks and not if a modified file is binary.
2022-12-14docs: document --param=ipa-sra-ptrwrap-growth-factorMartin Liska
gcc/ChangeLog: * doc/invoke.texi: Document ipa-sra-ptrwrap-growth-factor.
2022-12-14tree-optimization/107617 - big-endian .LEN_STORE VNRichard Biener
The following fixes a mistake in interpreting .LEN_STORE definitions during value-numbering when in big-endian mode. We cannot offset the encoding of the RHS but instead encode to an offsetted position which is then treated correctly by the endian aware copying code. PR tree-optimization/107617 * tree-ssa-sccvn.cc (vn_walk_cb_data::push_partial_def): Handle negative pd.rhs_off. (vn_reference_lookup_3): Properly provide pd.rhs_off for .LEN_STORE on big-endian targets.
2022-12-14Tidyup fixes relating to python3 detection and documentation generation.Gaius Mulley
Fixes a typo and improves the warning configure.ac message if python3 is not found. Remove gcc/m2/target-independent/*rst files for now. Provide demangler function for system data types comment. gcc/ChangeLog: * configure.ac (ACX_CHECK_PROG_VER): Improve warning message. * doc/install.texi (GM2): Update description about documentation created if no python3 is detected. gcc/m2/ChangeLog: * Make-maintainer.in (m2-target-independent-doc-rst): Disabled. * gm2-libs/SYSTEM.def: Corrected typo. * target-independent/SYSTEM-pim.texi: (Rebuilt). * target-independent/gm2-libs.texi: (Rebuilt). * tools-src/def2doc.py (demangle_system_datatype): New function. (emit_texinfo_content) Call demangle_system_datatype. (emit_sphinx_content) Call demangle_system_datatype. * target-independent/Builtins.rst: (Removed). * target-independent/SYSTEM-iso.rst: (Removed). * target-independent/SYSTEM-pim.rst: (Removed). * target-independent/gm2-libs.rst: (Removed). Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
2022-12-13libgccjit: Allow comparing vector typesAntoni Boucher
gcc/jit/ChangeLog: PR jit/108078 * jit-recording.h: Add vector_type::is_same_type_as method gcc/testsuite/ChangeLog: PR jit/108078 * jit.dg/test-vector-types.cc: Add tests for vector type comparison Co-authored-by: Guillaume Gomez <guillaume1.gomez@gmail.com> Signed-off-by: Guillaume Gomez <guillaume1.gomez@gmail.com>
2022-12-14Daily bump.GCC Administrator
2022-12-14ipa: Avoid looking for IPA-SRA replacements where there are noneMartin Jambor
While modifying the code, I realized that we do look into statements even when there are no replacements. This patch adds the necessary early bail-outs to avoid that. ipa_param_body_adjustments::modify_call_stmt cannot have the same at the very beginning because calls can still contain otherwise removed parameters that need to be removed from the statements too. gcc/ChangeLog: 2022-11-11 Martin Jambor <mjambor@suse.cz> * ipa-param-manipulation.cc (ipa_param_body_adjustments::modify_expression): Bail out early if there are no replacements. (ipa_param_body_adjustments::modify_assignment): Likewise.
2022-12-14ipa-sra: Forward propagation of sizes which are safe to dereferenceMartin Jambor
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.
2022-12-14ipa-sra: Be optimistic about Fortran descriptorsMartin Jambor
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.
2022-12-14ipa-sra: Move caller->callee propagation before callee->caller oneMartin Jambor
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
2022-12-14ipa-sra: Treat REFERENCE_TYPES as always dereferencableMartin Jambor
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
2022-12-14ipa-cp: Leave removal of unused parameters to IPA-SRAMartin Jambor
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.
2022-12-14ipa: Better way of applying both IPA-CP and IPA-SRA (PR 103227)Martin Jambor
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.
2022-12-14ipa-cp: Write transformation summaries of all functionsMartin Jambor
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.
2022-12-13Introduce target independent copies of document chapters.Gaius Mulley
This patch introduces target independent copies of document chapters which will be used if HAVE_PYTHON is no, thus providing a fall back for documentation production. gcc/m2/ChangeLog: * doc/gm2.texi: Tidy up mailing testsuite results (formatting). * Make-lang.in (gm2-libs-texi-check): Copy target-dependent copy if HAVE_PYTHON is no. (gm2-libs-rst-check) Copy target-dependent copy if HAVE_PYTHON is no. (SYSTEM-pim-texi-check) Copy target-dependent copy if HAVE_PYTHON is no. (SYSTEM-pim-rst-check) Copy target-dependent copy if HAVE_PYTHON is no. (SYSTEM-iso-texi-check) Copy target-dependent copy if HAVE_PYTHON is no. (SYSTEM-iso-rst-check) Copy target-dependent copy if HAVE_PYTHON is no. (Builtins.texi-check) Copy target-dependent copy if HAVE_PYTHON is no. (Builtins.rst-check) Copy target-dependent copy if HAVE_PYTHON is no. * Make-maintainer.in (m2-target-independent-doc): New rule. (m2-target-independent-doc-texi) New rule. (m2-target-independent-doc-rst) New rule. * gm2-libs-coroutines/SYSTEM.def: Tidied up comments. * gm2-libs-iso/README.texi: Corrected dates. * gm2-libs-iso/SYSTEM.def: Tidied up comments. * gm2-libs/README.texi: Corrected dates. * tools-src/def2doc.py (emit_texinfo_content): Do not change state in texinfo files. Replace @SYSTEM_DATATYPES@ with 'Target specific data types.'. Replace @SYSTEM_TYPES@ with '(* Target specific data types. *)' * target-independent/Builtins.rst: New file. * target-independent/Builtins.texi: New file. * target-independent/gm2-libs.rst: New file. * target-independent/gm2-libs.texi: New file. * target-independent/readme.txt: New file. * target-independent/SYSTEM-iso.rst: New file. * target-independent/SYSTEM-iso.texi: New file. * target-independent/SYSTEM-pim.rst: New file. * target-independent/SYSTEM-pim.texi: New file. Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
2022-12-13i386: Fix up *concat*_{5,6,7} patterns [PR108044]Jakub Jelinek
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.
2022-12-13libstdc++: Update backtrace-rename.hJakub Jelinek
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.
2022-12-13Fortran: NULL pointer dereference while parsing a function [PR107423]Steve Kargl
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.
2022-12-13AArch64: Fix ILP32 tbranchTamar Christina
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.
2022-12-13vect-patterns: Fix up vect_recog_rotate_pattern [PR108064]Jakub Jelinek
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.
2022-12-13tree-optimization/105801 - CCP and .DEFERRED_INITRichard Biener
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.
2022-12-13gccrs: Add README, CONTRIBUTING and compiler logoPhilip Herron
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.
2022-12-13gccrs: Add config-lang.inPhilip Herron
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.
2022-12-13gccrs: Add fatal_error when experimental flag is not presentArthur Cohen
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'.
2022-12-13gccrs: Add GCC Rust front-end Make-lang.inPhilip Herron
This is the Makefile for our front-end. gcc/rust/ * Make-lang.in: New.
2022-12-13gccrs: Add lang.optPhilip Herron
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.
2022-12-13gccrs: Add lang-spec.hPhilip Herron
This specifies the extensions of the Rust language. gcc/rust/ * lang-specs.h: New.
2022-12-13gccrs: Compiler proper interface kicks off the pipelinePhilip Herron
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.
2022-12-13gccrs: Add compiler driverPhilip Herron
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.
2022-12-13gccrs: These are wrappers ported from reusing gccgoPhilip Herron
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.
2022-12-13gccrs: Add HIR to GCC GENERIC lowering entry pointPhilip Herron
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>
2022-12-13gccrs: Add HIR to GCC GENERIC lowering for all nodesPhilip Herron
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>
2022-12-13gccrs: Add base for HIR to GCC GENERIC loweringPhilip Herron
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>
2022-12-13gccrs: Add metadata output passPhilip Herron
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.
2022-12-13gccrs: Add unused variable scanPhilip Herron
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.
2022-12-13gccrs: Add dead code scan on HIRThomas Young
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.
2022-12-13gccrs: Add privacy checksArthur Cohen
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.
2022-12-13gccrs: Add const checkerArthur Cohen
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.
2022-12-13gccrs: Add unsafe checks for RustArthur Cohen
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.
2022-12-13gccrs: Add remaining type system transformationsPhilip Herron
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.
2022-12-13gccrs: Add Rust type informationPhilip Herron
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.
2022-12-13gccrs: Add type resolution and trait solving passPhilip Herron
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.
2022-12-13gccrs: Add helpers mappings canonical path and lang itemsPhilip Herron
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.
2022-12-13gccrs: Add attributes checkerArthur Cohen
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.