Derive attributes should be parsed before attempting to retrieve any
traits. This will convert the tokenstream to a list of path if this
hasn't been done previously.
gcc/rust/ChangeLog:
* ast/rust-ast.cc (Attribute::get_traits_to_derive): Convert
tokenstream to path list.
Member function is_derive was overly constrained, the attribute changes
when we parse it's meta items and it no longer contains a tokenstream
while staying a derive.
Having copy and any other constructor stuff might lead to a breakage in
the future where the node id differs due to a newly constructed
SimplePath node. This change will allow us to assert the NodeId is from
the ast and not any copy made in between.
gcc/rust/ChangeLog:
* ast/rust-ast.cc (Attribute::get_traits_to_derive): Change
return type to a vector of references.
* ast/rust-ast.h: Update constructor.
* expand/rust-expand-visitor.cc (ExpandVisitor::expand_inner_stmts):
Update function call.
Philip Herron [Mon, 4 Sep 2023 14:28:46 +0000 (15:28 +0100)]
gccrs: Fix match-expression code-gen
We were massing the match scruitinee expression as a way to access the
result of the expression. This is wrong and needs to be stored in a
temporary otherwise it will cause the code to be regnerated for each time
it is used. This is not an issue in the case where the expression is only
used once.
Fixes #1895
gcc/rust/ChangeLog:
* backend/rust-compile-expr.cc (CompileExpr::visit): use a temp for the value
gcc/testsuite/ChangeLog:
* rust/execute/torture/iter1.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gccrs: Rename libproc_macro to libproc_macro_internal
The name was a bit misleading since libproc_macro is a rust library that
should we should be able to link against some rust code. This cpp
library was the layer below the libproc_macro library, the "real" gcc
libproc_macro act as a translation layer for the internal library.
gcc/rust/ChangeLog:
* expand/rust-macro-expand.h: Change include directive with the
new name.
* expand/rust-proc-macro.h (RUST_PROC_MACRO_H): Likewise.
* util/rust-hir-map.h: Likewise.
* util/rust-token-converter.h: Likewise.
* util/rust-token-converter.cc: Remove useless include
directive.
* Make-lang.in: Rename library.
libgrust/ChangeLog:
* Makefile.am: Change library name.
* Makefile.in: Likewise.
* configure.ac: Likewise.
* configure: Regenerate.
* libproc_macro/Makefile.am: Moved to...
* libproc_macro_internal/Makefile.am: ...here.
* libproc_macro/Makefile.in: Moved to...
* libproc_macro_internal/Makefile.in: ...here.
* libproc_macro/bridge.h: Moved to...
* libproc_macro_internal/bridge.h: ...here.
* libproc_macro/ffistring.cc: Moved to...
* libproc_macro_internal/ffistring.cc: ...here.
* libproc_macro/ffistring.h: Moved to...
* libproc_macro_internal/ffistring.h: ...here.
* libproc_macro/group.cc: Moved to...
* libproc_macro_internal/group.cc: ...here.
* libproc_macro/group.h: Moved to...
* libproc_macro_internal/group.h: ...here.
* libproc_macro/ident.cc: Moved to...
* libproc_macro_internal/ident.cc: ...here.
* libproc_macro/ident.h: Moved to...
* libproc_macro_internal/ident.h: ...here.
* libproc_macro/literal.cc: Moved to...
* libproc_macro_internal/literal.cc: ...here.
* libproc_macro/literal.h: Moved to...
* libproc_macro_internal/literal.h: ...here.
* libproc_macro/proc_macro.cc: Moved to...
* libproc_macro_internal/proc_macro.cc: ...here.
* libproc_macro/proc_macro.h: Moved to...
* libproc_macro_internal/proc_macro.h: ...here.
* libproc_macro/punct.cc: Moved to...
* libproc_macro_internal/punct.cc: ...here.
* libproc_macro/punct.h: Moved to...
* libproc_macro_internal/punct.h: ...here.
* libproc_macro/registration.h: Moved to...
* libproc_macro_internal/registration.h: ...here.
* libproc_macro/rust/bridge.rs: Moved to...
* libproc_macro_internal/rust/bridge.rs: ...here.
* libproc_macro/rust/bridge/ffistring.rs: Moved to...
* libproc_macro_internal/rust/bridge/ffistring.rs: ...here.
* libproc_macro/rust/bridge/group.rs: Moved to...
* libproc_macro_internal/rust/bridge/group.rs: ...here.
* libproc_macro/rust/bridge/ident.rs: Moved to...
* libproc_macro_internal/rust/bridge/ident.rs: ...here.
* libproc_macro/rust/bridge/literal.rs: Moved to...
* libproc_macro_internal/rust/bridge/literal.rs: ...here.
* libproc_macro/rust/bridge/punct.rs: Moved to...
* libproc_macro_internal/rust/bridge/punct.rs: ...here.
* libproc_macro/rust/bridge/span.rs: Moved to...
* libproc_macro_internal/rust/bridge/span.rs: ...here.
* libproc_macro/rust/bridge/token_stream.rs: Moved to...
* libproc_macro_internal/rust/bridge/token_stream.rs: ...here.
* libproc_macro/rust/group.rs: Moved to...
* libproc_macro_internal/rust/group.rs: ...here.
* libproc_macro/rust/ident.rs: Moved to...
* libproc_macro_internal/rust/ident.rs: ...here.
* libproc_macro/rust/lib.rs: Moved to...
* libproc_macro_internal/rust/lib.rs: ...here.
* libproc_macro/rust/literal.rs: Moved to...
* libproc_macro_internal/rust/literal.rs: ...here.
* libproc_macro/rust/punct.rs: Moved to...
* libproc_macro_internal/rust/punct.rs: ...here.
* libproc_macro/rust/span.rs: Moved to...
* libproc_macro_internal/rust/span.rs: ...here.
* libproc_macro/rust/token_stream.rs: Moved to...
* libproc_macro_internal/rust/token_stream.rs: ...here.
* libproc_macro/span.cc: Moved to...
* libproc_macro_internal/span.cc: ...here.
* libproc_macro/span.h: Moved to...
* libproc_macro_internal/span.h: ...here.
* libproc_macro/tokenstream.cc: Moved to...
* libproc_macro_internal/tokenstream.cc: ...here.
* libproc_macro/tokenstream.h: Moved to...
* libproc_macro_internal/tokenstream.h: ...here.
* libproc_macro/tokentree.cc: Moved to...
* libproc_macro_internal/tokentree.cc: ...here.
* libproc_macro/tokentree.h: Moved to...
* libproc_macro_internal/tokentree.h: ...here.
Raiki Tamura [Fri, 18 Aug 2023 04:00:47 +0000 (13:00 +0900)]
gccrs: Add check for no_mangle attribute
gcc/rust/ChangeLog:
* lex/rust-input-source.h: Move constants from here...
* util/rust-codepoint.h (struct Codepoint): ... to here
* util/rust-attributes.cc (check_no_mangle_function): New function.
(AttributeChecker::visit): Use it.
* util/rust-unicode.cc (is_ascii_only): New function.
* util/rust-unicode.h (is_ascii_only): Likewise.
* backend/rust-mangle.cc (legacy_mangle_name): Use it.
* util/rust-punycode.cc (extract_basic_string): Likewise.
* lex/rust-lex.cc (Lexer::parse_byte_char): Likewise.
Philip Herron [Thu, 31 Aug 2023 10:33:27 +0000 (11:33 +0100)]
gccrs: Fix move_val_init
The intrinsic move_val_init was being optimized away even at -O0 because
the function looked "pure" but this adds in the attributes to enforce that
this function has side-effects to override that bad assumption by the
middle-end.
Addresses #1895
gcc/rust/ChangeLog:
* backend/rust-compile-intrinsic.cc (move_val_init_handler): mark as side-effects
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Thu, 31 Aug 2023 10:32:18 +0000 (11:32 +0100)]
gccrs: Fix overflow intrinsic use before init
The overflow intrinsic returns a tuple of (value, boolean) where it value
is the operator result and boolean if it overflowed or not. The intrinsic
here did not initilize the resulting tuple and therefore was creating a use
before init error resulting in garbage results
Addresses #1895
gcc/rust/ChangeLog:
* backend/rust-compile-intrinsic.cc (op_with_overflow_inner): fix use before init
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Mon, 28 Aug 2023 13:20:04 +0000 (14:20 +0100)]
gccrs: Fix bad uninit intrinsic
We were using the DECL_RESULT but this just contains the TREE_TYPE of the
retval. It was also missing taking the address of the destination for the
memset call. This changes the code to create a temp variable for the return
value and asserts the destination size is the same as the size of the
template param.
Fixes #2583
gcc/rust/ChangeLog:
* backend/rust-compile-intrinsic.cc (enter_intrinsic_block): take the locals vector
(uninit_handler): make a temp variable and use the address of it
gcc/testsuite/ChangeLog:
* rust/execute/torture/issue-2583.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
We need to collect the early resolver's macros error to emit them at a
later stage after further expansion in order to retrieve macros defined
by other macro invocations.
Register some mappings for macro invocations and macro definitions.
gcc/rust/ChangeLog:
* resolve/rust-early-name-resolver-2.0.cc (Early::visit):
Collect error instead of emitting it. Also add invocation
registration.
* resolve/rust-early-name-resolver-2.0.h (std::function<void):
Add type definition for collection.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit):
Register macro rule definition in mappings.
* rust-session-manager.cc (Session::expansion): Add macro
resolve error collection.
Muhammad Mahad [Sun, 20 Aug 2023 12:32:29 +0000 (17:32 +0500)]
gccrs: diagnostics: Added non-const `rich_location *` function
Currently, gccrs using the const `rich_location &`, and
then using the cast to convert it to the functions which
was used to emit the errors, having the overloaded is
good, similiar to other frontends.
Owen Avery [Sat, 19 Aug 2023 17:13:21 +0000 (13:13 -0400)]
gccrs: Namespace related tweaks
gcc/rust/ChangeLog:
* backend/rust-tree.cc
(Rust::gt_pch_nx): Move external function declaration ...
(gt_pch_nx): ... out of Rust namespace.
* backend/rust-tree.h
(OVL_FIRST): Qualify function name.
Philip Herron [Mon, 21 Aug 2023 11:35:26 +0000 (12:35 +0100)]
gccrs: Fix compilation of types which hold onto dangling infer vars
There is a case where some generic types are holding onto inference
variable pointers directly. So this gives the backend a chance to do one
final lookup to resolve the type.
This now allows us to compile a full test case for iterators but there is
still one miscompilation in here which results in a segv on O2 and bad
result on -O0.
Addresses #1895
gcc/rust/ChangeLog:
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): do a final lookup
gcc/testsuite/ChangeLog:
* rust/compile/iterators1.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Muhammad Mahad [Tue, 15 Aug 2023 16:29:03 +0000 (21:29 +0500)]
gccrs: [E0391] Detected type dependency cycle
This errorcode & message emits when cycle
detected when computing the super predicates
of `x` which requires computing the super
predicates of `y`, which again requires
computing the super predicates of `x`,
completing the cycle.
gcc/rust/ChangeLog:
* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait):
Updated errorcode & more userfriendly message.
gcc/testsuite/ChangeLog:
* rust/compile/issue-1589.rs: Updated comment for dejagnu.
* rust/compile/trait-cycle.rs: New relevant test.
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Muhammad Mahad [Wed, 16 Aug 2023 12:40:09 +0000 (17:40 +0500)]
gccrs: [E0164] Neither tuple struct nor tuple variant used as a pattern
Checking if pattern has items, before returing solves ICE.
Added error code and rich location.
Also, fixes https://github.com/Rust-GCC/gccrs/issues/2430
gcc/rust/ChangeLog:
* ast/rust-pattern.h: No need of assertion, we are handling it.
* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
Added check which emits error instead of using assertion.
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
Added rich location and error code.
gcc/testsuite/ChangeLog:
* rust/compile/match5.rs:
Updated comment for dejagnu.
* rust/compile/pattern-struct.rs: New test for ICE.
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Muhammad Mahad [Thu, 10 Aug 2023 17:10:09 +0000 (22:10 +0500)]
gccrs: Support for rich-loc & errorcode in parser error
Added method of binding ErrorCode & rich location to
parser and expansion errors.
Fixes https://github.com/Rust-GCC/gccrs/issues/2385
gcc/rust/ChangeLog:
* rust-diagnostics.cc (va_constructor):
Added constructor for all possible cases.
(Error::Error): Updated error struct
for all possible cases.
* rust-diagnostics.h (struct Error):
Updated error struct to support error
code & rich location support.
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Arthur Cohen [Thu, 3 Aug 2023 14:40:07 +0000 (16:40 +0200)]
gccrs: diagnostics: Fix mismatch between new[] and free
We cannot use `free` on a pointer allocated through `new[]`, and this
causes an ASAN failure. This fixes it by using `xcalloc` instead of
`new[]` when creating description buffers for our error codes.
gcc/rust/ChangeLog:
* rust-diagnostics.cc: Switch from new[] to xcalloc
Philip Herron [Sat, 12 Aug 2023 17:18:51 +0000 (18:18 +0100)]
gccrs: improve name mangling hash
We can endup with duplicate symbol names for different intrinsics with our
current hash setup. This adds in the mappings and extra info to improve
hash uniqueness.
Addresses #1895
gcc/rust/ChangeLog:
* backend/rust-compile-intrinsic.cc (check_for_cached_intrinsic):
simplify this cached intrinsic check
* backend/rust-mangle.cc (legacy_mangle_item): use new interface
* typecheck/rust-tyty.h: new managle helper
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
We need to solve the generic argument T from the impl block by infering the
arguments there and applying them so that when we apply the generic
argument bool we dont end up in the case of missing number of generics.
Arthur Cohen [Thu, 3 Aug 2023 15:24:14 +0000 (17:24 +0200)]
gccrs: macro-expand: Keep optional references to last_{def, invoc}
This avoids a use-after-free when reaching the recursion limit.
gcc/rust/ChangeLog:
* expand/rust-macro-expand.h: Keep optional references for last_def
and last_invoc.
* expand/rust-macro-expand.cc (MacroExpander::expand_invoc): Store
optional references.
* rust-session-manager.cc (Session::expansion): Use tl::optional's APIs
for better checking.
* rust/compile/bad_as_bool_char.rs:
Updated comment to pass test case.
* rust/compile/cast1.rs: likewise.
* rust/compile/cast4.rs: likewise.
* rust/compile/cast5.rs: likewise.
* rust/compile/all-cast.rs: New test for all error codes.
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Muhammad Mahad [Tue, 8 Aug 2023 19:27:08 +0000 (00:27 +0500)]
gccrs: [E0658] Unstable langauge feature
gcc/rust/ChangeLog:
* checks/errors/rust-const-checker.cc (ConstChecker::visit):
Use of mutable reference in constant functions.
* checks/errors/rust-feature-gate.cc (FeatureGate::gate):
ErrorCode for intrinsics are subject to change.
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Arthur Cohen [Thu, 27 Jul 2023 08:06:37 +0000 (10:06 +0200)]
gccrs: nr2.0: Add complex macro name resolution test cases
gcc/testsuite/ChangeLog:
* rust/compile/name_resolution6.rs: New test.
* rust/compile/name_resolution7.rs: New test.
* rust/compile/name_resolution8.rs: New test.
* rust/compile/name_resolution9.rs: New test.
Arthur Cohen [Thu, 27 Jul 2023 08:06:13 +0000 (10:06 +0200)]
gccrs: nr2.0: Add Early name resolution visitor
This visitor takes care of resolving macro invocations, procedural macros
and imports - it is used in conjunction with the `TopLevel` pass and
the macro expander.
gcc/rust/ChangeLog:
* Make-lang.in: Add new object file.
* resolve/rust-early-name-resolver-2.0.cc: New file.
* resolve/rust-early-name-resolver-2.0.h: New file.
Arthur Cohen [Thu, 20 Jul 2023 15:52:14 +0000 (17:52 +0200)]
gccrs: forever stack: Add path resolution
gcc/rust/ChangeLog:
* resolve/rust-forever-stack.h
(insert_at_root): New method.
(resolve_path): New method.
(reverse_iter): Iterate on `Node`s instead of `Rib`s
* resolve/rust-forever-stack.hxx: Add path resolution.
Muhammad Mahad [Wed, 2 Aug 2023 11:21:15 +0000 (16:21 +0500)]
gccrs: [E0308] mismatch types on assignment
This errorcode emits when there are
mismatch types between lhs & rhs of
assignment operator & refactored
message. This error code was used
in many test cases, so updated the
error comments.
gcc/rust/ChangeLog:
* typecheck/rust-unify.cc (UnifyRules::emit_type_mismatch):
refactored & called error function.