Thomas Schwinge [Wed, 22 Feb 2023 09:15:19 +0000 (10:15 +0100)]
Rust: Move void_list_node init to common code
Apply commit r13-2682-g8ff2a92a0450243e52d3299a13b30f208bafa7e0
"Move void_list_node init to common code" to the Rust front end, too.
gcc/rust/
* rust-lang.cc (grs_langhook_init): Do not initialize
void_list_node.
Thomas Schwinge [Wed, 14 Dec 2022 16:16:42 +0000 (17:16 +0100)]
Add '-Wno-complain-wrong-lang', and use it in 'gcc/testsuite/lib/target-supports.exp:check_compile' and elsewhere
I noticed that GCC/Rust recently lost all LTO variants in torture testing:
PASS: rust/compile/torture/all_doc_comment_line_blocks.rs -O0 (test for excess errors)
PASS: rust/compile/torture/all_doc_comment_line_blocks.rs -O1 (test for excess errors)
PASS: rust/compile/torture/all_doc_comment_line_blocks.rs -O2 (test for excess errors)
-PASS: rust/compile/torture/all_doc_comment_line_blocks.rs -O2 -flto -fno-use-linker-plugin -flto-partition=none (test for excess errors)
-PASS: rust/compile/torture/all_doc_comment_line_blocks.rs -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects (test for excess errors)
PASS: rust/compile/torture/all_doc_comment_line_blocks.rs -O3 -g (test for excess errors)
PASS: rust/compile/torture/all_doc_comment_line_blocks.rs -Os (test for excess errors)
Etc.
The reason is that when probing for availability of LTO, we run into:
spawn [...]/build-gcc/gcc/testsuite/rust/../../gccrs -B[...]/build-gcc/gcc/testsuite/rust/../../ -fdiagnostics-plain-output -frust-incomplete-and-experimental-compiler-do-not-use -flto -c -o lto8274.o lto8274.c
cc1: warning: command-line option '-frust-incomplete-and-experimental-compiler-do-not-use' is valid for Rust but not for C
For GCC/Rust testing, this flag is (as of recently) defaulted in
'gcc/testsuite/lib/rust.exp:rust_init':
lappend ALWAYS_RUSTFLAGS "additional_flags=-frust-incomplete-and-experimental-compiler-do-not-use"
A few more "command-line option [...] is valid for [...] but not for [...]"
instances were found in the test suite logs, when more than one language is
involved.
With '-Wno-complain-wrong-lang' used in
'gcc/testsuite/lib/target-supports.exp:check_compile', we get back:
PASS: rust/compile/torture/all_doc_comment_line_blocks.rs -O0 (test for excess errors)
PASS: rust/compile/torture/all_doc_comment_line_blocks.rs -O1 (test for excess errors)
PASS: rust/compile/torture/all_doc_comment_line_blocks.rs -O2 (test for excess errors)
+PASS: rust/compile/torture/all_doc_comment_line_blocks.rs -O2 -flto -fno-use-linker-plugin -flto-partition=none (test for excess errors)
+PASS: rust/compile/torture/all_doc_comment_line_blocks.rs -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects (test for excess errors)
PASS: rust/compile/torture/all_doc_comment_line_blocks.rs -O3 -g (test for excess errors)
PASS: rust/compile/torture/all_doc_comment_line_blocks.rs -Os (test for excess errors)
Etc., and in total:
=== rust Summary for unix ===
# of expected passes [-4990-]{+6718+}
# of expected failures [-39-]{+51+}
Anything that 'gcc/opts-global.cc:complain_wrong_lang' might do is cut
short by '-Wno-complain-wrong-lang', not just the one 'warning'
diagnostic. This corresponds to what already exists via
'lang_hooks.complain_wrong_lang_p'.
The 'gcc/opts-common.cc:prune_options' changes follow the same rationale
as PR67640 "driver passes -fdiagnostics-color= always last": we need to
process '-Wno-complain-wrong-lang' early, so that it properly affects
other options appearing before it on the command line.
gcc/
* common.opt (-Wcomplain-wrong-lang): New.
* doc/invoke.texi (-Wno-complain-wrong-lang): Document it.
* opts-common.cc (prune_options): Handle it.
* opts-global.cc (complain_wrong_lang): Use it.
gcc/testsuite/
* gcc.dg/Wcomplain-wrong-lang-1.c: New.
* gcc.dg/Wcomplain-wrong-lang-2.c: Likewise.
* gcc.dg/Wcomplain-wrong-lang-3.c: Likewise.
* gcc.dg/Wcomplain-wrong-lang-4.c: Likewise.
* gcc.dg/Wcomplain-wrong-lang-5.c: Likewise.
* lib/target-supports.exp (check_compile): Use
'-Wno-complain-wrong-lang'.
* g++.dg/abi/empty12.C: Likewise.
* g++.dg/abi/empty13.C: Likewise.
* g++.dg/abi/empty14.C: Likewise.
* g++.dg/abi/empty15.C: Likewise.
* g++.dg/abi/empty16.C: Likewise.
* g++.dg/abi/empty17.C: Likewise.
* g++.dg/abi/empty18.C: Likewise.
* g++.dg/abi/empty19.C: Likewise.
* g++.dg/abi/empty22.C: Likewise.
* g++.dg/abi/empty25.C: Likewise.
* g++.dg/abi/empty26.C: Likewise.
* gfortran.dg/bind-c-contiguous-1.f90: Likewise.
* gfortran.dg/bind-c-contiguous-4.f90: Likewise.
* gfortran.dg/bind-c-contiguous-5.f90: Likewise.
libgomp/
* testsuite/libgomp.fortran/alloc-10.f90: Use
'-Wno-complain-wrong-lang'.
* testsuite/libgomp.fortran/alloc-11.f90: Likewise.
* testsuite/libgomp.fortran/alloc-7.f90: Likewise.
* testsuite/libgomp.fortran/alloc-9.f90: Likewise.
* testsuite/libgomp.fortran/allocate-1.f90: Likewise.
* testsuite/libgomp.fortran/depend-4.f90: Likewise.
* testsuite/libgomp.fortran/depend-5.f90: Likewise.
* testsuite/libgomp.fortran/depend-6.f90: Likewise.
* testsuite/libgomp.fortran/depend-7.f90: Likewise.
* testsuite/libgomp.fortran/depend-inoutset-1.f90: Likewise.
* testsuite/libgomp.fortran/examples-4/declare_target-1.f90:
Likewise.
* testsuite/libgomp.fortran/examples-4/declare_target-2.f90:
Likewise.
* testsuite/libgomp.fortran/order-reproducible-1.f90: Likewise.
* testsuite/libgomp.fortran/order-reproducible-2.f90: Likewise.
* testsuite/libgomp.oacc-fortran/parallel-dims.f90: Likewise.
* testsuite/libgomp.fortran/task-detach-6.f90: Remove left-over
'dg-prune-output'.
Thomas Schwinge [Mon, 20 Feb 2023 12:01:50 +0000 (13:01 +0100)]
Rust: Don't depend on unused 'target-libffi', 'target-libbacktrace'
For example:
configure: error: "libffi has not been ported to nvptx-unknown-none."
Follow-up to commit
a75f038c069cc3a23b214854bedf04321fe88bc5
"gccrs: Add config-lang.in", which said:
> This was a copy/paste from gccgo front-end. We do not use any of the
> target_libs yet, [...]
gcc/rust/
* config-lang.in (target_libs): Remove.
Thomas Schwinge [Fri, 10 Feb 2023 09:43:24 +0000 (10:43 +0100)]
In 'contrib/config-list.mk', clarify i686-symbolics-gnu to i686-gnu
Already in the first revision of 'contrib/config-list.mk', i686-symbolics-gnu
has been present, but it's not clear to me whether that was meant to be
Symbolics as in the manufacturer, <https://en.wikipedia.org/wiki/Symbolics>,
with GNU (that is, GNU/Hurd) kernel/operating system (user land), or Symbolics
kernel with GNU operating system (user land)?
I can't find any mention of "Symbolics" in the history of 'config.sub'
upstream.
Either way, GCC configures i686-symbolics-gnu exactly the same as i686-gnu:
$ sed -n -e '/Using .* host machine hooks\.$/q' -e '/^Using the following target machine macro files:$/,$p' log/i686-gnu-make.out
Using the following target machine macro files:
[...]/gcc/config/vxworks-dummy.h
[...]/gcc/config/i386/i386.h
[...]/gcc/config/i386/unix.h
[...]/gcc/config/i386/att.h
[...]/gcc/config/elfos.h
[...]/gcc/config/gnu-user.h
[...]/gcc/config/glibc-stdint.h
[...]/gcc/config/i386/gnu-user-common.h
[...]/gcc/config/i386/gnu-user.h
[...]/gcc/config/gnu.h
[...]/gcc/config/i386/gnu.h
[...]/gcc/config/initfini-array.h
..., so let's clarify i686-symbolics-gnu to i686-gnu.
contrib/
* config-list.mk (LIST): Clarify i686-symbolics-gnu to i686-gnu.
GCC Administrator [Wed, 22 Feb 2023 00:18:49 +0000 (00:18 +0000)]
Daily bump.
David Malcolm [Tue, 21 Feb 2023 21:58:36 +0000 (16:58 -0500)]
analyzer: stop exploring the path after certain diagnostics [PR108830]
PR analyzer/108830 reports a situation in which there are lots of
followup -Wanalyzer-null-dereference warnings after the first access of
a NULL pointer, leading to very noisy output from -fanalyzer.
The analyzer's logic for stopping emitting multiple warnings from a
state machine doesn't quite work for NULL pointers: it attempts to
transition the malloc state machine's NULL pointer to the "stop" state,
which doesn't seem to make much sense in retrospect, and seems to get
confused over types.
Similarly, poisoned_value_diagnostic can be very noisy for uninit
variables, emitting a warning for every access to an uninitialized
variable. In theory, region_model::check_for_poison makes some attempts
to suppress followups, but only for the symbolic value itself; if the
user's code keeps accessing the same region, we would get a warning on
each one. For example, this showed up in Doom's s_sound.c where there
were 7 followup uninit warnings after the first uninit warning in
"S_ChangeMusic".
This patch adds an extra mechanism, giving pending diagnostics the
option of stopping the analysis of an execution path if they're saved
for emission on it, and turning this on for these warnings:
-Wanalyzer-null-dereference
-Wanalyzer-null-argument
-Wanalyzer-use-after-free
-Wanalyzer-use-of-pointer-in-stale-stack-frame
-Wanalyzer-use-of-uninitialized-value
Doing so should hopefully reduce the cascades of diagnostics that
-fanalyzer can sometimes emit.
I added a -fno-analyzer-suppress-followups for the cases where you
really want the followup warnings (e.g. in some DejaGnu tests, and
for microbenchmarks of UB detection, such as PR analyzer/104224).
Integration testing shows this patch reduces the number of probable
false positives reported by 94, and finds one more true positive:
Comparison: 9.34% -> 10.91%
GOOD: 66 -> 67 (+1)
BAD: 641 -> 547 (-94)
where the affected warnings/projects are:
-Wanalyzer-null-dereference: 0.00% GOOD: 0 BAD: 269 -> 239 (-30)
Unclassified: 257 -> 228 (-29)
apr-1.7.0: 12 -> 5 (-7)
doom: 1 -> 0 (-1)
haproxy-2.7.1: 47 -> 41 (-6)
ImageMagick-7.1.0-57: 13 -> 9 (-4)
qemu-7.2.0: 165 -> 154 (-11)
Known false: 7 -> 6 (-1)
xz-5.4.0: 4 -> 3 (-1)
-Wanalyzer-use-of-uninitialized-value: 0.00% GOOD: 0 BAD: 143 -> 80 (-63)
Known false: 47 -> 16 (-31)
doom: 42 -> 11 (-31)
Unclassified: 96 -> 64 (-32)
coreutils-9.1: 14 -> 10 (-4)
haproxy-2.7.1: 29 -> 23 (-6)
qemu-7.2.0: 48 -> 26 (-22)
-Wanalyzer-null-argument: 0.00% -> 2.33% GOOD: 0 -> 1 (+1) BAD: 43 -> 42 (-1)
Unclassified: 39 -> 38 (-1)
due to coreutils-9.1: 9 -> 8 (-1)
True positive: 0 -> 1 (+1)
(in haproxy-2.7.1)
gcc/analyzer/ChangeLog:
PR analyzer/108830
* analyzer.opt (fanalyzer-suppress-followups): New option.
* engine.cc (impl_region_model_context::warn): Terminate the path
if the diagnostic's terminate_path_p vfunc returns true and
-fanalyzer-suppress-followups is true (the default).
(impl_sm_context::warn): Likewise, for both overloads.
* pending-diagnostic.h (pending_diagnostic::terminate_path_p): New
vfunc.
* program-state.cc (program_state::on_edge): Terminate the path if
the ctxt requests it during updating the edge.
* region-model.cc (poisoned_value_diagnostic::terminate_path_p):
New vfunc.
* sm-malloc.cc (null_deref::terminate_path_p): New vfunc.
(null_arg::terminate_path_p): New vfunc.
gcc/ChangeLog:
PR analyzer/108830
* doc/invoke.texi: Document -fno-analyzer-suppress-followups.
gcc/testsuite/ChangeLog:
PR analyzer/108830
* gcc.dg/analyzer/attribute-nonnull.c: Update for
-Wanalyzer-use-of-uninitialized-value terminating analysis along
a path.
* gcc.dg/analyzer/call-summaries-2.c: Likewise.
* gcc.dg/analyzer/data-model-1.c: Likewise.
* gcc.dg/analyzer/data-model-5.c: Likewise.
* gcc.dg/analyzer/doom-s_sound-pr108867.c: New test.
* gcc.dg/analyzer/memset-CVE-2017-18549-1.c: Add
-fno-analyzer-suppress-followups.
* gcc.dg/analyzer/null-deref-pr108830.c: New test.
* gcc.dg/analyzer/pipe-1.c: Add -fno-analyzer-suppress-followups.
* gcc.dg/analyzer/pipe-void-return.c: Likewise.
* gcc.dg/analyzer/pipe2-1.c: Likewise.
* gcc.dg/analyzer/pr101547.c: Update for
-Wanalyzer-use-of-uninitialized-value terminating analysis along
a path.
* gcc.dg/analyzer/pr101875.c: Likewise.
* gcc.dg/analyzer/pr104224-split.c: New test, based on...
* gcc.dg/analyzer/pr104224.c: Add
-fno-analyzer-suppress-followups.
* gcc.dg/analyzer/realloc-2.c: Add
-fno-analyzer-suppress-followups.
* gcc.dg/analyzer/realloc-3.c: Likewise.
* gcc.dg/analyzer/realloc-5.c: Likewise.
* gcc.dg/analyzer/stdarg-1-ms_abi.c: Likewise.
* gcc.dg/analyzer/stdarg-1-sysv_abi.c: Likewise.
* gcc.dg/analyzer/stdarg-1.c: Likewise.
* gcc.dg/analyzer/symbolic-1.c: Likewise.
* gcc.dg/analyzer/symbolic-7.c: Update for
-Wanalyzer-use-of-uninitialized-value terminating analysis along a
path.
* gcc.dg/analyzer/uninit-4.c: Likewise.
* gcc.dg/analyzer/uninit-8.c: New test.
* gcc.dg/analyzer/uninit-pr94713.c: Update for
-Wanalyzer-use-of-uninitialized-value terminating analysis along a
path.
* gcc.dg/analyzer/zlib-6a.c: Add -fno-analyzer-suppress-followups.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Max Filippov [Tue, 21 Feb 2023 19:49:35 +0000 (11:49 -0800)]
gcc: xtensa: fix PR target/108876
gcc/
PR target/108876
* config/xtensa/xtensa.cc (xtensa_expand_epilogue): Drop emit_use
for A0_REG.
* config/xtensa/xtensa.md (sibcall, sibcall_internal)
(sibcall_value, sibcall_value_internal): Add 'use' expression
for A0_REG.
Harald Anlauf [Mon, 20 Feb 2023 20:28:09 +0000 (21:28 +0100)]
Fortran: improve checking of character length specification [PR96025]
gcc/fortran/ChangeLog:
PR fortran/96025
* parse.cc (check_function_result_typed): Improve type check of
specification expression for character length and return status.
(parse_spec): Use status from above.
* resolve.cc (resolve_fntype): Prevent use of invalid specification
expression for character length.
gcc/testsuite/ChangeLog:
PR fortran/96025
* gfortran.dg/pr96025.f90: New test.
Iain Buclaw [Fri, 3 Feb 2023 22:40:20 +0000 (23:40 +0100)]
libphobos: Merge upstream phobos
e5a521ab2.
Phobos changes:
- Unicode tables have been updated to version 15.
libphobos/ChangeLog:
* src/MERGE: Merge upstream phobos
e5a521ab2.
Iain Buclaw [Sun, 29 Jan 2023 20:06:59 +0000 (21:06 +0100)]
d: Merge upstream dmd, druntime
09faa4eacd, phobos
13ef27a56.
D front-end changes:
- Import dmd v2.102.0-beta.1
- `static assert' now supports multiple message arguments.
D runtime changes:
- Import druntime v2.102.0-beta.1
- The default `Throwable.TraceInfo' generation now is `@nogc'.
- `Object.factory' method has now been deprecated.
Phobos changes:
- Import phobos v2.102.0-beta.1
- Added float- and double-precision implementations for log
function families in std.math.
- `std.typecons.Unique' now calls `destroy` on struct types
gcc/d/ChangeLog:
* Make-lang.in (D_FRONTEND_OBJS): Add d/location.o.
* d-lang.cc (d_init_options): Update for new front-end interface.
(d_post_options): Call Loc::set after handling options.
* dmd/MERGE: Merge upstream dmd
09faa4eacd.
* dmd/VERSION: Bump version to v2.102.0-beta.1.
libphobos/ChangeLog:
* libdruntime/MERGE: Merge upstream druntime
09faa4eacd.
* src/MERGE: Merge upstream phobos
13ef27a56.
* testsuite/libphobos.exceptions/refcounted.d: Add test for chained
reference counted exceptions.
* testsuite/libphobos.shared/finalize.d: Add dg-warning for deprecated
factory interfaces.
* testsuite/libphobos.gc/issue22843.d: New test.
gcc/testsuite/ChangeLog:
* gdc.dg/simd2a.d: Update.
* gdc.dg/simd2b.d: Update.
* gdc.dg/simd2c.d: Update.
* gdc.dg/simd2d.d: Update.
* gdc.dg/simd2e.d: Update.
* gdc.dg/simd2f.d: Update.
* gdc.dg/simd2g.d: Update.
* gdc.dg/simd2h.d: Update.
* gdc.dg/simd2i.d: Update.
* gdc.dg/simd2j.d: Update.
Iain Buclaw [Sun, 29 Jan 2023 20:25:40 +0000 (21:25 +0100)]
d: Only handle the left-to-right evaluation of a call expression during gimplify
Removes an unnecessary rewriting of the front-end AST during lowering.
gcc/d/ChangeLog:
* d-codegen.cc (d_build_call): Remove front-end expansion of
side-effects in a call expression.
* d-gimplify.cc (d_gimplify_call_expr): Gimplify the callee before its
arguments.
Iain Buclaw [Sun, 29 Jan 2023 20:17:47 +0000 (21:17 +0100)]
d: Set doing_semantic_analysis_p before calling functionSemantic3
As functions which have semantic analysis ran late may still require
the use of CTFE built-ins to be evaluated.
gcc/d/ChangeLog:
* decl.cc (DeclVisitor::visit (FuncDeclaration *)): Set
doing_semantic_analysis_p before calling functionSemantic3.
gcc/testsuite/ChangeLog:
* gdc.dg/ctfeintrinsics.d: New test.
Iain Buclaw [Sun, 29 Jan 2023 20:14:48 +0000 (21:14 +0100)]
libphobos: Add @nogc to gcc.backtrace and gcc.libbacktrace modules.
libphobos/ChangeLog:
* libdruntime/gcc/backtrace.d (simpleErrorCallback): Add @nogc.
(LibBacktrace.initLibBacktrace): Likewise.
(LibBacktrace.this): Likewise.
(UnwindBacktrace.this): Likewise.
(getBacktrace): Likewise.
(getBacktraceSymbols): Likewise.
* libdruntime/gcc/libbacktrace.d.in (backtrace_create_state):
Likewise.
(backtrace_full): Likewise.
(backtrace_simple): Likewise.
(backtrace_print): Likewise.
(backtrace_pcinfo): Likewise.
(backtrace_syminfo): Likewise.
Richard Biener [Tue, 21 Feb 2023 12:02:31 +0000 (13:02 +0100)]
tree-optimization/108691 - remove trigger-happy assert
The following gets rid of the idea that we should prevent setjmp
like calls from popping up in uncontrolled way in the IL for now.
The solution is probably to handle it similar as noreturn has
the ctrl-altering flag on stmts, but use another flag, for example
ctrl-receiving which would also make sure the stmt is first.
PR tree-optimization/108691
* tree-ssa-dce.cc (eliminate_unnecessary_stmts): Remove
assert about calls_setjmp not becoming true when it was false.
* gcc.dg/pr108691.c: New testcase.
Richard Biener [Mon, 20 Feb 2023 11:58:50 +0000 (12:58 +0100)]
tree-optimization/108793 - niter compute type mismatch
When computing the number of iterations until wrap types are mixed up,
eventually leading to checking ICEs with a pointer bitwise inversion.
The following uses niter_type for the calculation.
PR tree-optimization/108793
* tree-ssa-loop-niter.cc (number_of_iterations_until_wrap):
Use convert operands to niter_type when computing num.
* gcc.dg/torture/pr108793.c: New testcase.
Thomas Schwinge [Tue, 21 Feb 2023 12:49:42 +0000 (13:49 +0100)]
Update copyright years.
... which accidentally had gotten reverted in recent
commit r13-6156-g1e8eb102200902e12c1b00e867e338be0a92c292
"gccrs: dump: Emit visibility when dumping items".
Raiki Tamura [Thu, 15 Dec 2022 17:27:59 +0000 (02:27 +0900)]
gccrs: add math intrinsics
gcc/rust/ChangeLog:
* backend/rust-builtins.cc (BuiltinsContext::setup_math_fns): New functions.
gcc/testsuite/ChangeLog:
* rust/compile/torture/intrinsics-math.rs: New test.
Arthur Cohen [Thu, 17 Nov 2022 15:50:58 +0000 (16:50 +0100)]
gccrs: const evaluator: Remove get_nth_callarg
We only used one path of the C++ folder's get_nth_callarg function:
CALL_EXPR_ARG. Replace all calls to get_nth_callarg by macro calls to
CALL_EXPR_ARG
gcc/rust/ChangeLog:
* backend/rust-constexpr.cc (get_nth_callarg): Remove function.
(rs_bind_parameters_in_call): Use CALL_EXPR_ARG instead.
(potential_constant_expression_1): Likewise.
Thomas Schwinge [Wed, 7 Dec 2022 08:18:26 +0000 (09:18 +0100)]
gccrs: Repair 'gcc/rust/lang.opt' comment
... lost in #1527 commit
138a6260124740208b8f3aff2e38617f43b05fe8
"rust: Add -frust-compile-until option".
gcc/rust/ChangeLog:
* lang.opt: Fix ordering of file.
Philip Herron [Mon, 5 Dec 2022 02:20:55 +0000 (02:20 +0000)]
gccrs: Cleanup unused parameters to fix the bootstrap build
gcc/rust/ChangeLog:
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Remove unused parameters.
* backend/rust-constexpr.cc (constant_value_1): Likewise.
(fold_non_dependent_init): Likewise.
* backend/rust-tree.cc (publicly_uniquely_derived_p): Likewise.
(instantiation_dependent_expression_p): Likewise.
(type_has_nontrivial_copy_init): Likewise.
(is_normal_capture_proxy): Likewise.
(resolve_nondeduced_context): Likewise.
(undeduced_auto_decl): Likewise.
(require_deduced_type): Likewise.
* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): Likewise.
* checks/errors/privacy/rust-reachability.cc (ReachabilityVisitor::visit): Likewise.
* checks/errors/privacy/rust-visibility-resolver.cc (VisibilityResolver::visit): Likewise.
* checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise.
* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise.
* checks/lints/rust-lint-marklive.cc (MarkLive::go): Likewise.
* checks/lints/rust-lint-unused-var.cc (unused_var_walk_fn): Likewise.
* expand/rust-macro-builtins.cc (try_expand_single_string_literal): Likewise.
(try_expand_many_expr): Likewise.
(parse_single_string_literal): Likewise.
(MacroBuiltin::assert_handler): Likewise.
(MacroBuiltin::file_handler): Likewise.
(MacroBuiltin::column_handler): Likewise.
(MacroBuiltin::concat_handler): Likewise.
(MacroBuiltin::env_handler): Likewise.
(MacroBuiltin::line_handler): Likewise.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise.
(ASTLoweringBase::handle_doc_item_attribute): Likewise.
* hir/rust-hir-dump.cc (Dump::visit): Likewise.
* hir/tree/rust-hir-full-test.cc (ConstGenericParam::accept_vis): Likewise.
* lex/rust-lex.cc (Lexer::parse_utf8_escape): Likewise.
(Lexer::parse_string): Likewise.
(Lexer::parse_char_or_lifetime): Likewise.
* lex/rust-lex.h: Likewise.
* metadata/rust-export-metadata.cc: Likewise.
* resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Likewise.
* resolve/rust-ast-resolve-type.cc (ResolveType::visit): Likewise.
(ResolveTypeToCanonicalPath::visit): Likewise.
* resolve/rust-ast-verify-assignee.h: Likewise.
* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit): Likewise.
* typecheck/rust-hir-type-check-expr.h: Likewise.
* typecheck/rust-hir-type-check-item.h: Likewise.
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): Likewise.
* typecheck/rust-tyty-rules.h: Likewise.
* util/rust-attributes.cc (AttributeChecker::visit): Likewise.
Philip Herron [Mon, 5 Dec 2022 00:31:18 +0000 (00:31 +0000)]
gccrs: Skip this debug test case which is failing on the latest mac-os devtools and its only for debug info
gcc/testsuite/ChangeLog:
* rust/debug/chartype.rs: Skip testcases on Darwin architectures.
Philip Herron [Mon, 7 Nov 2022 13:43:04 +0000 (13:43 +0000)]
gccrs: Fix undefined behaviour issues on macos
This adds missing copy constructors to HIR::PathExprSegment which were
wrongly defaulting to empty vectors when apply specified generic arguments
to method calls.
gcc/rust/ChangeLog:
* hir/tree/rust-hir-expr.h: Add const `get_method_name`.
* hir/tree/rust-hir-full-decls.h (struct GenericArgs): Move from `struct`...
(class GenericArgs): ...to `class`.
* hir/tree/rust-hir-path.h (struct GenericArgs): Likewise.
(class GenericArgs): Clear `type_args` in copy constructor.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Reorder
debug print.
* typecheck/rust-tyty.h: Add default constructors for `SubstitutionArgumentMappings`.
Philip Herron [Fri, 21 Oct 2022 14:43:54 +0000 (15:43 +0100)]
gccrs: Add initial support for argument capture of closures
When we have a closure expression that captures a parent function's
variable we must setup the closure data to contain this. Ignoring
moveability and mutability requires for now, this patch creates the closure
structure with fields for each of the captured variables. When it comes to
compilation of the closure expression in order to support nested closures
we must setup a context of implicit mappings so that for all path
resolution we hit this implicit closure mappings lookups code before any
lookup_var_decl as this decl will not exist so the order here is important
during path resolution which is a similar problem to match expression
destructuring.
Fixes #195
gcc/rust/ChangeLog:
* backend/rust-compile-context.cc (Context::push_closure_context): New function.
(Context::pop_closure_context): Likewise.
(Context::insert_closure_binding): Likewise.
(Context::lookup_closure_binding): Likewise.
* backend/rust-compile-context.h: Declare new functions and closure mappings.
* backend/rust-compile-expr.cc (CompileExpr::visit): Visit captures properly.
(CompileExpr::generate_closure_function): Compile captures properly.
* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve): Check for
closure bindings.
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Compile capture list's
types as well.
gcc/testsuite/ChangeLog:
* rust/execute/torture/closure3.rs: New test.
Philip Herron [Fri, 21 Oct 2022 14:39:52 +0000 (15:39 +0100)]
gccrs: Add capture tracking to the type info for closures
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Pass captures
properly to `TyTy::ClosureType` constructor.
* typecheck/rust-tyty.cc (ClosureType::as_string): Fix string representation.
(ClosureType::clone): Pass `captures` argument.
* typecheck/rust-tyty.h: Add `captures` field.
Philip Herron [Fri, 21 Oct 2022 12:40:40 +0000 (13:40 +0100)]
gccrs: Add closure binding's tracking to name resolution
When we have a closure block referencing variables in a parent function,
we must track what these are. We do this by having a context of closures
so if we have a variable reference and its declared in a rib whose node id
is less than the node id of the closure's node id we know it must be a
captured variable. We also need to iterate all possible closure contexts
as we might be in the case of a nested closure.
Addresses #195
gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Use proper closure
contexts.
* resolve/rust-name-resolver.cc (Scope::lookup_decl_type): New function.
(Scope::lookup_rib_for_decl): Likewise.
(Resolver::insert_resolved_name): Insert captured items.
(Resolver::push_closure_context): New function.
(Resolver::pop_closure_context): Likewise.
(Resolver::insert_captured_item): Likewise.
(Resolver::decl_needs_capture): Likewise.
(Resolver::get_captures): Likewise.
* resolve/rust-name-resolver.h: Declare new functions.
Philip Herron [Fri, 21 Oct 2022 11:54:52 +0000 (12:54 +0100)]
gccrs: Refactor name resolver to take a Rib::ItemType
This allows us to track the type of declaration that is stored within a
Rib.
gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Add Rib argument.
(ResolveExpr::resolve_closure_param): Likewise.
* resolve/rust-ast-resolve-implitem.h: Likewise.
* resolve/rust-ast-resolve-item.cc (ResolveTraitItems::visit): Likewise.
(ResolveItem::visit): Likewise.
* resolve/rust-ast-resolve-pattern.cc (PatternDeclaration::visit): Likewise.
* resolve/rust-ast-resolve-pattern.h: Likewise.
* resolve/rust-ast-resolve-stmt.h: Likewise.
* resolve/rust-ast-resolve-toplevel.h: Likewise.
* resolve/rust-ast-resolve-type.h: Likewise.
* resolve/rust-name-resolver.cc (Rib::lookup_decl_type): Likewise.
(Scope::insert): Likewise.
(Resolver::insert_builtin_types): Likewise.
* resolve/rust-name-resolver.h: Likewise.
Philip Herron [Fri, 21 Oct 2022 12:01:43 +0000 (13:01 +0100)]
gccrs: Get rid of make builtin macro
This macro is a mess and a helper method is much better for this case.
gcc/rust/ChangeLog:
* resolve/rust-name-resolver.cc (MKBUILTIN_TYPE): Remove macro.
(Rib::Rib): Remove `mappings` field.
(Resolver::generate_builtins): Use `setup_builtin` instead of macro.
(Resolver::setup_builtin): New function.
* resolve/rust-name-resolver.h: Declare `setup_builtin`, add FIXME
comment.
Raiki Tamura [Wed, 16 Nov 2022 08:15:24 +0000 (17:15 +0900)]
gccrs: Improve lexer dump
gcc/rust/ChangeLog:
* lex/rust-lex.cc (Lexer::Lexer): Add `dump_lex` boolean flag.
(Lexer::skip_token): Dump tokens if flag is enabled.
(Lexer::dump_and_skip): New function.
* lex/rust-lex.h: Include optional.h and declare functions.
* parse/rust-parse-impl.h (Parser::debug_dump_lex_output): Remove old
unused function.
* parse/rust-parse.h: Likewise.
* rust-session-manager.cc (Session::compile_crate): Pass lexer dump
option to lexer.
(Session::dump_lex): New function.
* util/rust-optional.h: Add missing constructor.
Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
Dave [Wed, 16 Nov 2022 23:06:44 +0000 (17:06 -0600)]
gccrs: Remove default location. Add visibility location to create_* functions
gcc/rust/ChangeLog:
* ast/rust-item.h: Remoe default location for Visibility class.
* parse/rust-parse-impl.h (Parser::parse_visibility): Pass proper location
when instantiating visibilities.
Jakub Dupak [Wed, 16 Nov 2022 13:16:51 +0000 (14:16 +0100)]
gccrs: ast: Dump no comma after self in fn params if it is the last one
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit): Fix dumping of fn params.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Wed, 16 Nov 2022 13:03:07 +0000 (14:03 +0100)]
gccrs: ast: Dump remove /* stmp */ comment to not clutter the dump
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit): Remove extraneous string when
dumping statements.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Wed, 16 Nov 2022 12:59:16 +0000 (13:59 +0100)]
gccrs: ast: Remove unused include in rust-ast-dump.cc
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc: Remove unused include.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Wed, 16 Nov 2022 12:58:50 +0000 (13:58 +0100)]
gccrs: ast: Dump generic parameters
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit): Add missing visitor.
* ast/rust-ast-dump.h: Likewise.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Tue, 15 Nov 2022 17:39:41 +0000 (18:39 +0100)]
gccrs: ast: Dump type param type
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit): Add missing visitor.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Tue, 15 Nov 2022 16:02:00 +0000 (17:02 +0100)]
gccrs: ast: Dump trait object type one bound
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit): Add missing visitor.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Tue, 15 Nov 2022 14:52:34 +0000 (15:52 +0100)]
gccrs: ast: Dump parenthesised type
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit): Add missing visitor.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Tue, 15 Nov 2022 14:49:05 +0000 (15:49 +0100)]
gccrs: ast: Dump trait object type
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit): Add missing visitor.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Tue, 15 Nov 2022 14:44:48 +0000 (15:44 +0100)]
gccrs: ast: Dump impl trait type
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit): Add missing visitor.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Tue, 15 Nov 2022 14:42:08 +0000 (15:42 +0100)]
gccrs: ast: Dump impl trait type one bound
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit): Add missing visitor.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Mon, 7 Nov 2022 16:09:33 +0000 (17:09 +0100)]
gccrs: ast: Dump bare function type
+ Return FunctionQualifiers as ref to work in ast dump
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit): Add missing visitor.
* ast/rust-ast-dump.h: Add missing getter declaration.
* ast/rust-ast-full-test.cc (BareFunctionType::as_string): Fix bare function
string representation.
* ast/rust-type.h (class BareFunctionType): Declare said getter.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Sun, 6 Nov 2022 20:29:56 +0000 (21:29 +0100)]
gccrs: ast: Dump inferred type
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit): Add missing visitor.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Sun, 6 Nov 2022 20:27:49 +0000 (21:27 +0100)]
gccrs: ast: Dump tuple type
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit): Add missing tuple type visitor.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Sun, 6 Nov 2022 20:23:12 +0000 (21:23 +0100)]
gccrs: ast: Dump never type
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit): Add missing never type visitor.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Sun, 6 Nov 2022 20:21:34 +0000 (21:21 +0100)]
gccrs: ast: Dump raw pointer type
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit): Add missing RawPointer visitor.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Sun, 6 Nov 2022 19:54:40 +0000 (20:54 +0100)]
gccrs: ast: Dump array type
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit): Add missing array visitor
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Sun, 6 Nov 2022 19:49:17 +0000 (20:49 +0100)]
gccrs: ast: Dump slice type
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit): Add missing slice visitor.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Fri, 4 Nov 2022 22:48:12 +0000 (23:48 +0100)]
gccrs: ast: Dump where clause and recursively needed nodes
This is currently needed for lifetimes to use the existing infrastructure.
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit): Add missing visitors.
* ast/rust-ast-dump.h: Likewise.
* ast/rust-ast.h: Add `get_lifetime_bounds` method.
* ast/rust-item.h: Add missing getter for lifetimes.
* ast/rust-type.h: Likewise.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Fri, 4 Nov 2022 22:30:24 +0000 (23:30 +0100)]
gccrs: ast: add visit overload for references
This is currently needed for lifetimes to use the existing infrastructure.
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit): Add new reference visitor wrapper.
* ast/rust-ast-dump.h: Declare it.
* ast/rust-item.h: Add mutable visibility getters.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Arthur Cohen [Wed, 2 Nov 2022 08:52:01 +0000 (09:52 +0100)]
gccrs: typecheck: Fix overzealous `delete` call
gcc/rust/ChangeLog:
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Fix extra call
to `delete`.
Dave [Thu, 10 Nov 2022 05:17:50 +0000 (23:17 -0600)]
gccrs: add Location to AST::Visibility
gcc/rust/ChangeLog:
* ast/rust-item.h: Add location member.
* hir/rust-ast-lower.cc (translate_visibility): Pass location argument.
* hir/tree/rust-hir-item.h: Fix constructor to accept Location argument.
Raiki Tamura [Wed, 9 Nov 2022 09:49:12 +0000 (18:49 +0900)]
gccrs: add lang item "phantom_data"
gcc/rust/ChangeLog:
* util/rust-lang-item.h: Add handling for `phantom_data` lang item.
gcc/testsuite/ChangeLog:
* rust/compile/torture/phantom_data.rs: New test.
Jakub Dupak [Fri, 28 Oct 2022 15:58:39 +0000 (17:58 +0200)]
gccrs: ast: Dump unit struct
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit): Add handling for unit structures.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Fri, 28 Oct 2022 15:27:16 +0000 (17:27 +0200)]
gccrs: ast: refer correctly to arguments in docs-strings
gcc/rust/ChangeLog:
* ast/rust-ast-dump.h: Fix documentation.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Thu, 27 Oct 2022 23:37:48 +0000 (01:37 +0200)]
gccrs: ast: transform helper methods to visits and add methods to simplify repeated patterns
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::go): Use new API.
(Dump::format_function_param): Refactor.
(Dump::visit_items_joined_by_separator): New function.
(Dump::emit_attrib): Refactor.
(Dump::visit_as_line): New function.
(Dump::visit_items_as_lines): Likewise.
(Dump::visit_items_as_block): Likewise.
(Dump::visit): Use new API.
(Dump::emit_visibility): Likewise.
(Dump::emit_indented_string): Likewise.
(Dump::emit_generic_params): Likewise.
(Dump::format_tuple_field): Likewise.
(Dump::format_struct_field): Likewise.
(Dump::format_function_common): Likewise.
(Dump::visit_function_common): Likewise.
* ast/rust-ast-dump.h: Declare new functions and add documentation.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Thu, 27 Oct 2022 20:27:55 +0000 (22:27 +0200)]
gccrs: ast: visitor pattern -> overload syntax compatibility layer
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit): Add new visit function for overloading.
* ast/rust-ast-dump.h: Add documentation for layer.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Arthur Cohen [Wed, 26 Oct 2022 15:00:55 +0000 (17:00 +0200)]
gccrs: intrinsics: Implement atomic_load intrinsics
gcc/rust/ChangeLog:
* backend/rust-builtins.cc (BuiltinsContext::setup_atomic_fns): Declare atomic
load intrinsics.
* backend/rust-compile-intrinsic.cc (atomic_load_handler_inner): New handler.
(atomic_load_handler): Likewise.
(unchecked_op_handler): Remove `static` function qualifier.
(build_atomic_builtin_name): Handle load intrinsics.
(atomic_store_handler_inner): New handler.
gcc/testsuite/ChangeLog:
* rust/compile/torture/intrinsics-3.rs:
* rust/execute/torture/atomic_load.rs: New test.
Arthur Cohen [Wed, 26 Oct 2022 14:35:12 +0000 (16:35 +0200)]
gccrs: intrinsics: Cleanup error handling around atomic_store_*
gcc/rust/ChangeLog:
* backend/rust-compile-intrinsic.cc (check_for_basic_integer_type): New function.
(build_atomic_builtin_name): Use HIR Type instead of `tree`.
(atomic_store_handler_inner): Cleanup error handling.
(unchecked_op_inner): Likewise.
gcc/testsuite/ChangeLog:
* rust/compile/torture/intrinsics-5.rs: Fix error message.
Arthur Cohen [Wed, 26 Oct 2022 14:06:53 +0000 (16:06 +0200)]
gccrs: intrinsics: Use lambdas for wrapping_<op> intrinsics
gcc/rust/ChangeLog:
* backend/rust-compile-intrinsic.cc (wrapping_op_handler): Refactor to return
an `std::function`.
(wrapping_op_handler_inner): Rename.
(wrapping_add_handler): Remove function.
(wrapping_sub_handler): Likewise.
(wrapping_mul_handler): Likewise.
Arthur Cohen [Wed, 26 Oct 2022 13:57:54 +0000 (15:57 +0200)]
gccrs: intrinsics: Add unchecked operation intrinsics
gcc/rust/ChangeLog:
* backend/rust-compile-intrinsic.cc (is_basic_integer_type): New function.
(unchecked_op_inner): New handler.
(unchecked_op_handler): New handler.
gcc/testsuite/ChangeLog:
* rust/compile/torture/intrinsics-6.rs: New test.
* rust/compile/torture/intrinsics-7.rs: New test.
Arthur Cohen [Tue, 25 Oct 2022 09:24:10 +0000 (11:24 +0200)]
gccrs: intrinsics: Add early implementation for atomic_store_{seqcst, relaxed, release}
gcc/rust/ChangeLog:
* backend/rust-builtins.cc (BuiltinsContext::setup_atomic_fns): New function.
(BuiltinsContext::setup): Call `setup_atomic_fns`.
* backend/rust-builtins.h: Declare `setup_atomic_fns`.
* backend/rust-compile-intrinsic.cc (atomic_store_handler_inner): New function.
(atomic_store_handler): New handler.
(make_unsigned_long_tree): Add helper around making unsigned long trees.
(prefetch_data_handler): Use `make_unsigned_long_tree`.
(build_atomic_builtin_name): New function.
gcc/testsuite/ChangeLog:
* rust/compile/torture/intrinsics-4.rs: New test.
* rust/compile/torture/intrinsics-5.rs: New test.
* rust/execute/torture/atomic_store.rs: New test.
Arthur Cohen [Mon, 24 Oct 2022 11:20:41 +0000 (13:20 +0200)]
gccrs: constexpr: Add `rust_sorry_at` in places relying on init values
gcc/rust/ChangeLog:
* backend/rust-constexpr.cc (build_anon_member_initialization): Workaround uninitialized
values.
(build_data_member_initialization): Likewise.
Arthur Cohen [Tue, 25 Oct 2022 08:48:43 +0000 (10:48 +0200)]
gccrs: intrinsics: Add `sorry_handler` intrinsic handler
gcc/rust/ChangeLog:
* backend/rust-compile-intrinsic.cc (sorry_handler): New intrinsic handler.
gcc/testsuite/ChangeLog:
* rust/compile/torture/intrinsics-3.rs: New test.
Arthur Cohen [Mon, 24 Oct 2022 15:28:11 +0000 (17:28 +0200)]
gccrs: builtins: Rename all bang macro handlers
gcc/rust/ChangeLog:
* expand/rust-macro-builtins.cc (MacroBuiltin::assert): Rename to...
(MacroBuiltin::assert_handler): ..this.
(MacroBuiltin::file): Rename to...
(MacroBuiltin::file_handler): ..this.
(MacroBuiltin::column): Rename to...
(MacroBuiltin::column_handler): ..this.
(MacroBuiltin::include_bytes): Rename to...
(MacroBuiltin::include_bytes_handler): ..this.
(MacroBuiltin::include_str): Rename to...
(MacroBuiltin::include_str_handler): ..this.
(MacroBuiltin::compile_error): Rename to...
(MacroBuiltin::compile_error_handler): ..this.
(MacroBuiltin::concat): Rename to...
(MacroBuiltin::concat_handler): ..this.
(MacroBuiltin::env): Rename to...
(MacroBuiltin::env_handler): ..this.
(MacroBuiltin::cfg): Rename to...
(MacroBuiltin::cfg_handler): ..this.
(MacroBuiltin::include): Rename to...
(MacroBuiltin::include_handler): ..this.
(MacroBuiltin::line): Rename to...
(MacroBuiltin::line_handler): ..this.
* expand/rust-macro-builtins.h: Rename all handlers.
* util/rust-hir-map.cc (Mappings::insert_macro_def): Use new handler
names.
Simon Cook [Tue, 12 Apr 2022 14:45:56 +0000 (16:45 +0200)]
gccrs: rust: Allow gccrs to build on x86_64-apple-darwin with clang/libc++
gcc/rust/ChangeLog:
* util/rust-inline-visitor.h: Remove some offending system includes.
YizhePKU [Tue, 13 Apr 2021 07:28:36 +0000 (07:28 +0000)]
gccrs: Implement the inline visitor
gcc/rust/ChangeLog:
* util/rust-inline-visitor.h: New file.
Philip Herron [Thu, 20 Oct 2022 17:31:02 +0000 (18:31 +0100)]
gccrs: Support Closure calls as generic trait bounds
gcc/rust/ChangeLog:
* backend/rust-compile-expr.cc (CompileExpr::visit): Refactor checking of closures.
(CompileExpr::generate_possible_fn_trait_call): New function.
* backend/rust-compile-expr.h: Declare `generate_possible_fn_trait_call`.
gcc/testsuite/ChangeLog:
* rust/execute/torture/closure2.rs: New test.
Philip Herron [Thu, 20 Oct 2022 17:05:43 +0000 (18:05 +0100)]
gccrs: Add missing type resolution for function type segments
gcc/rust/ChangeLog:
* typecheck/rust-tyty-bounds.cc (TypeCheckBase::get_predicate_from_bound): Add missing
implementation.
Philip Herron [Thu, 20 Oct 2022 16:59:27 +0000 (17:59 +0100)]
gccrs: Add missing hir lowering to function type-path segments
gcc/rust/ChangeLog:
* Make-lang.in: Compile rust-ast-lower-type.cc.
* ast/rust-path.h: Add `get_locus` method to `TypePathFunction`.
* hir/rust-ast-lower-base.cc (ASTLowerTypePath::visit): Move implementation to
rust-ast-lower-type.cc.
(ASTLowerQualifiedPathInType::visit): Likewise.
(ASTLoweringType::visit): Likewise.
* hir/rust-ast-lower-type.h: Move implementations to source file.
* hir/tree/rust-hir-path.h: Likewise.
* hir/rust-ast-lower-type.cc: New file.
Philip Herron [Thu, 20 Oct 2022 16:59:03 +0000 (17:59 +0100)]
gccrs: Add missing name resolution to Function type-path segments
gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-type.cc (ResolveRelativeTypePath::go): Add missing handling of
function case.
Philip Herron [Wed, 19 Oct 2022 17:02:36 +0000 (18:02 +0100)]
gccrs: Closure support at CallExpr
gcc/rust/ChangeLog:
* backend/rust-compile-context.h: Add new functions: `insert_closure_decl` and
`lookup_closure_decl`.
* backend/rust-compile-expr.cc (CompileExpr::visit): Start compiling Closures properly.
(CompileExpr::generate_closure_function): New function.
(CompileExpr::generate_closure_fntype): Likewise.
* backend/rust-compile-expr.h: Declare `generate_closure_function` and
`generate_closure_fntype`.
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Visit closure types properly.
* backend/rust-mangle.cc (legacy_mangle_name): Add support for closures.
* backend/rust-tree.h (RS_CLOSURE_FLAG): Add new tree macro.
(RS_CLOSURE_TYPE_P): And checking for it on tree nodes.
* typecheck/rust-tyty.cc (ClosureType::is_equal): Add implementation.
gcc/testsuite/ChangeLog:
* rust/execute/torture/closure1.rs: New test.
Philip Herron [Tue, 18 Oct 2022 12:21:40 +0000 (13:21 +0100)]
gccrs: Initial Type resolution for closures
gcc/rust/ChangeLog:
* hir/tree/rust-hir-expr.h: Add `get_params` method.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Typecheck closure nodes.
(TypeCheckExpr::resolve_fn_trait_call): New function.
* typecheck/rust-hir-type-check-expr.h: Declare `resolve_fn_trait_call` and
`resolve_possible_fn_trait_call_method_name`.
* typecheck/rust-hir-type-check.h: Declare `get_context_type`.
* typecheck/rust-tyctx.cc (TypeCheckContextItem::get_context_type): New function.
* typecheck/rust-tyty-cmp.h: Visit closures properly.
* typecheck/rust-tyty-rules.h: Likewise.
* typecheck/rust-tyty.cc (BaseType::bounds_compatible): Add commented out assertin.
(ClosureType::as_string): Implement it.
(ClosureType::clone): Fix closure cloning.
(ClosureType::setup_fn_once_output): New function.
* typecheck/rust-tyty.h: Improve `ClosureType` class and declare `setup_fn_once_output`.
Philip Herron [Wed, 19 Oct 2022 17:30:36 +0000 (18:30 +0100)]
gccrs: Add closures to lints and error checking
gcc/rust/ChangeLog:
* checks/errors/rust-const-checker.cc (ConstChecker::visit): Visit closures properly.
* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise.
* checks/lints/rust-lint-marklive.h: Likewise.
Philip Herron [Wed, 19 Oct 2022 09:59:18 +0000 (10:59 +0100)]
gccrs: Refactor method call type checking
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Simplify method
call type checking by removing visitor and instead using one static cast. Use the
new interface.
* typecheck/rust-tyty-call.cc (TypeCheckMethodCallExpr::visit): Likewise.
(TypeCheckMethodCallExpr::go): Likewise.
(TypeCheckMethodCallExpr::check): Likewise.
* typecheck/rust-tyty-call.h (class TypeCheckMethodCallExpr): Likewise.
(class Argument): Likewise.
Philip Herron [Mon, 17 Oct 2022 16:51:15 +0000 (17:51 +0100)]
gccrs: Add name resolution for closures
gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Visit closure properly when
name resolving.
(ResolveExpr::resolve_closure_param): Implement closure name resolving.
* resolve/rust-ast-resolve-expr.h: Declare visitors for closure types.
Philip Herron [Mon, 17 Oct 2022 16:27:01 +0000 (17:27 +0100)]
gccrs: Formatting cleanup in HIR lowering pattern
gcc/rust/ChangeLog:
* hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::ASTLoweringPattern):
Improve formatting.
(ASTLoweringPattern::translate): Likewise.
* hir/rust-ast-lower-pattern.h: Likewise.
* resolve/rust-ast-resolve-expr.h: Likewise.
Philip Herron [Mon, 17 Oct 2022 15:51:05 +0000 (16:51 +0100)]
gccrs: Refactor expression hir lowering into cc file
gcc/rust/ChangeLog:
* Make-lang.in: Add new object file for expression lowering.
* ast/rust-expr.h: Move implementation of expr lowering to source file.
* backend/rust-compile-block.h: Likewise.
* backend/rust-compile-expr.cc (CompileExpr::visit): Likewise.
* backend/rust-compile-expr.h: Likewise.
* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): Likewise.
* checks/errors/privacy/rust-privacy-reporter.h: Likewise.
* checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise.
* checks/errors/rust-const-checker.h: Likewise.
* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise.
* checks/errors/rust-unsafe-checker.h: Likewise.
* hir/rust-ast-lower-base.h: Likewise.
* hir/rust-ast-lower-expr.h (RUST_AST_LOWER_EXPR): Likewise.
* hir/rust-ast-lower.cc (ASTLoweringBase::lower_closure_param): Likewise.
* hir/rust-hir-dump.cc (Dump::visit): Likewise.
* hir/rust-hir-dump.h: Likewise.
* hir/tree/rust-hir-expr.h (class ClosureExpr): Likewise.
(class ClosureExprInner): Likewise.
(class ClosureExprInnerTyped): Likewise.
* hir/tree/rust-hir-full-decls.h (class ClosureExprInner): Likewise.
(class ClosureExprInnerTyped): Likewise.
* hir/tree/rust-hir-full-test.cc (ClosureExprInnerTyped::as_string): Likewise.
(ClosureExprInner::as_string): Likewise.
(ClosureExprInner::accept_vis): Likewise.
(ClosureExpr::accept_vis): Likewise.
(ClosureExprInnerTyped::accept_vis): Likewise.
* hir/tree/rust-hir-visitor.h: Likewise.
* hir/tree/rust-hir.h (class Expr): Likewise.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise.
* typecheck/rust-hir-type-check-expr.h: Likewise.
* hir/rust-ast-lower-expr.cc: New file.
Philip Herron [Mon, 17 Oct 2022 15:50:34 +0000 (16:50 +0100)]
gccrs: Add missing fn_once_output langitem
gcc/rust/ChangeLog:
* util/rust-lang-item.h: Add handling for `fn_once_output`.
Arthur Cohen [Wed, 19 Oct 2022 12:53:43 +0000 (14:53 +0200)]
gccrs: ast: Improve Fragment API
gcc/rust/ChangeLog:
* ast/rust-ast-fragment.cc (Fragment::Fragment): Add better APIs.
(Fragment::complete): New function.
(Fragment::unexpanded): New function.
* ast/rust-ast-fragment.h: Declare new APIs and add documentation.
* expand/rust-attribute-visitor.h: Use new Fragment API.
* expand/rust-macro-builtins.cc (MacroBuiltin::file): Likewise.
(MacroBuiltin::column): Likewise.
(MacroBuiltin::include_bytes): Likewise.
(MacroBuiltin::include_str): Likewise.
(MacroBuiltin::concat): Likewise.
(MacroBuiltin::env): Likewise.
(MacroBuiltin::cfg): Likewise.
(MacroBuiltin::include): Likewise.
(MacroBuiltin::line): Likewise.
* expand/rust-macro-expand.cc (parse_many): Likewise.
(transcribe_expression): Likewise.
(transcribe_type): Likewise.
* expand/rust-macro-expand.h (struct MacroExpander): Likewise.
Arthur Cohen [Wed, 19 Oct 2022 12:05:54 +0000 (14:05 +0200)]
gccrs: rust: Replace uses of ASTFragment -> Fragment
gcc/rust/ChangeLog:
* ast/rust-ast.h (class ASTFragment): Remove old ASTFragment class.
* ast/rust-macro.h (class MacroRulesDefinition): Use new Fragment API.
* expand/rust-attribute-visitor.h: Likewise.
* expand/rust-macro-builtins.cc (macro_end_token): Likewise.
(MacroBuiltin::assert): Likewise.
(MacroBuiltin::file): Likewise.
(MacroBuiltin::column): Likewise.
(MacroBuiltin::include_bytes): Likewise.
(MacroBuiltin::include_str): Likewise.
(MacroBuiltin::compile_error): Likewise.
(MacroBuiltin::concat): Likewise.
(MacroBuiltin::env): Likewise.
(MacroBuiltin::cfg): Likewise.
(MacroBuiltin::include): Likewise.
(MacroBuiltin::line): Likewise.
* expand/rust-macro-builtins.h: Likewise.
* expand/rust-macro-expand.cc (MacroExpander::expand_decl_macro): Likewise.
(MacroExpander::expand_invoc): Likewise.
(MacroExpander::match_repetition): Likewise.
(parse_many): Likewise.
(transcribe_many_items): Likewise.
(transcribe_many_ext): Likewise.
(transcribe_many_trait_items): Likewise.
(transcribe_many_impl_items): Likewise.
(transcribe_many_trait_impl_items): Likewise.
(transcribe_expression): Likewise.
(transcribe_type): Likewise.
(transcribe_on_delimiter): Likewise.
(tokens_to_str): Likewise.
* expand/rust-macro-expand.h (struct MacroExpander): Likewise.
* util/rust-hir-map.cc (Mappings::insert_macro_def): Likewise.
Arthur Cohen [Wed, 19 Oct 2022 11:54:04 +0000 (13:54 +0200)]
gccrs: ast: Refactor ASTFragment -> Fragment class
gcc/rust/ChangeLog:
* Make-lang.in: Add `rust-ast-fragment.o` object file.
* ast/rust-ast-fragment.cc: New file.
* ast/rust-ast-fragment.h: New file.
Philip Herron [Mon, 17 Oct 2022 10:35:26 +0000 (11:35 +0100)]
gccrs: Add check for recursive trait cycles
gcc/rust/ChangeLog:
* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): Check if a
trait query is currently in progress.
* typecheck/rust-hir-type-check.h (class TraitQueryGuard): Add helpers around
checking for trait queries and inserting them.
gcc/testsuite/ChangeLog:
* rust/compile/issue-1589.rs: New test.
Arthur Cohen [Tue, 27 Sep 2022 14:24:59 +0000 (16:24 +0200)]
gccrs: dump: Dump macro rules definition
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit): Add missing visitors for macro definition dumping.
(get_delimiters): New function.
* ast/rust-ast-dump.h: Declare `get_delimiters` and add documentation.
* ast/rust-macro.h: Add `get_token_tree` method.
Jakub Dupak [Sat, 15 Oct 2022 19:30:40 +0000 (21:30 +0200)]
gccrs: ast: Module: unloaded module and inner attributes
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit): Properly handle unloaded modules.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Arthur Cohen [Fri, 14 Oct 2022 14:55:47 +0000 (16:55 +0200)]
gccrs: dump: Fix module dumping
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit): Fix formatting when dumping modules.
Arthur Cohen [Tue, 27 Sep 2022 13:52:57 +0000 (15:52 +0200)]
gccrs: dump: Dump items within modules
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit): Dump items in modules properly.
Arthur Cohen [Tue, 27 Sep 2022 13:50:39 +0000 (15:50 +0200)]
gccrs: dump: Emit visibility when dumping items
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc: Emit visibility when dumping items.
Philip Herron [Fri, 14 Oct 2022 15:06:33 +0000 (16:06 +0100)]
gccrs: Support outer attribute handling on trait items just like normal items
gcc/rust/ChangeLog:
* hir/rust-ast-lower-base.h (class ItemWrapper): New class.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::handle_outer_attributes): Use
`ItemWrapper` class.
(ASTLoweringBase::handle_doc_item_attribute): Likewise.
(ASTLoweringBase::handle_lang_item_attribute): Likewise.
* hir/rust-ast-lower-implitem.h: Check outer attributes on items.
* hir/tree/rust-hir-item.h: Add `get_trait_locus` methods.
* hir/tree/rust-hir.h: Likewise.
* util/rust-hir-map.h: Add defId mappings and associated functions.
* util/rust-hir-map.cc (Mappings::insert_defid_mapping): Implement insertion to said
mappings.
(Mappings::lookup_trait_item_defid): And looking up said mappings.
Jakub Dupak [Fri, 14 Oct 2022 10:38:19 +0000 (12:38 +0200)]
gccrs: ast: dump TypeAlias
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit): Add code for dumping type aliases.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Philip Herron [Fri, 14 Oct 2022 13:00:16 +0000 (14:00 +0100)]
gccrs: Refactor TraitResolver to not require a visitor
gcc/rust/ChangeLog:
* typecheck/rust-hir-trait-resolve.cc (TraitResolver::TraitResolver): Do not nullptr init
`resolved_trait_reference` anymore.
(TraitResolver::resolve_path): Simplify function and rename to...
(TraitResolver::resolve_path_to_trait): ...this.
(TraitResolver::lookup_path): Use new interface.
* typecheck/rust-hir-trait-resolve.h (class TraitResolver): Do not inherit `HIRFullVisitor`
class anymore.
David Faust [Thu, 13 Oct 2022 17:23:44 +0000 (10:23 -0700)]
gccrs: ast: dump: RangeExprs
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit): Add dump for RangeExprs.
David Faust [Thu, 13 Oct 2022 17:15:05 +0000 (10:15 -0700)]
gccrs: ast: dump: various simple Exprs
Adds dump for:
- BorrowExpr
- DereferenceExpr
- ErrorPropagationExpr
- NegationExpr
- TypeCastExpr
- GroupedExpr
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit): Add dump for, BorrowExpr, DereferenceExpr,
ErrorPropagationExpr, NegationExpr, TypeCastExpr and GroupedExpr.
David Faust [Thu, 13 Oct 2022 17:14:38 +0000 (10:14 -0700)]
gccrs: ast: dump: ArrayExpr
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit): Add dump code for ArrayExpr.
David Faust [Thu, 13 Oct 2022 16:28:33 +0000 (09:28 -0700)]
gccrs: ast: dump: ComparisonExpr and LazyBooleanExpr
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit): Add dumps for ComparisonExpr and
LazyBooleanExpr.
David Faust [Thu, 13 Oct 2022 16:27:35 +0000 (09:27 -0700)]
gccrs: ast: dump: minor fixups to IfExpr formatting
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit): Fix IfExpr formatting.
David Faust [Thu, 13 Oct 2022 16:25:57 +0000 (09:25 -0700)]
gccrs: ast: dump: fix extra newline in block without tail
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit): Fix block formatting.
Philip Herron [Thu, 13 Oct 2022 09:10:37 +0000 (10:10 +0100)]
gccrs: Method resolution must support multiple candidates
This patch fixes bad method resolution in our operator_overload_9 case.
When we have a &mut reference to something and we deref we must resolve to
the mutable reference impl block. The interface we are using to resolve
methods is the can_eq interface which allows for permissive mutability
which means allowing for mutable reference being unified with an immutable
one. This meant we actual match against both the immutable and mutable
version leading to multiple candidate error.
The fix here adds a method resolution flag to the can_eq interface so that
we enforce mutability equality. The other hack is that we do not allow
can_eq of ParamTypes to generic Slices. I think there is some subtle thing
going on for that case. The Rustc method resolver actually filters the
impl blocks for reference types based looking up the relevant lang items
we need to do this as well but is a much larger refactor to our method
resolver which should be done seperately.
Fixes #1588
gcc/rust/ChangeLog:
* typecheck/rust-autoderef.cc: Add support for multiple resolution candidates.
* typecheck/rust-hir-dot-operator.cc (MethodResolver::MethodResolver): Edit
`try_result` field and change constructor.
(MethodResolver::Probe): Return set of candidates instead of singular candidate.
(MethodResolver::select): Add better implementation to account for multiple
candidates.
* typecheck/rust-hir-dot-operator.h (struct MethodCandidate): Overload comparison
operator in order to store them in `std::set`.
* typecheck/rust-hir-inherent-impl-overlap.h: Do not fail assertion on missing type.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Adapt code to use
multiple candidates.
* typecheck/rust-tyty.cc (set_cmp_autoderef_mode): Add code to handle automatic
derefs properly.
(reset_cmp_autoderef_mode): Add helper function to reset said mode.
* typecheck/rust-tyty.h (set_cmp_autoderef_mode): Declare function.
(reset_cmp_autoderef_mode): Likewise.
* typecheck/rust-tyty-cmp.h: Add handling of `autoderef_cmp_flag`
gcc/testsuite/ChangeLog:
* rust/compile/generics7.rs: Fix test with missing assertion.
* rust/execute/torture/operator_overload_9.rs: Fix test assertion.
Philip Herron [Wed, 12 Oct 2022 11:26:24 +0000 (12:26 +0100)]
gccrs: Add ABI mappings for rust-call to map to ABI::RUST
gcc/rust/ChangeLog:
* util/rust-abi.cc (get_abi_from_string): Add missing "rust-call"
possibility for ABI variant.
Philip Herron [Wed, 12 Oct 2022 11:25:52 +0000 (12:25 +0100)]
gccrs: Add mappings for fn_once lang item
gcc/rust/ChangeLog:
* util/rust-lang-item.h: Add `fn_once` lang item.
Philip Herron [Thu, 6 Oct 2022 13:46:17 +0000 (14:46 +0100)]
gccrs: Support type resolution on super traits on dyn objects
When checking if specified bounds satisfy other bounds we must lookup the
super traits. To finish the support for super traits we need to redo the
computation of method addresses to support super traits.
Addresses #914
gcc/rust/ChangeLog:
* backend/rust-compile.cc: Add note about missing support for super
traits.
* typecheck/rust-tyty.cc (BaseType::satisfies_bound): New function.
(BaseType::bounds_compatible): New function.
(DynamicObjectType::get_object_items): New function.
* typecheck/rust-hir-trait-ref.h: Use new API to perform type resolution
on dyn objects.
Arthur Cohen [Tue, 11 Oct 2022 09:12:50 +0000 (11:12 +0200)]
gccrs: early-name-resolver: Add simple macro name resolution
This name resolver performs the same macro name resolution as what was
previously done by the AttrVisitor visitor and macro expander.
It also resolves macro expressions in builtin-macros properly, as well
as expanded AST nodes when necessary.
gcc/rust/ChangeLog:
* Make-lang.in: Compile early name resolver.
* expand/rust-attribute-visitor.cc (AttrVisitor::visit): Move macro
name resolution.
* expand/rust-macro-builtins.cc (try_expand_macro_expression): Run ENR
when recursively expanding macros.
* expand/rust-macro-expand.cc (MacroExpander::expand_invoc): No longer
perform name resolution in `expand_invoc`.
* expand/rust-macro-expand.h (struct MacroExpander): Keep ENR within
MacroExpander.
* rust-session-manager.cc (Session::expansion): Run ENR.
* resolve/rust-early-name-resolver.cc: New file.
* resolve/rust-early-name-resolver.h: New file.