[gcc r15-8392] gccrs: imports: Add FinalizeImports class

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:333a4cbff7ef62208647c234af12caa35271b59c

commit r15-8392-g333a4cbff7ef62208647c234af12caa35271b59c
Author: Arthur Cohen 
Date:   Thu Apr 4 17:07:54 2024 +0200

gccrs: imports: Add FinalizeImports class

gcc/rust/ChangeLog:

* Make-lang.in: Add new object file.
* ast/rust-item.h: Constify method.
* resolve/rust-early-name-resolver-2.0.cc (Early::go): Call into
the imports finalizer.
(Early::resolve_glob_import): Remove old resolution.
(Early::resolve_rebind_import): Likewise.
* resolve/rust-toplevel-name-resolver-2.0.cc (GlobbingVisitor::go):
New function.
(GlobbingVisitor::visit): Likewise.
(TopLevel::visit): Do not call into handle_use_* functions anymore.
* resolve/rust-toplevel-name-resolver-2.0.h (class GlobbingVisitor):
New.
* resolve/rust-finalize-imports-2.0.cc: New file.
* resolve/rust-finalize-imports-2.0.h: New file.

Diff:
---
 gcc/rust/Make-lang.in  |   1 +
 gcc/rust/ast/rust-item.h   |   2 +-
 gcc/rust/resolve/rust-early-name-resolver-2.0.cc   |  31 +---
 gcc/rust/resolve/rust-finalize-imports-2.0.cc  | 206 +
 gcc/rust/resolve/rust-finalize-imports-2.0.h   |  96 ++
 .../resolve/rust-toplevel-name-resolver-2.0.cc | 112 ---
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h |  25 +--
 7 files changed, 309 insertions(+), 164 deletions(-)

diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index 950cd3af0735..c1a3c1fe9f34 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -131,6 +131,7 @@ GRS_OBJS = \
 rust/rust-default-resolver.o \
 rust/rust-toplevel-name-resolver-2.0.o \
 rust/rust-early-name-resolver-2.0.o \
+   rust/rust-finalize-imports-2.0.o \
 rust/rust-late-name-resolver-2.0.o \
rust/rust-immutable-name-resolution-context.o \
 rust/rust-early-name-resolver.o \
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index bd9113ffa237..2ae7c44398bc 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -1213,7 +1213,7 @@ public:
 
   std::string as_string () const override;
 
-  NewBindType get_new_bind_type () { return bind_type; }
+  NewBindType get_new_bind_type () const { return bind_type; }
 
   void accept_vis (ASTVisitor &vis) override;
 
diff --git a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
index 884c05a93c34..41d0a075 100644
--- a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
@@ -21,6 +21,7 @@
 #include "rust-diagnostics.h"
 #include "rust-toplevel-name-resolver-2.0.h"
 #include "rust-attributes.h"
+#include "rust-finalize-imports-2.0.h"
 
 namespace Rust {
 namespace Resolver2_0 {
@@ -57,6 +58,9 @@ Early::go (AST::Crate &crate)
   for (auto &&import : toplevel.get_imports_to_resolve ())
 build_import_mapping (std::move (import));
 
+  // Once this is done, we finalize their resolution
+  FinalizeImports::go (import_mappings, toplevel, ctx);
+
   // We now proceed with resolving macros, which can be nested in almost any
   // items
   textual_scope.push ();
@@ -81,10 +85,6 @@ Early::resolve_glob_import (TopLevel::ImportKind &&glob)
   // up the module proper in `FinalizeImports`
   import_mappings.insert ({std::move (glob), resolved->get_node_id ()});
 
-  // FIXME: This needs to be done in `FinalizeImports`
-  // GlobbingVisitor gvisitor (ctx);
-  // gvisitor.go (result.value ());
-
   return true;
 }
 
@@ -169,29 +169,6 @@ Early::resolve_rebind_import (TopLevel::ImportKind 
&&rebind_import)
 {
   auto &path = rebind_import.to_resolve;
 
-  // We can fetch the value here as `resolve_rebind` will only be called on
-  // imports of the right kind
-  auto &rebind = rebind_import.rebind.value ();
-
-  location_t locus = UNKNOWN_LOCATION;
-  std::string declared_name;
-
-  // FIXME: This needs to be done in `FinalizeImports`
-  switch (rebind.get_new_bind_type ())
-{
-case AST::UseTreeRebind::NewBindType::IDENTIFIER:
-  declared_name = rebind.get_identifier ().as_string ();
-  locus = rebind.get_identifier ().get_locus ();
-  break;
-case AST::UseTreeRebind::NewBindType::NONE:
-  declared_name = path.get_final_segment ().as_string ();
-  locus = path.get_final_segment ().get_locus ();
-  break;
-case AST::UseTreeRebind::NewBindType::WILDCARD:
-  rust_unreachable ();
-  break;
-}
-
   return ctx.values.resolve_path (path.get_segments ())
 .or_else ([&] () { return ctx.types.resolve_path (path.get_segments ()); })
 .or_else ([&] () { return ctx.macros.resolve_path (path.get_segments ()); 
})
diff --git a/gcc/rust/resolve/rust-finalize-imports-2.0.cc 
b/gcc/rust/resolve/rust-finalize-imports-2.0.cc
new file mode 100644
inde

[gcc r15-8397] gccrs: Insert imports in all namespaces they were resolved in

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:3118129c0c96a87f187b319c65b819b71e633f2f

commit r15-8397-g3118129c0c96a87f187b319c65b819b71e633f2f
Author: Arthur Cohen 
Date:   Mon Apr 8 18:44:15 2024 +0200

gccrs: Insert imports in all namespaces they were resolved in

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc 
(Early::resolve_simple_import):
Insert import in all namespaces where they were resolved.
(Early::resolve_rebind_import): Likewise.
* resolve/rust-early-name-resolver-2.0.h: Improve APIs, make them
accept multiple resolutions.
* resolve/rust-finalize-imports-2.0.cc: Handle multiple resolutions.
* resolve/rust-name-resolution-context.h (resolve_path): Remove 
function.

Diff:
---
 gcc/rust/resolve/rust-early-name-resolver-2.0.cc | 74 ++--
 gcc/rust/resolve/rust-early-name-resolver-2.0.h  | 66 +
 gcc/rust/resolve/rust-finalize-imports-2.0.cc| 17 +++---
 gcc/rust/resolve/rust-name-resolution-context.h  | 26 -
 4 files changed, 106 insertions(+), 77 deletions(-)

diff --git a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
index 47582a6f339a..5201c32e24dc 100644
--- a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
@@ -94,44 +94,54 @@ Early::resolve_glob_import (NodeId use_dec_id, 
TopLevel::ImportKind &&glob)
 bool
 Early::resolve_simple_import (NodeId use_dec_id, TopLevel::ImportKind &&import)
 {
-  return ctx.resolve_path (import.to_resolve)
-.map ([&] (std::pair def_ns) {
-  // We insert an empty vector, unless an element was already present for
-  // `use_dec_id` - which is returned in the tuple's first member
-  auto tuple = import_mappings.insert ({use_dec_id, {}});
-  // We then get that tuple's first member, which will be an iterator to 
the
-  // existing vec> OR an iterator to our newly
-  // created empty vector (plus its key since this is a hashmap iterator).
-  // we then access the second member of the pair to get access to the
-  // vector directly.
-  auto &imports = tuple.first->second;
-
-  imports.emplace_back (
-   std::make_pair (std::move (import), ImportData::Simple (def_ns)));
-})
-.has_value ();
+  auto definitions = resolve_path_in_all_ns (import.to_resolve);
+
+  // if we've found at least one definition, then we're good
+  if (definitions.empty ())
+return false;
+
+  // We insert an empty vector, unless an element was already present for
+  // `use_dec_id` - which is returned in the tuple's first member
+  auto tuple = import_mappings.insert ({use_dec_id, {}});
+  // We then get that tuple's first member, which will be an iterator to the
+  // existing vec> OR an iterator to our newly
+  // created empty vector (plus its key since this is a hashmap iterator).
+  // we then access the second member of the pair to get access to the
+  // vector directly.
+  auto &imports = tuple.first->second;
+
+  imports.emplace_back (
+std::make_pair (std::move (import),
+   ImportData::Simple (std::move (definitions;
+
+  return true;
 }
 
 bool
 Early::resolve_rebind_import (NodeId use_dec_id,
  TopLevel::ImportKind &&rebind_import)
 {
-  return ctx.resolve_path (rebind_import.to_resolve)
-.map ([&] (std::pair def_ns) {
-  // We insert an empty vector, unless an element was already present for
-  // `use_dec_id` - which is returned in the tuple's first member
-  auto tuple = import_mappings.insert ({use_dec_id, {}});
-  // We then get that tuple's first member, which will be an iterator to 
the
-  // existing vec> OR an iterator to our newly
-  // created empty vector (plus its key since this is a hashmap iterator).
-  // we then access the second member of the pair to get access to the
-  // vector directly.
-  auto &imports = tuple.first->second;
-
-  imports.emplace_back (std::make_pair (std::move (rebind_import),
-   ImportData::Rebind (def_ns)));
-})
-.has_value ();
+  auto definitions = resolve_path_in_all_ns (rebind_import.to_resolve);
+
+  // if we've found at least one definition, then we're good
+  if (definitions.empty ())
+return false;
+
+  // We insert an empty vector, unless an element was already present for
+  // `use_dec_id` - which is returned in the tuple's first member
+  auto tuple = import_mappings.insert ({use_dec_id, {}});
+  // We then get that tuple's first member, which will be an iterator to the
+  // existing vec> OR an iterator to our newly
+  // created empty vector (plus its key since this is a hashmap iterator).
+  // we then access the second member of the pair to get access to the
+  // vector directly.
+  auto &imports = tuple.first->second;
+
+  imports.emplace_back (
+std::make_pair (std:

[gcc r15-8405] gccrs: Add default resolver parent functions by default

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:0da43a254cfbf7c7476c2e2a539b816d3bd5c89a

commit r15-8405-g0da43a254cfbf7c7476c2e2a539b816d3bd5c89a
Author: Pierre-Emmanuel Patry 
Date:   Thu Sep 5 15:39:59 2024 +0200

gccrs: Add default resolver parent functions by default

gcc/rust/ChangeLog:

* resolve/rust-finalize-imports-2.0.h: Add parent member functions
from default resolver.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/resolve/rust-finalize-imports-2.0.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/gcc/rust/resolve/rust-finalize-imports-2.0.h 
b/gcc/rust/resolve/rust-finalize-imports-2.0.h
index 2b3157e9b421..0fba5a517a19 100644
--- a/gcc/rust/resolve/rust-finalize-imports-2.0.h
+++ b/gcc/rust/resolve/rust-finalize-imports-2.0.h
@@ -97,6 +97,8 @@ public:
   void go (AST::Crate &crate);
 
 private:
+  using AST::DefaultASTVisitor::visit;
+
   void visit (AST::UseDeclaration &) override;
 
   Early::ImportMappings data;


[gcc r15-8407] gccrs: Move failing test to xfail

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:2aed733f113a2bea5bb2f92e78d978dd90b50afc

commit r15-8407-g2aed733f113a2bea5bb2f92e78d978dd90b50afc
Author: Pierre-Emmanuel Patry 
Date:   Wed Sep 4 17:13:04 2024 +0200

gccrs: Move failing test to xfail

We want to begin experimenting with this new name resolution 2.0
algorithm as soon as possible. This test highlight a problem where the
compiler should emit an error and should be fixed soon.

gcc/testsuite/ChangeLog:

* rust/compile/name_resolution21.rs: Move to...
* rust/compile/xfail/name_resolution21.rs: ...here.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/testsuite/rust/compile/{ => xfail}/name_resolution21.rs | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/rust/compile/name_resolution21.rs 
b/gcc/testsuite/rust/compile/xfail/name_resolution21.rs
similarity index 62%
rename from gcc/testsuite/rust/compile/name_resolution21.rs
rename to gcc/testsuite/rust/compile/xfail/name_resolution21.rs
index 3d0af2b37b76..df48d0015987 100644
--- a/gcc/testsuite/rust/compile/name_resolution21.rs
+++ b/gcc/testsuite/rust/compile/xfail/name_resolution21.rs
@@ -5,7 +5,8 @@ pub mod foo {
 }
 
 use foo::bar;
-use foo::bar; // { dg-error ".bar. defined multiple times" }
+use foo::bar;
+// { dg-error ".bar. defined multiple times" "" { xfail *-*-* } .-1 }
 
 fn main() {
 bar!();


[gcc r15-8396] gccrs: early: Do not emit errors for unresolved imports, store them instead

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:924446743f6e21efa745ec1b051e9f37887e32f9

commit r15-8396-g924446743f6e21efa745ec1b051e9f37887e32f9
Author: Arthur Cohen 
Date:   Sat Apr 6 23:23:39 2024 +0200

gccrs: early: Do not emit errors for unresolved imports, store them instead

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc (Early::visit_attributes):
Store errors for later.

Diff:
---
 gcc/rust/resolve/rust-early-name-resolver-2.0.cc | 15 +--
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
index ac8eb940c8d5..47582a6f339a 100644
--- a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
@@ -161,8 +161,9 @@ Early::build_import_mapping (
}
 
   if (!found)
-   rust_error_at (path.get_final_segment ().get_locus (), ErrorCode::E0433,
-  "unresolved import %qs", path.as_string ().c_str ());
+   collect_error (Error (path.get_final_segment ().get_locus (),
+ ErrorCode::E0433, "unresolved import %qs",
+ path.as_string ().c_str ()));
 }
 }
 
@@ -303,8 +304,9 @@ Early::visit_attributes (std::vector &attrs)
  if (!definition.has_value ())
{
  // FIXME: Change to proper error message
- rust_error_at (trait.get ().get_locus (),
-"could not resolve trait");
+ collect_error (Error (trait.get ().get_locus (),
+   "could not resolve trait %qs",
+   trait.get ().as_string ().c_str ()));
  continue;
}
 
@@ -326,8 +328,9 @@ Early::visit_attributes (std::vector &attrs)
  if (!definition.has_value ())
{
  // FIXME: Change to proper error message
- rust_error_at (attr.get_locus (),
-"could not resolve attribute macro invocation");
+ collect_error (
+   Error (attr.get_locus (),
+  "could not resolve attribute macro invocation"));
  return;
}
  auto pm_def = mappings.lookup_attribute_proc_macro_def (


[gcc r15-8400] gccrs: Loop on expansion if a new export has been defined

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:1ac4b59dee2ae094bee351d67bf15321b48499a3

commit r15-8400-g1ac4b59dee2ae094bee351d67bf15321b48499a3
Author: Pierre-Emmanuel Patry 
Date:   Wed Aug 21 17:14:46 2024 +0200

gccrs: Loop on expansion if a new export has been defined

When a use statement requires a reexported item it cannot find it in
the same pass, an additional pass shall be performed. This means we need
to detect whether a new item has been reexported and resolve until the
end.

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc (Early::Early): Add dirty
flag initialization.
(Early::go): Set dirty flag using top level resolver.
* resolve/rust-early-name-resolver-2.0.h: Add dirty flag.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::TopLevel):
Initialize dirty flag.
(TopLevel::insert_or_error_out): Set dirty flag on successful
namespace modification.
* resolve/rust-toplevel-name-resolver-2.0.h: Add dirty flag.
* rust-session-manager.cc (Session::expansion): Modify fixed point
condition to include name resolution modifications.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/resolve/rust-early-name-resolver-2.0.cc| 4 +++-
 gcc/rust/resolve/rust-early-name-resolver-2.0.h | 4 
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc | 7 ---
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h  | 6 ++
 gcc/rust/rust-session-manager.cc| 5 -
 5 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
index c4f9b27e297a..55330487fd7a 100644
--- a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
@@ -26,7 +26,8 @@
 namespace Rust {
 namespace Resolver2_0 {
 
-Early::Early (NameResolutionContext &ctx) : DefaultResolver (ctx) {}
+Early::Early (NameResolutionContext &ctx) : DefaultResolver (ctx), dirty 
(false)
+{}
 
 void
 Early::insert_once (AST::MacroInvocation &invocation, NodeId resolved)
@@ -61,6 +62,7 @@ Early::go (AST::Crate &crate)
   // Once this is done, we finalize their resolution
   FinalizeImports (std::move (import_mappings), toplevel, ctx).go (crate);
 
+  dirty = toplevel.is_dirty ();
   // We now proceed with resolving macros, which can be nested in almost any
   // items
   textual_scope.push ();
diff --git a/gcc/rust/resolve/rust-early-name-resolver-2.0.h 
b/gcc/rust/resolve/rust-early-name-resolver-2.0.h
index ec1d914c05da..a7ad0f78fb8e 100644
--- a/gcc/rust/resolve/rust-early-name-resolver-2.0.h
+++ b/gcc/rust/resolve/rust-early-name-resolver-2.0.h
@@ -34,9 +34,13 @@ class Early : public DefaultResolver
 {
   using DefaultResolver::visit;
 
+  bool dirty;
+
 public:
   Early (NameResolutionContext &ctx);
 
+  bool is_dirty () { return dirty; }
+
   void go (AST::Crate &crate);
 
   const std::vector &get_macro_resolve_errors () const
diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
index 47f3adee14c2..6a54978a67cb 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -27,7 +27,7 @@ namespace Rust {
 namespace Resolver2_0 {
 
 TopLevel::TopLevel (NameResolutionContext &resolver)
-  : DefaultResolver (resolver)
+  : DefaultResolver (resolver), dirty (false)
 {}
 
 template 
@@ -47,8 +47,9 @@ TopLevel::insert_or_error_out (const Identifier &identifier,
   node_locations.emplace (node_id, locus);
 
   auto result = ctx.insert (identifier, node_id, ns);
-
-  if (!result && result.error ().existing != node_id)
+  if (result)
+dirty = true;
+  else if (result.error ().existing != node_id)
 {
   rich_location rich_loc (line_table, locus);
   rich_loc.add_range (node_locations[result.error ().existing]);
diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
index acb60d36e133..99ed65398c6a 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
@@ -43,6 +43,8 @@ public:
 
   void go (AST::Crate &crate);
 
+  bool is_dirty () { return dirty; }
+
   // Each import will be transformed into an instance of `ImportKind`, a class
   // representing some of the data we need to resolve in the
   // `EarlyNameResolver`. Basically, for each `UseTree` that we see in
@@ -129,6 +131,10 @@ public:
Namespace ns);
 
 private:
+  // If a new export has been defined whilst visiting the visitor is considered
+  // dirty
+  bool dirty;
+
   // FIXME: Do we move these to our mappings?
   std::unordered_map node_locations;
 
diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc
index a5cd97f18d76..5668d4

[gcc r15-8406] gccrs: Make AST default visitor visit functions public

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:331ddca72d18102751f301421979eb20213c0723

commit r15-8406-g331ddca72d18102751f301421979eb20213c0723
Author: Pierre-Emmanuel Patry 
Date:   Thu Sep 5 16:13:30 2024 +0200

gccrs: Make AST default visitor visit functions public

Make those functions public so they can be used within a lambda on GCC
4.8.

gcc/rust/ChangeLog:

* ast/rust-ast-visitor.h: Make visit functions public.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/ast/rust-ast-visitor.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/gcc/rust/ast/rust-ast-visitor.h b/gcc/rust/ast/rust-ast-visitor.h
index 56fea88a0619..50b93016d62a 100644
--- a/gcc/rust/ast/rust-ast-visitor.h
+++ b/gcc/rust/ast/rust-ast-visitor.h
@@ -244,7 +244,6 @@ class DefaultASTVisitor : public ASTVisitor
 public:
   virtual void visit (AST::Crate &crate);
 
-protected:
   virtual void visit (AST::Token &tok) override;
   virtual void visit (AST::DelimTokenTree &delim_tok_tree) override;
   virtual void visit (AST::AttrInputMetaItemContainer &input) override;


[gcc r15-8404] gccrs: Change lambda content with default visitor call

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:75a2b87938569850027e038a6af3c0f492be2cbf

commit r15-8404-g75a2b87938569850027e038a6af3c0f492be2cbf
Author: Pierre-Emmanuel Patry 
Date:   Thu Sep 5 13:54:48 2024 +0200

gccrs: Change lambda content with default visitor call

We can reduce code duplication by using the default visitor functions
from within the scoped lambda function.

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc (DefaultResolver::visit): Use
default visitor instead.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/resolve/rust-default-resolver.cc | 83 +--
 1 file changed, 13 insertions(+), 70 deletions(-)

diff --git a/gcc/rust/resolve/rust-default-resolver.cc 
b/gcc/rust/resolve/rust-default-resolver.cc
index 026172167998..57b1cc448158 100644
--- a/gcc/rust/resolve/rust-default-resolver.cc
+++ b/gcc/rust/resolve/rust-default-resolver.cc
@@ -30,13 +30,7 @@ DefaultResolver::visit (AST::BlockExpr &expr)
   // extracting the lambda from the `scoped` call otherwise the code looks like
   // a hot turd thanks to our .clang-format
 
-  auto inner_fn = [this, &expr] () {
-for (auto &stmt : expr.get_statements ())
-  stmt->accept_vis (*this);
-
-if (expr.has_tail_expr ())
-  expr.get_tail_expr ().accept_vis (*this);
-  };
+  auto inner_fn = [this, &expr] () { AST::DefaultASTVisitor::visit (expr); };
 
   ctx.scoped (Rib::Kind::Normal, expr.get_node_id (), inner_fn);
 }
@@ -44,10 +38,7 @@ DefaultResolver::visit (AST::BlockExpr &expr)
 void
 DefaultResolver::visit (AST::Module &module)
 {
-  auto item_fn = [this, &module] () {
-for (auto &item : module.get_items ())
-  item->accept_vis (*this);
-  };
+  auto item_fn = [this, &module] () { AST::DefaultASTVisitor::visit (module); 
};
 
   ctx.scoped (Rib::Kind::Module, module.get_node_id (), item_fn,
  module.get_name ());
@@ -56,38 +47,8 @@ DefaultResolver::visit (AST::Module &module)
 void
 DefaultResolver::visit (AST::Function &function)
 {
-  auto def_fn = [this, &function] () {
-for (auto &p : function.get_function_params ())
-  {
-   if (p->is_variadic ())
- {
-   auto ¶m = static_cast (*p);
-   if (param.has_pattern ())
- param.get_pattern ().accept_vis (*this);
- }
-   else if (p->is_self ())
- {
-   auto ¶m = static_cast (*p);
-
-   if (param.has_type ())
- param.get_type ().accept_vis (*this);
-
-   param.get_lifetime ().accept_vis (*this);
- }
-   else
- {
-   auto ¶m = static_cast (*p);
-   param.get_pattern ().accept_vis (*this);
-   param.get_type ().accept_vis (*this);
- }
-  }
-
-if (function.has_return_type ())
-  visit (function.get_return_type ());
-
-if (function.has_body ())
-  function.get_definition ().value ()->accept_vis (*this);
-  };
+  auto def_fn
+= [this, &function] () { AST::DefaultASTVisitor::visit (function); };
 
   ctx.scoped (Rib::Kind::Function, function.get_node_id (), def_fn);
 }
@@ -95,20 +56,14 @@ DefaultResolver::visit (AST::Function &function)
 void
 DefaultResolver::visit (AST::ForLoopExpr &expr)
 {
-  ctx.scoped (Rib::Kind::Normal, expr.get_node_id (), [this, &expr] () {
-expr.get_pattern ().accept_vis (*this);
-expr.get_iterator_expr ().accept_vis (*this);
-expr.get_loop_block ().accept_vis (*this);
-  });
+  ctx.scoped (Rib::Kind::Normal, expr.get_node_id (),
+ [this, &expr] () { AST::DefaultASTVisitor::visit (expr); });
 }
 
 void
 DefaultResolver::visit (AST::Trait &trait)
 {
-  auto inner_fn = [this, &trait] () {
-for (auto &item : trait.get_trait_items ())
-  item->accept_vis (*this);
-  };
+  auto inner_fn = [this, &trait] () { AST::DefaultASTVisitor::visit (trait); };
 
   ctx.scoped (Rib::Kind::TraitOrImpl, trait.get_node_id (), inner_fn,
  trait.get_identifier () /* FIXME: Is that valid?*/);
@@ -117,11 +72,7 @@ DefaultResolver::visit (AST::Trait &trait)
 void
 DefaultResolver::visit (AST::InherentImpl &impl)
 {
-  auto inner_fn = [this, &impl] () {
-visit (impl.get_type ());
-for (auto &item : impl.get_impl_items ())
-  item->accept_vis (*this);
-  };
+  auto inner_fn = [this, &impl] () { AST::DefaultASTVisitor::visit (impl); };
 
   ctx.scoped (Rib::Kind::TraitOrImpl, impl.get_node_id (), inner_fn);
 }
@@ -129,10 +80,7 @@ DefaultResolver::visit (AST::InherentImpl &impl)
 void
 DefaultResolver::visit (AST::TraitImpl &impl)
 {
-  auto inner_fn = [this, &impl] () {
-for (auto &item : impl.get_impl_items ())
-  item->accept_vis (*this);
-  };
+  auto inner_fn = [this, &impl] () { AST::DefaultASTVisitor::visit (impl); };
 
   ctx.scoped (Rib::Kind::TraitOrImpl, impl.get_node_id (), inner_fn);
 }
@@ -155,10 +103,7 @@ DefaultResolver::visit (AST::Enum &type)
 {
   // FIXME: Do we need to scope anything by default?
 
-  auto variant_fn = [this, &type

[gcc r15-8390] gccrs: toplevel: Build list of imports for Early to resolve

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:8ed0cc70f73ab88218e587977cc0c181eb58453e

commit r15-8390-g8ed0cc70f73ab88218e587977cc0c181eb58453e
Author: Arthur Cohen 
Date:   Thu Apr 4 15:42:29 2024 +0200

gccrs: toplevel: Build list of imports for Early to resolve

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc: Comment out handle_use
call and error emission.
* resolve/rust-toplevel-name-resolver-2.0.h: Create ImportKind 
class.

Diff:
---
 .../resolve/rust-toplevel-name-resolver-2.0.cc | 37 --
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h | 59 ++
 2 files changed, 81 insertions(+), 15 deletions(-)

diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
index b18b86ca8218..3ce163075081 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -749,21 +749,28 @@ TopLevel::visit (AST::UseDeclaration &use)
   const auto &tree = use.get_tree ();
   flatten (tree.get (), paths, glob_path, rebind_path, this->ctx);
 
-  for (auto &path : paths)
-if (!handle_use_dec (path))
-  rust_error_at (path.get_final_segment ().get_locus (), ErrorCode::E0433,
-"unresolved import %qs", path.as_string ().c_str ());
-
-  for (auto &glob : glob_path)
-if (!handle_use_glob (glob))
-  rust_error_at (glob.get_final_segment ().get_locus (), ErrorCode::E0433,
-"unresolved import %qs", glob.as_string ().c_str ());
-
-  for (auto &rebind : rebind_path)
-if (!handle_rebind (rebind))
-  rust_error_at (rebind.first.get_final_segment ().get_locus (),
-ErrorCode::E0433, "unresolved import %qs",
-rebind.first.as_string ().c_str ());
+  for (auto &&path : paths)
+imports_to_resolve.emplace_back (ImportKind::Simple (std::move (path)));
+
+  // if (!handle_use_dec (path))
+  //   rust_error_at (path.get_final_segment ().get_locus (), ErrorCode::E0433,
+  //"unresolved import %qs", path.as_string ().c_str ());
+
+  for (auto &&glob : glob_path)
+imports_to_resolve.emplace_back (ImportKind::Glob (std::move (glob)));
+
+  // if (!handle_use_glob (glob))
+  //   rust_error_at (glob.get_final_segment ().get_locus (), ErrorCode::E0433,
+  //"unresolved import %qs", glob.as_string ().c_str ());
+
+  for (auto &&rebind : rebind_path)
+imports_to_resolve.emplace_back (
+  ImportKind::Rebind (std::move (rebind.first), std::move 
(rebind.second)));
+
+  // if (!handle_rebind (rebind))
+  //   rust_error_at (rebind.first.get_final_segment ().get_locus (),
+  //ErrorCode::E0433, "unresolved import %qs",
+  //rebind.first.as_string ().c_str ());
 }
 
 } // namespace Resolver2_0
diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
index affddb97d50c..12c85c86a815 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
@@ -19,7 +19,10 @@
 #ifndef RUST_TOPLEVEL_NAME_RESOLVER_2_0_H
 #define RUST_TOPLEVEL_NAME_RESOLVER_2_0_H
 
+#include "optional.h"
 #include "rust-ast-visitor.h"
+#include "rust-ast.h"
+#include "rust-item.h"
 #include "rust-name-resolution-context.h"
 #include "rust-default-resolver.h"
 
@@ -87,6 +90,62 @@ private:
   // definition and its new local name.
   std::unordered_map node_forwarding;
 
+  // Each import will be transformed into an instance of `ImportKind`, a class
+  // representing some of the data we need to resolve in the
+  // `EarlyNameResolver`. Basically, for each `UseTree` that we see in
+  // `TopLevel`, create one of these. `TopLevel` should build a list of these
+  // `ImportKind`s, which `Early` can then resolve to their proper definitions.
+  // Then, a final pass will insert the definitions into the `ForeverStack` -
+  // `FinalizeImports`.
+  //
+  // Using this struct should be very simple - each path within a `UseTree`
+  // becomes one `ImportKind`. The complex case is glob imports, in which case
+  // one glob import will become one `ImportKind` which will later become
+  // multiple definitions thanks to the `GlobbingVisitor`.
+  struct ImportKind
+  {
+enum class Kind
+{
+  Glob,
+  Simple,
+  Rebind,
+} kind;
+
+static ImportKind Glob (AST::SimplePath &&to_resolve)
+{
+  return ImportKind (Kind::Glob, std::move (to_resolve));
+}
+
+static ImportKind Simple (AST::SimplePath &&to_resolve)
+{
+  return ImportKind (Kind::Simple, std::move (to_resolve));
+}
+
+static ImportKind Rebind (AST::SimplePath &&to_resolve,
+ AST::UseTreeRebind &&rebind)
+{
+  return ImportKind (Kind::Rebind, std::move (to_resolve),
+std::move (rebind));
+}
+
+// The path for `Early` to resolve.
+AST::SimplePath to_resolve;
+
+// 

[gcc r15-8388] gccrs: nr2.0: default-visitor: Conditionally visit type in self parameters.

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:68af48783006d7c51371b0e8634e82ef0256e4ab

commit r15-8388-g68af48783006d7c51371b0e8634e82ef0256e4ab
Author: Arthur Cohen 
Date:   Wed Mar 27 17:20:15 2024 +0100

gccrs: nr2.0: default-visitor: Conditionally visit type in self parameters.

This could trigger an assertions as `get_type` on `SelfParam` asserts that
the self param does have a given type, which is not always the case.

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc (DefaultResolver::visit): Do not
visit self's type if it does not have one.

Diff:
---
 gcc/rust/resolve/rust-default-resolver.cc | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/resolve/rust-default-resolver.cc 
b/gcc/rust/resolve/rust-default-resolver.cc
index 89e7e39f5bb8..b2cdc5f52d2a 100644
--- a/gcc/rust/resolve/rust-default-resolver.cc
+++ b/gcc/rust/resolve/rust-default-resolver.cc
@@ -68,7 +68,10 @@ DefaultResolver::visit (AST::Function &function)
else if (p->is_self ())
  {
auto ¶m = static_cast (*p);
-   param.get_type ().accept_vis (*this);
+
+   if (param.has_type ())
+ param.get_type ().accept_vis (*this);
+
param.get_lifetime ().accept_vis (*this);
  }
else


[gcc r15-8413] gccrs: This test requires the standard library

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:6f8ca7f2516012326d2a68927543fff5e1a29611

commit r15-8413-g6f8ca7f2516012326d2a68927543fff5e1a29611
Author: Pierre-Emmanuel Patry 
Date:   Thu Sep 26 22:51:17 2024 +0200

gccrs: This test requires the standard library

It requires the standard library and Copy to work correctly which we
cannot provide. Stopping the compiler before the name resolution allow us
to prevent an error whilst resolving Copy and keep the test's goal.

gcc/testsuite/ChangeLog:

* rust/compile/functions_without_body.rs: Add compile step argument.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/testsuite/rust/compile/functions_without_body.rs | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/testsuite/rust/compile/functions_without_body.rs 
b/gcc/testsuite/rust/compile/functions_without_body.rs
index 36ddea52161e..0a0e6021e84b 100644
--- a/gcc/testsuite/rust/compile/functions_without_body.rs
+++ b/gcc/testsuite/rust/compile/functions_without_body.rs
@@ -1,3 +1,4 @@
+// { dg-additional-options "-frust-compile-until=nameresolution" }
 struct MyStruct;
 
 trait X {}


[gcc r15-8424] gccrs: Fix some issues with canonical path fetching in name resolution 2.0

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:e71b4d671a71588c0fd7d6833bbec539e82562e3

commit r15-8424-ge71b4d671a71588c0fd7d6833bbec539e82562e3
Author: Owen Avery 
Date:   Tue Oct 8 23:29:27 2024 -0400

gccrs: Fix some issues with canonical path fetching in name resolution 2.0

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-enumitem.cc: Add includes.
(TypeCheckEnumItem::visit): Fetch canonical paths properly when
name resolution 2.0 is enabled.
* typecheck/rust-hir-type-check-implitem.cc: Add includes.
(TypeCheckImplItem::visit): Fetch canonical paths properly when
name resolution 2.0 is enabled.
* typecheck/rust-hir-type-check-item.cc: Add include.
(TypeCheckItem::visit): Fetch canonical paths properly when name
resolution 2.0 is enabled.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/typecheck/rust-hir-type-check-enumitem.cc | 80 +++---
 gcc/rust/typecheck/rust-hir-type-check-implitem.cc | 23 ++-
 gcc/rust/typecheck/rust-hir-type-check-item.cc | 43 ++--
 gcc/testsuite/rust/compile/nr2/exclude |  8 ---
 4 files changed, 132 insertions(+), 22 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc 
b/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc
index 72d8791fe561..a9154c647867 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc
@@ -20,6 +20,10 @@
 #include "rust-hir-type-check-expr.h"
 #include "rust-hir-type-check-enumitem.h"
 #include "rust-type-util.h"
+#include "rust-immutable-name-resolution-context.h"
+
+// for flag_name_resolution_2_0
+#include "options.h"
 
 namespace Rust {
 namespace Resolver {
@@ -75,8 +79,23 @@ TypeCheckEnumItem::visit (HIR::EnumItem &item)
   rust_assert (ok);
   context->insert_type (mapping, isize);
 
-  auto canonical_path
-= mappings.lookup_canonical_path (item.get_mappings ().get_nodeid ());
+  tl::optional canonical_path;
+
+  if (flag_name_resolution_2_0)
+{
+  auto nr_ctx
+   = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+  canonical_path
+   = nr_ctx.types.to_canonical_path (item.get_mappings ().get_nodeid ());
+}
+  else
+{
+  canonical_path
+   = mappings.lookup_canonical_path (item.get_mappings ().get_nodeid ());
+}
+
+  rust_assert (canonical_path.has_value ());
 
   RustIdent ident{*canonical_path, item.get_locus ()};
   variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (),
@@ -104,8 +123,23 @@ TypeCheckEnumItem::visit (HIR::EnumItemDiscriminant &item)
  TyTy::TyWithLocation (expected_ty),
  TyTy::TyWithLocation (capacity_type), item.get_locus ());
 
-  auto canonical_path
-= mappings.lookup_canonical_path (item.get_mappings ().get_nodeid ());
+  tl::optional canonical_path;
+
+  if (flag_name_resolution_2_0)
+{
+  auto nr_ctx
+   = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+  canonical_path
+   = nr_ctx.types.to_canonical_path (item.get_mappings ().get_nodeid ());
+}
+  else
+{
+  canonical_path
+   = mappings.lookup_canonical_path (item.get_mappings ().get_nodeid ());
+}
+
+  rust_assert (canonical_path.has_value ());
 
   RustIdent ident{*canonical_path, item.get_locus ()};
   variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (),
@@ -151,8 +185,23 @@ TypeCheckEnumItem::visit (HIR::EnumItemTuple &item)
   rust_assert (ok);
   context->insert_type (mapping, isize);
 
-  auto canonical_path
-= mappings.lookup_canonical_path (item.get_mappings ().get_nodeid ());
+  tl::optional canonical_path;
+
+  if (flag_name_resolution_2_0)
+{
+  auto nr_ctx
+   = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+  canonical_path
+   = nr_ctx.types.to_canonical_path (item.get_mappings ().get_nodeid ());
+}
+  else
+{
+  canonical_path
+   = mappings.lookup_canonical_path (item.get_mappings ().get_nodeid ());
+}
+
+  rust_assert (canonical_path.has_value ());
 
   RustIdent ident{*canonical_path, item.get_locus ()};
   variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (),
@@ -197,8 +246,23 @@ TypeCheckEnumItem::visit (HIR::EnumItemStruct &item)
   rust_assert (ok);
   context->insert_type (mapping, isize);
 
-  auto canonical_path
-= mappings.lookup_canonical_path (item.get_mappings ().get_nodeid ());
+  tl::optional canonical_path;
+
+  if (flag_name_resolution_2_0)
+{
+  auto nr_ctx
+   = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+  canonical_path
+   = nr_ctx.types.to_canonical_path (item.get_mappings ().get_nodeid ());
+}
+  else
+{
+  canonical_path
+   = mappings.lookup_canonical_path (item.get_mappings (

[gcc r15-8414] gccrs: Add box definition to avoid error

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:141b2f9c7bb9b4060d39a0ae404c50b0c71b5ba0

commit r15-8414-g141b2f9c7bb9b4060d39a0ae404c50b0c71b5ba0
Author: Pierre-Emmanuel Patry 
Date:   Thu Sep 26 22:59:48 2024 +0200

gccrs: Add box definition to avoid error

Box definition is part of the standard library and cannot be found during
name resolution. This simple definition prevent any error from being
emitted.

gcc/testsuite/ChangeLog:

* rust/compile/box_syntax_feature_gate.rs: Add box land item
definition.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/testsuite/rust/compile/box_syntax_feature_gate.rs | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/gcc/testsuite/rust/compile/box_syntax_feature_gate.rs 
b/gcc/testsuite/rust/compile/box_syntax_feature_gate.rs
index 8eb5503dde6c..5f62a59a04bf 100644
--- a/gcc/testsuite/rust/compile/box_syntax_feature_gate.rs
+++ b/gcc/testsuite/rust/compile/box_syntax_feature_gate.rs
@@ -1,4 +1,6 @@
 // { dg-options "-frust-compile-until=lowering" }
+#[lang = "owned_box"]
+pub struct Box;
 
 fn main() {
 let x: Box<_> = box 1; //{ dg-error "box expression syntax is 
experimental." "" { target *-*-* }  }


[gcc r15-8300] gccrs: [gccrs#3045] #[may_dangle] in safe impl

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:3c5e87297bd56b7d95ecdf9f3ca9e9110cfc34c7

commit r15-8300-g3c5e87297bd56b7d95ecdf9f3ca9e9110cfc34c7
Author: Liam Naddell 
Date:   Sat Jul 6 20:34:28 2024 -0400

gccrs: [gccrs#3045] #[may_dangle] in safe impl

gcc/rust/ChangeLog:
* ast/rust-ast.cc:
Fix Attribute constructors to copy inner_attribute
* checks/errors/rust-unsafe-checker.cc:
Add pass for #[may_dangle] in safe impl's
* hir/rust-ast-lower-item.cc:
Add support for unsafe impl's
* hir/rust-ast-lower-type.cc:
Lower attributes in impl's from AST to HIR
* hir/rust-hir-dump.cc:
Change single attribute to AttrVec
* hir/tree/rust-hir-item.h:
Add unsafe support to Impl blocks in HIR
* hir/tree/rust-hir.cc:
Change single attribute to AttrVec
* hir/tree/rust-hir.h:
Add has/get_outer_attribute to GenericParam

gcc/testsuite/ChangeLog:
* rust/compile/issue-3045-1.rs:
Add test for #[may_dangle] Generic Type triggering error
* rust/compile/issue-3045-2.rs:
Add test for #[may_dangle] Lifetime triggering error

Signed-off-by: Liam Naddell 

Diff:
---
 gcc/rust/ast/rust-ast.cc  |  4 +++-
 gcc/rust/checks/errors/rust-unsafe-checker.cc | 18 +-
 gcc/rust/hir/rust-ast-lower-item.cc   |  5 +++--
 gcc/rust/hir/rust-ast-lower-type.cc   | 14 --
 gcc/rust/hir/rust-hir-dump.cc |  3 ++-
 gcc/rust/hir/tree/rust-hir-item.h | 26 ++
 gcc/rust/hir/tree/rust-hir.cc | 22 --
 gcc/rust/hir/tree/rust-hir.h  | 26 ++
 gcc/testsuite/rust/compile/issue-3045-1.rs| 21 +
 gcc/testsuite/rust/compile/issue-3045-2.rs| 20 
 10 files changed, 122 insertions(+), 37 deletions(-)

diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc
index bf7d31d86764..1d52352daaa9 100644
--- a/gcc/rust/ast/rust-ast.cc
+++ b/gcc/rust/ast/rust-ast.cc
@@ -311,7 +311,8 @@ Attribute::get_traits_to_derive ()
 
 // Copy constructor must deep copy attr_input as unique pointer
 Attribute::Attribute (Attribute const &other)
-  : path (other.path), locus (other.locus)
+  : path (other.path), locus (other.locus),
+inner_attribute (other.inner_attribute)
 {
   // guard to protect from null pointer dereference
   if (other.attr_input != nullptr)
@@ -324,6 +325,7 @@ Attribute::operator= (Attribute const &other)
 {
   path = other.path;
   locus = other.locus;
+  inner_attribute = other.inner_attribute;
   // guard to protect from null pointer dereference
   if (other.attr_input != nullptr)
 attr_input = other.attr_input->clone_attr_input ();
diff --git a/gcc/rust/checks/errors/rust-unsafe-checker.cc 
b/gcc/rust/checks/errors/rust-unsafe-checker.cc
index c6ed92215657..4c8db3a554e7 100644
--- a/gcc/rust/checks/errors/rust-unsafe-checker.cc
+++ b/gcc/rust/checks/errors/rust-unsafe-checker.cc
@@ -784,7 +784,23 @@ UnsafeChecker::visit (Trait &trait)
 void
 UnsafeChecker::visit (ImplBlock &impl)
 {
-  // FIXME: Handle unsafe impls
+  bool safe = !impl.is_unsafe ();
+  // Check for unsafe-only attributes on generics and lifetimes
+  if (safe)
+for (auto &parm : impl.get_generic_params ())
+  {
+   for (auto o_attr : parm->get_outer_attrs ())
+ {
+   rust_assert (!o_attr.is_inner_attribute ());
+
+   Rust::AST::SimplePath path = o_attr.get_path ();
+   if (path == Values::Attributes::MAY_DANGLE)
+ rust_error_at (
+   o_attr.get_locus (), ErrorCode::E0569,
+   "use of % is unsafe and requires unsafe impl");
+ }
+  }
+
   for (auto &item : impl.get_impl_items ())
 item->accept_vis (*this);
 }
diff --git a/gcc/rust/hir/rust-ast-lower-item.cc 
b/gcc/rust/hir/rust-ast-lower-item.cc
index 25345ce75894..0ef4f357c8ed 100644
--- a/gcc/rust/hir/rust-ast-lower-item.cc
+++ b/gcc/rust/hir/rust-ast-lower-item.cc
@@ -542,7 +542,7 @@ ASTLoweringItem::visit (AST::InherentImpl &impl_block)
 mapping, std::move (impl_items), std::move (generic_params),
 std::unique_ptr (impl_type), nullptr, where_clause, polarity,
 vis, impl_block.get_inner_attrs (), impl_block.get_outer_attrs (),
-impl_block.get_locus ());
+impl_block.get_locus (), false);
   translated = hir_impl_block;
 
   mappings.insert_hir_impl_block (hir_impl_block);
@@ -623,6 +623,7 @@ void
 ASTLoweringItem::visit (AST::TraitImpl &impl_block)
 {
   std::vector> where_clause_items;
+  bool unsafe = impl_block.is_unsafe ();
   for (auto &item : impl_block.get_where_clause ().get_items ())
 {
   HIR::WhereClauseItem *i = ASTLowerWhereClauseItem::translate (*item);
@@ -696,7 +697,7 @@ ASTLoweringItem::visit (AST::TraitImpl &impl_block)
 

[gcc r15-8416] gccrs: Postpone break on error after name resolution

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:ff388c8b1ca6f8f6e42a7a0a5388b18aed5a4176

commit r15-8416-gff388c8b1ca6f8f6e42a7a0a5388b18aed5a4176
Author: Pierre-Emmanuel Patry 
Date:   Thu Sep 26 23:17:59 2024 +0200

gccrs: Postpone break on error after name resolution

We need the top level to run at least once before breaking because it
will be required by the other name resolution steps.

gcc/rust/ChangeLog:

* rust-session-manager.cc (Session::expansion): Break on error after
top level name resolution.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/rust-session-manager.cc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc
index 5668d4d65d39..11ff25062d04 100644
--- a/gcc/rust/rust-session-manager.cc
+++ b/gcc/rust/rust-session-manager.cc
@@ -925,9 +925,6 @@ Session::expansion (AST::Crate &crate, 
Resolver2_0::NameResolutionContext &ctx)
 {
   CfgStrip ().go (crate);
   // Errors might happen during cfg strip pass
-  if (saw_errors ())
-   break;
-
   bool visitor_dirty = false;
 
   if (flag_name_resolution_2_0)
@@ -940,6 +937,9 @@ Session::expansion (AST::Crate &crate, 
Resolver2_0::NameResolutionContext &ctx)
   else
Resolver::EarlyNameResolver ().go (crate);
 
+  if (saw_errors ())
+   break;
+
   ExpandVisitor (expander).go (crate);
 
   fixed_point_reached = !expander.has_changed () && !visitor_dirty;


[gcc r15-8423] gccrs: Improve Rib::Definition shadowing

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:84f5e7b12e750e48051a9cc0bd969b2e2f73117b

commit r15-8423-g84f5e7b12e750e48051a9cc0bd969b2e2f73117b
Author: Owen Avery 
Date:   Fri Oct 4 17:33:42 2024 -0400

gccrs: Improve Rib::Definition shadowing

gcc/rust/ChangeLog:

* resolve/rust-finalize-imports-2.0.cc
(GlobbingVisitor::visit): Replace calls to insert_shadowable with
insert_globbed.
* resolve/rust-forever-stack.h
(ForeverStack::insert_globbed): Add.
* resolve/rust-forever-stack.hxx
(ForeverStack::insert_globbed): Add.
(ForeverStack::dfs): Handle modifications to Rib::Definition
fields.
* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Make IdentifierPattern-based declarations
shadowable.
* resolve/rust-name-resolution-context.cc
(NameResolutionContext::insert_globbed): Add.
* resolve/rust-name-resolution-context.h
(NameResolutionContext::insert_globbed): Add.
* resolve/rust-rib.cc
(Rib::Definition::Definition): Use Rib::Definition::Mode to
indicate shadowing mode instead of boolean, handle modifications
to Rib::Definition fields.
(Rib::Definition::is_ambiguous): Handle modifications to
Rib::Definition fields.
(Rib::Definition::to_string): Likewise.
(Rib::Definition::Shadowable): Handle changed constructor
signature.
(Rib::Definition::NonShadowable): Likewise.
(Rib::Definition::Globbed): Add.
(Rib::insert): Handle changes to Rib::Definition fields.
* resolve/rust-rib.h
(Rib::Definition::Globbed): Add.
(Rib::Definition::ids): Remove.
(Rib::Definition::ids_shadowable): Add.
(Rib::Definition::ids_non_shadowable): Add.
(Rib::Definition::ids_globbed): Add.
(Rib::Definition::get_node_id): Handle modifications to
Rib::Definition fields.
(Rib::Definition::Mode): Add.
(Rib::Definition::Definition): Use Rib::Definition::Mode to
indicate shadowing mode instead of boolean.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove shadow1.rs.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/resolve/rust-finalize-imports-2.0.cc|  44 +-
 gcc/rust/resolve/rust-forever-stack.h|  16 
 gcc/rust/resolve/rust-forever-stack.hxx  |  24 +-
 gcc/rust/resolve/rust-late-name-resolver-2.0.cc  |   4 +-
 gcc/rust/resolve/rust-name-resolution-context.cc |  18 
 gcc/rust/resolve/rust-name-resolution-context.h  |   3 +
 gcc/rust/resolve/rust-rib.cc | 103 +--
 gcc/rust/resolve/rust-rib.h  |  30 ++-
 gcc/testsuite/rust/compile/nr2/exclude   |   1 -
 9 files changed, 187 insertions(+), 56 deletions(-)

diff --git a/gcc/rust/resolve/rust-finalize-imports-2.0.cc 
b/gcc/rust/resolve/rust-finalize-imports-2.0.cc
index 5ce05a9c6240..71916ae432bd 100644
--- a/gcc/rust/resolve/rust-finalize-imports-2.0.cc
+++ b/gcc/rust/resolve/rust-finalize-imports-2.0.cc
@@ -37,32 +37,32 @@ void
 GlobbingVisitor::visit (AST::Module &module)
 {
   if (module.get_visibility ().is_public ())
-ctx.insert_shadowable (module.get_name (), module.get_node_id (),
-  Namespace::Types);
+ctx.insert_globbed (module.get_name (), module.get_node_id (),
+   Namespace::Types);
 }
 
 void
 GlobbingVisitor::visit (AST::MacroRulesDefinition ¯o)
 {
   if (macro.get_visibility ().is_public ())
-ctx.insert_shadowable (macro.get_rule_name (), macro.get_node_id (),
-  Namespace::Macros);
+ctx.insert_globbed (macro.get_rule_name (), macro.get_node_id (),
+   Namespace::Macros);
 }
 
 void
 GlobbingVisitor::visit (AST::Function &function)
 {
   if (function.get_visibility ().is_public ())
-ctx.insert_shadowable (function.get_function_name (),
-  function.get_node_id (), Namespace::Values);
+ctx.insert_globbed (function.get_function_name (), function.get_node_id (),
+   Namespace::Values);
 }
 
 void
 GlobbingVisitor::visit (AST::StaticItem &static_item)
 {
   if (static_item.get_visibility ().is_public ())
-ctx.insert_shadowable (static_item.get_identifier (),
-  static_item.get_node_id (), Namespace::Values);
+ctx.insert_globbed (static_item.get_identifier (),
+   static_item.get_node_id (), Namespace::Values);
 }
 
 void
@@ -70,11 +70,11 @@ GlobbingVisitor::visit (AST::StructStruct &struct_item)
 {
   if (struct_item.get_visibility ().is_public ())
 {
-  ctx.insert_shadowable (struct_item.get_identifier (),
-struct_item.get_node_id (), Nam

[gcc r15-8425] gccrs: Handle TypeAlias during toplevel resolution 2.0

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:b05e174a34799f5a24235ff5d553387963c41da4

commit r15-8425-gb05e174a34799f5a24235ff5d553387963c41da4
Author: Owen Avery 
Date:   Thu Oct 10 00:46:01 2024 -0400

gccrs: Handle TypeAlias during toplevel resolution 2.0

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Handle TypeAlias.
* resolve/rust-toplevel-name-resolver-2.0.h
(TopLevel::visit): Likewise.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove type-alias1.rs.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc | 9 +
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h  | 1 +
 gcc/testsuite/rust/compile/nr2/exclude  | 1 -
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
index 35732e244b4f..b0e0c1b52dce 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -348,6 +348,15 @@ TopLevel::visit (AST::ConstantItem &const_item)
   DefaultResolver::visit (const_item);
 }
 
+void
+TopLevel::visit (AST::TypeAlias &type_item)
+{
+  insert_or_error_out (type_item.get_new_type_name (), type_item,
+  Namespace::Types);
+
+  DefaultResolver::visit (type_item);
+}
+
 static void
 flatten_rebind (
   const AST::UseTreeRebind &glob,
diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
index 09b22612f78c..cc301ed7fddf 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
@@ -161,6 +161,7 @@ private:
   void visit (AST::Enum &enum_item) override;
   void visit (AST::Union &union_item) override;
   void visit (AST::ConstantItem &const_item) override;
+  void visit (AST::TypeAlias &type_item) override;
   void visit (AST::ExternCrate &crate) override;
   void visit (AST::TypeParam &type_param) override;
 
diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index e0aa15531e1f..1faa7b53622e 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -206,7 +206,6 @@ traits7.rs
 traits8.rs
 traits9.rs
 tuple_struct1.rs
-type-alias1.rs
 type-bindings1.rs
 unconstrained_type_param.rs
 undeclared_label.rs


[gcc r15-8420] gccrs: add test case to show impl block on ! works

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:5e416545361ab39fcced3b2c153a93887615fd64

commit r15-8420-g5e416545361ab39fcced3b2c153a93887615fd64
Author: Philip Herron 
Date:   Thu Sep 26 15:25:21 2024 +0100

gccrs: add test case to show impl block on ! works

The resolution with ! was fixed in: 09cfe530f9c this adds a
test case to show the other issue is also fixed.

Fixes #2951

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 is crashing here
* rust/compile/issue-2951.rs: New test.

Signed-off-by: Philip Herron 

Diff:
---
 gcc/testsuite/rust/compile/issue-2951.rs | 13 +
 gcc/testsuite/rust/compile/nr2/exclude   |  1 +
 2 files changed, 14 insertions(+)

diff --git a/gcc/testsuite/rust/compile/issue-2951.rs 
b/gcc/testsuite/rust/compile/issue-2951.rs
new file mode 100644
index ..d30a3bf2adf1
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-2951.rs
@@ -0,0 +1,13 @@
+#[lang = "sized"]
+pub trait Sized {}
+
+#[lang = "clone"]
+pub trait Clone: Sized {
+fn clone(&self) -> Self;
+}
+
+impl Clone for ! {
+fn clone(&self) -> Self {
+*self
+}
+}
diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index 50781e56b85e..c30af607edb4 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -253,3 +253,4 @@ issue-3139-1.rs
 issue-3139-2.rs
 issue-3139-3.rs
 issue-3036.rs
+issue-2951.rs


[gcc r15-8421] gccrs: Add test case to show ICE is fixed

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:ac5821890051d71cf55169c4f7e91801ca5f8ba2

commit r15-8421-gac5821890051d71cf55169c4f7e91801ca5f8ba2
Author: Philip Herron 
Date:   Wed Oct 2 14:23:26 2024 +0100

gccrs: Add test case to show ICE is fixed

This was resolved in: 18422c9c386 which was missing the name
resolution step for unit-types.

Fixes #2203

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude:
* rust/compile/issue-2203.rs: New test.

Signed-off-by: Philip Herron 

Diff:
---
 gcc/testsuite/rust/compile/issue-2203.rs | 3 +++
 gcc/testsuite/rust/compile/nr2/exclude   | 1 +
 2 files changed, 4 insertions(+)

diff --git a/gcc/testsuite/rust/compile/issue-2203.rs 
b/gcc/testsuite/rust/compile/issue-2203.rs
new file mode 100644
index ..961381d69f75
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-2203.rs
@@ -0,0 +1,3 @@
+trait A {}
+
+impl A for () {}
diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index c30af607edb4..e792462ba332 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -254,3 +254,4 @@ issue-3139-2.rs
 issue-3139-3.rs
 issue-3036.rs
 issue-2951.rs
+issue-2203.rs
\ No newline at end of file


[gcc r15-8411] gccrs: Change resolved type segment

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:ad4c2360e393cd7f24b5c7b2405ffa80e92fcf4d

commit r15-8411-gad4c2360e393cd7f24b5c7b2405ffa80e92fcf4d
Author: Pierre-Emmanuel Patry 
Date:   Thu Sep 26 22:43:18 2024 +0200

gccrs: Change resolved type segment

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.h: Add visit function 
prototype.
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Change 
resolved
type segment.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/resolve/rust-late-name-resolver-2.0.cc | 13 +++--
 gcc/rust/resolve/rust-late-name-resolver-2.0.h  |  1 +
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
index df67b4f9873c..287972c34cef 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -224,14 +224,23 @@ Late::visit (AST::TypePath &type)
   // maybe we can overload `resolve_path` to only do
   // typepath-like path resolution? that sounds good
 
-  auto resolved = ctx.types.get (type.get_segments ().back ()->as_string ());
-  if (resolved)
+  auto str = type.get_segments ().back ()->get_ident_segment ().as_string ();
+  auto values = ctx.types.peek ().get_values ();
+
+  if (auto resolved = ctx.types.get (str))
 ctx.map_usage (Usage (type.get_node_id ()),
   Definition (resolved->get_node_id ()));
   else
 rust_unreachable ();
 }
 
+void
+Late::visit (AST::StructStruct &s)
+{
+  auto s_vis = [this, &s] () { AST::DefaultASTVisitor::visit (s); };
+  ctx.scoped (Rib::Kind::Item, s.get_node_id (), s_vis);
+}
+
 void
 Late::visit (AST::StructExprStructBase &s)
 {
diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.h 
b/gcc/rust/resolve/rust-late-name-resolver-2.0.h
index b44b2d96387c..c4d0d82162ef 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.h
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.h
@@ -48,6 +48,7 @@ public:
   void visit (AST::TypePath &) override;
   void visit (AST::StructExprStructBase &) override;
   void visit (AST::StructExprStructFields &) override;
+  void visit (AST::StructStruct &) override;
 
 private:
   /* Setup Rust's builtin types (u8, i32, !...) in the resolver */


[gcc r15-8419] rust: fix ICE during name resolution for impls on unit-types

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:566ae2082c0205f96986dd36f8f01705b7c731b7

commit r15-8419-g566ae2082c0205f96986dd36f8f01705b7c731b7
Author: Philip Herron 
Date:   Fri Sep 20 17:38:14 2024 +0100

rust: fix ICE during name resolution for impls on unit-types

The canonical paths need to support unit-types which are technically a
TupleType with no fields. This handles this case and adds an unreachable.

Fixes #3036

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-type.cc 
(ResolveTypeToCanonicalPath::visit): add unit-type catch
* resolve/rust-ast-resolve-type.h: likewise

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/issue-3036.rs: New test.

Signed-off-by: Philip Herron 

Diff:
---
 gcc/rust/resolve/rust-ast-resolve-type.cc |  9 +
 gcc/rust/resolve/rust-ast-resolve-type.h  |  2 ++
 gcc/testsuite/rust/compile/issue-3036.rs  | 14 ++
 gcc/testsuite/rust/compile/nr2/exclude|  1 +
 4 files changed, 26 insertions(+)

diff --git a/gcc/rust/resolve/rust-ast-resolve-type.cc 
b/gcc/rust/resolve/rust-ast-resolve-type.cc
index cee259cceb45..ec5e8a762a70 100644
--- a/gcc/rust/resolve/rust-ast-resolve-type.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-type.cc
@@ -507,6 +507,15 @@ ResolveTypeToCanonicalPath::visit (AST::NeverType &type)
   result = CanonicalPath::new_seg (type.get_node_id (), "!");
 }
 
+void
+ResolveTypeToCanonicalPath::visit (AST::TupleType &type)
+{
+  if (!type.is_unit_type ())
+rust_unreachable ();
+
+  result = CanonicalPath::new_seg (type.get_node_id (), "()");
+}
+
 ResolveTypeToCanonicalPath::ResolveTypeToCanonicalPath ()
   : ResolverBase (), result (CanonicalPath::create_empty ())
 {}
diff --git a/gcc/rust/resolve/rust-ast-resolve-type.h 
b/gcc/rust/resolve/rust-ast-resolve-type.h
index 5e382445a148..561948e85b83 100644
--- a/gcc/rust/resolve/rust-ast-resolve-type.h
+++ b/gcc/rust/resolve/rust-ast-resolve-type.h
@@ -248,6 +248,8 @@ public:
 
   void visit (AST::NeverType &type) override;
 
+  void visit (AST::TupleType &type) override;
+
 private:
   ResolveTypeToCanonicalPath ();
 
diff --git a/gcc/testsuite/rust/compile/issue-3036.rs 
b/gcc/testsuite/rust/compile/issue-3036.rs
new file mode 100644
index ..4418ccc04cb9
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3036.rs
@@ -0,0 +1,14 @@
+#[lang = "sized"]
+trait Sized {}
+
+#[stable(feature = "rust1", since = "1.0.0")]
+pub trait Default: Sized {
+#[stable(feature = "rust1", since = "1.0.0")]
+fn default() -> Self;
+}
+
+impl Default for () {
+fn default() -> () {
+()
+}
+}
diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index bfb51fd7fee9..50781e56b85e 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -252,3 +252,4 @@ issue-3082.rs
 issue-3139-1.rs
 issue-3139-2.rs
 issue-3139-3.rs
+issue-3036.rs


[gcc r15-8409] gccrs: Do not assert insertion result

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:193b66070ef07fe3c734b39faebf7ad2cf28bdee

commit r15-8409-g193b66070ef07fe3c734b39faebf7ad2cf28bdee
Author: Pierre-Emmanuel Patry 
Date:   Tue Sep 17 16:15:40 2024 +0200

gccrs: Do not assert insertion result

We might have some duplicated name in some pattern and we should
therefore not assert the non duplication of identifiers.

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Remove
assertion and explicitely tells why we ignore the insertion result.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/resolve/rust-late-name-resolver-2.0.cc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
index fa759d7bc8be..df67b4f9873c 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -152,10 +152,10 @@ Late::visit (AST::IdentifierPattern &identifier)
   // do we insert in labels or in values
   // but values does not allow shadowing... since functions cannot shadow
   // do we insert functions in labels as well?
-  auto ok
-= ctx.values.insert (identifier.get_ident (), identifier.get_node_id ());
 
-  rust_assert (ok);
+  // We do want to ignore duplicated data because some situations rely on it.
+  std::ignore
+= ctx.values.insert (identifier.get_ident (), identifier.get_node_id ());
 }
 
 void


[gcc r15-8427] gccrs: Insert static items into the value namespace

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:0d88e726aa017db639fa8848d7ec5be2ecc13507

commit r15-8427-g0d88e726aa017db639fa8848d7ec5be2ecc13507
Author: Owen Avery 
Date:   Fri Oct 11 01:24:14 2024 -0400

gccrs: Insert static items into the value namespace

gcc/rust/ChangeLog:

* backend/rust-compile-item.cc
(CompileItem::visit): Check canonical path of StaticItem
properly when name resolution 2.0 is enabled.
* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Insert static items into the value namespace.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/backend/rust-compile-item.cc   | 19 +--
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc |  3 +++
 gcc/testsuite/rust/compile/nr2/exclude  |  2 --
 3 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-item.cc 
b/gcc/rust/backend/rust-compile-item.cc
index c0cac686e8d9..08787163c2a5 100644
--- a/gcc/rust/backend/rust-compile-item.cc
+++ b/gcc/rust/backend/rust-compile-item.cc
@@ -42,8 +42,23 @@ CompileItem::visit (HIR::StaticItem &var)
 
   tree type = TyTyResolveCompile::compile (ctx, resolved_type);
 
-  auto canonical_path = ctx->get_mappings ().lookup_canonical_path (
-var.get_mappings ().get_nodeid ());
+  tl::optional canonical_path;
+
+  if (flag_name_resolution_2_0)
+{
+  auto nr_ctx
+   = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+  canonical_path
+   = nr_ctx.values.to_canonical_path (var.get_mappings ().get_nodeid ());
+}
+  else
+{
+  canonical_path = ctx->get_mappings ().lookup_canonical_path (
+   var.get_mappings ().get_nodeid ());
+}
+
+  rust_assert (canonical_path.has_value ());
 
   HIR::Expr *const_value_expr = var.get_expr ().get ();
   ctx->push_const_context ();
diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
index b0e0c1b52dce..d3a3c5d78bc9 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -248,6 +248,9 @@ TopLevel::visit (AST::StaticItem &static_item)
 = [this, &static_item] () { static_item.get_expr ().accept_vis (*this); };
 
   ctx.scoped (Rib::Kind::Item, static_item.get_node_id (), sub_vis);
+
+  insert_or_error_out (static_item.get_identifier ().as_string (), static_item,
+  Namespace::Values);
 }
 
 void
diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index 1faa7b53622e..166977e7bacc 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -100,8 +100,6 @@ issue-2139.rs
 issue-2142.rs
 issue-2165.rs
 issue-2166.rs
-issue-2178.rs
-issue-2188.rs
 issue-2190-1.rs
 issue-2190-2.rs
 issue-2195.rs


[gcc r15-8431] gccrs: Provide input operand for gccrs

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:81397a9f53440ed6fb816480784fd9b14a3fca57

commit r15-8431-g81397a9f53440ed6fb816480784fd9b14a3fca57
Author: badumbatish 
Date:   Wed Sep 4 23:59:36 2024 -0700

gccrs: Provide input operand for gccrs

gcc/rust/ChangeLog:

* backend/rust-compile-asm.cc (CompileAsm::asm_construct_inputs):
Provide input operand for gccrs
* expand/rust-macro-builtins-asm.cc (parse_reg_operand_in):
Move expr to In
(expand_inline_asm_strings):
Add comments to debug strings

gcc/testsuite/ChangeLog:

* rust/compile/inline_asm_parse_operand.rs:
Remove inout, functionality not supported. Remove redundant {}
* rust/execute/torture/inline_asm_mov_x_5_ARM.rs: Add operand in
* rust/execute/torture/inline_asm_mov_x_5_x86_64.rs: Likewise

Diff:
---
 gcc/rust/backend/rust-compile-asm.cc   | 22 --
 gcc/rust/expand/rust-macro-builtins-asm.cc |  9 +
 .../rust/compile/inline_asm_parse_operand.rs   |  6 +++---
 .../rust/execute/torture/inline_asm_mov_x_5_ARM.rs | 14 +-
 .../execute/torture/inline_asm_mov_x_5_x86_64.rs   | 19 +++
 5 files changed, 56 insertions(+), 14 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-asm.cc 
b/gcc/rust/backend/rust-compile-asm.cc
index 8294feb21978..e85d08d05792 100644
--- a/gcc/rust/backend/rust-compile-asm.cc
+++ b/gcc/rust/backend/rust-compile-asm.cc
@@ -1,5 +1,4 @@
 #include "rust-compile-asm.h"
-#include "rust-system.h"
 #include "rust-compile-expr.h"
 namespace Rust {
 namespace Compile {
@@ -107,7 +106,26 @@ tree
 CompileAsm::asm_construct_inputs (HIR::InlineAsm &expr)
 {
   // TODO: Do i need to do this?
-  return NULL_TREE;
+  tree head = NULL_TREE;
+  for (auto &input : expr.get_operands ())
+{
+  if (input.get_register_type () == 
AST::InlineAsmOperand::RegisterType::In)
+   {
+ auto in = input.get_in ();
+
+ tree in_tree = CompileExpr::Compile (in.expr.get (), this->ctx);
+ // expects a tree list
+ // TODO: This assumes that the input is a register
+ std::string expr_name = "r";
+ auto name = build_string (expr_name.size () + 1, expr_name.c_str ());
+ head
+   = chainon (head, build_tree_list (build_tree_list (NULL_TREE, name),
+ in_tree));
+
+ /*head = chainon (head, out_tree);*/
+   }
+}
+  return head;
 }
 
 tree
diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index 1017d9fd6c4d..e970f285202e 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -330,8 +330,8 @@ parse_reg_operand_in (InlineAsmContext inline_asm_ctx)
 
   // TODO: When we've succesfully parse an expr, remember to clone_expr()
   // instead of nullptr
-  // struct AST::InlineAsmOperand::In in (reg, nullptr);
-  // inline_asm_ctx.inline_asm.operands.push_back (in);
+  struct AST::InlineAsmOperand::In in (reg, std::move (expr));
+  inline_asm_ctx.inline_asm.operands.push_back (in);
   return inline_asm_ctx;
 }
   return tl::unexpected (NONCOMMITED);
@@ -792,8 +792,9 @@ expand_inline_asm_strings (InlineAsmContext inline_asm_ctx)
 * trait});*/
 
transformed_template_str += "%" + std::to_string (idx);
-   /*std::cout << "argument implicitly is: " << idx <<
-* std::endl;*/
+   // std::cout << "argument implicitly is: " << idx <<
+   // std::endl; std::cout << "transformed template str is:"
+   // << transformed_template_str << std::endl;
/*std::cout << "trait: " << trait.to_string () <<
 * std::endl;*/
/*std::cout << "arg: " << arg.to_string () << std::endl;*/
diff --git a/gcc/testsuite/rust/compile/inline_asm_parse_operand.rs 
b/gcc/testsuite/rust/compile/inline_asm_parse_operand.rs
index e0efe1c420da..c7bc152c7ced 100644
--- a/gcc/testsuite/rust/compile/inline_asm_parse_operand.rs
+++ b/gcc/testsuite/rust/compile/inline_asm_parse_operand.rs
@@ -8,7 +8,7 @@ macro_rules! asm {
 fn main() -> i32 {
 unsafe {
 asm!(
-"add {}, {}",
+"add {}, 1",
 in(reg) 0
 );
 }
@@ -21,15 +21,15 @@ fn main() -> i32 {
 unsafe {
 asm!(
 "add {}, {}",
-inout(reg) num1 =>_num1,
 in(reg) _num2,
+out(reg) _num1,
 );
 }
 
 let mut _output_testing: u32 = 0;
 unsafe {
 asm!(
-"add {}, {}",
+"add {}, 1",
 in(reg) _num1,
 //out(reg) _,
 );
diff --git a/gcc/testsuite/rust/execute/torture/inline_asm_mov_x_5_ARM.rs 
b/gcc/testsuite/rust/execute/torture/inline_asm_mov_x

[gcc r15-8434] gccrs: Handle const generic parameters during resolution 2.0

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:225748e0f12ea94181560d9cc6bc18a877e6addc

commit r15-8434-g225748e0f12ea94181560d9cc6bc18a877e6addc
Author: Owen Avery 
Date:   Tue Oct 15 22:10:35 2024 -0400

gccrs: Handle const generic parameters during resolution 2.0

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Handle ConstGenericParam.
* resolve/rust-toplevel-name-resolver-2.0.h
(TopLevel::visit): Likewise.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc | 8 
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h  | 1 +
 2 files changed, 9 insertions(+)

diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
index d3a3c5d78bc9..92a115108e6c 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -286,6 +286,14 @@ TopLevel::visit (AST::TypeParam &type_param)
 Namespace::Types);
 }
 
+void
+TopLevel::visit (AST::ConstGenericParam &const_param)
+{
+  insert_or_error_out (const_param.get_name (), const_param, 
Namespace::Values);
+
+  DefaultResolver::visit (const_param);
+}
+
 void
 TopLevel::visit (AST::TupleStruct &tuple_struct)
 {
diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
index cc301ed7fddf..e9e0306f11a1 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
@@ -164,6 +164,7 @@ private:
   void visit (AST::TypeAlias &type_item) override;
   void visit (AST::ExternCrate &crate) override;
   void visit (AST::TypeParam &type_param) override;
+  void visit (AST::ConstGenericParam &const_param) override;
 
   void visit (AST::UseDeclaration &use) override;
 };


[gcc r15-8296] libstdc++: Support maps deduction from_range of tuples.

2025-03-19 Thread Tomasz Kaminski via Libstdc++-cvs
https://gcc.gnu.org/g:d50171bc07006dfb56cae487d72913e5d2567716

commit r15-8296-gd50171bc07006dfb56cae487d72913e5d2567716
Author: Tomasz Kamiński 
Date:   Wed Mar 19 11:42:50 2025 +0100

libstdc++: Support maps deduction from_range of tuples.

This implements part of LWG4223 that enables deduction for maps types
(map, unordered_map, flat_map and non-unique equivalent) from
(from_range, rg, ...) arguments, where rg is range of tuple
or other pair-like.

libstdc++-v3/ChangeLog:

* include/bits/ranges_base.h (__detail::__range_key_type):
Replace RV::first_type with tuple_element_t<0, RV>.
(__detail::__range_mapped_type) Replace RV::second_type
with tuple_element_t<1, RV>.
* testsuite/23_containers/flat_map/1.cc: New tests.
* testsuite/23_containers/flat_multimap/1.cc: New tests.
* testsuite/23_containers/map/cons/from_range.cc: New tests.
* testsuite/23_containers/multimap/cons/from_range.cc: New tests.
* testsuite/23_containers/unordered_map/cons/from_range.cc: New 
tests.
* testsuite/23_containers/unordered_multimap/cons/from_range.cc:
New tests.

Reviewed-by: Jonathan Wakely 
Signed-off-by: Tomasz Kamiński 

Diff:
---
 libstdc++-v3/include/bits/ranges_base.h| 10 +++-
 libstdc++-v3/testsuite/23_containers/flat_map/1.cc | 61 
 .../testsuite/23_containers/flat_multimap/1.cc | 65 ++
 .../testsuite/23_containers/map/cons/from_range.cc |  8 ++-
 .../23_containers/multimap/cons/from_range.cc  |  8 ++-
 .../23_containers/unordered_map/cons/from_range.cc |  8 ++-
 .../unordered_multimap/cons/from_range.cc  | 12 +++-
 7 files changed, 158 insertions(+), 14 deletions(-)

diff --git a/libstdc++-v3/include/bits/ranges_base.h 
b/libstdc++-v3/include/bits/ranges_base.h
index c9687c256e99..13bfbb3795bf 100644
--- a/libstdc++-v3/include/bits/ranges_base.h
+++ b/libstdc++-v3/include/bits/ranges_base.h
@@ -41,6 +41,10 @@
 #include 
 #include 
 
+#if __glibcxx_ranges_to_container // C++ >= 23
+# include  // for tuple_element_t
+#endif
+
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wpedantic" // __int128
 
@@ -1093,13 +1097,15 @@ namespace __detail
   = ranges::input_range<_Rg>
  && convertible_to, _Tp>;
 
+  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+  // 4223. Deduction guides for maps are mishandling tuples and references
   template
 using __range_key_type
-  = remove_const_t::first_type>;
+  = remove_const_t>>;
 
   template
 using __range_mapped_type
-  = typename ranges::range_value_t<_Range>::second_type;
+  = tuple_element_t<1, ranges::range_value_t<_Range>>;
 
   // The allocator's value_type for map-like containers.
   template
diff --git a/libstdc++-v3/testsuite/23_containers/flat_map/1.cc 
b/libstdc++-v3/testsuite/23_containers/flat_map/1.cc
index 00254dc2ee62..d9d88c4df6ec 100644
--- a/libstdc++-v3/testsuite/23_containers/flat_map/1.cc
+++ b/libstdc++-v3/testsuite/23_containers/flat_map/1.cc
@@ -11,6 +11,67 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+
+struct Gt {
+  template
+  bool operator()(T const& l, U const & r) const
+  { return l > r; }
+};
+
+void
+test_deduction_guide()
+{
+  __gnu_test::test_input_range> r(0, 0);
+  std::flat_map it1(r.begin(), r.begin());
+  static_assert(std::is_same_v>);
+  std::flat_map fr1(std::from_range, r);
+  static_assert(std::is_same_v>);
+
+  Gt cmp;
+  std::flat_map it2(r.begin(), r.begin(), cmp);
+  static_assert(std::is_same_v>);
+  std::flat_map fr2(std::from_range, r, cmp);
+  static_assert(std::is_same_v>);
+
+  using Alloc = __gnu_test::SimpleAllocator>;
+  Alloc alloc;
+  // No matching deduction guide
+  // std::flat_map it3(r.begin(), r.begin(), alloc);
+  std::flat_map fr3(std::from_range, r, alloc);
+  static_assert(std::is_same_v<
+ decltype(fr3),
+ std::flat_map,
+  std::vector>,
+  std::vector>>>);
+
+  // No matching deduction guide
+  // std::flat_map it4(r.begin(), r.begin(), cmp, alloc);
+  std::flat_map fr4(std::from_range, r, cmp, alloc);
+  static_assert(std::is_same_v<
+ decltype(fr4),
+ std::flat_map>,
+  std::vector>>>);
+
+  // LWG4223: deduces flat_map, which in turn instantiates
+  // std::vector that is ill-formed.
+  // __gnu_test::test_input_range> r2(0, 0);
+  // std::flat_map it5(r2.begin(), r2.begin());
+  // std::flat_map fr5(std::from_range, r2);
+
+  // LWG4223: deduces flat_map
+  //__gnu_test::test_input_range> r3(0, 0);
+  // std::flat_map it6(r3.begin(), r3.begin());
+  // std::flat_map fr6(std::from_range, r3);
+
+  __gnu_test::test_input_range> r4(0, 0);
+  std::flat_map it7(r4.begin(), r4.begin());
+  static_assert(std::is_same_v>);
+  std::flat_map fr7(std::from_range, r4);
+  static_assert(std::is_same_v>);
+}
 
 template class KeyContainer, template class 
Mapped

[gcc r15-8297] Fortran: Fix comp call in associate [PR119272]

2025-03-19 Thread Andre Vehreschild via Gcc-cvs
https://gcc.gnu.org/g:9a13dc48a3ac3282aaf9a77516b4f02faa60e393

commit r15-8297-g9a13dc48a3ac3282aaf9a77516b4f02faa60e393
Author: Andre Vehreschild 
Date:   Mon Mar 17 08:24:04 2025 +0100

Fortran: Fix comp call in associate [PR119272]

PR fortran/119272

gcc/fortran/ChangeLog:

* resolve.cc (resolve_compcall): Postpone error report when
symbol is not resolved yet for component call resolve.

gcc/testsuite/ChangeLog:

* gfortran.dg/associate_74.f90: New test.

Diff:
---
 gcc/fortran/resolve.cc |  5 ++--
 gcc/testsuite/gfortran.dg/associate_74.f90 | 47 ++
 2 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index ddd982702309..b9c469a5beca 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -7351,8 +7351,9 @@ resolve_compcall (gfc_expr* e, const char **name)
   /* Check that's really a FUNCTION.  */
   if (!e->value.compcall.tbp->function)
 {
-  gfc_error ("%qs at %L should be a FUNCTION",
-e->value.compcall.name, &e->where);
+  if (e->symtree && e->symtree->n.sym->resolve_symbol_called)
+   gfc_error ("%qs at %L should be a FUNCTION", e->value.compcall.name,
+  &e->where);
   return false;
 }
 
diff --git a/gcc/testsuite/gfortran.dg/associate_74.f90 
b/gcc/testsuite/gfortran.dg/associate_74.f90
new file mode 100644
index ..057d63534c1c
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/associate_74.f90
@@ -0,0 +1,47 @@
+!{ dg-do run }
+
+! Check that PR119272 is fixed
+! Contributed by Xing Jing Wei  
+
+module pr119272_module
+   type, public :: test_type
+  contains
+  procedure :: scal_function
+  procedure :: arr_function
+   end type test_type
+   contains
+   function scal_function(this) result(smth)
+  class(test_type) :: this
+  integer :: smth
+  smth = 2
+   end function
+   function arr_function(this) result(smth)
+  class(test_type) :: this
+  integer :: smth(9)
+  smth = (/(i, i=1, 9)/)
+   end function
+end module
+
+program pr119272
+  use pr119272_module
+  implicit none
+  
+  type(test_type) :: a
+  
+  call test_subroutine(a)
+  contains
+  subroutine test_subroutine(a)
+class(test_type) :: a
+integer :: i
+integer,parameter :: temp_int(3) = [ 1, 2, 3]
+integer,parameter :: identity(9) = (/(i* 5, i= 9, 1, -1)/)
+associate(temp => temp_int(a%scal_function()))
+if (temp /= 2) stop 1
+end associate
+
+associate(temparr => identity(a%arr_function()))
+if (any(temparr /= (/(i* 5, i= 9, 1, -1)/))) stop 2
+end associate
+  end subroutine
+end program
+


[gcc r15-8438] gccrs: Use name resolver 2.0 in const checker

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:7e4a3039c2485b6d34b06f3f01d93f6ee1b892d8

commit r15-8438-g7e4a3039c2485b6d34b06f3f01d93f6ee1b892d8
Author: Owen Avery 
Date:   Tue Oct 15 15:33:46 2024 -0400

gccrs: Use name resolver 2.0 in const checker

gcc/rust/ChangeLog:

* checks/errors/rust-const-checker.cc: Add includes.
(ConstChecker::visit): Use name resolver 2.0 to lookup
function definitions when name resolution 2.0 is enabled.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/checks/errors/rust-const-checker.cc | 16 +++-
 gcc/testsuite/rust/compile/nr2/exclude   |  3 ---
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/checks/errors/rust-const-checker.cc 
b/gcc/rust/checks/errors/rust-const-checker.cc
index 2beee2102796..84c09dd307e2 100644
--- a/gcc/rust/checks/errors/rust-const-checker.cc
+++ b/gcc/rust/checks/errors/rust-const-checker.cc
@@ -22,6 +22,10 @@
 #include "rust-hir-stmt.h"
 #include "rust-hir-item.h"
 #include "rust-system.h"
+#include "rust-immutable-name-resolution-context.h"
+
+// for flag_name_resolution_2_0
+#include "options.h"
 
 namespace Rust {
 namespace HIR {
@@ -354,8 +358,18 @@ ConstChecker::visit (CallExpr &expr)
   NodeId ast_node_id = expr.get_fnexpr ()->get_mappings ().get_nodeid ();
   NodeId ref_node_id;
 
+  if (flag_name_resolution_2_0)
+{
+  auto &nr_ctx
+   = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+  if (auto id = nr_ctx.lookup (ast_node_id))
+   ref_node_id = *id;
+  else
+   return;
+}
   // We don't care about types here
-  if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id))
+  else if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id))
 return;
 
   if (auto definition_id = mappings.lookup_node_to_hir (ref_node_id))
diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index a698164fbd56..ecef6d2bb259 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -27,8 +27,6 @@ closure_no_type_anno.rs
 complex-path1.rs
 complex_qualified_path_in_expr.rs
 const-issue1440.rs
-const1.rs
-const3.rs
 const_generics_3.rs
 const_generics_4.rs
 const_generics_5.rs
@@ -38,7 +36,6 @@ derive_macro1.rs
 derive_macro3.rs
 derive_macro4.rs
 derive_macro6.rs
-diagnostic_underline.rs
 expected_type_args2.rs
 expected_type_args3.rs
 feature_rust_attri0.rs


[gcc r15-8432] gccrs: Fix compiler error on ast wrong implicit construct push_back

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:064459884acb15eb41fe6d8e64602d407d86ccc9

commit r15-8432-g064459884acb15eb41fe6d8e64602d407d86ccc9
Author: badumbatish 
Date:   Wed Oct 16 22:41:47 2024 -0700

gccrs: Fix compiler error on ast wrong implicit construct push_back

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-asm.cc (parse_reg_operand_in): Fix
compiler error on ast wrong implicit construct push_back

Diff:
---
 gcc/rust/expand/rust-macro-builtins-asm.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index e970f285202e..5ed24d641cef 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -314,6 +314,7 @@ parse_reg_operand_in (InlineAsmContext inline_asm_ctx)
   // For the keyword IN, currently we count it as a seperate keyword called
   // Rust::IN search for #define RS_TOKEN_LIST in code base.
   auto &parser = inline_asm_ctx.parser;
+  location_t locus = parser.peek_current_token ()->get_locus ();
   if (!inline_asm_ctx.is_global_asm () && parser.skip_token (IN))
 {
   auto reg = parse_reg (inline_asm_ctx);
@@ -331,7 +332,7 @@ parse_reg_operand_in (InlineAsmContext inline_asm_ctx)
   // TODO: When we've succesfully parse an expr, remember to clone_expr()
   // instead of nullptr
   struct AST::InlineAsmOperand::In in (reg, std::move (expr));
-  inline_asm_ctx.inline_asm.operands.push_back (in);
+  inline_asm_ctx.inline_asm.operands.emplace_back (in, locus);
   return inline_asm_ctx;
 }
   return tl::unexpected (NONCOMMITED);


[gcc r15-8437] gccrs: Load unloaded modules during toplevel resolution 2.0

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:48bde05f60025df1b565ad5b7f492ac4cf24f1ad

commit r15-8437-g48bde05f60025df1b565ad5b7f492ac4cf24f1ad
Author: Owen Avery 
Date:   Tue Oct 15 22:24:29 2024 -0400

gccrs: Load unloaded modules during toplevel resolution 2.0

This may load conditionally compiled modules too eagerly.

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Load unloaded modules before attempting to
visit their items.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove issue-1089.rs.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc | 11 +++
 gcc/testsuite/rust/compile/nr2/exclude  |  1 -
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
index 92a115108e6c..c9d51039f0ee 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -76,6 +76,17 @@ TopLevel::visit (AST::Module &module)
 {
   insert_or_error_out (module.get_name (), module, Namespace::Types);
 
+  // Parse the module's items if they haven't been expanded and the file
+  // should be parsed (i.e isn't hidden behind an untrue or impossible cfg
+  // directive
+  // TODO: make sure this is right
+  // TODO: avoid loading items if cfg attributes are present?
+  //   might not be needed if this runs after early resolution?
+  // This was copied from the old early resolver method
+  // 'accumulate_escaped_macros'
+  if (module.get_kind () == AST::Module::UNLOADED)
+module.load_items ();
+
   auto sub_visitor = [this, &module] () {
 for (auto &item : module.get_items ())
   item->accept_vis (*this);
diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index f91cf3132c79..a698164fbd56 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -62,7 +62,6 @@ infer-crate-name.rs
 issue-1019.rs
 issue-1031.rs
 issue-1034.rs
-issue-1089.rs
 issue-1128.rs
 issue-1129-2.rs
 issue-1130.rs


[gcc r15-8439] gccrs: Use name resolver 2.0 for compiling break/continue

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:15b1c03198811a88b2796605d887f141b1bce49d

commit r15-8439-g15b1c03198811a88b2796605d887f141b1bce49d
Author: Owen Avery 
Date:   Tue Oct 15 14:56:04 2024 -0400

gccrs: Use name resolver 2.0 for compiling break/continue

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc
(CompileExpr::visit): Use name resolver 2.0 to lookup label
definitions for break and continue statements when name
resolution 2.0 is enabled.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/backend/rust-compile-expr.cc | 41 +++
 1 file changed, 37 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-expr.cc 
b/gcc/rust/backend/rust-compile-expr.cc
index 6458c42d78d1..7251cc82d6ed 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -753,8 +753,24 @@ CompileExpr::visit (HIR::BreakExpr &expr)
   if (expr.has_label ())
 {
   NodeId resolved_node_id = UNKNOWN_NODEID;
-  if (!ctx->get_resolver ()->lookup_resolved_label (
-   expr.get_label ().get_mappings ().get_nodeid (), &resolved_node_id))
+  if (flag_name_resolution_2_0)
+   {
+ auto &nr_ctx
+   = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+ if (auto id
+ = nr_ctx.lookup (expr.get_label ().get_mappings ().get_nodeid ()))
+   resolved_node_id = *id;
+   }
+  else
+   {
+ NodeId tmp = UNKNOWN_NODEID;
+ if (ctx->get_resolver ()->lookup_resolved_label (
+   expr.get_label ().get_mappings ().get_nodeid (), &tmp))
+   resolved_node_id = tmp;
+   }
+
+  if (resolved_node_id == UNKNOWN_NODEID)
{
  rust_error_at (
expr.get_label ().get_locus (),
@@ -799,8 +815,25 @@ CompileExpr::visit (HIR::ContinueExpr &expr)
   if (expr.has_label ())
 {
   NodeId resolved_node_id = UNKNOWN_NODEID;
-  if (!ctx->get_resolver ()->lookup_resolved_label (
-   expr.get_label ().get_mappings ().get_nodeid (), &resolved_node_id))
+  if (flag_name_resolution_2_0)
+   {
+ auto &nr_ctx
+   = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+ if (auto id
+ = nr_ctx.lookup (expr.get_label ().get_mappings ().get_nodeid ()))
+   resolved_node_id = *id;
+   }
+  else
+   {
+ NodeId tmp = UNKNOWN_NODEID;
+
+ if (ctx->get_resolver ()->lookup_resolved_label (
+   expr.get_label ().get_mappings ().get_nodeid (), &tmp))
+   resolved_node_id = tmp;
+   }
+
+  if (resolved_node_id == UNKNOWN_NODEID)
{
  rust_error_at (
expr.get_label ().get_locus (),


[gcc r15-8354] gccrs: Make inline mov compiles

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:23eb5d2c3a03e262e164342c18dfb8f61017f01f

commit r15-8354-g23eb5d2c3a03e262e164342c18dfb8f61017f01f
Author: badumbatish 
Date:   Tue Aug 27 18:15:26 2024 -0700

gccrs: Make inline mov compiles

gcc/rust/ChangeLog:

* backend/rust-compile-asm.cc (CompileAsm::asm_build_expr):
Remove debug
* expand/rust-macro-builtins-asm.cc (expand_inline_asm_strings):
properly formatted via rust instead of c
(parse_asm): formatted comment
(parse_format_strings): formatted comment
* hir/tree/rust-hir-expr.h: fix is_simple_asm()

gcc/testsuite/ChangeLog:

* rust/compile/inline_asm_parse_operand.rs: Fix format asm
* rust/compile/inline_asm_parse_output_operand.rs:
Fix format asm
* rust/execute/torture/inline_asm_mov_x_5.rs: Move to...
* rust/execute/inline_asm_mov_x_5.rs: ...here.

Diff:
---
 gcc/rust/backend/rust-compile-asm.cc   |  2 +-
 gcc/rust/expand/rust-macro-builtins-asm.cc | 67 ++
 gcc/rust/hir/tree/rust-hir-expr.h  |  4 +-
 .../rust/compile/inline_asm_parse_operand.rs   | 14 +++--
 .../compile/inline_asm_parse_output_operand.rs |  2 +-
 .../execute/{torture => }/inline_asm_mov_x_5.rs|  5 +-
 6 files changed, 71 insertions(+), 23 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-asm.cc 
b/gcc/rust/backend/rust-compile-asm.cc
index 92d60d756864..045cc2866fd7 100644
--- a/gcc/rust/backend/rust-compile-asm.cc
+++ b/gcc/rust/backend/rust-compile-asm.cc
@@ -26,7 +26,7 @@ CompileAsm::asm_build_expr (HIR::InlineAsm &expr)
   ASM_BASIC_P (asm_expr) = expr.is_simple_asm ();
   ASM_VOLATILE_P (asm_expr) = false;
   ASM_INLINE_P (asm_expr) = expr.is_inline_asm ();
-  Backend::debug (asm_expr);
+  /*Backend::debug (asm_expr);*/
   return asm_expr;
 }
 
diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index 379e5d8b967b..65bc6c581928 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -761,6 +761,8 @@ expand_inline_asm_strings (InlineAsmContext &inline_asm_ctx)
   auto &inline_asm = inline_asm_ctx.inline_asm;
 
   auto str_vec = inline_asm.get_template_strs ();
+
+  decltype (str_vec) resulting_template_vec;
   for (auto &template_str : str_vec)
 {
   /*std::cout << template_str.symbol << std::endl;*/
@@ -769,20 +771,57 @@ expand_inline_asm_strings (InlineAsmContext 
&inline_asm_ctx)
  Fmt::ffi::ParseMode::InlineAsm);
   auto pieces_vec = pieces.get_pieces ();
 
+  std::string transformed_template_str = "";
   for (size_t i = 0; i < pieces_vec.size (); i++)
{
  auto piece = pieces_vec[i];
  if (piece.tag == Fmt::ffi::Piece::Tag::String)
{
+ transformed_template_str += piece.string._0.to_string ();
+   }
+ else if (piece.tag == Fmt::ffi::Piece::Tag::NextArgument)
+   {
+ /*std::cout << "   " << i << ": "*/
+ /*<< piece.next_argument._0.to_string () << std::endl;*/
+
+ auto next_argument = piece.next_argument._0;
+ switch (piece.next_argument._0.position.tag)
+   {
+ case Fmt::ffi::Position::Tag::ArgumentImplicitlyIs: {
+   auto idx = next_argument.position.argument_implicitly_is._0;
+   /*auto trait = next_argument.format;*/
+   /*auto arg = arguments.at (idx);*/
+
+   /* // FIXME(Arthur): This API sucks*/
+   /* rust_assert (arg.get_kind ().kind*/
+   /*== AST::FormatArgumentKind::Kind::Normal);*/
+   /**/
+   /* args.push_back ({arg.get_expr ().clone_expr (),
+* trait});*/
+
+   transformed_template_str += "%" + std::to_string (idx);
+   /*std::cout << "argument implicitly is: " << idx <<
+* std::endl;*/
+   /*std::cout << "trait: " << trait.to_string () <<
+* std::endl;*/
+   /*std::cout << "arg: " << arg.to_string () << std::endl;*/
+ }
+ break;
+   case Fmt::ffi::Position::Tag::ArgumentIs:
+   case Fmt::ffi::Position::Tag::ArgumentNamed:
+ rust_sorry_at (inline_asm.get_locus (),
+"unhandled argument position specifier");
+ break;
+   }
}
- /*std::cout << "   " << i << ": " << piece.string._0.to_string
-  * ()*/
- /*   << std::endl;*/
}
+  template_str.symbol = transformed_template_str;
 }
 
+  inline_asm.template_strs = str_vec;
   return inline_asm_ctx;
 }
+
 tl::optional
 parse_asm (location_t invoc_locus, AST:

[gcc r15-8301] gccrs: Move procedural macro test to their own directory

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:4d6b34b669c4d274ce80baeedc7b29b4e719efdc

commit r15-8301-g4d6b34b669c4d274ce80baeedc7b29b4e719efdc
Author: Pierre-Emmanuel Patry 
Date:   Thu Jul 25 14:27:41 2024 +0200

gccrs: Move procedural macro test to their own directory

gcc/testsuite/ChangeLog:

* rust/compile/macros/proc/proc_macro.exp: New deja gnu file to 
execute
proc-macro tests.
* rust/compile/proc_macro_attribute_crate_type.rs: Move to...
* rust/compile/macros/proc/attribute_crate_type.rs: ...here.
* rust/compile/proc_macro_attribute_non_function.rs: Move to...
* rust/compile/macros/proc/attribute_non_function.rs: ...here.
* rust/compile/proc_macro_attribute_non_root_function.rs: Move to...
* rust/compile/macros/proc/attribute_non_root_function.rs: ...here.
* rust/compile/proc_macro_attribute_non_root_method.rs: Move to...
* rust/compile/macros/proc/attribute_non_root_method.rs: ...here.
* rust/compile/proc_macro_attribute_non_root_module.rs: Move to...
* rust/compile/macros/proc/attribute_non_root_module.rs: ...here.
* rust/compile/proc_macro_attribute_private.rs: Move to...
* rust/compile/macros/proc/attribute_private.rs: ...here.
* rust/compile/proc_macro_crate_type.rs: Move to...
* rust/compile/macros/proc/crate_type.rs: ...here.
* rust/compile/proc_macro_derive_crate_type.rs: Move to...
* rust/compile/macros/proc/derive_crate_type.rs: ...here.
* rust/compile/proc_macro_derive_malformed.rs: Move to...
* rust/compile/macros/proc/derive_malformed.rs: ...here.
* rust/compile/proc_macro_derive_non_function.rs: Move to...
* rust/compile/macros/proc/derive_non_function.rs: ...here.
* rust/compile/proc_macro_derive_non_root_function.rs: Move to...
* rust/compile/macros/proc/derive_non_root_function.rs: ...here.
* rust/compile/proc_macro_derive_non_root_module.rs: Move to...
* rust/compile/macros/proc/derive_non_root_module.rs: ...here.
* rust/compile/proc_macro_derive_private.rs: Move to...
* rust/compile/macros/proc/derive_private.rs: ...here.
* rust/compile/proc_macro_non_function.rs: Move to...
* rust/compile/macros/proc/non_function.rs: ...here.
* rust/compile/proc_macro_non_root_function.rs: Move to...
* rust/compile/macros/proc/non_root_function.rs: ...here.
* rust/compile/proc_macro_non_root_method.rs: Move to...
* rust/compile/macros/proc/non_root_method.rs: ...here.
* rust/compile/proc_macro_non_root_module.rs: Move to...
* rust/compile/macros/proc/non_root_module.rs: ...here.
* rust/compile/proc_macro_derive_non_root_method.rs: Move to...
* rust/compile/macros/proc/non_root_trait_method.rs: ...here.
* rust/compile/proc_macro_private.rs: Move to...
* rust/compile/macros/proc/private.rs: ...here.
* rust/compile/proc_macro_pub_function.rs: Move to...
* rust/compile/macros/proc/pub_function.rs: ...here.
* rust/compile/proc_macro_pub_module.rs: Move to...
* rust/compile/macros/proc/pub_module.rs: ...here.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 .../proc/attribute_crate_type.rs}  |  0
 .../proc/attribute_non_function.rs}|  0
 .../proc/attribute_non_root_function.rs}   |  0
 .../proc/attribute_non_root_method.rs} |  0
 .../proc/attribute_non_root_module.rs} |  0
 .../proc/attribute_private.rs} |  0
 .../proc/crate_type.rs}|  0
 .../proc/derive_crate_type.rs} |  0
 .../proc/derive_malformed.rs}  |  0
 .../proc/derive_non_function.rs}   |  0
 .../proc/derive_non_root_function.rs}  |  0
 .../proc/derive_non_root_module.rs}|  0
 .../proc/derive_private.rs}|  0
 .../proc/non_function.rs}  |  0
 .../proc/non_root_function.rs} |  0
 .../proc/non_root_method.rs}   |  0
 .../proc/non_root_module.rs}   |  0
 .../proc/non_root_trait_method.rs} |  0
 .../proc/private.rs}   |  0
 .../rust/compile/macros/proc/proc_macro.exp| 35 ++
 .../proc/pub_function.rs}  |  0
 .../proc/pub_module.rs}|  0
 22 files changed, 35 insertions(+)

diff --git a/gcc/testsuite/rust/compile/proc_macro_attribute_crate_type.rs 
b/gcc/testsuite/rust/compile/macros/proc/attribute_crate_type.rs
similarity index 100%
rename from gcc/testsuite/rust/compile/proc_macro_attribute_crate_type.rs

[gcc r15-8299] gccrs: Add rustc test directory for testsuite adaptor

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:1a921c844bf5b92a5389575e384c69e8103d2fad

commit r15-8299-g1a921c844bf5b92a5389575e384c69e8103d2fad
Author: Muhammad Mahad 
Date:   Sun Jul 21 17:35:46 2024 +

gccrs: Add rustc test directory for testsuite adaptor

gcc/testsuite/ChangeLog:

* rust/rustc/README.md: information about
rustc external directory.
* rust/rustc/rustc.exp: New test.

Signed-off-by: Muhammad Mahad 

Diff:
---
 gcc/testsuite/rust/rustc/README.md |  4 
 gcc/testsuite/rust/rustc/rustc.exp | 35 +++
 2 files changed, 39 insertions(+)

diff --git a/gcc/testsuite/rust/rustc/README.md 
b/gcc/testsuite/rust/rustc/README.md
new file mode 100644
index ..ddf4d95e9a85
--- /dev/null
+++ b/gcc/testsuite/rust/rustc/README.md
@@ -0,0 +1,4 @@
+This repository contains test cases from the 
+[rustc test suite](https://github.com/rust-lang/rust/tree/master/tests). The
+conversion of these tests into the DejaGnu format is done by the rustc 
+testsuite adaptor, a tool specifically designed for this purpose.
diff --git a/gcc/testsuite/rust/rustc/rustc.exp 
b/gcc/testsuite/rust/rustc/rustc.exp
new file mode 100644
index ..ac891db246e3
--- /dev/null
+++ b/gcc/testsuite/rust/rustc/rustc.exp
@@ -0,0 +1,35 @@
+# Copyright (C) 2021-2024 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# .
+
+# Compile tests, no torture testing.
+#
+# These tests raise errors in the front end; torture testing doesn't apply.
+
+# Load support procs.
+load_lib rust-dg.exp
+
+# Initialize `dg'.
+dg-init
+
+# Main loop.
+set saved-dg-do-what-default ${dg-do-what-default}
+
+set dg-do-what-default "compile"
+dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.rs]] "" ""
+set dg-do-what-default ${saved-dg-do-what-default}
+
+# All done.
+dg-finish


[gcc r15-8306] gccrs: Fix the parser's operand and flags storage

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:d2c9afb7bc8278bdf946599f58da18c76d3d1d2f

commit r15-8306-gd2c9afb7bc8278bdf946599f58da18c76d3d1d2f
Author: badumbatish 
Date:   Tue Jul 23 22:17:12 2024 -0700

gccrs: Fix the parser's operand and flags storage

gcc/rust/ChangeLog:

* ast/rust-expr.h (struct InlineAsmOperand):
Add construction for register_type
* expand/rust-macro-builtins-asm.cc (parse_reg_operand):
Fix parsing logic & reassignment logic
(parse_reg_operand_in): Fix parsing
(parse_reg_operand_out): Fix parsing
(parse_reg_operand_inout): Fix parsing
(parse_reg_operand_unexpected): Remove rust_unreachable()
(parse_asm_arg): Fix parsing logic
* expand/rust-macro-builtins-asm.h: Add = operator overloading

gcc/testsuite/ChangeLog:

* rust/compile/inline_asm_illegal_operands.rs: Test now passing
* rust/compile/inline_asm_parse_operand.rs: Remove _, not
supported right now

Diff:
---
 gcc/rust/ast/rust-expr.h   |  5 +-
 gcc/rust/expand/rust-macro-builtins-asm.cc | 63 +++---
 gcc/rust/expand/rust-macro-builtins-asm.h  | 10 +++-
 .../rust/compile/inline_asm_illegal_operands.rs|  6 +--
 .../rust/compile/inline_asm_parse_operand.rs   |  4 +-
 5 files changed, 60 insertions(+), 28 deletions(-)

diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index 9477bf06d6c0..8a3baf7ca2b4 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -4964,8 +4964,9 @@ struct InlineAsmOperand
 
   InlineAsmOperand () {}
   InlineAsmOperand (const InlineAsmOperand &other)
-: in (other.in), out (other.out), in_out (other.in_out),
-  split_in_out (other.split_in_out), cnst (other.cnst), sym (other.sym)
+: register_type (other.register_type), in (other.in), out (other.out),
+  in_out (other.in_out), split_in_out (other.split_in_out),
+  cnst (other.cnst), sym (other.sym)
   {}
 
   void set_in (const tl::optional ®)
diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index 214265d63a89..d270621d1bf1 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -227,20 +227,28 @@ parse_reg_operand (InlineAsmContext inline_asm_ctx)
   // Loop over and execute the parsing functions, if the parser successfullly
   // parses or if the parser fails to parse while it has committed to a token,
   // we propogate the result.
+  tl::expected parsing_operand (
+inline_asm_ctx);
   for (auto &parse_func : parse_funcs)
 {
-  auto parsing_operand
-   = tl::expected (inline_asm_ctx);
-  parsing_operand.map (parse_func);
+  auto result = parsing_operand.and_then (parse_func);
 
   // Per rust's asm.rs's structure
   // After we've parse successfully, we break out and do a local validation
   // of named, positional & explicit register operands
 
-  if (parsing_operand.has_value ())
-   break;
-  if (parsing_operand.error () == COMMITTED)
-   return parsing_operand;
+  if (result.has_value ())
+   {
+ //
+ inline_asm_ctx = *result;
+ break;
+   }
+  else if (result.error () == COMMITTED
+  && parse_func != parse_reg_operand_unexpected)
+   return result;
+  else if (result.error () == COMMITTED
+  && parse_func == parse_reg_operand_unexpected)
+   return inline_asm_ctx;
 }
 
   auto &inline_asm = inline_asm_ctx.inline_asm;
@@ -303,7 +311,7 @@ parse_reg_operand_in (InlineAsmContext inline_asm_ctx)
  return tl::unexpected (COMMITTED);
}
 
-  auto expr = parse_format_string (inline_asm_ctx);
+  auto expr = parser.parse_expr ();
 
   // TODO: When we've succesfully parse an expr, remember to clone_expr()
   // instead of nullptr
@@ -323,14 +331,19 @@ parse_reg_operand_out (InlineAsmContext inline_asm_ctx)
   if (!inline_asm_ctx.is_global_asm () && check_identifier (parser, "out"))
 {
   auto reg = parse_reg (inline_asm_ctx);
+  std::unique_ptr expr = parser.parse_expr ();
 
-  auto expr = parse_format_string (inline_asm_ctx);
+  rust_assert (expr != nullptr);
+
+  /*auto expr_ptr =
+std::make_unique(AST::LiteralExpr(Literal))*/
 
   // TODO: When we've succesfully parse an expr, remember to clone_expr()
   // instead of nullptr
-  //  struct AST::InlineAsmOperand::Out out (reg, false, nullptr);
-  //  reg_operand.set_out (out);
-  //  inline_asm_ctx.inline_asm.operands.push_back (reg_operand);
+  struct AST::InlineAsmOperand::Out out (reg, false, std::move (expr));
+
+  reg_operand.set_out (out);
+  inline_asm_ctx.inline_asm.operands.push_back (reg_operand);
 
   return inline_asm_ctx;
 }
@@ -378,7 +391,10 @@ parse_reg_operand_inout (InlineAs

[gcc r15-8304] gccrs: Move mbe macro tests to their own directory

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:724aad6009fbb850d18e2f99484b10a2fbfe75ed

commit r15-8304-g724aad6009fbb850d18e2f99484b10a2fbfe75ed
Author: Pierre-Emmanuel Patry 
Date:   Mon Jul 29 14:27:32 2024 +0200

gccrs: Move mbe macro tests to their own directory

gcc/testsuite/ChangeLog:

* rust/compile/macro-delim.rs: Move to...
* rust/compile/macros/mbe/macro-delim.rs: ...here.
* rust/compile/macro-issue1053-2.rs: Move to...
* rust/compile/macros/mbe/macro-issue1053-2.rs: ...here.
* rust/compile/macro-issue1053.rs: Move to...
* rust/compile/macros/mbe/macro-issue1053.rs: ...here.
* rust/compile/macro-issue1224.rs: Move to...
* rust/compile/macros/mbe/macro-issue1224.rs: ...here.
* rust/compile/macro-issue1233.rs: Move to...
* rust/compile/macros/mbe/macro-issue1233.rs: ...here.
* rust/compile/macro-issue1395-2.rs: Move to...
* rust/compile/macros/mbe/macro-issue1395-2.rs: ...here.
* rust/compile/macro-issue1395.rs: Move to...
* rust/compile/macros/mbe/macro-issue1395.rs: ...here.
* rust/compile/macro-issue1400-2.rs: Move to...
* rust/compile/macros/mbe/macro-issue1400-2.rs: ...here.
* rust/compile/macro-issue1400.rs: Move to...
* rust/compile/macros/mbe/macro-issue1400.rs: ...here.
* rust/compile/macro-issue2092.rs: Move to...
* rust/compile/macros/mbe/macro-issue2092.rs: ...here.
* rust/compile/macro-issue2192.rs: Move to...
* rust/compile/macros/mbe/macro-issue2192.rs: ...here.
* rust/compile/macro-issue2194.rs: Move to...
* rust/compile/macros/mbe/macro-issue2194.rs: ...here.
* rust/compile/macro-issue2229.rs: Move to...
* rust/compile/macros/mbe/macro-issue2229.rs: ...here.
* rust/compile/macro-issue2264.rs: Move to...
* rust/compile/macros/mbe/macro-issue2264.rs: ...here.
* rust/compile/macro-issue2268.rs: Move to...
* rust/compile/macros/mbe/macro-issue2268.rs: ...here.
* rust/compile/macro-issue2273.rs: Move to...
* rust/compile/macros/mbe/macro-issue2273.rs: ...here.
* rust/compile/macro-issue2653.rs: Move to...
* rust/compile/macros/mbe/macro-issue2653.rs: ...here.
* rust/compile/macro-issue2983_2984.rs: Move to...
* rust/compile/macros/mbe/macro-issue2983_2984.rs: ...here.
* rust/compile/macro1.rs: Move to...
* rust/compile/macros/mbe/macro1.rs: ...here.
* rust/compile/macro10.rs: Move to...
* rust/compile/macros/mbe/macro10.rs: ...here.
* rust/compile/macro11.rs: Move to...
* rust/compile/macros/mbe/macro11.rs: ...here.
* rust/compile/macro12.rs: Move to...
* rust/compile/macros/mbe/macro12.rs: ...here.
* rust/compile/macro13.rs: Move to...
* rust/compile/macros/mbe/macro13.rs: ...here.
* rust/compile/macro14.rs: Move to...
* rust/compile/macros/mbe/macro14.rs: ...here.
* rust/compile/macro15.rs: Move to...
* rust/compile/macros/mbe/macro15.rs: ...here.
* rust/compile/macro16.rs: Move to...
* rust/compile/macros/mbe/macro16.rs: ...here.
* rust/compile/macro17.rs: Move to...
* rust/compile/macros/mbe/macro17.rs: ...here.
* rust/compile/macro18.rs: Move to...
* rust/compile/macros/mbe/macro18.rs: ...here.
* rust/compile/macro19.rs: Move to...
* rust/compile/macros/mbe/macro19.rs: ...here.
* rust/compile/macro2.rs: Move to...
* rust/compile/macros/mbe/macro2.rs: ...here.
* rust/compile/macro20.rs: Move to...
* rust/compile/macros/mbe/macro20.rs: ...here.
* rust/compile/macro21.rs: Move to...
* rust/compile/macros/mbe/macro21.rs: ...here.
* rust/compile/macro22.rs: Move to...
* rust/compile/macros/mbe/macro22.rs: ...here.
* rust/compile/macro23.rs: Move to...
* rust/compile/macros/mbe/macro23.rs: ...here.
* rust/compile/macro25.rs: Move to...
* rust/compile/macros/mbe/macro25.rs: ...here.
* rust/compile/macro26.rs: Move to...
* rust/compile/macros/mbe/macro26.rs: ...here.
* rust/compile/macro27.rs: Move to...
* rust/compile/macros/mbe/macro27.rs: ...here.
* rust/compile/macro28.rs: Move to...
* rust/compile/macros/mbe/macro28.rs: ...here.
* rust/compile/macro29.rs: Move to...
* rust/compile/macros/mbe/macro29.rs: ...here.
* rust/compile/macro3.rs: Move to...
* rust/compile/macros/mbe/macro3.rs: ...here.
* rust/compile/macro30.rs: Move to...
  

[gcc r15-8320] gccrs: Map locations to placeholder regions

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:6f009aedaff88e359aee82628bccf683315222c6

commit r15-8320-g6f009aedaff88e359aee82628bccf683315222c6
Author: Kushal Pal 
Date:   Thu Jul 25 11:57:35 2024 +

gccrs: Map locations to placeholder regions

Mapped placeholder regions to their respective HIR nodes so we can fetch
locations during error reporting.

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder.h: Map regions to
their respective HIR nodes.
* checks/errors/borrowck/rust-bir.h (struct Function):
Add unordered_map to maintain the mapping.

Signed-off-by: Kushal Pal 

Diff:
---
 gcc/rust/checks/errors/borrowck/rust-bir-builder.h | 23 ++
 gcc/rust/checks/errors/borrowck/rust-bir.h |  1 +
 2 files changed, 24 insertions(+)

diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder.h 
b/gcc/rust/checks/errors/borrowck/rust-bir-builder.h
index b7d0651fcddb..e3d61b5b36e8 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-builder.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder.h
@@ -50,6 +50,8 @@ public:
   handle_param (param);
 
 handle_body (*function.get_definition ());
+auto region_hir_map
+  = map_region_to_hir (function.get_generic_params (), 
ctx.fn_free_regions);
 
 return Function{
   std::move (ctx.place_db),
@@ -57,6 +59,7 @@ public:
   std::move (ctx.basic_blocks),
   std::move (ctx.fn_free_regions),
   std::move (universal_region_bounds),
+  std::move (region_hir_map),
   function.get_locus (),
 };
   }
@@ -161,6 +164,26 @@ private:
push_return (return_location);
   }
   }
+
+  // Maps named lifetime parameters to their respective HIR node
+  const std::unordered_map
+  map_region_to_hir (
+const std::vector> &generic_params,
+const FreeRegions ®ions)
+  {
+std::unordered_map result;
+size_t region_index = 0;
+for (auto &generic_param : generic_params)
+  {
+   if (generic_param->get_kind ()
+   == HIR::GenericParam::GenericKind::LIFETIME)
+ {
+   result[regions[region_index++]]
+ = static_cast (generic_param.get ());
+ }
+  }
+return result;
+  }
 };
 
 } // namespace BIR
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir.h 
b/gcc/rust/checks/errors/borrowck/rust-bir.h
index 583d1ebd58fa..e8b7e39c550f 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir.h
@@ -47,6 +47,7 @@ struct Function
   std::vector basic_blocks;
   FreeRegions universal_regions;
   std::vector> universal_region_bounds;
+  std::unordered_map region_hir_map;
   location_t location;
 };


[gcc r15-8309] gccrs: Set up the hir lowering for operand

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:29d7d760147fee56916a8e1e7676226a95e96b95

commit r15-8309-g29d7d760147fee56916a8e1e7676226a95e96b95
Author: badumbatish 
Date:   Sat Jul 27 01:19:11 2024 -0700

gccrs: Set up the hir lowering for operand

gcc/rust/ChangeLog:

* hir/rust-ast-lower-expr.cc (from_operand):
Set up the lowering for operand
(ASTLoweringExpr::visit): Likewise
* hir/tree/rust-hir-expr.h (struct InlineAsmRegOrRegClass):
Not necessary, kept from ast
(struct AnonConst): Set up lowering for operand
(class InlineAsmOperand): Likewise, add getters

Diff:
---
 gcc/rust/hir/rust-ast-lower-expr.cc | 100 +-
 gcc/rust/hir/tree/rust-hir-expr.h   | 257 ++--
 2 files changed, 343 insertions(+), 14 deletions(-)

diff --git a/gcc/rust/hir/rust-ast-lower-expr.cc 
b/gcc/rust/hir/rust-ast-lower-expr.cc
index be7ff413c93f..45277e877144 100644
--- a/gcc/rust/hir/rust-ast-lower-expr.cc
+++ b/gcc/rust/hir/rust-ast-lower-expr.cc
@@ -829,6 +829,92 @@ ASTLoweringExpr::visit (AST::ClosureExprInnerTyped &expr)
expr.get_locus ());
 }
 
+HIR::InlineAsmOperand
+from_operand (const AST::InlineAsmOperand &operand)
+{
+  using RegisterType = AST::InlineAsmOperand::RegisterType;
+  using Operand = HIR::InlineAsmOperand;
+  auto type = operand.get_register_type ();
+
+  /*In,*/
+  /*Out,*/
+  /*InOut,*/
+  /*SplitInOut,*/
+  /*Const,*/
+  /*Sym,*/
+  /*Label,*/
+  if (type == RegisterType::In)
+{
+  auto in_value = operand.get_in ();
+
+  struct Operand::In in (in_value.reg,
+std::unique_ptr (ASTLoweringExpr::translate (
+  *in_value.expr.get (;
+  return in;
+}
+  else if (type == RegisterType::Out)
+{
+  auto out_value = operand.get_out ();
+  struct Operand::Out out (out_value.reg, out_value.late,
+  std::unique_ptr (
+ASTLoweringExpr::translate (
+  *out_value.expr.get (;
+  return out;
+}
+  else if (type == RegisterType::InOut)
+{
+  auto inout_value = operand.get_in_out ();
+  struct Operand::InOut inout (inout_value.reg, inout_value.late,
+  std::unique_ptr (
+ASTLoweringExpr::translate (
+  *inout_value.expr.get (;
+  return inout;
+}
+  else if (type == RegisterType::SplitInOut)
+{
+  auto split_in_out_value = operand.get_split_in_out ();
+  struct Operand::SplitInOut split_in_out (
+   split_in_out_value.reg, split_in_out_value.late,
+   std::unique_ptr (
+ ASTLoweringExpr::translate (*split_in_out_value.in_expr.get ())),
+   std::unique_ptr (
+ ASTLoweringExpr::translate (*split_in_out_value.out_expr.get (;
+  return split_in_out;
+}
+  else if (type == RegisterType::Const)
+{
+  auto const_value = operand.get_const ();
+  struct HIR::AnonConst anon_const (
+   const_value.anon_const.id,
+   std::unique_ptr (
+ ASTLoweringExpr::translate (*const_value.anon_const.expr.get (;
+  struct Operand::Const cnst
+  {
+   anon_const
+  };
+  return cnst;
+}
+  else if (type == RegisterType::Sym)
+{
+  auto sym_value = operand.get_sym ();
+  struct Operand::Sym sym (std::unique_ptr (
+   ASTLoweringExpr::translate (*sym_value.expr.get (;
+  return sym;
+}
+  else if (type == RegisterType::Label)
+{
+  auto label_value = operand.get_label ();
+  struct Operand::Label label (label_value.label_name,
+  std::unique_ptr (
+ASTLoweringExpr::translate (
+  *label_value.expr.get (;
+  return label;
+}
+  else
+{
+  rust_unreachable ();
+}
+}
 void
 ASTLoweringExpr::visit (AST::InlineAsm &expr)
 {
@@ -837,10 +923,22 @@ ASTLoweringExpr::visit (AST::InlineAsm &expr)
 mappings.get_next_hir_id (crate_num),
 mappings.get_next_localdef_id (crate_num));
 
+  std::vector hir_operands;
+  std::vector ast_operands = expr.get_operands ();
+  /*int ast_operands_size = ast_operands.size ();*/
+  for (auto &operand : ast_operands)
+{
+  hir_operands.push_back (from_operand (operand));
+}
+  /*int hir_operands_size = hir_operands.size ();*/
+
+  /*rust_debug ("{bdbt} : There are %d ast operands prelowering and %d hir "*/
+  /* "operands after lowering\n",*/
+  /* ast_operands_size, hir_operands_size);*/
   translated
 = new HIR::InlineAsm (expr.get_locus (), expr.is_global_asm,
  expr.get_template_ (), expr.get_template_strs (),
- expr.get_operands (), expr.get_clobber_abi (),

[gcc r15-8308] gccrs: Improve compressed point bit manipulation

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:ec9d9b6b2cbab28d58c5fe0d3f2e03845d8e00db

commit r15-8308-gec9d9b6b2cbab28d58c5fe0d3f2e03845d8e00db
Author: Kushal Pal 
Date:   Wed Jul 31 10:53:35 2024 +

gccrs: Improve compressed point bit manipulation

gcc/rust/ChangeLog:

* checks/errors/borrowck/polonius/rust-polonius.h (struct 
FullPoint):
Added comments and made extraction of statement more verbose for
better understanding.
* checks/errors/borrowck/ffi-polonius/src/lib.rs: Likewise.

Signed-off-by: Kushal Pal 

Diff:
---
 .../checks/errors/borrowck/ffi-polonius/src/lib.rs  | 17 -
 .../checks/errors/borrowck/polonius/rust-polonius.h | 21 +++--
 2 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/gcc/rust/checks/errors/borrowck/ffi-polonius/src/lib.rs 
b/gcc/rust/checks/errors/borrowck/ffi-polonius/src/lib.rs
index c5c0ae9756e5..b21dee3cbc66 100644
--- a/gcc/rust/checks/errors/borrowck/ffi-polonius/src/lib.rs
+++ b/gcc/rust/checks/errors/borrowck/ffi-polonius/src/lib.rs
@@ -105,9 +105,24 @@ impl From for AllFacts {
 
 fn print_point(point: GccrsAtom) {
 let val: usize = point.into();
+// Point is a 32 bit unsigned integer
+// 16   15  1
+//  xxx x
+// ^~~~ ^~~ ^
+// ||   |
+// basic_block  |   start/mid
+//  statement
+// the left most 16 bits store the basic block number
+// the right most bit, represents the start/mid status
+// the remaining 15 bits between these two represent the statement
 let mid = val % 2 == 1;
 let bb = val >> 16;
-let stmt = (val >> 1) & ((1 << 15) - 1);
+// firstly we can get rid of right most bit by performing left shift once
+let hide_left_most_bit = val >> 1;
+// now we only need the 15 bits on the right
+// we can mask the remaining bits by performing bitwise AND with fifteen
+// 1's which in hexadecimal is 0x7FFF
+let stmt = hide_left_most_bit & 0x7FFF;
 eprint!("{}(bb{}[{}])", if mid { "Mid" } else { "Start" }, bb, stmt);
 }
 
diff --git a/gcc/rust/checks/errors/borrowck/polonius/rust-polonius.h 
b/gcc/rust/checks/errors/borrowck/polonius/rust-polonius.h
index 4447ad594304..0ce214218212 100644
--- a/gcc/rust/checks/errors/borrowck/polonius/rust-polonius.h
+++ b/gcc/rust/checks/errors/borrowck/polonius/rust-polonius.h
@@ -35,7 +35,7 @@ struct FullPoint
   bool mid;
 
   /** Expands a compressed `Point` into its components.
-   * See `Point` docs for encoding details.
+   * See `Point` docs for encoding details in ./rust-polonius-ffi.h
*/
   explicit FullPoint (Point point)
 : bb (extract_bb (point)), stmt (extract_stmt (point)),
@@ -45,7 +45,24 @@ struct FullPoint
   static uint32_t extract_bb (Point point) { return point >> 16; }
   static uint32_t extract_stmt (Point point)
   {
-return (point >> 1) & ((1 << 15) - 1);
+// Point is a 32 bit unsigned integer
+// 16   15  1
+//  xxx x
+// ^~~~ ^~~ ^
+// ||   |
+// basic_block  |   start/mid
+//  statement
+// the left most 16 bits store the basic block number
+// the right most bit, represents the start/mid status
+// the remaining 15 bits between these two represent the statement number
+// which we need to extract in this fucntion
+//
+// firstly we can get rid of right most bit by performing left shift once
+auto hide_left_most_bit = point >> 1;
+// now we only need the 15 bits on the right
+// we can mask the remaining bits by performing bitwise AND with fifteen
+// 1's which in hexadecimal is 0x7FFF
+return hide_left_most_bit & 0x7FFF;
   }
   static bool extract_mid (Point point) { return point & 1; }


[gcc r15-8322] gccrs: Move errors with locations

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:5c2ecc630d95077e533d6cac6bf6c4e0f16ba623

commit r15-8322-g5c2ecc630d95077e533d6cac6bf6c4e0f16ba623
Author: Kushal Pal 
Date:   Mon Aug 12 05:48:27 2024 +

gccrs: Move errors with locations

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-borrow-checker-diagnostics.cc
(BorrowCheckerDiagnostics::report_move_errors): Specify
locations for code causing errors and related moves.

gcc/testsuite/ChangeLog:

* rust/borrowck/test_move.rs: Test rich-errors related to moves.
* rust/borrowck/test_move_conditional.rs: Likewise.

Signed-off-by: Kushal Pal 

Diff:
---
 .../borrowck/rust-borrow-checker-diagnostics.cc| 39 +--
 gcc/testsuite/rust/borrowck/test_move.rs   | 22 +--
 .../rust/borrowck/test_move_conditional.rs | 45 --
 3 files changed, 96 insertions(+), 10 deletions(-)

diff --git a/gcc/rust/checks/errors/borrowck/rust-borrow-checker-diagnostics.cc 
b/gcc/rust/checks/errors/borrowck/rust-borrow-checker-diagnostics.cc
index dc010291073d..f2e4c38cfa0f 100644
--- a/gcc/rust/checks/errors/borrowck/rust-borrow-checker-diagnostics.cc
+++ b/gcc/rust/checks/errors/borrowck/rust-borrow-checker-diagnostics.cc
@@ -34,11 +34,42 @@ BorrowCheckerDiagnostics::report_errors ()
 void
 BorrowCheckerDiagnostics::report_move_errors ()
 {
-  if (!move_errors.empty ())
+  for (const auto &pair : move_errors)
 {
-  rust_error_at (hir_function->get_locus (),
-"Found move errors in function %s",
-hir_function->get_function_name ().as_string ().c_str ());
+  auto error_location = get_statement (pair.first).get_location ();
+
+  // in future, we can use the assigned at location to hint the
+  // user to implement copy trait for the type
+  /*
+  for (auto it : facts.path_assigned_at_base)
+   {
+ if (pair.second[0] == it.first)
+   {
+ auto point_assigned_at = it.second;
+ auto assigned_at_location
+   = get_statement (point_assigned_at).get_location ();
+   }
+   }
+   */
+
+  std::vector labels{
+   {"moved value used here", error_location}};
+  // add labels to all the moves for the given path
+  for (auto it : facts.path_moved_at_base)
+   {
+ if (pair.second[0] == it.first)
+   {
+ auto point_moved_at = it.second;
+ // don't label the move location where the error occured
+ if (pair.first != point_moved_at)
+   {
+ auto move_at_location
+   = get_statement (point_moved_at).get_location ();
+ labels.push_back ({"value moved here", move_at_location});
+   }
+   }
+   }
+  multi_label_error ("use of moved value", error_location, labels);
 }
 }
 
diff --git a/gcc/testsuite/rust/borrowck/test_move.rs 
b/gcc/testsuite/rust/borrowck/test_move.rs
index 26a1a5b7bdec..b6475839c04a 100644
--- a/gcc/testsuite/rust/borrowck/test_move.rs
+++ b/gcc/testsuite/rust/borrowck/test_move.rs
@@ -1,11 +1,27 @@
-// { dg-additional-options "-frust-compile-until=compilation 
-frust-borrowcheck" }
-fn test_move() { // { dg-error "Found move errors in function test_move" }
+// { dg-additional-options "-frust-compile-until=compilation 
-frust-borrowcheck -fdiagnostics-show-caret -fdiagnostics-show-line-numbers" }
+// { dg-enable-nn-line-numbers "" }
+
+fn test_move() {
 struct A {
 i: i32,
 }
 let a = A { i: 1 };
 let b = a;
-let c = a;
+let c = a; //~ ERROR
+// { dg-error "use of moved value" "" { target *-*-* } .-1 }
+/*
+ { dg-begin-multiline-output "" }
+   NN | let b = a;
+  | ~
+  | |
+  | value moved here
+   NN | let c = a; //~ ERROR
+  | ^
+  | |
+  | moved value used here
+ { dg-end-multiline-output "" }
+ */
+
 }
 
 fn test_move_fixed() {
diff --git a/gcc/testsuite/rust/borrowck/test_move_conditional.rs 
b/gcc/testsuite/rust/borrowck/test_move_conditional.rs
index e1e8e2025cf1..94882bca5a77 100644
--- a/gcc/testsuite/rust/borrowck/test_move_conditional.rs
+++ b/gcc/testsuite/rust/borrowck/test_move_conditional.rs
@@ -1,6 +1,7 @@
-// { dg-additional-options "-frust-compile-until=compilation 
-frust-borrowcheck" }
+// { dg-additional-options "-frust-compile-until=compilation 
-frust-borrowcheck -fdiagnostics-show-caret -fdiagnostics-show-line-numbers" }
+// { dg-enable-nn-line-numbers "" }
 
-fn test_move_conditional(b1: bool, b2:bool) { // { dg-error "Found move errors 
in function test_move" }
+fn test_move_conditional(b1: bool, b2:bool) {
 struct A {
 i: i32,
 }
@@ -9,9 +10,47 @@ fn test_move_conditional(b1: bool, b2:bool) { // { dg-error 
"Found move errors i
 let b = a;
 if b1 {

[gcc r15-8305] gccrs: Fixed bitwise operation in `extract_stmt`

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:86d5412d85b907fd63b5c86817e35e506ea3f7f0

commit r15-8305-g86d5412d85b907fd63b5c86817e35e506ea3f7f0
Author: Kushal Pal 
Date:   Fri Jul 26 07:51:43 2024 +

gccrs: Fixed bitwise operation in `extract_stmt`

gcc/rust/ChangeLog:

* checks/errors/borrowck/polonius/rust-polonius.h (struct 
FullPoint):
This is the correct way of extracting the required bits.

Signed-off-by: Kushal Pal 

Diff:
---
 gcc/rust/checks/errors/borrowck/polonius/rust-polonius.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/rust/checks/errors/borrowck/polonius/rust-polonius.h 
b/gcc/rust/checks/errors/borrowck/polonius/rust-polonius.h
index b013a93671c5..4447ad594304 100644
--- a/gcc/rust/checks/errors/borrowck/polonius/rust-polonius.h
+++ b/gcc/rust/checks/errors/borrowck/polonius/rust-polonius.h
@@ -45,7 +45,7 @@ struct FullPoint
   static uint32_t extract_bb (Point point) { return point >> 16; }
   static uint32_t extract_stmt (Point point)
   {
-return (point & ~(1 << 16)) >> 1;
+return (point >> 1) & ((1 << 15) - 1);
   }
   static bool extract_mid (Point point) { return point & 1; }


[gcc r15-8307] gccrs: Use new constructors and control flow for operand

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:03e7521c90abe2f592640a2ad9d3b26ef91ab5a5

commit r15-8307-g03e7521c90abe2f592640a2ad9d3b26ef91ab5a5
Author: badumbatish 
Date:   Mon Jul 29 19:00:47 2024 -0700

gccrs: Use new constructors and control flow for operand

gcc/rust/ChangeLog:

* ast/rust-expr.h (struct InlineAsmOperand): changed to class
(class InlineAsmOperand): Have appropriate constructor,
and getter
* expand/rust-macro-builtins-asm.cc (parse_reg_operand):
Use the new implement constructors and new control flow.
(parse_reg_operand_in): Likewise
(parse_reg_operand_out): Likewise
(parse_reg_operand_inout): Likewise
(parse_reg_operand_const): Likewise

Diff:
---
 gcc/rust/ast/rust-expr.h   | 98 --
 gcc/rust/expand/rust-macro-builtins-asm.cc | 39 +---
 2 files changed, 53 insertions(+), 84 deletions(-)

diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index 8a3baf7ca2b4..749fdc05f2ba 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -4768,8 +4768,9 @@ struct InlineAsmRegOrRegClass
   location_t locus;
 };
 
-struct InlineAsmOperand
+class InlineAsmOperand
 {
+public:
   enum RegisterType
   {
 In,
@@ -4952,75 +4953,52 @@ struct InlineAsmOperand
 }
   };
 
-  RegisterType register_type;
-
-  tl::optional in;
-  tl::optional out;
-  tl::optional in_out;
-  tl::optional split_in_out;
-  tl::optional cnst;
-  tl::optional sym;
-  tl::optional label;
-
-  InlineAsmOperand () {}
   InlineAsmOperand (const InlineAsmOperand &other)
 : register_type (other.register_type), in (other.in), out (other.out),
   in_out (other.in_out), split_in_out (other.split_in_out),
   cnst (other.cnst), sym (other.sym)
   {}
 
-  void set_in (const tl::optional ®)
-  {
-this->register_type = In;
-
-if (reg.has_value ())
-  this->in = reg.value ();
-  }
-
-  void set_out (const tl::optional ®)
-  {
-this->register_type = Out;
-
-if (reg.has_value ())
-  this->out = reg.value ();
-  }
-
-  void set_in_out (const tl::optional ®)
-  {
-this->register_type = InOut;
-if (reg.has_value ())
-  this->in_out = reg.value ();
-  }
-
-  void set_split_in_out (const tl::optional ®)
-  {
-this->register_type = SplitInOut;
-if (reg.has_value ())
-  this->split_in_out = reg.value ();
-  }
-
-  void set_cnst (const tl::optional ®)
-  {
-this->register_type = Const;
-if (reg.has_value ())
-  this->cnst = reg.value ();
-  }
+  InlineAsmOperand (const struct In ®) : register_type (In), in (reg) {}
+  InlineAsmOperand (const struct Out ®) : register_type (Out), out (reg) {}
+  InlineAsmOperand (const struct InOut ®)
+: register_type (InOut), in_out (reg)
+  {}
+  InlineAsmOperand (const struct SplitInOut ®)
+: register_type (SplitInOut), split_in_out (reg)
+  {}
+  InlineAsmOperand (const struct Const ®) : register_type (Const), cnst 
(reg)
+  {}
+  InlineAsmOperand (const struct Sym ®) : register_type (Sym), sym (reg) {}
+  InlineAsmOperand (const struct Label ®)
+: register_type (Label), label (reg)
+  {}
 
-  void set_sym (const tl::optional ®)
-  {
-this->register_type = Sym;
-if (reg.has_value ())
-  this->sym = reg.value ();
-  }
+  location_t get_locus () const { return locus; }
+  RegisterType get_register_type () const { return register_type; }
+
+  // Potentially fail immediately if you don't use get_register_type() to
+  // inspect the RegisterType first before calling the following functions 
Check
+  // first
+  struct In get_in () const { return in.value (); }
+  struct Out get_out () const { return out.value (); }
+  struct InOut get_in_out () const { return in_out.value (); }
+  struct SplitInOut get_split_in_out () const { return split_in_out.value (); }
+  struct Const get_const () const { return cnst.value (); }
+  struct Sym get_sym () const { return sym.value (); }
+  struct Label get_label () const { return label.value (); }
 
-  void set_label (const tl::optional ®)
-  {
-this->register_type = Label;
-if (reg.has_value ())
-  this->label = reg.value ();
-  }
+private:
+  RegisterType register_type;
 
   location_t locus;
+  tl::optional in;
+  tl::optional out;
+  tl::optional in_out;
+  tl::optional split_in_out;
+  tl::optional cnst;
+  tl::optional sym;
+  tl::optional label;
 };
 
 struct InlineAsmPlaceHolder
diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index d270621d1bf1..7f0498fdef4b 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -193,7 +193,6 @@ parse_reg_operand (InlineAsmContext inline_asm_ctx)
   //   None
   //   };
   auto &parser = inline_asm_ctx.parser;
-  AST::InlineAsmOperand reg_operand;
   auto token = parser.peek_current_token ();
   auto iden_token = parser.peek_current_token ()

[gcc r15-8298] gccrs: Properly striping struct fields when using attrs

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:af654898a7b10b8789f6f0246169e24f4743643c

commit r15-8298-gaf654898a7b10b8789f6f0246169e24f4743643c
Author: Antonio Gomes 
Date:   Thu Jul 18 22:50:54 2024 -0300

gccrs: Properly striping struct fields when using attrs

gcc/rust/ChangeLog:
* expand/rust-cfg-strip.cc:
Strip struct expr fields and strip fields in struct definition
* expand/rust-cfg-strip.h:
Signatures for new function maybe_strip_struct_expr_fields

gcc/testsuite/ChangeLog:
* rust/compile/macro-issue2983_2984.rs:
Add test to check for correct stripped fields

Signed-off-by: Antonio Gomes 

Diff:
---
 gcc/rust/expand/rust-cfg-strip.cc  | 26 +
 gcc/rust/expand/rust-cfg-strip.h   |  2 ++
 gcc/testsuite/rust/compile/macro-issue2983_2984.rs | 27 ++
 3 files changed, 55 insertions(+)

diff --git a/gcc/rust/expand/rust-cfg-strip.cc 
b/gcc/rust/expand/rust-cfg-strip.cc
index 8abc5cb766e8..4e6a8ac2b5fa 100644
--- a/gcc/rust/expand/rust-cfg-strip.cc
+++ b/gcc/rust/expand/rust-cfg-strip.cc
@@ -194,6 +194,26 @@ CfgStrip::maybe_strip_struct_fields 
(std::vector &fields)
 }
 }
 
+void
+CfgStrip::maybe_strip_struct_expr_fields (
+  std::vector> &fields)
+{
+  for (auto it = fields.begin (); it != fields.end ();)
+{
+  auto &field = *it;
+
+  auto &field_attrs = field->get_outer_attrs ();
+  expand_cfg_attrs (field_attrs);
+  if (fails_cfg_with_expand (field_attrs))
+   {
+ it = fields.erase (it);
+ continue;
+   }
+
+  ++it;
+}
+}
+
 void
 CfgStrip::maybe_strip_tuple_fields (std::vector &fields)
 {
@@ -962,6 +982,8 @@ CfgStrip::visit (AST::StructExprStructFields &expr)
   "cannot strip expression in this position - outer "
   "attributes not allowed");
 }
+
+  maybe_strip_struct_expr_fields (expr.get_fields ());
 }
 
 void
@@ -1852,6 +1874,10 @@ CfgStrip::visit (AST::StructStruct &struct_item)
 }
 
   AST::DefaultASTVisitor::visit (struct_item);
+
+  /* strip struct fields if required - this is presumably
+   * allowed by spec */
+  maybe_strip_struct_fields (struct_item.get_fields ());
 }
 void
 CfgStrip::visit (AST::TupleStruct &tuple_struct)
diff --git a/gcc/rust/expand/rust-cfg-strip.h b/gcc/rust/expand/rust-cfg-strip.h
index 773bfdeaf8c1..4900ae893edd 100644
--- a/gcc/rust/expand/rust-cfg-strip.h
+++ b/gcc/rust/expand/rust-cfg-strip.h
@@ -36,6 +36,8 @@ public:
   void go (AST::Crate &crate);
 
   void maybe_strip_struct_fields (std::vector &fields);
+  void maybe_strip_struct_expr_fields (
+std::vector> &fields);
   void maybe_strip_tuple_fields (std::vector &fields);
   void maybe_strip_function_params (
 std::vector> ¶ms);
diff --git a/gcc/testsuite/rust/compile/macro-issue2983_2984.rs 
b/gcc/testsuite/rust/compile/macro-issue2983_2984.rs
new file mode 100644
index ..637d5728c507
--- /dev/null
+++ b/gcc/testsuite/rust/compile/macro-issue2983_2984.rs
@@ -0,0 +1,27 @@
+pub struct ReadDir {
+pub inner: i32,
+#[cfg(not(A))]
+pub end_of_stream: bool,
+#[cfg(A)]
+pub end_of_stream_but_different: bool,
+}
+
+fn main() {
+// Success
+let _ = ReadDir {
+inner: 14,
+#[cfg(not(A))]
+end_of_stream: false,
+#[cfg(A)]
+end_of_stream_but_different: false,
+};
+
+// Error
+let _ = ReadDir {
+inner: 14,
+end_of_stream: false,
+end_of_stream_but_different: false, // { dg-error "failed to resolve 
type for field" }
+// { dg-error "unknown field" "" { target *-*-* } .-1 }
+// { dg-prune-output "compilation terminated" }
+};
+}


[gcc r15-8315] gccrs: Loan errors with locations

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:6777f6cf2ad3b749be31346be6f7a9d79b7f082b

commit r15-8315-g6777f6cf2ad3b749be31346be6f7a9d79b7f082b
Author: Kushal Pal 
Date:   Thu Jul 18 08:12:49 2024 +

gccrs: Loan errors with locations

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-borrow-checker-diagnostics.cc
(BorrowCheckerDiagnostics::report_loan_errors): Add label to
where the borrow occurs and where the invalid access occurs.
(BorrowCheckerDiagnostics::get_statement):
Fetch BIR::Statement from Polonius::Point
(BorrowCheckerDiagnostics::get_loan):
Fetch BIR::Loan from Polonius::Loan
* checks/errors/borrowck/rust-borrow-checker-diagnostics.h:
Function definition of helpers.

gcc/testsuite/ChangeLog:

* rust/borrowck/reference.rs: Test rich errors for
borrow-checker.
* rust/borrowck/return_ref_to_local.rs: Likewise.
* rust/borrowck/tmp.rs: Likewise.
* rust/borrowck/use_while_mut.rs: Likewise.
* rust/borrowck/use_while_mut_fr.rs: Likewise.
* rust/borrowck/well_formed_function_inputs.rs: Likewise.

Signed-off-by: Kushal Pal 

Diff:
---
 .../borrowck/rust-borrow-checker-diagnostics.cc| 47 ++-
 .../borrowck/rust-borrow-checker-diagnostics.h | 13 +++
 gcc/testsuite/rust/borrowck/reference.rs   | 96 --
 gcc/testsuite/rust/borrowck/return_ref_to_local.rs | 15 +++-
 gcc/testsuite/rust/borrowck/tmp.rs | 95 +++--
 gcc/testsuite/rust/borrowck/use_while_mut.rs   | 21 -
 gcc/testsuite/rust/borrowck/use_while_mut_fr.rs| 19 -
 .../rust/borrowck/well_formed_function_inputs.rs   | 21 -
 8 files changed, 295 insertions(+), 32 deletions(-)

diff --git a/gcc/rust/checks/errors/borrowck/rust-borrow-checker-diagnostics.cc 
b/gcc/rust/checks/errors/borrowck/rust-borrow-checker-diagnostics.cc
index a8eaa807ebb0..0365dc3bd6fe 100644
--- a/gcc/rust/checks/errors/borrowck/rust-borrow-checker-diagnostics.cc
+++ b/gcc/rust/checks/errors/borrowck/rust-borrow-checker-diagnostics.cc
@@ -17,6 +17,8 @@
 // .
 
 #include "rust-borrow-checker-diagnostics.h"
+#include "polonius/rust-polonius-ffi.h"
+#include "rust-diagnostics.h"
 
 namespace Rust {
 namespace BIR {
@@ -43,11 +45,16 @@ BorrowCheckerDiagnostics::report_move_errors ()
 void
 BorrowCheckerDiagnostics::report_loan_errors ()
 {
-  if (!loan_errors.empty ())
+  for (const auto &pair : loan_errors)
 {
-  rust_error_at (hir_function->get_locus (),
-"Found loan errors in function %s",
-hir_function->get_function_name ().as_string ().c_str ());
+  auto error_location = get_statement (pair.first).get_location ();
+  for (const auto &loan : pair.second)
+   {
+ auto loan_struct = get_loan (loan);
+ multi_label_error ("use of borrowed value", error_location,
+{{"borrow occurs here", loan_struct.location},
+ {"borrowed value used here", error_location}});
+   }
 }
 }
 
@@ -63,5 +70,37 @@ BorrowCheckerDiagnostics::report_subset_errors ()
 }
 }
 
+const BIR::Statement &
+BorrowCheckerDiagnostics::get_statement (Polonius::Point point)
+{
+  auto statement_index = Polonius::FullPoint::extract_stmt (point);
+  auto bb_index = Polonius::FullPoint::extract_bb (point);
+  // assert that the extracted indexes are valid
+  rust_assert (bb_index < bir_function.basic_blocks.size ());
+  rust_assert (statement_index
+  < bir_function.basic_blocks[bb_index].statements.size ());
+  return bir_function.basic_blocks[bb_index].statements[statement_index];
+}
+
+const BIR::Loan &
+BorrowCheckerDiagnostics::get_loan (Polonius::Loan loan)
+{
+  return bir_function.place_db.get_loans ()[loan];
+}
+
+void
+BorrowCheckerDiagnostics::multi_label_error (
+  const char *error_message, location_t error_location,
+  std::vector location_label_pairs)
+{
+  rich_location r{line_table, error_location};
+  for (auto &label_location : location_label_pairs)
+{
+  r.add_range (label_location.location, SHOW_RANGE_WITHOUT_CARET,
+  &label_location.label);
+}
+  rust_error_at (r, "%s", error_message);
+}
+
 } // namespace BIR
 } // namespace Rust
diff --git a/gcc/rust/checks/errors/borrowck/rust-borrow-checker-diagnostics.h 
b/gcc/rust/checks/errors/borrowck/rust-borrow-checker-diagnostics.h
index 90d5ed8aaef7..136f46790751 100644
--- a/gcc/rust/checks/errors/borrowck/rust-borrow-checker-diagnostics.h
+++ b/gcc/rust/checks/errors/borrowck/rust-borrow-checker-diagnostics.h
@@ -22,6 +22,7 @@
 #include "polonius/rust-polonius.h"
 #include "rust-bir.h"
 #include "rust-hir-item.h"
+#include "text-range-label.h"
 
 namespace Rust {
 namespace BIR {
@@ -62,6 +63,18 @@ private:
   void report_move_errors ();
   void repor

[gcc r15-8329] gccrs: feature-gate: Cleanup visitor and constructor

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:85a3c48f51dbef4e74f806aca36825a6164db636

commit r15-8329-g85a3c48f51dbef4e74f806aca36825a6164db636
Author: Arthur Cohen 
Date:   Wed Aug 21 15:42:58 2024 +0200

gccrs: feature-gate: Cleanup visitor and constructor

This commit turns a few of the fields into `tl::optional` and cleanups
the constructor with a couple default parameters. We can also reuse the
variable that we are `switch`ing on, instead of repeating the enum variants
each time.

Most importantly, the `FeatureGate` visitor now uses the `DefaultAstVisitor`
correctly, and will now visit nested items. This means that we have to
fix a bunch of the testsuite as some feature attributes were missing.

gcc/rust/ChangeLog:

* checks/errors/rust-feature.cc (Feature::create): Reuse variable,
remove now optional parameters from constructor.
* checks/errors/rust-feature.h: Cleanup class definition.
* checks/errors/rust-feature-gate.cc (FeatureGate::gate): Use 
optional.
* checks/errors/rust-feature-gate.h: Cleanup visitor implementation.

gcc/testsuite/ChangeLog:

* rust/compile/assume.rs: Add missing feature attribute.
* rust/compile/issue-1901.rs: Likewise.
* rust/compile/issue-1981.rs: Likewise.
* rust/compile/sizeof-stray-infer-var-bug.rs: Likewise.
* rust/compile/torture/intrinsics-8.rs: Likewise.
* rust/compile/torture/transmute-size-check-1.rs: Likewise.
* rust/compile/torture/transmute1.rs: Likewise.
* rust/compile/torture/uninit-intrinsic-1.rs: Likewise.
* rust/execute/torture/issue-1436.rs: Likewise.
* rust/execute/torture/issue-2583.rs: Likewise.

Diff:
---
 .../checks/errors/borrowck/ffi-polonius/Cargo.lock |  39 ++
 gcc/rust/checks/errors/rust-feature-gate.cc|  10 +-
 gcc/rust/checks/errors/rust-feature-gate.h | 136 -
 gcc/rust/checks/errors/rust-feature.cc |  40 +++---
 gcc/rust/checks/errors/rust-feature.h  |  13 +-
 gcc/testsuite/rust/compile/assume.rs   |   2 +
 gcc/testsuite/rust/compile/issue-1901.rs   |   2 +
 gcc/testsuite/rust/compile/issue-1981.rs   |   2 +
 .../rust/compile/sizeof-stray-infer-var-bug.rs |   2 +
 gcc/testsuite/rust/compile/torture/intrinsics-8.rs |   2 +
 .../rust/compile/torture/transmute-size-check-1.rs |   2 +
 gcc/testsuite/rust/compile/torture/transmute1.rs   |   2 +
 .../rust/compile/torture/uninit-intrinsic-1.rs |   2 +
 gcc/testsuite/rust/execute/torture/issue-1436.rs   |   3 +
 gcc/testsuite/rust/execute/torture/issue-2583.rs   |   2 +
 15 files changed, 90 insertions(+), 169 deletions(-)

diff --git a/gcc/rust/checks/errors/borrowck/ffi-polonius/Cargo.lock 
b/gcc/rust/checks/errors/borrowck/ffi-polonius/Cargo.lock
new file mode 100644
index ..f7cbd414caf5
--- /dev/null
+++ b/gcc/rust/checks/errors/borrowck/ffi-polonius/Cargo.lock
@@ -0,0 +1,39 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 3
+
+[[package]]
+name = "datafrog"
+version = "2.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index";
+checksum = "a0afaad2b26fa326569eb264b1363e8ae3357618c43982b3f285f0774ce76b69"
+
+[[package]]
+name = "ffi-polonius"
+version = "0.1.0"
+dependencies = [
+ "polonius-engine",
+]
+
+[[package]]
+name = "log"
+version = "0.4.22"
+source = "registry+https://github.com/rust-lang/crates.io-index";
+checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24"
+
+[[package]]
+name = "polonius-engine"
+version = "0.13.0"
+source = "registry+https://github.com/rust-lang/crates.io-index";
+checksum = "c4e8e505342045d397d0b6674dcb82d6faf5cf40484d30eeb88fc82ef14e903f"
+dependencies = [
+ "datafrog",
+ "log",
+ "rustc-hash",
+]
+
+[[package]]
+name = "rustc-hash"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index";
+checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
diff --git a/gcc/rust/checks/errors/rust-feature-gate.cc 
b/gcc/rust/checks/errors/rust-feature-gate.cc
index ca19374b4f36..4ab614e88537 100644
--- a/gcc/rust/checks/errors/rust-feature-gate.cc
+++ b/gcc/rust/checks/errors/rust-feature-gate.cc
@@ -21,6 +21,7 @@
 #include "rust-attribute-values.h"
 #include "rust-ast-visitor.h"
 #include "rust-feature.h"
+#include "rust-ast-full.h"
 
 namespace Rust {
 
@@ -75,16 +76,17 @@ FeatureGate::gate (Feature::Name name, location_t loc,
   if (!valid_features.count (name))
 {
   auto feature = Feature::create (name);
-  auto issue = feature.issue ();
-  if (issue > 0)
+  if (auto issue = feature.issue ())
{
+ auto issue_number = issue.value ();
  const char *fmt_str
= "%s. see issue %u "
  " for mo

[gcc r15-8314] gccrs: Add location to BIR::Statement of kind RETURN

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:715b62375c2f2a16a21221246b85c2298906f5f3

commit r15-8314-g715b62375c2f2a16a21221246b85c2298906f5f3
Author: Kushal Pal 
Date:   Fri Jul 19 07:30:03 2024 +

gccrs: Add location to BIR::Statement of kind RETURN

This commit adds location_t to BIR::Statement where type is RETURN.

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc 
(ExprStmtBuilder::visit):
Add location parameter.
* checks/errors/borrowck/rust-bir-builder.h: Likewise.
* checks/errors/borrowck/rust-bir-builder-internal.h: Add helper
function for pushing return statements.
* checks/errors/borrowck/rust-bir.h: Remove `expr` parameter as
it is only needed for ASSIGNMENT statements, for which we
already have a constructor.

Signed-off-by: Kushal Pal 

Diff:
---
 gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc | 4 ++--
 gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h   | 6 ++
 gcc/rust/checks/errors/borrowck/rust-bir-builder.h| 5 -
 gcc/rust/checks/errors/borrowck/rust-bir.h| 7 +++
 4 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc 
b/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
index 49b830124d75..3515bdf030b6 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
@@ -485,10 +485,10 @@ ExprStmtBuilder::visit (HIR::ReturnExpr &ret)
   push_assignment (RETURN_VALUE_PLACE,
   move_place (visit_expr (*ret.get_expr ()),
   ret.get_expr ()->get_locus ()),
-  ret.get_locus ());
+  ret.get_expr ()->get_locus ());
 }
   unwind_until (ROOT_SCOPE);
-  ctx.get_current_bb ().statements.emplace_back (Statement::Kind::RETURN);
+  push_return (ret.get_locus ());
   translated = INVALID_PLACE;
 }
 
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h 
b/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h
index 16fcb6abca73..34726cf4840c 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h
@@ -303,6 +303,12 @@ protected: // Helpers to add BIR statements
   place);
   }
 
+  void push_return (location_t location)
+  {
+ctx.get_current_bb ().statements.emplace_back (Statement::Kind::RETURN,
+  INVALID_PLACE, location);
+  }
+
   PlaceId borrow_place (PlaceId place_id, TyTy::BaseType *ty,
location_t location)
   {
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder.h 
b/gcc/rust/checks/errors/borrowck/rust-bir-builder.h
index 4f7d2b074757..b7d0651fcddb 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-builder.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder.h
@@ -155,7 +155,10 @@ private:
   ctx.place_db[RETURN_VALUE_PLACE].tyty),
 body.get_end_locus ());
  }
-   ctx.get_current_bb ().statements.emplace_back (Statement::Kind::RETURN);
+   auto return_location = body.has_expr ()
+? body.get_final_expr ()->get_locus ()
+: body.get_end_locus ();
+   push_return (return_location);
   }
   }
 };
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir.h 
b/gcc/rust/checks/errors/borrowck/rust-bir.h
index 0e0ef6643f52..74c53a68a026 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir.h
@@ -78,8 +78,8 @@ private:
   std::unique_ptr expr;
   TyTy::BaseType *type;
   // stores location of the actual expression from source code
-  // currently only available when kind == Kind::ASSIGNMENT
-  // FIXME: Add location for Statements other than ASSIGNMENT
+  // currently only available when kind is ASSIGNMENT | RETURN
+  // FIXME: Add location for other statement kinds
   location_t location;
 
 public:
@@ -88,9 +88,8 @@ public:
   {}
 
   explicit Statement (Kind kind, PlaceId place = INVALID_PLACE,
- AbstractExpr *expr = nullptr,
  location_t location = UNKNOWN_LOCATION)
-: kind (kind), place (place), expr (expr), location (location)
+: kind (kind), place (place), location (location)
   {}
 
   explicit Statement (Kind kind, PlaceId place, TyTy::BaseType *type,


[gcc r15-8313] gccrs: Implement resolve expr for inline asm ast

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:cbb99fedcfcb094371e8db71d741e9dcaa4c47fd

commit r15-8313-gcbb99fedcfcb094371e8db71d741e9dcaa4c47fd
Author: badumbatish 
Date:   Tue Jul 30 20:22:48 2024 -0700

gccrs: Implement resolve expr for inline asm ast

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit):
Implement resolve expr for inline asm ast
(translate_operand): Likewise.
* resolve/rust-ast-resolve-expr.h: Likewise.

Diff:
---
 gcc/rust/resolve/rust-ast-resolve-expr.cc | 67 ---
 gcc/rust/resolve/rust-ast-resolve-expr.h  |  2 +
 2 files changed, 63 insertions(+), 6 deletions(-)

diff --git a/gcc/rust/resolve/rust-ast-resolve-expr.cc 
b/gcc/rust/resolve/rust-ast-resolve-expr.cc
index 44ba2a8dffc4..7c2ba9c9d2cf 100644
--- a/gcc/rust/resolve/rust-ast-resolve-expr.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-expr.cc
@@ -347,6 +347,60 @@ ResolveExpr::visit (AST::BlockExpr &expr)
   resolver->get_label_scope ().pop ();
 }
 
+void
+translate_operand (AST::InlineAsm &expr, const CanonicalPath &prefix,
+  const CanonicalPath &canonical_prefix)
+{
+  const auto &operands = expr.get_operands ();
+  using RegisterType = AST::InlineAsmOperand::RegisterType;
+  for (auto &operand : operands)
+{
+  switch (operand.get_register_type ())
+   {
+ case RegisterType::In: {
+   auto in = operand.get_in ();
+   ResolveExpr::go (*in.expr, prefix, canonical_prefix);
+   break;
+ }
+ case RegisterType::Out: {
+   auto out = operand.get_out ();
+   ResolveExpr::go (*out.expr, prefix, canonical_prefix);
+   break;
+ }
+ case RegisterType::InOut: {
+   auto in_out = operand.get_in_out ();
+   ResolveExpr::go (*in_out.expr, prefix, canonical_prefix);
+   break;
+ }
+ case RegisterType::SplitInOut: {
+   auto split_in_out = operand.get_split_in_out ();
+   ResolveExpr::go (*split_in_out.in_expr, prefix, canonical_prefix);
+   ResolveExpr::go (*split_in_out.out_expr, prefix, canonical_prefix);
+   break;
+ }
+ case RegisterType::Const: {
+   auto anon_const = operand.get_const ().anon_const;
+   ResolveExpr::go (*anon_const.expr, prefix, canonical_prefix);
+   break;
+ }
+ case RegisterType::Sym: {
+   auto sym = operand.get_sym ();
+   ResolveExpr::go (*sym.expr, prefix, canonical_prefix);
+   break;
+ }
+ case RegisterType::Label: {
+   auto label = operand.get_label ();
+   ResolveExpr::go (*label.expr, prefix, canonical_prefix);
+   break;
+ }
+   }
+}
+}
+void
+ResolveExpr::visit (AST::InlineAsm &expr)
+{
+  translate_operand (expr, prefix, canonical_prefix);
+}
 void
 ResolveExpr::visit (AST::UnsafeBlockExpr &expr)
 {
@@ -478,12 +532,13 @@ ResolveExpr::visit (AST::BreakExpr &expr)
   auto &break_expr = expr.get_break_expr ();
   if (break_expr.get_ast_kind () == AST::Kind::IDENTIFIER)
{
- /* This is a break with an expression, and the expression is just a
-single identifier.  See if the identifier is either "rust" or
-"gcc", in which case we have "break rust" or "break gcc", and so
-may need to emit our funny error.  We cannot yet emit the error
-here though, because the identifier may still be in scope, and
-ICE'ing on valid programs would not be very funny.  */
+ /* This is a break with an expression, and the expression is
+just a single identifier.  See if the identifier is either
+"rust" or "gcc", in which case we have "break rust" or "break
+gcc", and so may need to emit our funny error.  We cannot yet
+emit the error here though, because the identifier may still
+be in scope, and ICE'ing on valid programs would not be very
+funny.  */
  std::string ident
= static_cast (break_expr).as_string ();
  if (ident == "rust" || ident == "gcc")
diff --git a/gcc/rust/resolve/rust-ast-resolve-expr.h 
b/gcc/rust/resolve/rust-ast-resolve-expr.h
index 75b07b81ec79..51a69e9886cc 100644
--- a/gcc/rust/resolve/rust-ast-resolve-expr.h
+++ b/gcc/rust/resolve/rust-ast-resolve-expr.h
@@ -20,6 +20,7 @@
 #define RUST_AST_RESOLVE_EXPR_H
 
 #include "rust-ast-resolve-base.h"
+#include "rust-ast.h"
 #include "rust-ast-resolve-pattern.h"
 
 namespace Rust {
@@ -54,6 +55,7 @@ public:
   void visit (AST::IfLetExpr &expr) override;
   void visit (AST::IfLetExprConseqElse &expr) override;
   void visit (AST::BlockExpr &expr) override;
+  void visit (AST::InlineAsm &expr) override;
   void visit (AST::UnsafeBlockExpr &expr) override;
   void visit (AST::ArrayElemsValues &elems) override;
   void visit (AST::ArrayExpr &expr) override;


[gcc r15-8339] gccrs: Setting up interfaces for codegen

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:0a03b4862107763bbce731d4f94373f4fd30a38c

commit r15-8339-g0a03b4862107763bbce731d4f94373f4fd30a38c
Author: jjasmine 
Date:   Sun Jun 23 19:47:17 2024 -0700

gccrs: Setting up interfaces for codegen

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit):
Setting up interfaces for codegen
* hir/tree/rust-hir-expr.h: Likewise.

Diff:
---
 gcc/rust/backend/rust-compile-expr.cc |  6 --
 gcc/rust/hir/tree/rust-hir-expr.h | 26 ++
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-expr.cc 
b/gcc/rust/backend/rust-compile-expr.cc
index 7c7bc225e7e9..2792e8b5f043 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -321,8 +321,10 @@ CompileExpr::visit (HIR::IfExpr &expr)
 void
 CompileExpr::visit (HIR::InlineAsm &expr)
 {
-  tree test_string = build_string(expr.template_strs[0].symbol.size() + 1, 
expr.template_strs[0].symbol.c_str());
-  debug(test_string);
+  // translated = build_asm_expr()(expr.get_locus(),
+  //  expr.construct_string_tree(), expr.construct_outputs(),
+  //  expr.construct_inputs(),   expr.construct_clobber_tree(),
+  //  expr.construct_label_tree(), expr.is_simple(), expr.is_inline_asm());
 }
 
 void
diff --git a/gcc/rust/hir/tree/rust-hir-expr.h 
b/gcc/rust/hir/tree/rust-hir-expr.h
index 7b2e32ec259d..ee469806847d 100644
--- a/gcc/rust/hir/tree/rust-hir-expr.h
+++ b/gcc/rust/hir/tree/rust-hir-expr.h
@@ -25,6 +25,7 @@
 #include "rust-hir-path.h"
 #include "rust-operators.h"
 #include "rust-expr.h"
+#include "tree.h"
 namespace Rust {
 namespace HIR {
 
@@ -4163,8 +4164,33 @@ public:
 
   {}
 
+  tree construct_string_tree ()
+  {
+if (template_strs.empty ())
+  return build_string (1, "");
+// Initialize to NULL_TREE
+tree string_chain = NULL_TREE;
+
+for (const auto &template_str : template_strs)
+  {
+   auto str = template_str.symbol;
+   auto string_tree = build_string (str.size () + 1, str.c_str ());
+
+   string_chain = tree_cons (NULL_TREE, string_tree, string_chain);
+  }
+// Reverse the chain before returning
+return nreverse (string_chain);
+  }
+
+  tree construct_clobber_tree () { return NULL_TREE; }
+  tree construct_label_tree () { return NULL_TREE; }
+  tree construct_inputs () { return NULL_TREE; }
+  tree construct_outputs () { return NULL_TREE; }
   // This function checks if the assembly macro is "simple" or not, according 
to
   // the tree defition (tree.h) of the
+
+  // SIMPLE indicates whether there was anything at all after the
+  // string in the asm expression
   bool is_simple ()
   {
 return operands.size () == 0 && clobber_abi.size () == 0


[gcc r15-8331] gccrs: Add typecheck for path patterns.

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:4f58a20d7e27aaa63e21dba072013b496baa94d1

commit r15-8331-g4f58a20d7e27aaa63e21dba072013b496baa94d1
Author: Raiki Tamura 
Date:   Fri Aug 9 23:56:55 2024 +0900

gccrs: Add typecheck for path patterns.

gcc/rust/ChangeLog:

* hir/tree/rust-hir.cc (Item::item_kind_string): New function.
* hir/tree/rust-hir.h: New function.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
Modify to check all arms in match expressions even if some 
of them
has errors.
* typecheck/rust-hir-type-check-pattern.cc 
(TypeCheckPattern::visit):
Add and fix check for path patterns.

gcc/testsuite/ChangeLog:

* rust/compile/issue-2324-2.rs: Fix error message.
* rust/compile/match9.rs: New test.

Signed-off-by: Raiki Tamura 

Diff:
---
 gcc/rust/hir/tree/rust-hir.cc |  38 +++
 gcc/rust/hir/tree/rust-hir.h  |   2 +
 gcc/rust/typecheck/rust-hir-type-check-expr.cc|  13 ++-
 gcc/rust/typecheck/rust-hir-type-check-pattern.cc | 118 +-
 gcc/testsuite/rust/compile/issue-2324-2.rs|   2 +-
 gcc/testsuite/rust/compile/match9.rs  |  30 ++
 6 files changed, 175 insertions(+), 28 deletions(-)

diff --git a/gcc/rust/hir/tree/rust-hir.cc b/gcc/rust/hir/tree/rust-hir.cc
index 6290e72669e2..8e0d444ce152 100644
--- a/gcc/rust/hir/tree/rust-hir.cc
+++ b/gcc/rust/hir/tree/rust-hir.cc
@@ -212,6 +212,44 @@ Module::as_string () const
   return str + "\n";
 }
 
+std::string
+Item::item_kind_string (Item::ItemKind kind)
+{
+  switch (kind)
+{
+case Item::ItemKind::Static:
+  return "static";
+case Item::ItemKind::Constant:
+  return "constant";
+case Item::ItemKind::TypeAlias:
+  return "type alias";
+case Item::ItemKind::Function:
+  return "function";
+case Item::ItemKind::UseDeclaration:
+  return "use declaration";
+case Item::ItemKind::ExternBlock:
+  return "extern block";
+case Item::ItemKind::ExternCrate:
+  return "extern crate";
+case Item::ItemKind::Struct:
+  return "struct";
+case Item::ItemKind::Union:
+  return "union";
+case Item::ItemKind::Enum:
+  return "enum";
+case Item::ItemKind::EnumItem:
+  return "enum item";
+case Item::ItemKind::Trait:
+  return "trait";
+case Item::ItemKind::Impl:
+  return "impl";
+case Item::ItemKind::Module:
+  return "module";
+default:
+  rust_unreachable ();
+}
+}
+
 std::string
 StaticItem::as_string () const
 {
diff --git a/gcc/rust/hir/tree/rust-hir.h b/gcc/rust/hir/tree/rust-hir.h
index 8a27161434e2..f8eb22db087a 100644
--- a/gcc/rust/hir/tree/rust-hir.h
+++ b/gcc/rust/hir/tree/rust-hir.h
@@ -220,6 +220,8 @@ public:
 Module,
   };
 
+  static std::string item_kind_string (ItemKind kind);
+
   virtual ItemKind get_item_kind () const = 0;
 
   // Unique pointer custom clone function
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc 
b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index 81d829525504..38734d58948b 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -1465,6 +1465,7 @@ TypeCheckExpr::visit (HIR::MatchExpr &expr)
   TyTy::BaseType *scrutinee_tyty
 = TypeCheckExpr::Resolve (expr.get_scrutinee_expr ().get ());
 
+  bool saw_error = false;
   std::vector kase_block_tys;
   for (auto &kase : expr.get_match_cases ())
 {
@@ -1475,7 +1476,10 @@ TypeCheckExpr::visit (HIR::MatchExpr &expr)
  TyTy::BaseType *kase_arm_ty
= TypeCheckPattern::Resolve (pattern.get (), scrutinee_tyty);
  if (kase_arm_ty->get_kind () == TyTy ::TypeKind::ERROR)
-   return;
+   {
+ saw_error = true;
+ continue;
+   }
 
  TyTy::BaseType *checked_kase = unify_site (
expr.get_mappings ().get_hirid (),
@@ -1484,7 +1488,10 @@ TypeCheckExpr::visit (HIR::MatchExpr &expr)
TyTy::TyWithLocation (kase_arm_ty, pattern->get_locus ()),
expr.get_locus ());
  if (checked_kase->get_kind () == TyTy::TypeKind::ERROR)
-   return;
+   {
+ saw_error = true;
+ continue;
+   }
}
 
   // check the kase type
@@ -1492,6 +1499,8 @@ TypeCheckExpr::visit (HIR::MatchExpr &expr)
= TypeCheckExpr::Resolve (kase.get_expr ().get ());
   kase_block_tys.push_back (kase_block_ty);
 }
+  if (saw_error)
+return;
 
   if (kase_block_tys.size () == 0)
 {
diff --git a/gcc/rust/typecheck/rust-hir-type-check-pattern.cc 
b/gcc/rust/typecheck/rust-hir-type-check-pattern.cc
index 2b0b02ad5ef0..a4f9a908feb4 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-pattern.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-pattern.cc
@@ -43,32 +43,100 @@ TypeCheckPattern::Resolve (

[gcc r15-8342] gccrs: Successfully produce pseudo-nop

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:0f347d53597f8c325dcea34ee19749e1ddf429d2

commit r15-8342-g0f347d53597f8c325dcea34ee19749e1ddf429d2
Author: badumbatish 
Date:   Sat Jul 6 13:17:00 2024 -0700

gccrs: Successfully produce pseudo-nop

gcc/rust/ChangeLog:

* backend/rust-compile-asm.cc (CompileAsm::add_stmt):
Deleted
(CompileAsm::CompileAsm):
Successfully produce pseudo-nop
(CompileAsm::visit): Likewise
(CompileAsm::asm_build_asm_stmt): Likewise
(CompileAsm::asm_construct_string_tree): Likewise
(CompileAsm::asm_is_inline): Likewise
* backend/rust-compile-asm.h (class CompileAsm): Likewise
* backend/rust-compile-expr.cc (CompileExpr::visit): Likewise

Diff:
---
 gcc/rust/backend/rust-compile-asm.cc  | 178 +-
 gcc/rust/backend/rust-compile-asm.h   |  73 +-
 gcc/rust/backend/rust-compile-expr.cc |   3 +-
 3 files changed, 224 insertions(+), 30 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-asm.cc 
b/gcc/rust/backend/rust-compile-asm.cc
index bc11696ed101..fe080f6aa6b9 100644
--- a/gcc/rust/backend/rust-compile-asm.cc
+++ b/gcc/rust/backend/rust-compile-asm.cc
@@ -2,34 +2,17 @@
 
 #include "rust-tree.h"
 #include "rust-system.h"
+#include 
 namespace Rust {
 namespace Compile {
 
-tree
-CompileAsm::add_stmt (tree t)
+CompileAsm::CompileAsm (Context *ctx)
+  : HIRCompileBase (ctx), translated (error_mark_node)
+{}
+void
+CompileAsm::visit (HIR::InlineAsm &expr)
 {
-  enum tree_code code = TREE_CODE (t);
-
-  if (EXPR_P (t) && code != LABEL_EXPR)
-{
-  if (!EXPR_HAS_LOCATION (t))
-   SET_EXPR_LOCATION (t, input_location);
-
-  /* When we expand a statement-tree, we must know whether or not the
-statements are full-expressions.  We record that fact here.  */
-  if (STATEMENT_CODE_P (TREE_CODE (t)))
-   STMT_IS_FULL_EXPR_P (t) = stmts_are_full_exprs_p ();
-}
-
-  if (code == LABEL_EXPR || code == CASE_LABEL_EXPR)
-STATEMENT_LIST_HAS_LABEL (cur_stmt_list) = 1;
-
-  /* Add T to the statement-tree.  Non-side-effect statements need to be
- recorded during statement expressions.  */
-  gcc_checking_assert (!stmt_list_stack->is_empty ());
-  append_to_statement_list_force (t, &cur_stmt_list);
-
-  return t;
+  return ctx->add_statement (asm_build_expr (expr));
 }
 tree
 CompileAsm::asm_build_asm_stmt (HIR::InlineAsm &expr)
@@ -43,7 +26,7 @@ CompileAsm::asm_build_asm_stmt (HIR::InlineAsm &expr)
   //   return add_stmt (args);
   // }
   //
-  return add_stmt (asm_build_expr (expr));
+  return NULL_TREE;
 }
 tree
 CompileAsm::asm_build_expr (HIR::InlineAsm &expr)
@@ -116,6 +99,8 @@ CompileAsm::asm_construct_string_tree (HIR::InlineAsm &expr)
 {
   if (expr.template_strs.empty ())
 return build_string (1, "");
+  else
+return build_string (4, "nop");
   // Initialize to NULL_TREE
   tree string_chain = NULL_TREE;
 
@@ -168,3 +153,146 @@ CompileAsm::asm_is_inline (HIR::InlineAsm &expr)
 }
 } // namespace Compile
 } // namespace Rust
+  //
+  //
+  // The following section serves as documentation for PR revieweres and future
+  // asm developers. It documents the inspriation for the implementation of the
+  // CompileAsm class
+
+// From the implementation of c-typeck.cc
+// tree
+// build_asm_stmt (bool is_volatile, tree args)
+//{
+//   if (is_volatile)
+// ASM_VOLATILE_P (args) = 1;
+//   return add_stmt (args);
+// }
+//
+///* Build an asm-expr, whose components are a STRING, some OUTPUTS,
+//   some INPUTS, and some CLOBBERS.  The latter three may be NULL.
+//   SIMPLE indicates whether there was anything at all after the
+//   string in the asm expression -- asm("blah") and asm("blah" : )
+//   are subtly different.  We use a ASM_EXPR node to represent this.
+//   LOC is the location of the asm, and IS_INLINE says whether this
+//   is asm inline.  */
+// tree
+// build_asm_expr (location_t loc, tree string, tree outputs, tree inputs,
+// tree clobbers, tree labels, bool simple, bool is_inline)
+//{
+//  tree tail;
+//  tree args;
+//  int i;
+//  const char *constraint;
+//  const char **oconstraints;
+//  bool allows_mem, allows_reg, is_inout;
+//  int ninputs, noutputs;
+//
+//  ninputs = list_length (inputs);
+//  noutputs = list_length (outputs);
+//  oconstraints = (const char **) alloca (noutputs * sizeof (const char *));
+//
+//  string = resolve_asm_operand_names (string, outputs, inputs, labels);
+//
+//  /* Remove output conversions that change the type but not the mode.  */
+//  for (i = 0, tail = outputs; tail; ++i, tail = TREE_CHAIN (tail))
+//{
+//  tree output = TREE_VALUE (tail);
+//
+//  output = c_fully_fold (output, false, NULL, true);
+//
+//  /* ??? Really, this should not be here.  Users should be using a
+//  proper lvalue, dammit.  But there's a long history of using casts
+//  in the output operands.  In cases like longlong.h, thi

[gcc r15-8327] gccrs: Fix the disorder struct and class in inline asm

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:9ba10b08213a25854909836660f28914149d723b

commit r15-8327-g9ba10b08213a25854909836660f28914149d723b
Author: badumbatish 
Date:   Mon Aug 19 16:39:11 2024 -0700

gccrs: Fix the disorder struct and class in inline asm

gcc/rust/ChangeLog:

* ast/rust-ast-full-decls.h (struct InlineAsmOperand):
Change to class
(class InlineAsmOperand): Change from struct
* hir/tree/rust-hir-full-decls.h (struct InlineAsmRegOrRegClass):
Removed from decl, used from AST
(struct AnonConst): new decl from rust-hir-expr.h
(class InlineAsmOperand): new decl from rust-hir-expr.h

Diff:
---
 gcc/rust/ast/rust-ast-full-decls.h  | 2 +-
 gcc/rust/hir/tree/rust-hir-full-decls.h | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/ast/rust-ast-full-decls.h 
b/gcc/rust/ast/rust-ast-full-decls.h
index 85f7373678a0..80d217e0c528 100644
--- a/gcc/rust/ast/rust-ast-full-decls.h
+++ b/gcc/rust/ast/rust-ast-full-decls.h
@@ -148,7 +148,7 @@ class AsyncBlockExpr;
 enum class InlineAsmOption;
 struct AnonConst;
 struct InlineAsmRegOrRegClass;
-struct InlineAsmOperand;
+class InlineAsmOperand;
 struct InlineAsmPlaceHolder;
 struct InlineAsmTemplatePiece;
 struct TupleClobber;
diff --git a/gcc/rust/hir/tree/rust-hir-full-decls.h 
b/gcc/rust/hir/tree/rust-hir-full-decls.h
index efe7c450fd26..64be7bf93d1f 100644
--- a/gcc/rust/hir/tree/rust-hir-full-decls.h
+++ b/gcc/rust/hir/tree/rust-hir-full-decls.h
@@ -125,7 +125,8 @@ class AwaitExpr;
 class AsyncBlockExpr;
 class InlineAsmReg;
 class InlineAsmRegClass;
-struct InlineAsmRegOrRegClass;
+struct AnonConst;
+class InlineAsmOperand;
 class InlineAsm;
 
 // rust-stmt.h


[gcc r15-8328] gccrs: attributes: Start handling prelude_import properly

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:231b18b071b8a809765841461cd307770ae2ee8d

commit r15-8328-g231b18b071b8a809765841461cd307770ae2ee8d
Author: Arthur Cohen 
Date:   Wed Aug 21 15:09:23 2024 +0200

gccrs: attributes: Start handling prelude_import properly

This commit adds basic handling for the `#[prelude_import]` attribute,
without doing anything functionality wise.

gcc/rust/ChangeLog:

* checks/errors/rust-feature-gate.cc (FeatureGate::visit): Add base
feature gating for `#[feature(prelude_import)]`.
* checks/errors/rust-feature-gate.h: Likewise.
* checks/errors/rust-feature.cc (Feature::create): Likewise.
* checks/errors/rust-feature.h: Likewise.
* util/rust-attribute-values.h: Add base handling for 
`#[prelude_import]`
attribute.
* util/rust-attributes.cc: Likewise.

gcc/testsuite/ChangeLog:

* rust/compile/prelude_import.rs: New test.

Diff:
---
 gcc/rust/checks/errors/rust-feature-gate.cc  |  8 
 gcc/rust/checks/errors/rust-feature-gate.h   |  2 +-
 gcc/rust/checks/errors/rust-feature.cc   |  4 
 gcc/rust/checks/errors/rust-feature.h|  1 +
 gcc/rust/util/rust-attribute-values.h|  1 +
 gcc/rust/util/rust-attributes.cc |  3 ++-
 gcc/testsuite/rust/compile/prelude_import.rs | 12 
 7 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/checks/errors/rust-feature-gate.cc 
b/gcc/rust/checks/errors/rust-feature-gate.cc
index 580afc9e1103..ca19374b4f36 100644
--- a/gcc/rust/checks/errors/rust-feature-gate.cc
+++ b/gcc/rust/checks/errors/rust-feature-gate.cc
@@ -217,4 +217,12 @@ FeatureGate::visit (AST::RangePattern &pattern)
  "exclusive range pattern syntax is experimental");
 }
 
+void
+FeatureGate::visit (AST::UseTreeGlob &use)
+{
+  // At the moment, UseTrees do not have outer attributes, but they should. we
+  // need to eventually gate `#[prelude_import]` on use-trees based on the
+  // #[feature(prelude_import)]
+}
+
 } // namespace Rust
diff --git a/gcc/rust/checks/errors/rust-feature-gate.h 
b/gcc/rust/checks/errors/rust-feature-gate.h
index 31c2ed659044..7d62a63a61ba 100644
--- a/gcc/rust/checks/errors/rust-feature-gate.h
+++ b/gcc/rust/checks/errors/rust-feature-gate.h
@@ -107,7 +107,7 @@ public:
   void visit (AST::TypeBoundWhereClauseItem &item) override {}
   void visit (AST::Module &module) override {}
   void visit (AST::ExternCrate &crate) override {}
-  void visit (AST::UseTreeGlob &use_tree) override {}
+  void visit (AST::UseTreeGlob &use_tree) override;
   void visit (AST::UseTreeList &use_tree) override {}
   void visit (AST::UseTreeRebind &use_tree) override {}
   void visit (AST::UseDeclaration &use_decl) override {}
diff --git a/gcc/rust/checks/errors/rust-feature.cc 
b/gcc/rust/checks/errors/rust-feature.cc
index 917e3b2bdd06..eba8f5bfea81 100644
--- a/gcc/rust/checks/errors/rust-feature.cc
+++ b/gcc/rust/checks/errors/rust-feature.cc
@@ -58,6 +58,9 @@ Feature::create (Feature::Name name)
   return Feature (Feature::Name::EXCLUSIVE_RANGE_PATTERN,
  Feature::State::ACTIVE, "exclusive_range_pattern",
  "1.11.0", 37854, tl::nullopt, "");
+case Feature::Name::PRELUDE_IMPORT:
+  return Feature (Feature::Name::PRELUDE_IMPORT, Feature::State::ACTIVE,
+ "prelude_import", "1.0.0", 0, tl::nullopt, "");
 default:
   rust_unreachable ();
 }
@@ -79,6 +82,7 @@ const std::map 
Feature::name_hash_map = {
   {"dropck_eyepatch", Feature::Name::DROPCK_EYEPATCH},
   {"raw_ref_op", Feature::Name::RAW_REF_OP},
   {"exclusive_range_pattern", Feature::Name::EXCLUSIVE_RANGE_PATTERN},
+  {"prelude_import", Feature::Name::PRELUDE_IMPORT},
 }; // namespace Rust
 
 tl::optional
diff --git a/gcc/rust/checks/errors/rust-feature.h 
b/gcc/rust/checks/errors/rust-feature.h
index 698aac2dc635..2b134e2d2c86 100644
--- a/gcc/rust/checks/errors/rust-feature.h
+++ b/gcc/rust/checks/errors/rust-feature.h
@@ -50,6 +50,7 @@ public:
 DROPCK_EYEPATCH,
 RAW_REF_OP,
 EXCLUSIVE_RANGE_PATTERN,
+PRELUDE_IMPORT,
   };
 
   const std::string &as_string () { return m_name_str; }
diff --git a/gcc/rust/util/rust-attribute-values.h 
b/gcc/rust/util/rust-attribute-values.h
index 90417012ed71..ef01e67dc528 100644
--- a/gcc/rust/util/rust-attribute-values.h
+++ b/gcc/rust/util/rust-attribute-values.h
@@ -56,6 +56,7 @@ public:
   static constexpr auto &RUSTC_CONST_STABLE = "rustc_const_stable";
   static constexpr auto &RUSTC_CONST_UNSTABLE = "rustc_const_unstable";
   static constexpr auto &MAY_DANGLE = "may_dangle";
+  static constexpr auto &PRELUDE_IMPORT = "prelude_import";
 };
 } // namespace Values
 } // namespace Rust
diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc
index c9e376400fdd..958f7c352849 100644
--- a/gcc/rust/util/rust-attributes.cc
+++ b/gcc/rust/util/rust-attributes.cc
@@ -64,7

[gcc r15-8338] gccrs: Local testing for build_string and debug()

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:12703f67ffd72b3842e99cf2b5558aafa2444727

commit r15-8338-g12703f67ffd72b3842e99cf2b5558aafa2444727
Author: jjasmine 
Date:   Sun Jun 23 10:39:12 2024 -0700

gccrs: Local testing for build_string and debug()

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit):
Local testing for build_string and debug()

Diff:
---
 gcc/rust/backend/rust-compile-expr.cc | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/backend/rust-compile-expr.cc 
b/gcc/rust/backend/rust-compile-expr.cc
index e23c691d1dbc..7c7bc225e7e9 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -320,7 +320,10 @@ CompileExpr::visit (HIR::IfExpr &expr)
 
 void
 CompileExpr::visit (HIR::InlineAsm &expr)
-{}
+{
+  tree test_string = build_string(expr.template_strs[0].symbol.size() + 1, 
expr.template_strs[0].symbol.c_str());
+  debug(test_string);
+}
 
 void
 CompileExpr::visit (HIR::IfExprConseqElse &expr)


[gcc r15-8324] gccrs: ast: PathPattern: Remove `remove_all_segments` method

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:b4e8bc15f597e1f0e1a5dfae8081f37efaabb88c

commit r15-8324-gb4e8bc15f597e1f0e1a5dfae8081f37efaabb88c
Author: Arthur Cohen 
Date:   Mon Jun 24 16:50:43 2024 +0200

gccrs: ast: PathPattern: Remove `remove_all_segments` method

This method was used only for stripping PathPattern AST nodes during
`cfg-strip`, which seems like a misnomer and makes it a good candidate
for simplification.

gcc/rust/ChangeLog:

* ast/rust-path.h (class PathInExpression): Remove 
`remove_all_segments`
method, add a `marked_for_strip` flag instead.

Diff:
---
 gcc/rust/ast/rust-path.h | 17 ++---
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/gcc/rust/ast/rust-path.h b/gcc/rust/ast/rust-path.h
index b20f31cc4adf..53ccf1dbb6b4 100644
--- a/gcc/rust/ast/rust-path.h
+++ b/gcc/rust/ast/rust-path.h
@@ -581,13 +581,6 @@ protected:
* possible, and creates a SimplePath from them. */
   SimplePath convert_to_simple_path (bool with_opening_scope_resolution) const;
 
-  // Removes all segments of the path.
-  void remove_all_segments ()
-  {
-segments.clear ();
-segments.shrink_to_fit ();
-  }
-
 public:
   /* Returns whether the path is a single segment (excluding qualified path
* initial as segment). */
@@ -611,6 +604,8 @@ class PathInExpression : public PathPattern, public PathExpr
   location_t locus;
   NodeId _node_id;
 
+  bool marked_for_strip;
+
 public:
   std::string as_string () const override;
 
@@ -621,7 +616,8 @@ public:
 : PathPattern (std::move (path_segments)),
   outer_attrs (std::move (outer_attrs)),
   has_opening_scope_resolution (has_opening_scope_resolution),
-  locus (locus), _node_id (Analysis::Mappings::get ().get_next_node_id ())
+  locus (locus), _node_id (Analysis::Mappings::get ().get_next_node_id ()),
+  marked_for_strip (false)
   {}
 
   // Creates an error state path in expression.
@@ -650,9 +646,8 @@ public:
 
   void accept_vis (ASTVisitor &vis) override;
 
-  // Invalid if path is empty (error state), so base stripping on that.
-  void mark_for_strip () override { remove_all_segments (); }
-  bool is_marked_for_strip () const override { return is_error (); }
+  void mark_for_strip () override { marked_for_strip = true; }
+  bool is_marked_for_strip () const override { return marked_for_strip; }
 
   bool opening_scope_resolution () const
   {


[gcc r15-8321] gccrs: Subset errors with locations

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:9bba18fcb828ae2c4c85ba7ec1832923e04d2a75

commit r15-8321-g9bba18fcb828ae2c4c85ba7ec1832923e04d2a75
Author: Kushal Pal 
Date:   Fri Jul 26 07:40:58 2024 +

gccrs: Subset errors with locations

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-borrow-checker-diagnostics.cc
(BorrowCheckerDiagnostics::report_subset_errors): Highlight
lifetime locations while reporting subset errors.
(BorrowCheckerDiagnostics::get_lifetime_param): Helper function
to fetch HIR::Lifetime node from Polonius::Origin.
* checks/errors/borrowck/rust-borrow-checker-diagnostics.h:
Definition of helper function.

gcc/testsuite/ChangeLog:

* rust/borrowck/subset.rs: Better subset errors.

Signed-off-by: Kushal Pal 

Diff:
---
 .../borrowck/rust-borrow-checker-diagnostics.cc| 43 +++---
 .../borrowck/rust-borrow-checker-diagnostics.h |  1 +
 gcc/testsuite/rust/borrowck/subset.rs  | 29 +--
 3 files changed, 64 insertions(+), 9 deletions(-)

diff --git a/gcc/rust/checks/errors/borrowck/rust-borrow-checker-diagnostics.cc 
b/gcc/rust/checks/errors/borrowck/rust-borrow-checker-diagnostics.cc
index 0365dc3bd6fe..dc010291073d 100644
--- a/gcc/rust/checks/errors/borrowck/rust-borrow-checker-diagnostics.cc
+++ b/gcc/rust/checks/errors/borrowck/rust-borrow-checker-diagnostics.cc
@@ -61,12 +61,38 @@ BorrowCheckerDiagnostics::report_loan_errors ()
 void
 BorrowCheckerDiagnostics::report_subset_errors ()
 {
-  if (!subset_errors.empty ())
+  // remove duplicates in subset_errors
+  //
+  // Polonius may output subset errors for same 2 origins at multiple points
+  // so to avoid duplicating the errors, we can remove the elements in subset
+  // errors with same origin pair
+  std::vector>>
+deduplicated_subset_errors;
+
+  for (auto pair : subset_errors)
 {
-  rust_error_at (hir_function->get_locus (),
-"Found subset errors in function %s. Some lifetime "
-"constraints need to be added.",
-hir_function->get_function_name ().as_string ().c_str ());
+  auto it = std::find_if (
+   deduplicated_subset_errors.begin (), deduplicated_subset_errors.end (),
+   [&pair] (std::pair> element) {
+ return element.second == pair.second;
+   });
+  if (it == deduplicated_subset_errors.end ())
+   {
+ deduplicated_subset_errors.push_back (pair);
+   }
+}
+  for (const auto &error : deduplicated_subset_errors)
+{
+  auto first_lifetime_location
+   = get_lifetime_param (error.second.first)->get_locus ();
+  auto second_lifetime_location
+   = get_lifetime_param (error.second.second)->get_locus ();
+  multi_label_error (
+   "subset error, some lifetime constraints need to be added",
+   bir_function.location,
+   {{"lifetime defined here", first_lifetime_location},
+{"lifetime defined here", second_lifetime_location},
+{"subset error occurs in this function", bir_function.location}});
 }
 }
 
@@ -88,6 +114,13 @@ BorrowCheckerDiagnostics::get_loan (Polonius::Loan loan)
   return bir_function.place_db.get_loans ()[loan];
 }
 
+const HIR::LifetimeParam *
+BorrowCheckerDiagnostics::get_lifetime_param (Polonius::Origin origin)
+
+{
+  return bir_function.region_hir_map.at (origin);
+}
+
 void
 BorrowCheckerDiagnostics::multi_label_error (
   const char *error_message, location_t error_location,
diff --git a/gcc/rust/checks/errors/borrowck/rust-borrow-checker-diagnostics.h 
b/gcc/rust/checks/errors/borrowck/rust-borrow-checker-diagnostics.h
index 136f46790751..9ab059152d72 100644
--- a/gcc/rust/checks/errors/borrowck/rust-borrow-checker-diagnostics.h
+++ b/gcc/rust/checks/errors/borrowck/rust-borrow-checker-diagnostics.h
@@ -66,6 +66,7 @@ private:
 
   const BIR::Statement &get_statement (Polonius::Point point);
   const BIR::Loan &get_loan (Polonius::Loan loan);
+  const HIR::LifetimeParam *get_lifetime_param (Polonius::Origin origin);
 
   struct LabelLocationPair
   {
diff --git a/gcc/testsuite/rust/borrowck/subset.rs 
b/gcc/testsuite/rust/borrowck/subset.rs
index d7c00ca966c1..5b4a663a0c3d 100644
--- a/gcc/testsuite/rust/borrowck/subset.rs
+++ b/gcc/testsuite/rust/borrowck/subset.rs
@@ -1,8 +1,19 @@
-// { dg-additional-options "-frust-compile-until=compilation 
-frust-borrowcheck" }
+// { dg-additional-options "-frust-compile-until=compilation 
-frust-borrowcheck -fdiagnostics-show-caret -fdiagnostics-show-line-numbers" }
+// { dg-enable-nn-line-numbers "" }
 
 fn missing_subset<'a, 'b>(x: &'a u32, y: &'b u32) -> &'a u32 {
-// { dg-error "Found subset errors in function missing_subset" "" { target 
*-*-* } .-1 }
+// { dg-error "subset error, some lifetime constraints need to be added" 
"" { target *-*-* } .-1 }
 y //~ ERROR
+/*
+ { dg-begin-multiline-output "" }
+   NN | fn m

[gcc r15-8325] gccrs: ast: Remove PathExpr abstract class

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:21d5cef96adfb26ea67d03bdfaacbd1fe8742d6e

commit r15-8325-g21d5cef96adfb26ea67d03bdfaacbd1fe8742d6e
Author: Arthur Cohen 
Date:   Mon Jun 24 17:04:13 2024 +0200

gccrs: ast: Remove PathExpr abstract class

Inherit directly from ExprWithoutBlock instead.

gcc/rust/ChangeLog:

* ast/rust-ast.h (class PathExpr): Remove class.
* ast/rust-path.h (class PathInExpression): Inherit from 
ExprWithoutBlock.
(class QualifiedPathInExpression): Likewise.

Diff:
---
 gcc/rust/ast/rust-ast.h  | 5 -
 gcc/rust/ast/rust-path.h | 4 ++--
 2 files changed, 2 insertions(+), 7 deletions(-)

diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h
index 4f40efff2a9d..f5a2e77af3f9 100644
--- a/gcc/rust/ast/rust-ast.h
+++ b/gcc/rust/ast/rust-ast.h
@@ -2048,11 +2048,6 @@ public:
   }
 };
 
-// Base path expression AST node - abstract
-class PathExpr : public ExprWithoutBlock
-{
-};
-
 } // namespace AST
 } // namespace Rust
 
diff --git a/gcc/rust/ast/rust-path.h b/gcc/rust/ast/rust-path.h
index 53ccf1dbb6b4..bf758018b58a 100644
--- a/gcc/rust/ast/rust-path.h
+++ b/gcc/rust/ast/rust-path.h
@@ -597,7 +597,7 @@ public:
 
 /* AST node representing a path-in-expression pattern (path that allows
  * generic arguments) */
-class PathInExpression : public PathPattern, public PathExpr
+class PathInExpression : public PathPattern, public ExprWithoutBlock
 {
   std::vector outer_attrs;
   bool has_opening_scope_resolution;
@@ -1221,7 +1221,7 @@ public:
 
 /* AST node representing a qualified path-in-expression pattern (path that
  * allows specifying trait functions) */
-class QualifiedPathInExpression : public PathPattern, public PathExpr
+class QualifiedPathInExpression : public PathPattern, public ExprWithoutBlock
 {
   std::vector outer_attrs;
   QualifiedPathType path_type;


[gcc r15-8310] gccrs: Turn to switch case, use new helper functions

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:b2032da1143eb63b7cd1548c3e270e0003780517

commit r15-8310-gb2032da1143eb63b7cd1548c3e270e0003780517
Author: badumbatish 
Date:   Tue Jul 30 09:13:15 2024 -0700

gccrs: Turn to switch case, use new helper functions

gcc/rust/ChangeLog:

* hir/rust-ast-lower-expr.cc (translate_operand_in):
Turn to switch case, use new helper functions
(translate_operand_out): Likewise.
(translate_operand_inout): Likewise.
(translate_operand_split_in_out): Likewise.
(translate_operand_const): Likewise.
(translate_operand_sym): Likewise.
(translate_operand_label): Likewise.
(from_operand): Likewise.
(ASTLoweringExpr::visit): Likewise.

Diff:
---
 gcc/rust/hir/rust-ast-lower-expr.cc | 164 +---
 1 file changed, 94 insertions(+), 70 deletions(-)

diff --git a/gcc/rust/hir/rust-ast-lower-expr.cc 
b/gcc/rust/hir/rust-ast-lower-expr.cc
index 45277e877144..9dd88b47b981 100644
--- a/gcc/rust/hir/rust-ast-lower-expr.cc
+++ b/gcc/rust/hir/rust-ast-lower-expr.cc
@@ -25,6 +25,7 @@
 #include "rust-ast.h"
 #include "rust-diagnostics.h"
 #include "rust-system.h"
+#include "tree/rust-hir-expr.h"
 
 namespace Rust {
 namespace HIR {
@@ -829,11 +830,86 @@ ASTLoweringExpr::visit (AST::ClosureExprInnerTyped &expr)
expr.get_locus ());
 }
 
+HIR::InlineAsmOperand
+translate_operand_in (const AST::InlineAsmOperand &operand)
+{
+  auto in_value = operand.get_in ();
+
+  struct HIR::InlineAsmOperand::In in (
+in_value.reg,
+std::unique_ptr (ASTLoweringExpr::translate (*in_value.expr.get 
(;
+  return in;
+}
+
+HIR::InlineAsmOperand
+translate_operand_out (const AST::InlineAsmOperand &operand)
+{
+  auto out_value = operand.get_out ();
+  struct HIR::InlineAsmOperand::Out out (out_value.reg, out_value.late,
+std::unique_ptr (
+  ASTLoweringExpr::translate (
+*out_value.expr.get (;
+  return out;
+}
+HIR::InlineAsmOperand
+translate_operand_inout (const AST::InlineAsmOperand &operand)
+{
+  auto inout_value = operand.get_in_out ();
+  struct HIR::InlineAsmOperand::InOut inout (inout_value.reg, inout_value.late,
+std::unique_ptr (
+  ASTLoweringExpr::translate (
+*inout_value.expr.get (;
+  return inout;
+}
+HIR::InlineAsmOperand
+translate_operand_split_in_out (const AST::InlineAsmOperand &operand)
+{
+  auto split_in_out_value = operand.get_split_in_out ();
+  struct HIR::InlineAsmOperand::SplitInOut split_in_out (
+split_in_out_value.reg, split_in_out_value.late,
+std::unique_ptr (
+  ASTLoweringExpr::translate (*split_in_out_value.in_expr.get ())),
+std::unique_ptr (
+  ASTLoweringExpr::translate (*split_in_out_value.out_expr.get (;
+  return split_in_out;
+}
+HIR::InlineAsmOperand
+translate_operand_const (const AST::InlineAsmOperand &operand)
+{
+  auto const_value = operand.get_const ();
+  struct HIR::AnonConst anon_const (const_value.anon_const.id,
+   std::unique_ptr (
+ ASTLoweringExpr::translate (
+   *const_value.anon_const.expr.get (;
+  struct HIR::InlineAsmOperand::Const cnst
+  {
+anon_const
+  };
+  return cnst;
+}
+
+HIR::InlineAsmOperand
+translate_operand_sym (const AST::InlineAsmOperand &operand)
+{
+  auto sym_value = operand.get_sym ();
+  struct HIR::InlineAsmOperand::Sym sym (std::unique_ptr (
+ASTLoweringExpr::translate (*sym_value.expr.get (;
+  return sym;
+}
+HIR::InlineAsmOperand
+translate_operand_label (const AST::InlineAsmOperand &operand)
+{
+  auto label_value = operand.get_label ();
+  struct HIR::InlineAsmOperand::Label label (label_value.label_name,
+std::unique_ptr (
+  ASTLoweringExpr::translate (
+*label_value.expr.get (;
+  return label;
+}
 HIR::InlineAsmOperand
 from_operand (const AST::InlineAsmOperand &operand)
 {
   using RegisterType = AST::InlineAsmOperand::RegisterType;
-  using Operand = HIR::InlineAsmOperand;
   auto type = operand.get_register_type ();
 
   /*In,*/
@@ -843,75 +919,23 @@ from_operand (const AST::InlineAsmOperand &operand)
   /*Const,*/
   /*Sym,*/
   /*Label,*/
-  if (type == RegisterType::In)
-{
-  auto in_value = operand.get_in ();
-
-  struct Operand::In in (in_value.reg,
-std::unique_ptr (ASTLoweringExpr::translate (
-  *in_value.expr.get (;
-  return in;
-}
-  else if (type == RegisterType::Out)
-{
-  auto out_value = operand.g

[gcc r15-8312] gccrs: Add location to BIR::Loan

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:37941c99df7cd15022ec27260cb7bc5de34dee98

commit r15-8312-g37941c99df7cd15022ec27260cb7bc5de34dee98
Author: Kushal Pal 
Date:   Tue Jul 9 10:37:27 2024 +

gccrs: Add location to BIR::Loan

This commit adds location_t to BIR::Loan, this location will point to
location is source code where the borrow occured, this information will
be useful for reporting borrow-checking errors.

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder-internal.h:
Fill location for loan.
* checks/errors/borrowck/rust-bir-place.h (struct Loan):
Add location field.

Signed-off-by: Kushal Pal 

Diff:
---
 gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h | 5 +++--
 gcc/rust/checks/errors/borrowck/rust-bir-place.h| 1 +
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h 
b/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h
index 46f811ea25a7..16fcb6abca73 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h
@@ -307,7 +307,7 @@ protected: // Helpers to add BIR statements
location_t location)
   {
 auto mutability = ty->as ()->mutability ();
-auto loan = ctx.place_db.add_loan ({mutability, place_id});
+auto loan = ctx.place_db.add_loan ({mutability, place_id, location});
 push_tmp_assignment (new BorrowExpr (place_id, loan,
 ctx.place_db.get_next_free_region ()),
 ty, location);
@@ -600,7 +600,8 @@ protected:
   {
 // TODO: deduplicate with borrow_place
 auto loan = ctx.place_db.add_loan (
-  {ty->as ()->mutability (), place_id});
+  {ty->as ()->mutability (), place_id,
+   location});
 return_expr (new BorrowExpr (place_id, loan,
 ctx.place_db.get_next_free_region ()),
 ty, location);
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-place.h 
b/gcc/rust/checks/errors/borrowck/rust-bir-place.h
index 8c38e8ed3cd8..66da3dab380c 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-place.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-place.h
@@ -162,6 +162,7 @@ struct Loan
 {
   Mutability mutability;
   PlaceId place;
+  location_t location;
 };
 
 /** Allocated places and keeps track of paths. */


[gcc r15-8323] gccrs: Attempted to access a nonexistent field [E0609]

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:bc2331a565d8005b91495df627f3fa72870770cc

commit r15-8323-gbc2331a565d8005b91495df627f3fa72870770cc
Author: Muhammad Mahad 
Date:   Thu Aug 15 16:44:55 2024 +

gccrs: Attempted to access a nonexistent field [E0609]

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
Add error code and update error message

gcc/testsuite/ChangeLog:

* rust/compile/nonexistent-field.rs: New test.

Signed-off-by: Muhammad Mahad 

Diff:
---
 gcc/rust/typecheck/rust-hir-type-check-expr.cc  |  7 +--
 gcc/testsuite/rust/compile/nonexistent-field.rs | 14 ++
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc 
b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index 0e897813d8f0..81d829525504 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -85,7 +85,9 @@ TypeCheckExpr::visit (HIR::TupleIndexExpr &expr)
   TupleIndex index = expr.get_tuple_index ();
   if ((size_t) index >= tuple->num_fields ())
{
- rust_error_at (expr.get_locus (), "unknown field at index %i", index);
+ rust_error_at (expr.get_locus (), ErrorCode::E0609,
+"no field %qi on type %qs", index,
+resolved->get_name ().c_str ());
  return;
}
 
@@ -1078,7 +1080,8 @@ TypeCheckExpr::visit (HIR::FieldAccessExpr &expr)
 &lookup, nullptr);
   if (!found)
 {
-  rust_error_at (expr.get_locus (), "unknown field [%s] for type [%s]",
+  rust_error_at (expr.get_locus (), ErrorCode::E0609,
+"no field %qs on type %qs",
 expr.get_field_name ().as_string ().c_str (),
 adt->as_string ().c_str ());
   return;
diff --git a/gcc/testsuite/rust/compile/nonexistent-field.rs 
b/gcc/testsuite/rust/compile/nonexistent-field.rs
new file mode 100644
index ..e20c49d3ebf4
--- /dev/null
+++ b/gcc/testsuite/rust/compile/nonexistent-field.rs
@@ -0,0 +1,14 @@
+#![allow(unused)]
+fn main() {
+struct StructWithFields {
+x: u32,
+}
+
+let s = StructWithFields { x: 0 };
+s.foo;
+// { dg-error "no field .foo. on type .StructWithFields.StructWithFields 
.x.u32... .E0609." "" { target *-*-* } .-1 }
+
+let numbers = (1, 2, 3);
+numbers.3;
+// { dg-error "no field .3. on type .., , .. 
.E0609." "" { target *-*-* } .-1 }
+}


[gcc r15-8340] gccrs: Scaffolding new compile-asm files

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:d7e88ed1c8d7eaadf6fc8b8f1e554d4fe6312e37

commit r15-8340-gd7e88ed1c8d7eaadf6fc8b8f1e554d4fe6312e37
Author: badumbatish 
Date:   Sun Jun 30 16:48:30 2024 -0700

gccrs: Scaffolding new compile-asm files

gcc/rust/ChangeLog:

* Make-lang.in:
Scaffolding new compile-asm files
* backend/rust-compile-expr.cc (CompileExpr::visit): Likewise
* hir/tree/rust-hir-expr.h: Likewise
* backend/rust-compile-asm.cc: New file. Likewise
* backend/rust-compile-asm.h: New file. Likewise

Diff:
---
 gcc/rust/Make-lang.in |  1 +
 gcc/rust/backend/rust-compile-asm.cc  | 80 +++
 gcc/rust/backend/rust-compile-asm.h   | 46 
 gcc/rust/backend/rust-compile-expr.cc |  9 ++--
 gcc/rust/hir/tree/rust-hir-expr.h | 35 ---
 5 files changed, 131 insertions(+), 40 deletions(-)

diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index c892fa3091e3..d291dd647654 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -196,6 +196,7 @@ GRS_OBJS = \
 rust/rust-compile-item.o \
 rust/rust-compile-implitem.o \
 rust/rust-compile-stmt.o \
+rust/rust-compile-asm.o \
 rust/rust-compile-expr.o \
 rust/rust-compile-type.o \
 rust/rust-compile-block.o \
diff --git a/gcc/rust/backend/rust-compile-asm.cc 
b/gcc/rust/backend/rust-compile-asm.cc
new file mode 100644
index ..5bc7bce07e66
--- /dev/null
+++ b/gcc/rust/backend/rust-compile-asm.cc
@@ -0,0 +1,80 @@
+#include "rust-compile-asm.h"
+
+#include "rust-tree.h"
+#include "rust-system.h"
+namespace Rust {
+namespace Compile {
+
+tree
+CompileAsm::asm_build_expr (HIR::InlineAsm &expr)
+{
+  return NULL_TREE;
+  // return build_asm_expr (CompileAsm::asm_get_locus (expr),
+  //CompileAsm::asm_construct_string_tree (expr),
+  //CompileAsm::asm_construct_outputs (expr),
+  //CompileAsm::asm_construct_inputs (expr),
+  //CompileAsm::asm_construct_clobber_tree (expr),
+  //CompileAsm::asm_construct_label_tree (expr),
+  //CompileAsm::asm_is_simple (expr),
+  //CompileAsm::asm_is_inline (expr));
+}
+
+location_t
+CompileAsm::asm_get_locus (HIR::InlineAsm &expr)
+{
+  return expr.get_locus ();
+}
+tree
+CompileAsm::asm_construct_string_tree (HIR::InlineAsm &expr)
+{
+  if (expr.template_strs.empty ())
+return build_string (1, "");
+  // Initialize to NULL_TREE
+  tree string_chain = NULL_TREE;
+
+  for (const auto &template_str : expr.template_strs)
+{
+  auto str = template_str.symbol;
+  auto string_tree = build_string (str.size () + 1, str.c_str ());
+
+  string_chain = tree_cons (NULL_TREE, string_tree, string_chain);
+}
+  // Reverse the chain before returning
+  return nreverse (string_chain);
+}
+tree
+CompileAsm::asm_construct_outputs (HIR::InlineAsm &expr)
+{
+  return NULL_TREE;
+}
+
+tree
+CompileAsm::asm_construct_inputs (HIR::InlineAsm &expr)
+{
+  return NULL_TREE;
+}
+
+tree
+CompileAsm::asm_construct_clobber_tree (HIR::InlineAsm &expr)
+{
+  return NULL_TREE;
+}
+tree
+CompileAsm::asm_construct_label_tree (HIR::InlineAsm &expr)
+{
+  return NULL_TREE;
+}
+
+bool
+CompileAsm::asm_is_simple (HIR::InlineAsm &expr)
+{
+  return true;
+}
+
+bool
+CompileAsm::asm_is_inline (HIR::InlineAsm &expr)
+{
+  return true;
+}
+} // namespace Compile
+} // namespace Rust
diff --git a/gcc/rust/backend/rust-compile-asm.h 
b/gcc/rust/backend/rust-compile-asm.h
new file mode 100644
index ..58f0f51e9cf4
--- /dev/null
+++ b/gcc/rust/backend/rust-compile-asm.h
@@ -0,0 +1,46 @@
+
+// Copyright (C) 2020-2024 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3.  If not see
+// .
+
+#ifndef RUST_COMPILE_ASM
+#define RUST_COMPILE_ASM
+
+#include "rust-compile-base.h"
+#include "rust-hir-visitor.h"
+
+namespace Rust {
+namespace Compile {
+
+class CompileAsm
+{
+public:
+  static tree asm_build_expr (HIR::InlineAsm &);
+  static location_t asm_get_locus (HIR::InlineAsm &);
+  static tree asm_construct_string_tree (HIR::InlineAsm &);
+  static tree asm_construct_outputs (HIR::InlineAsm &);
+  static tree asm_construct_inputs (HIR::InlineAsm &);
+  static tree asm_construct_clobber_tree (H

[gcc r15-8370] gccrs: Used `IndexVec` for Places

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:2f8367e5811c1251c6ac075bc8fe57523967e620

commit r15-8370-g2f8367e5811c1251c6ac075bc8fe57523967e620
Author: Kushal Pal 
Date:   Tue Aug 20 06:09:51 2024 +

gccrs: Used `IndexVec` for Places

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-place.h: Use strong types as
index.

Signed-off-by: Kushal Pal 

Diff:
---
 gcc/rust/checks/errors/borrowck/rust-bir-place.h | 56 
 1 file changed, 27 insertions(+), 29 deletions(-)

diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-place.h 
b/gcc/rust/checks/errors/borrowck/rust-bir-place.h
index ae8bec2e2735..148bd2a7f495 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-place.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-place.h
@@ -215,19 +215,22 @@ public:
   {
 internal_vector.emplace_back (std::forward (args)...);
   }
-  std::vector &get_vector () { return internal_vector; }
+
   size_t size () const { return internal_vector.size (); }
+
+  std::vector &get_vector () { return internal_vector; }
 };
 
 using Scopes = IndexVec;
 using Loans = IndexVec;
+using Places = IndexVec;
 
 /** Allocated places and keeps track of paths. */
 class PlaceDB
 {
 private:
   // Possible optimizations: separate variables to speedup lookup.
-  std::vector places;
+  Places places;
   std::unordered_map constants_lookup;
   Scopes scopes;
   ScopeId current_scope = ROOT_SCOPE;
@@ -245,11 +248,8 @@ public:
 scopes.emplace_back (); // Root scope.
   }
 
-  Place &operator[] (PlaceId id) { return places.at (id.value); }
-  const Place &operator[] (PlaceId id) const { return places.at (id.value); }
-
-  decltype (places)::const_iterator begin () const { return places.begin (); }
-  decltype (places)::const_iterator end () const { return places.end (); }
+  Place &operator[] (PlaceId id) { return places.at (id); }
+  const Place &operator[] (PlaceId id) const { return places.at (id); }
 
   size_t size () const { return places.size (); }
 
@@ -294,11 +294,11 @@ public:
   {
 places.emplace_back (std::forward (place));
 PlaceId new_place = {places.size () - 1};
-Place &new_place_ref = places[new_place.value]; // Intentional shadowing.
+Place &new_place_ref = places[new_place]; // Intentional shadowing.
 if (last_sibling == INVALID_PLACE)
-  places[new_place_ref.path.parent.value].path.first_child = new_place;
+  places[new_place_ref.path.parent].path.first_child = new_place;
 else
-  places[last_sibling.value].path.next_sibling = new_place;
+  places[last_sibling].path.next_sibling = new_place;
 
 if (new_place_ref.kind == Place::VARIABLE
|| new_place_ref.kind == Place::TEMPORARY)
@@ -332,16 +332,16 @@ public:
 PlaceId current = INVALID_PLACE;
 if (parent.value < places.size ())
   {
-   current = places[parent.value].path.first_child;
+   current = places[parent].path.first_child;
while (current != INVALID_PLACE)
  {
-   if (places[current.value].kind == kind
-   && places[current.value].variable_or_field_index == id)
+   if (places[current].kind == kind
+   && places[current].variable_or_field_index == id)
  {
-   rust_assert (places[current.value].tyty->is_equal (*tyty));
+   rust_assert (places[current].tyty->is_equal (*tyty));
return current;
  }
-   current = places[current.value].path.next_sibling;
+   current = places[current].path.next_sibling;
  }
   }
 return add_place ({kind, (uint32_t) id,
@@ -370,8 +370,8 @@ public:
 
 while (current.value != places.size ())
   {
-   if (places[current.value].kind == Place::VARIABLE
-   && places[current.value].variable_or_field_index == id)
+   if (places[current].kind == Place::VARIABLE
+   && places[current].variable_or_field_index == id)
  return current;
++current.value;
   }
@@ -383,25 +383,23 @@ public:
 LoanId id = {loans.size ()};
 loans.push_back (std::forward (loan));
 PlaceId borrowed_place = loans.get_vector ().rbegin ()->place;
-places[loans.get_vector ().rbegin ()->place.value].borrowed_by.push_back (
-  id);
-if (places[borrowed_place.value].kind == Place::DEREF)
+places[loans.get_vector ().rbegin ()->place].borrowed_by.push_back (id);
+if (places[borrowed_place].kind == Place::DEREF)
   {
-   places[places[borrowed_place.value].path.parent.value]
- .borrowed_by.push_back (id);
+   places[places[borrowed_place].path.parent].borrowed_by.push_back (id);
   }
 return id;
   }
 
   PlaceId get_var (PlaceId id) const
   {
-if (places[id.value].is_var ())
+if (places[id].is_var ())
   return id;
-rust_assert (places[id.value].is_path ());
+rust_assert (places[id].is_path ());
 PlaceId current = id;
-while (!places[current.value].is_var ())
+while (!p

[gcc r15-8363] gccrs: Strong type LoanId

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:9104447577afbbd3229d353cf48e46eb105cd130

commit r15-8363-g9104447577afbbd3229d353cf48e46eb105cd130
Author: Kushal Pal 
Date:   Wed Aug 7 08:44:03 2024 +

gccrs: Strong type LoanId

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-dump.cc (Dump::visit): Use new
API, i.e get_loan_id() instead of get_loan().
* checks/errors/borrowck/rust-bir-fact-collector.h (points): Use
value of LoanId in Polonius facts.
* checks/errors/borrowck/rust-bir-place.h (struct LoanId):
LoanId is a struct now.
* checks/errors/borrowck/rust-bir.h (class AbstractExpr): Use
new API, as we are getting a LoanId and not a loan itself.

Signed-off-by: Kushal Pal 

Diff:
---
 gcc/rust/checks/errors/borrowck/rust-bir-dump.cc   |  2 +-
 .../errors/borrowck/rust-bir-fact-collector.h  | 44 +++---
 gcc/rust/checks/errors/borrowck/rust-bir-place.h   | 20 +-
 gcc/rust/checks/errors/borrowck/rust-bir.h |  4 +-
 4 files changed, 42 insertions(+), 28 deletions(-)

diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc 
b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
index e69c0002b3c2..85ba3ee2ce4d 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
@@ -279,7 +279,7 @@ Dump::visit (const BorrowExpr &expr)
 {
   stream << "&"
 << "'?" << expr.get_origin () << " ";
-  if (func.place_db.get_loans ()[expr.get_loan ()].mutability
+  if (func.place_db.get_loan (expr.get_loan_id ()).mutability
   == Mutability::Mut)
 stream << "mut ";
   visit_place (expr.get_place ());
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h 
b/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h
index ebf8eec70538..774f2b9e2988 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h
@@ -305,7 +305,7 @@ protected: // Main collection entry points (for different 
categories).
 rust_debug ("\t_%u = BorrowExpr(_%u)", lhs.value - 1,
expr.get_place ().value - 1);
 
-auto loan = place_db.get_loans ()[expr.get_loan ()];
+auto loan = place_db.get_loan (expr.get_loan_id ());
 
 auto &base_place = place_db[expr.get_place ()];
 auto &ref_place = place_db[lhs];
@@ -324,14 +324,14 @@ protected: // Main collection entry points (for different 
categories).
   ->is_mutable ())
  rust_error_at (location,
 "Cannot reborrow immutable borrow as mutable");
-   issue_loan (expr.get_origin (), expr.get_loan ());
+   issue_loan (expr.get_origin (), expr.get_loan_id ());
  }
 
push_subset (main_loan_place.regions[0], {expr.get_origin ()});
   }
 else
   {
-   issue_loan (expr.get_origin (), expr.get_loan ());
+   issue_loan (expr.get_origin (), expr.get_loan_id ());
   }
 
 auto loan_regions = base_place.regions.prepend ({expr.get_origin ()});
@@ -511,24 +511,25 @@ protected: // Generic BIR operations.
 
   void issue_loan (Polonius::Origin origin, LoanId loan_id)
   {
-facts.loan_issued_at.emplace_back (origin, loan_id,
+facts.loan_issued_at.emplace_back (origin, loan_id.value,
   get_current_point_mid ());
 
-check_for_borrow_conficts (place_db.get_loans ()[loan_id].place, loan_id,
-  place_db.get_loans ()[loan_id].mutability);
+check_for_borrow_conficts (place_db.get_loan (loan_id).place, loan_id,
+  place_db.get_loan (loan_id).mutability);
   }
 
   void issue_locals_dealloc ()
   {
-for (LoanId loan_id = 0; loan_id < place_db.get_loans ().size (); 
++loan_id)
+for (LoanId loan_id = {0}; loan_id.value < place_db.get_loans ().size ();
+++loan_id.value)
   {
-   auto &loan = place_db.get_loans ()[loan_id];
+   auto &loan = place_db.get_loan (loan_id);
auto loaned_var_id = place_db.get_var (loan.place);
if (place_db[loaned_var_id].tyty->is ())
  continue;
if (loaned_var_id >= first_local)
  facts.loan_invalidated_at.emplace_back (get_current_point_start (),
- loan_id);
+ loan_id.value);
   }
   }
 
@@ -546,20 +547,20 @@ protected: // Generic BIR operations.
 place_db.for_each_path_segment (place_id, [&] (PlaceId id) {
   for (auto loan : place_db[id].borrowed_by)
{
- if (place_db.get_loans ()[loan].mutability == Mutability::Mut)
+ if (place_db.get_loan (loan).mutability == Mutability::Mut)
{
  facts.loan_invalidated_at.emplace_back (
-   get_current_point_start (), loan);
+   get_current_point_start (), loan.value);
   

[gcc r15-8364] gccrs: Strong type ScopeId

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:03fd4851cd271ab08089db7d4da68bed30ed3fdd

commit r15-8364-g03fd4851cd271ab08089db7d4da68bed30ed3fdd
Author: Kushal Pal 
Date:   Wed Aug 7 10:16:24 2024 +

gccrs: Strong type ScopeId

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
(ExprStmtBuilder::setup_loop): Use value of ScopeId.
(ExprStmtBuilder::visit): Use continue scope id instead of
continue basic block id.
* checks/errors/borrowck/rust-bir-builder-internal.h: Use value
of ScopeId.
* checks/errors/borrowck/rust-bir-dump.cc (Dump::go): Use
ROOT_VALUE instead of hardcoded 0.
(Dump::visit_scope): Use value of ScopeId.
* checks/errors/borrowck/rust-bir-place.h (struct ScopeId):
ScopeId is now a struct.
(std::numeric_limits::max): Set invalid ScopeId.

Signed-off-by: Kushal Pal 

Diff:
---
 .../errors/borrowck/rust-bir-builder-expr-stmt.cc  |  5 ++-
 .../errors/borrowck/rust-bir-builder-internal.h|  4 +-
 gcc/rust/checks/errors/borrowck/rust-bir-dump.cc   | 10 ++---
 gcc/rust/checks/errors/borrowck/rust-bir-place.h   | 43 +++---
 4 files changed, 39 insertions(+), 23 deletions(-)

diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc 
b/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
index 8d4d90aab80c..1713bf6fcf8d 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
@@ -45,7 +45,8 @@ ExprStmtBuilder::setup_loop (HIR::BaseLoopExpr &expr)
 
   BasicBlockId break_bb = new_bb ();
   // We are still outside the loop block;
-  ScopeId continue_scope = ctx.place_db.get_current_scope_id () + 1;
+  ScopeId continue_scope
+= ctx.place_db.get_current_scope_id ().next_scope_id ();
   ctx.loop_and_label_stack.emplace_back (true, label, label_var, break_bb,
 continue_bb, continue_scope);
 
@@ -414,7 +415,7 @@ ExprStmtBuilder::visit (HIR::ContinueExpr &cont)
   LoopAndLabelCtx info = cont.has_label () ? get_label_ctx (cont.get_label ())
   : get_unnamed_loop_ctx ();
   start_new_consecutive_bb ();
-  unwind_until (info.continue_bb);
+  unwind_until (info.continue_scope);
   push_goto (info.continue_bb);
   // No code allowed after continue. Handled in BlockExpr.
 }
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h 
b/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h
index b27f7717cd0c..e0d8bb3d2fcf 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h
@@ -156,7 +156,7 @@ protected:
 
 auto place_id = ctx.place_db.add_variable (nodeid, ty);
 
-if (ctx.place_db.get_current_scope_id () != 0)
+if (ctx.place_db.get_current_scope_id () != INVALID_SCOPE)
   push_storage_live (place_id);
 
 if (user_type_annotation)
@@ -170,7 +170,7 @@ protected:
   void pop_scope ()
   {
 auto &scope = ctx.place_db.get_current_scope ();
-if (ctx.place_db.get_current_scope_id () != 0)
+if (ctx.place_db.get_current_scope_id () != INVALID_SCOPE)
   {
std::for_each (scope.locals.rbegin (), scope.locals.rend (),
   [&] (PlaceId place) { push_storage_dead (place); });
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc 
b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
index 85ba3ee2ce4d..0c0e55567b5e 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
@@ -133,7 +133,7 @@ Dump::go (bool enable_simplify_cfg)
   stream << " {\n";
 
   // Print locals declaration.
-  visit_scope (0);
+  visit_scope (ROOT_SCOPE);
 
   // Print BBs.
   for (statement_bb = 0; statement_bb < func.basic_blocks.size ();
@@ -366,8 +366,8 @@ Dump::visit_scope (ScopeId id, size_t depth)
   if (scope.locals.empty () && scope.children.empty ())
 return;
 
-  if (id > 1)
-indent (depth) << "scope " << id - 1 << " {\n";
+  if (id.value > 1)
+indent (depth) << "scope " << id.value - 1 << " {\n";
 
   for (auto &local : scope.locals)
 {
@@ -385,9 +385,9 @@ Dump::visit_scope (ScopeId id, size_t depth)
   stream << "]\n";
 }
   for (auto &child : scope.children)
-visit_scope (child, (id >= 1) ? depth + 1 : depth);
+visit_scope (child, (id.value >= 1) ? depth + 1 : depth);
 
-  if (id > 1)
+  if (id.value > 1)
 indent (depth) << "}\n";
 }
 
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-place.h 
b/gcc/rust/checks/errors/borrowck/rust-bir-place.h
index c78492a2394f..f7018d3af7f0 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-place.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-place.h
@@ -165,13 +165,25 @@ public:
   }
 };
 
-using ScopeId = uint32_t;
+struct ScopeId
+{
+  uint32_t value

[gcc r15-8357] gccrs: Provide new asm test case for amd64

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:ca839781c9e121d80b19844b36967c2e14eaacb3

commit r15-8357-gca839781c9e121d80b19844b36967c2e14eaacb3
Author: badumbatish 
Date:   Sat Aug 31 23:37:19 2024 -0700

gccrs: Provide new asm test case for amd64

gcc/testsuite/ChangeLog:

* rust/execute/torture/inline_asm_mov_x_5.rs: Move to...
* rust/execute/torture/inline_asm_mov_x_5_ARM.rs: ...here.
* rust/execute/torture/inline_asm_mov_x_5_x86_64.rs: New test.

Diff:
---
 ...ne_asm_mov_x_5.rs => inline_asm_mov_x_5_ARM.rs} |  1 +
 .../execute/torture/inline_asm_mov_x_5_x86_64.rs   | 24 ++
 2 files changed, 25 insertions(+)

diff --git a/gcc/testsuite/rust/execute/torture/inline_asm_mov_x_5.rs 
b/gcc/testsuite/rust/execute/torture/inline_asm_mov_x_5_ARM.rs
similarity index 90%
rename from gcc/testsuite/rust/execute/torture/inline_asm_mov_x_5.rs
rename to gcc/testsuite/rust/execute/torture/inline_asm_mov_x_5_ARM.rs
index 4f1555e6f2d3..4e762608230f 100644
--- a/gcc/testsuite/rust/execute/torture/inline_asm_mov_x_5.rs
+++ b/gcc/testsuite/rust/execute/torture/inline_asm_mov_x_5_ARM.rs
@@ -1,3 +1,4 @@
+/* { dg-do run { target arm*-*-* } } */
 /* { dg-output "5\r*\n" }*/
 
 #![feature(rustc_attrs)]
diff --git a/gcc/testsuite/rust/execute/torture/inline_asm_mov_x_5_x86_64.rs 
b/gcc/testsuite/rust/execute/torture/inline_asm_mov_x_5_x86_64.rs
new file mode 100644
index ..c6086e00d460
--- /dev/null
+++ b/gcc/testsuite/rust/execute/torture/inline_asm_mov_x_5_x86_64.rs
@@ -0,0 +1,24 @@
+/* { dg-do run { target x86_64*-*-* } } */
+/* { dg-output "5\r*\n" }*/
+
+#![feature(rustc_attrs)]
+#[rustc_builtin_macro]
+macro_rules! asm {
+() => {};
+}
+
+extern "C" {
+fn printf(s: *const i8, ...);
+}
+
+fn main() -> i32 {
+let mut _x: i32 = 0;
+unsafe {
+asm!(
+"mov $5, {}",
+out(reg) _x
+);
+printf("%d\n\0" as *const str as *const i8, _x);
+}
+0
+}


[gcc r15-8367] gccrs: Used `IndexVec` for Scopes

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:1113b8e0340aec62eb471115619f9624d15fe86a

commit r15-8367-g1113b8e0340aec62eb471115619f9624d15fe86a
Author: Kushal Pal 
Date:   Mon Aug 19 09:38:52 2024 +

gccrs: Used `IndexVec` for Scopes

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-place.h:
Used `IndexVec` with ScopeId as index.

Signed-off-by: Kushal Pal 

Diff:
---
 gcc/rust/checks/errors/borrowck/rust-bir-place.h | 25 
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-place.h 
b/gcc/rust/checks/errors/borrowck/rust-bir-place.h
index 235646088920..bf4dfe625a0e 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-place.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-place.h
@@ -218,6 +218,8 @@ public:
   size_t size () const { return internal_vector.size (); }
 };
 
+using Scopes = IndexVec;
+
 /** Allocated places and keeps track of paths. */
 class PlaceDB
 {
@@ -225,7 +227,7 @@ private:
   // Possible optimizations: separate variables to speedup lookup.
   std::vector places;
   std::unordered_map constants_lookup;
-  std::vector scopes;
+  Scopes scopes;
   ScopeId current_scope = ROOT_SCOPE;
 
   std::vector loans;
@@ -257,14 +259,11 @@ public:
 
   ScopeId get_current_scope_id () const { return current_scope; }
 
-  const std::vector &get_scopes () const { return scopes; }
+  const Scopes &get_scopes () const { return scopes; }
 
-  const Scope &get_current_scope () const
-  {
-return scopes[current_scope.value];
-  }
+  const Scope &get_current_scope () const { return scopes[current_scope]; }
 
-  const Scope &get_scope (ScopeId id) const { return scopes[id.value]; }
+  const Scope &get_scope (ScopeId id) const { return scopes[id]; }
 
   FreeRegion get_next_free_region ()
   {
@@ -280,15 +279,15 @@ public:
   {
 ScopeId new_scope = {scopes.size ()};
 scopes.emplace_back ();
-scopes[new_scope.value].parent = current_scope;
-scopes[current_scope.value].children.push_back (new_scope);
+scopes[new_scope].parent = current_scope;
+scopes[current_scope].children.push_back (new_scope);
 current_scope = new_scope;
 return new_scope;
   }
 
   ScopeId pop_scope ()
   {
-current_scope = scopes[current_scope.value].parent;
+current_scope = scopes[current_scope].parent;
 return current_scope;
   }
 
@@ -304,7 +303,7 @@ public:
 
 if (new_place_ref.kind == Place::VARIABLE
|| new_place_ref.kind == Place::TEMPORARY)
-  scopes[current_scope.value].locals.push_back (new_place);
+  scopes[current_scope].locals.push_back (new_place);
 
 auto variances = Resolver::TypeCheckContext::get ()
   ->get_variance_analysis_ctx ()
@@ -494,9 +493,9 @@ private:
   WARN_UNUSED_RESULT bool is_in_scope (PlaceId place) const
   {
 for (ScopeId scope = current_scope; scope != INVALID_SCOPE;
-scope = scopes[scope.value].parent)
+scope = scopes[scope].parent)
   {
-   auto &scope_ref = scopes[scope.value];
+   auto &scope_ref = scopes[scope];
if (std::find (scope_ref.locals.begin (), scope_ref.locals.end (),
   place)
!= scope_ref.locals.end ())


[gcc r15-8360] gccrs: Strong type PlaceId

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:b168b618165977d4041aa553813462622bcd781f

commit r15-8360-gb168b618165977d4041aa553813462622bcd781f
Author: Kushal Pal 
Date:   Mon Aug 5 10:50:55 2024 +

gccrs: Strong type PlaceId

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-dump.cc (renumber_places):
Use value of PlaceId as index.
(Dump::visit_place): Likewise.
(Dump::visit_scope): Likewise.
(Dump::go): Refill `place_map` with for loop instead of
using std::iota().
* checks/errors/borrowck/rust-bir-fact-collector.h (points): Use
value as index.
* checks/errors/borrowck/rust-bir-place.h (struct PlaceId):
PlaceId is now a class holding a uint32_t value. Overloaded
comparision operators for easier comparision.

Signed-off-by: Kushal Pal 

Diff:
---
 gcc/rust/checks/errors/borrowck/rust-bir-dump.cc   | 25 +++---
 .../errors/borrowck/rust-bir-fact-collector.h  | 61 +--
 gcc/rust/checks/errors/borrowck/rust-bir-place.h   | 88 +-
 3 files changed, 103 insertions(+), 71 deletions(-)

diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc 
b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
index a35f47b86d6c..924c7d9a6e8a 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
@@ -53,16 +53,20 @@ renumber_places (const Function &func, std::vector 
&place_map)
 {
   // Renumbering places to avoid gaps in the place id space.
   // This is needed to match MIR's shape.
-  size_t next_out_id = 0;
+  PlaceId next_out_id = INVALID_PLACE;
 
-  for (size_t in_id = FIRST_VARIABLE_PLACE; in_id < func.place_db.size ();
-   ++in_id)
+  for (PlaceId in_id = FIRST_VARIABLE_PLACE;
+   in_id.value < func.place_db.size (); ++in_id.value)
 {
   const Place &place = func.place_db[in_id];
   if (place.kind == Place::VARIABLE || place.kind == Place::TEMPORARY)
-   place_map[in_id] = next_out_id++;
+   {
+ place_map[in_id.value] = next_out_id;
+ ++next_out_id.value;
+   }
+
   else
-   place_map[in_id] = INVALID_PLACE;
+   place_map[in_id.value] = INVALID_PLACE;
 }
 }
 
@@ -110,7 +114,10 @@ Dump::go (bool enable_simplify_cfg)
   // To avoid mutation of the BIR, we use indirection through bb_fold_map.
   std::iota (bb_fold_map.begin (), bb_fold_map.end (), 0);
 
-  std::iota (place_map.begin (), place_map.end (), 0);
+  for (size_t i = 0; i < place_map.size (); ++i)
+{
+  place_map[i] = {i};
+}
 
   if (enable_simplify_cfg)
 simplify_cfg (func, bb_fold_map);
@@ -119,7 +126,7 @@ Dump::go (bool enable_simplify_cfg)
 
   stream << "fn " << name << "(";
   print_comma_separated (stream, func.arguments, [this] (PlaceId place_id) {
-stream << "_" << place_map[place_id] << ": "
+stream << "_" << place_map[place_id.value].value << ": "
   << get_tyty_name (func.place_db[place_id].tyty);
   });
   stream << ") -> " << get_tyty_name (func.place_db[RETURN_VALUE_PLACE].tyty);
@@ -228,7 +235,7 @@ Dump::visit_place (PlaceId place_id)
 {
 case Place::TEMPORARY:
 case Place::VARIABLE:
-  stream << "_" << place_map[place_id];
+  stream << "_" << place_map[place_id.value].value;
   break;
 case Place::DEREF:
   stream << "(";
@@ -365,7 +372,7 @@ Dump::visit_scope (ScopeId id, size_t depth)
   for (auto &local : scope.locals)
 {
   indent (depth + 1) << "let _";
-  stream << place_map[local] << ": "
+  stream << place_map[local.value].value << ": "
 << get_tyty_name (func.place_db[local].tyty);
   stream << ";\t";
 
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h 
b/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h
index bddaf59f..fa7cbb38eef2 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h
@@ -88,8 +88,9 @@ public:
 protected: // Constructor and destructor.
   explicit FactCollector (Function &func)
 : place_db (func.place_db), basic_blocks (func.basic_blocks),
-  first_local (func.arguments.empty () ? FIRST_VARIABLE_PLACE
-  : *func.arguments.rbegin () + 1),
+  first_local (func.arguments.empty ()
+? FIRST_VARIABLE_PLACE
+: PlaceId{func.arguments.rbegin ()->value + 1}),
   location (func.location), tyctx (*Resolver::TypeCheckContext::get ()),
   next_fresh_region (place_db.peek_next_free_region ())
   {}
@@ -118,7 +119,8 @@ protected: // Main collection entry points (for different 
categories).
 
   void visit_places (const std::vector &args)
   {
-for (PlaceId place_id = 0; place_id < place_db.size (); ++place_id)
+for (PlaceId place_id = INVALID_PLACE; place_id.value < place_db.size ();
+++place_id.value)
   {

[gcc r15-8352] gccrs: Added noreturn checking for nevertype, new test

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:8b810b2c5d0e880759280bfa63afe2494d85ff8a

commit r15-8352-g8b810b2c5d0e880759280bfa63afe2494d85ff8a
Author: badumbatish 
Date:   Fri Aug 2 11:36:04 2024 -0700

gccrs: Added noreturn checking for nevertype, new test

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
Added noreturn checking for nevertype

gcc/testsuite/ChangeLog:

* rust/compile/inline_asm_typecheck.rs: New test.

Diff:
---
 gcc/rust/typecheck/rust-hir-type-check-expr.cc | 18 +++---
 gcc/testsuite/rust/compile/inline_asm_typecheck.rs | 21 +
 2 files changed, 32 insertions(+), 7 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc 
b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index a9255fc69f2a..ba22eaff4410 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -623,10 +623,9 @@ TypeCheckExpr::visit (HIR::BlockExpr &expr)
  && (((TyTy::InferType *) loop_context_type)->get_infer_kind ()
  != TyTy::InferType::GENERAL));
 
-  infered = loop_context_type_infered
- ? loop_context_type
- : TyTy::TupleType::get_unit_type (
- expr.get_mappings ().get_hirid ());
+  infered = loop_context_type_infered ? loop_context_type
+ : TyTy::TupleType::get_unit_type (
+   expr.get_mappings ().get_hirid ());
 }
   else
 {
@@ -829,9 +828,14 @@ TypeCheckExpr::visit (HIR::InlineAsm &expr)
 {
   typecheck_inline_asm_operand (expr);
 
-  // TODO: Hoise out if we have noreturn as an option
+  // NOTE: Hoise out if we have noreturn as an option
   // to return a never type
-  infered = TyTy::TupleType::get_unit_type (expr.get_mappings ().get_hirid ());
+  // TODO : new keyword for memory seems so shaky
+  if (expr.options.count (AST::InlineAsmOption::NORETURN) == 1)
+infered = new TyTy::NeverType (expr.get_mappings ().get_hirid ());
+  else
+infered
+  = TyTy::TupleType::get_unit_type (expr.get_mappings ().get_hirid ());
 }
 
 void
@@ -1625,7 +1629,7 @@ TypeCheckExpr::visit (HIR::ClosureExpr &expr)
   TyTy::TyVar result_type
 = expr.has_return_type ()
? TyTy::TyVar (
-   TypeCheckType::Resolve (expr.get_return_type ().get ())->get_ref ())
+ TypeCheckType::Resolve (expr.get_return_type ().get ())->get_ref ())
: TyTy::TyVar::get_implicit_infer_var (expr.get_locus ());
 
   // resolve the block
diff --git a/gcc/testsuite/rust/compile/inline_asm_typecheck.rs 
b/gcc/testsuite/rust/compile/inline_asm_typecheck.rs
new file mode 100644
index ..22b7fb162c1e
--- /dev/null
+++ b/gcc/testsuite/rust/compile/inline_asm_typecheck.rs
@@ -0,0 +1,21 @@
+#![feature(rustc_attrs)]
+
+#[rustc_builtin_macro]
+macro_rules! asm {
+() => {};
+}
+
+fn main() {
+let mut _num1: i32 = 10;
+let mut _num2: i32 = 10;
+unsafe {
+// This demonstrates that asm!'s is inferred with a unit type is 
parsed correctly.
+let _ = asm!("nop");
+
+// This errors out per rust spec
+//  The asm! block never returns, and its return type is defined 
as ! (never).
+//  Behavior is undefined if execution falls through past the end 
of the asm code.
+//  A noreturn asm block behaves just like a function which 
doesn't return; notably, local variables in scope are not dropped before it is 
invoked.
+let _ = asm!("nop", options(noreturn));
+}
+}


[gcc r15-8366] gccrs: Introduce `IndexVec`

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:d91f1148d85ae0801387975364a5338237ac6efc

commit r15-8366-gd91f1148d85ae0801387975364a5338237ac6efc
Author: Kushal Pal 
Date:   Mon Aug 19 09:28:25 2024 +

gccrs: Introduce `IndexVec`

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-place.h (struct Loan):
Introduce new class `IndexVec` inspired from IndexVec of rust.
It acts as a wrapper around `std::vector` and lets user specify
a strong type to use as index.

Signed-off-by: Kushal Pal 

Diff:
---
 gcc/rust/checks/errors/borrowck/rust-bir-place.h | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-place.h 
b/gcc/rust/checks/errors/borrowck/rust-bir-place.h
index f7018d3af7f0..235646088920 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-place.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-place.h
@@ -199,6 +199,25 @@ struct Loan
   location_t location;
 };
 
+// I is the index type, T is the contained type
+template  class IndexVec
+{
+  std::vector internal_vector;
+
+public:
+  T &at (I pid) { return internal_vector[pid.value]; }
+  const T &at (I pid) const { return internal_vector[pid.value]; }
+  T &operator[] (I pid) { return internal_vector[pid.value]; }
+  const T &operator[] (I pid) const { return internal_vector[pid.value]; }
+
+  void push_back (T &¶m) { internal_vector.push_back (std::move (param)); }
+  template  void emplace_back (Args &&... args)
+  {
+internal_vector.emplace_back (std::forward (args)...);
+  }
+  size_t size () const { return internal_vector.size (); }
+};
+
 /** Allocated places and keeps track of paths. */
 class PlaceDB
 {


[gcc r15-8348] gccrs: Move strip double quotes, add scaffold expand

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:6ec82928851302bed173b40fb9f95d4cf53a26e4

commit r15-8348-g6ec82928851302bed173b40fb9f95d4cf53a26e4
Author: badumbatish 
Date:   Fri Jul 26 20:26:01 2024 -0700

gccrs: Move strip double quotes, add scaffold expand

gcc/rust/ChangeLog:

* backend/rust-compile-asm.cc (strip_double_quotes):
Move strip double quotes to parse phase
(CompileAsm::asm_construct_string_tree): Likewise
* backend/rust-compile-asm.h (strip_double_quotes): Likewise
* expand/rust-macro-builtins-asm.cc (strip_double_quotes):
Likewise
(expand_inline_asm): Renamed to expand_inline_asm_strings
(expand_inline_asm_strings): Renamed from expand_inline_asm
(parse_asm): Move strip double quotes to parse phase
(parse_format_strings): Likewise
* expand/rust-macro-builtins-asm.h (strip_double_quotes):
Likewise
(expand_inline_asm_strings): Inline asm expansion fn
(expand_inline_asm_string): Inline asm expansion fn

Diff:
---
 gcc/rust/backend/rust-compile-asm.cc   | 16 +---
 gcc/rust/backend/rust-compile-asm.h|  3 ---
 gcc/rust/expand/rust-macro-builtins-asm.cc | 40 ++
 gcc/rust/expand/rust-macro-builtins-asm.h  |  9 +++
 4 files changed, 39 insertions(+), 29 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-asm.cc 
b/gcc/rust/backend/rust-compile-asm.cc
index 9305a9088bb5..30a8cacf203a 100644
--- a/gcc/rust/backend/rust-compile-asm.cc
+++ b/gcc/rust/backend/rust-compile-asm.cc
@@ -1,22 +1,8 @@
 #include "rust-compile-asm.h"
-
 #include "rust-system.h"
 namespace Rust {
 namespace Compile {
 
-std::string
-strip_double_quotes (const std::string &str)
-{
-  // Helper function strips the beginning and ending double quotes from a
-  // string.
-  std::string result = str;
-
-  rust_assert (result.size () >= 3);
-  result.erase (0, 1);
-  result.erase (result.size () - 1, 1);
-  return result;
-}
-
 CompileAsm::CompileAsm (Context *ctx)
   : HIRCompileBase (ctx), translated (error_mark_node)
 {}
@@ -86,7 +72,7 @@ CompileAsm::asm_construct_string_tree (HIR::InlineAsm &expr)
   // debugging and reading)
   std::stringstream ss;
   for (const auto &template_str : expr.template_strs)
-ss << strip_double_quotes (template_str.symbol) << "\n\t";
+ss << template_str.symbol << "\n\t";
 
   std::string result = ss.str ();
   return build_string (result.size () + 1, result.c_str ());
diff --git a/gcc/rust/backend/rust-compile-asm.h 
b/gcc/rust/backend/rust-compile-asm.h
index 8307d895bd51..05bb99ab40d4 100644
--- a/gcc/rust/backend/rust-compile-asm.h
+++ b/gcc/rust/backend/rust-compile-asm.h
@@ -26,9 +26,6 @@
 namespace Rust {
 namespace Compile {
 
-std::string
-strip_double_quotes (const std::string &);
-
 class CompileAsm : private HIRCompileBase, protected HIR::HIRExpressionVisitor
 {
 private:
diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index bbb8fff180ff..379e5d8b967b 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -742,26 +742,42 @@ parse_asm_arg (InlineAsmContext inline_asm_ctx)
   return tl::expected (inline_asm_ctx);
 }
 
+std::string
+strip_double_quotes (const std::string &str)
+{
+  // Helper function strips the beginning and ending double quotes from a
+  // string.
+  std::string result = str;
+
+  rust_assert (result.size () >= 3);
+  result.erase (0, 1);
+  result.erase (result.size () - 1, 1);
+  return result;
+}
+
 tl::expected
-expand_inline_asm (InlineAsmContext &inline_asm_ctx)
+expand_inline_asm_strings (InlineAsmContext &inline_asm_ctx)
 {
   auto &inline_asm = inline_asm_ctx.inline_asm;
 
   auto str_vec = inline_asm.get_template_strs ();
   for (auto &template_str : str_vec)
 {
-  std::cout << template_str.symbol << std::endl;
+  /*std::cout << template_str.symbol << std::endl;*/
 
   auto pieces = Fmt::Pieces::collect (template_str.symbol, false,
- Fmt::ffi::ParseMode::Format)
- .get_pieces ();
+ Fmt::ffi::ParseMode::InlineAsm);
+  auto pieces_vec = pieces.get_pieces ();
 
-  for (size_t i = 0; i < pieces.size (); i++)
+  for (size_t i = 0; i < pieces_vec.size (); i++)
{
- auto piece = pieces[i];
+ auto piece = pieces_vec[i];
  if (piece.tag == Fmt::ffi::Piece::Tag::String)
-   std::cout << "   " << i << ": " << piece.string._0.to_string ()
- << std::endl;
+   {
+   }
+ /*std::cout << "   " << i << ": " << piece.string._0.to_string
+  * ()*/
+ /*   << std::endl;*/
}
 }
 
@@ -798,7 +814,7 @@ parse_asm (location_t invoc_locus, AST::MacroInvocData 
&invoc,
   auto is_valid = (bool) resulting_context;
   if (is_va

[gcc r15-8351] gccrs: Perform lowering hir output operand to tree

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:0bad7500da4f08d03e668cbba8935a9f0803664c

commit r15-8351-g0bad7500da4f08d03e668cbba8935a9f0803664c
Author: badumbatish 
Date:   Thu Aug 1 16:22:32 2024 -0700

gccrs: Perform lowering hir output operand to tree

gcc/rust/ChangeLog:

* backend/rust-compile-asm.cc (CompileAsm::asm_build_expr):
Add debug comment
(CompileAsm::asm_construct_outputs):
Perform lowering hir output operand to tree

Diff:
---
 gcc/rust/backend/rust-compile-asm.cc | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/backend/rust-compile-asm.cc 
b/gcc/rust/backend/rust-compile-asm.cc
index 32ad84e60e7d..d179c355f21a 100644
--- a/gcc/rust/backend/rust-compile-asm.cc
+++ b/gcc/rust/backend/rust-compile-asm.cc
@@ -26,6 +26,7 @@ CompileAsm::asm_build_expr (HIR::InlineAsm &expr)
   ASM_BASIC_P (asm_expr) = expr.is_simple_asm ();
   ASM_VOLATILE_P (asm_expr) = false;
   ASM_INLINE_P (asm_expr) = expr.is_inline_asm ();
+  /*Backend::debug (asm_expr);*/
   return asm_expr;
 }
 
@@ -91,8 +92,17 @@ CompileAsm::asm_construct_outputs (HIR::InlineAsm &expr)
  == AST::InlineAsmOperand::RegisterType::Out)
{
  auto out = output.get_out ();
+
  tree out_tree = CompileExpr::Compile (out.expr.get (), this->ctx);
- Backend::debug (out_tree);
+ // expects a tree list
+ // TODO: This assumes that the output is a register
+ std::string expr_name = "=r";
+ auto name = build_string (expr_name.size () + 1, expr_name.c_str ());
+ head
+   = chainon (head, build_tree_list (build_tree_list (NULL_TREE, name),
+ out_tree));
+
+ /*Backend::debug (head);*/
  /*head = chainon (head, out_tree);*/
}
 }


[gcc r15-8349] gccrs: Lower the HIR to tree with CompileExpr

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:e91b55fb3b48d219ac50d9744778fc91cb1f7d37

commit r15-8349-ge91b55fb3b48d219ac50d9744778fc91cb1f7d37
Author: badumbatish 
Date:   Mon Jul 29 21:59:13 2024 -0700

gccrs: Lower the HIR to tree with CompileExpr

gcc/rust/ChangeLog:

* backend/rust-compile-asm.cc (CompileAsm::asm_construct_outputs):
Lower the HIR to tree with CompileExpr
* backend/rust-compile-asm.h: Remove static from method

Diff:
---
 gcc/rust/backend/rust-compile-asm.cc | 15 +++
 gcc/rust/backend/rust-compile-asm.h  | 18 +-
 2 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-asm.cc 
b/gcc/rust/backend/rust-compile-asm.cc
index 30a8cacf203a..32ad84e60e7d 100644
--- a/gcc/rust/backend/rust-compile-asm.cc
+++ b/gcc/rust/backend/rust-compile-asm.cc
@@ -1,5 +1,6 @@
 #include "rust-compile-asm.h"
 #include "rust-system.h"
+#include "rust-compile-expr.h"
 namespace Rust {
 namespace Compile {
 
@@ -82,14 +83,20 @@ tree
 CompileAsm::asm_construct_outputs (HIR::InlineAsm &expr)
 {
   // TODO: Do i need to do this?
-  int count = 0;
 
+  tree head = NULL_TREE;
   for (auto &output : expr.get_operands ())
 {
-  if (output.register_type == AST::InlineAsmOperand::RegisterType::Out)
-   count++;
+  if (output.get_register_type ()
+ == AST::InlineAsmOperand::RegisterType::Out)
+   {
+ auto out = output.get_out ();
+ tree out_tree = CompileExpr::Compile (out.expr.get (), this->ctx);
+ Backend::debug (out_tree);
+ /*head = chainon (head, out_tree);*/
+   }
 }
-  return NULL_TREE;
+  return head;
 }
 
 tree
diff --git a/gcc/rust/backend/rust-compile-asm.h 
b/gcc/rust/backend/rust-compile-asm.h
index 05bb99ab40d4..9779a4ad7fbe 100644
--- a/gcc/rust/backend/rust-compile-asm.h
+++ b/gcc/rust/backend/rust-compile-asm.h
@@ -46,15 +46,15 @@ public:
   // build_asm_expr (location_t loc, tree string, tree outputs, tree inputs,
   //   tree clobbers, tree labels, bool simple, bool is_inline)
   static const int ASM_TREE_ARRAY_LENGTH = 5;
-  static tree asm_build_expr (HIR::InlineAsm &);
-  static tree asm_build_stmt (location_t,
- const std::array &);
-
-  static tree asm_construct_string_tree (HIR::InlineAsm &);
-  static tree asm_construct_outputs (HIR::InlineAsm &);
-  static tree asm_construct_inputs (HIR::InlineAsm &);
-  static tree asm_construct_clobber_tree (HIR::InlineAsm &);
-  static tree asm_construct_label_tree (HIR::InlineAsm &);
+  tree asm_build_expr (HIR::InlineAsm &);
+  tree asm_build_stmt (location_t,
+  const std::array &);
+
+  tree asm_construct_string_tree (HIR::InlineAsm &);
+  tree asm_construct_outputs (HIR::InlineAsm &);
+  tree asm_construct_inputs (HIR::InlineAsm &);
+  tree asm_construct_clobber_tree (HIR::InlineAsm &);
+  tree asm_construct_label_tree (HIR::InlineAsm &);
 
   CompileAsm (Context *ctx);


[gcc r15-8353] gccrs: Use's array type when constring string tree

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:d3be8cb777bc74f85b4e06df054b42c441bf5df9

commit r15-8353-gd3be8cb777bc74f85b4e06df054b42c441bf5df9
Author: badumbatish 
Date:   Thu Aug 8 14:22:05 2024 -0700

gccrs: Use's array type when constring string tree

gcc/rust/ChangeLog:

* backend/rust-compile-asm.cc (CompileAsm::asm_build_expr):
Use's array type when constring string tree
(CompileAsm::asm_construct_string_tree):
Use's array type when constring string tree

Diff:
---
 gcc/rust/backend/rust-compile-asm.cc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-asm.cc 
b/gcc/rust/backend/rust-compile-asm.cc
index d179c355f21a..92d60d756864 100644
--- a/gcc/rust/backend/rust-compile-asm.cc
+++ b/gcc/rust/backend/rust-compile-asm.cc
@@ -26,7 +26,7 @@ CompileAsm::asm_build_expr (HIR::InlineAsm &expr)
   ASM_BASIC_P (asm_expr) = expr.is_simple_asm ();
   ASM_VOLATILE_P (asm_expr) = false;
   ASM_INLINE_P (asm_expr) = expr.is_inline_asm ();
-  /*Backend::debug (asm_expr);*/
+  Backend::debug (asm_expr);
   return asm_expr;
 }
 
@@ -74,10 +74,10 @@ CompileAsm::asm_construct_string_tree (HIR::InlineAsm &expr)
   // debugging and reading)
   std::stringstream ss;
   for (const auto &template_str : expr.template_strs)
-ss << template_str.symbol << "\n\t";
+ss << template_str.symbol << "\n";
 
   std::string result = ss.str ();
-  return build_string (result.size () + 1, result.c_str ());
+  return Backend::string_constant_expression (result);
 }
 
 tree


[gcc r15-8355] gccrs: Fix return type of asm mov 5 to i32:0, tortured

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:4d366e3da3d3f46aa7c7545bb127bb91c7049666

commit r15-8355-g4d366e3da3d3f46aa7c7545bb127bb91c7049666
Author: badumbatish 
Date:   Wed Aug 28 00:15:14 2024 -0700

gccrs: Fix return type of asm mov 5 to i32:0, tortured

gcc/testsuite/ChangeLog:

* rust/execute/inline_asm_mov_x_5.rs: Move to...
* rust/execute/torture/inline_asm_mov_x_5.rs: ...here.

Diff:
---
 gcc/testsuite/rust/execute/{ => torture}/inline_asm_mov_x_5.rs | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/rust/execute/inline_asm_mov_x_5.rs 
b/gcc/testsuite/rust/execute/torture/inline_asm_mov_x_5.rs
similarity index 93%
rename from gcc/testsuite/rust/execute/inline_asm_mov_x_5.rs
rename to gcc/testsuite/rust/execute/torture/inline_asm_mov_x_5.rs
index e09ea1a030ae..4f1555e6f2d3 100644
--- a/gcc/testsuite/rust/execute/inline_asm_mov_x_5.rs
+++ b/gcc/testsuite/rust/execute/torture/inline_asm_mov_x_5.rs
@@ -10,7 +10,7 @@ extern "C" {
 fn printf(s: *const i8, ...);
 }
 
-fn main() {
+fn main() -> i32 {
 let mut _x: i32 = 0;
 unsafe {
 asm!(
@@ -19,4 +19,5 @@ fn main() {
 );
 printf("%d\n\0" as *const str as *const i8, _x);
 }
+0
 }


[gcc r15-8359] gccrs: Avoid accidental insertion into map

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:2438584da1f8bbdfdc21b5a2a562472e0c572589

commit r15-8359-g2438584da1f8bbdfdc21b5a2a562472e0c572589
Author: Owen Avery 
Date:   Thu Sep 5 19:44:55 2024 -0400

gccrs: Avoid accidental insertion into map

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-pattern.cc
(PatternDeclaration::check_bindings_consistency): Check if
outer_bindings_map contains an entry before indexing.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/resolve/rust-ast-resolve-pattern.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/resolve/rust-ast-resolve-pattern.cc 
b/gcc/rust/resolve/rust-ast-resolve-pattern.cc
index 9b383b722c87..ee84be8942bc 100644
--- a/gcc/rust/resolve/rust-ast-resolve-pattern.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-pattern.cc
@@ -330,7 +330,8 @@ PatternDeclaration::check_bindings_consistency (
  if (!ident_is_outer_bound && !missing_bindings.count (ident))
missing_bindings.insert ({ident, inner_info});
 
- else if (outer_bindings_map[ident] != inner_info
+ else if (outer_bindings_map.count (ident)
+  && outer_bindings_map[ident] != inner_info
   && !inconsistent_bindings.count (ident))
inconsistent_bindings.insert ({ident, inner_info});
}


[gcc r15-8344] gccrs: Minor fix to asm codegen pr

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:d3e1f59ba8333b3b7e5e01a604c3f842a9ce535f

commit r15-8344-gd3e1f59ba8333b3b7e5e01a604c3f842a9ce535f
Author: badumbatish 
Date:   Thu Jul 18 07:34:43 2024 -0700

gccrs: Minor fix to asm codegen pr

gcc/rust/ChangeLog:

* backend/rust-compile-asm.cc (CompileAsm::asm_build_expr):
Use expr's is_simple_asm and is_inline_asm
(CompileAsm::asm_is_simple): removed
(CompileAsm::asm_is_inline): removed
* backend/rust-compile-asm.h: Add docs to ASM_TREE_ARRAY_LENGTH
* hir/tree/rust-hir-expr.h: Add is_simple_asm, is_inline_asm
and remove #include tree

Diff:
---
 gcc/rust/backend/rust-compile-asm.cc | 17 ++---
 gcc/rust/backend/rust-compile-asm.h  | 10 --
 gcc/rust/hir/tree/rust-hir-expr.h| 12 +++-
 3 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-asm.cc 
b/gcc/rust/backend/rust-compile-asm.cc
index 8fd62dd48c9d..0dd4f6720085 100644
--- a/gcc/rust/backend/rust-compile-asm.cc
+++ b/gcc/rust/backend/rust-compile-asm.cc
@@ -36,9 +36,9 @@ CompileAsm::asm_build_expr (HIR::InlineAsm &expr)
  asm_construct_clobber_tree (expr),
  asm_construct_label_tree (expr)});
 
-  ASM_BASIC_P (asm_expr) = CompileAsm::asm_is_simple (expr);
+  ASM_BASIC_P (asm_expr) = expr.is_simple_asm ();
   ASM_VOLATILE_P (asm_expr) = false;
-  ASM_INLINE_P (asm_expr) = CompileAsm::asm_is_inline (expr);
+  ASM_INLINE_P (asm_expr) = expr.is_inline_asm ();
   return asm_expr;
 }
 
@@ -120,18 +120,5 @@ CompileAsm::asm_construct_label_tree (HIR::InlineAsm &expr)
   return NULL_TREE;
 }
 
-bool
-CompileAsm::asm_is_simple (HIR::InlineAsm &expr)
-{
-  // TODO: Check back later to determine how an InlineAsm is simple.
-  return true;
-}
-
-bool
-CompileAsm::asm_is_inline (HIR::InlineAsm &expr)
-{
-  // TODO: Check back later to determine how an InlineAsm is inline.
-  return true;
-}
 } // namespace Compile
 } // namespace Rust
diff --git a/gcc/rust/backend/rust-compile-asm.h 
b/gcc/rust/backend/rust-compile-asm.h
index 15ffc707986f..8307d895bd51 100644
--- a/gcc/rust/backend/rust-compile-asm.h
+++ b/gcc/rust/backend/rust-compile-asm.h
@@ -40,6 +40,14 @@ public:
   // static tree Compile (HIR::Expr *expr, Context *ctx);
 
   // RELEVANT MEMBER FUNCTIONS
+
+  // The limit is 5 because it stands for the 5 things that the C version of
+  //  build_asm_expr accepts: string, output, input, clobber and label.
+  // The function signature is
+  //
+  // tree
+  // build_asm_expr (location_t loc, tree string, tree outputs, tree inputs,
+  //   tree clobbers, tree labels, bool simple, bool is_inline)
   static const int ASM_TREE_ARRAY_LENGTH = 5;
   static tree asm_build_expr (HIR::InlineAsm &);
   static tree asm_build_stmt (location_t,
@@ -50,8 +58,6 @@ public:
   static tree asm_construct_inputs (HIR::InlineAsm &);
   static tree asm_construct_clobber_tree (HIR::InlineAsm &);
   static tree asm_construct_label_tree (HIR::InlineAsm &);
-  static bool asm_is_simple (HIR::InlineAsm &);
-  static bool asm_is_inline (HIR::InlineAsm &);
 
   CompileAsm (Context *ctx);
 
diff --git a/gcc/rust/hir/tree/rust-hir-expr.h 
b/gcc/rust/hir/tree/rust-hir-expr.h
index 2b86d59f969f..8a42c8b3a675 100644
--- a/gcc/rust/hir/tree/rust-hir-expr.h
+++ b/gcc/rust/hir/tree/rust-hir-expr.h
@@ -25,7 +25,6 @@
 #include "rust-hir-path.h"
 #include "rust-operators.h"
 #include "rust-expr.h"
-#include "tree.h"
 namespace Rust {
 namespace HIR {
 
@@ -4147,6 +4146,17 @@ public:
 
   std::set get_options () { return options; }
 
+  bool is_simple_asm ()
+  {
+// TODO: Check back later to determine how an InlineAsm is simple.
+return true;
+  }
+
+  bool is_inline_asm ()
+  {
+// TODO: Check back later to determine how an InlineAsm is inline.
+return true;
+  }
   InlineAsm (location_t locus, bool is_global_asm,
 std::vector template_,
 std::vector template_strs,


[gcc r15-8336] gccrs: Scaffolding asm codegen

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:51f430a4642339af721dbc09af8db39aef8c744c

commit r15-8336-g51f430a4642339af721dbc09af8db39aef8c744c
Author: jjasmine 
Date:   Sat Jun 22 11:56:50 2024 -0700

gccrs: Scaffolding asm codegen

gcc/rust/ChangeLog:

* backend/rust-compile-block.h:
Scaffolding asm codegen
* backend/rust-compile-expr.cc (CompileExpr::visit): Likewise.
* backend/rust-compile-expr.h: Likewise.
* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc 
(ExprStmtBuilder::visit): Likewise.
* checks/errors/borrowck/rust-bir-builder-expr-stmt.h: Likewise.
* checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: Likewise.
* checks/errors/privacy/rust-privacy-reporter.cc 
(PrivacyReporter::visit): Likewise.
* checks/errors/privacy/rust-privacy-reporter.h: Likewise.
* hir/tree/rust-hir-expr.h: Likewise.
* hir/tree/rust-hir-visitor.h: Likewise.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): 
Likewise.
* typecheck/rust-hir-type-check-expr.h: Likewise.

Diff:
---
 gcc/rust/backend/rust-compile-block.h  |  2 ++
 gcc/rust/backend/rust-compile-expr.cc  |  4 
 gcc/rust/backend/rust-compile-expr.h   |  1 +
 gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc  |  5 +
 gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.h   |  1 +
 .../checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h |  2 ++
 gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc|  6 ++
 gcc/rust/checks/errors/privacy/rust-privacy-reporter.h |  1 +
 gcc/rust/hir/tree/rust-hir-expr.h  | 10 ++
 gcc/rust/hir/tree/rust-hir-visitor.h   |  1 +
 gcc/rust/typecheck/rust-hir-type-check-expr.cc |  6 ++
 gcc/rust/typecheck/rust-hir-type-check-expr.h  |  1 +
 12 files changed, 40 insertions(+)

diff --git a/gcc/rust/backend/rust-compile-block.h 
b/gcc/rust/backend/rust-compile-block.h
index b315c7765133..d226b4be9f4e 100644
--- a/gcc/rust/backend/rust-compile-block.h
+++ b/gcc/rust/backend/rust-compile-block.h
@@ -101,6 +101,7 @@ public:
   void visit (HIR::MatchExpr &) override {}
   void visit (HIR::AwaitExpr &) override {}
   void visit (HIR::AsyncBlockExpr &) override {}
+  void visit (HIR::InlineAsm &) override {}
 
 private:
   CompileConditionalBlocks (Context *ctx, Bvariable *result)
@@ -184,6 +185,7 @@ public:
   void visit (HIR::MatchExpr &) override {}
   void visit (HIR::AwaitExpr &) override {}
   void visit (HIR::AsyncBlockExpr &) override {}
+  void visit (HIR::InlineAsm &) override {}
 
 private:
   CompileExprWithBlock (Context *ctx, Bvariable *result)
diff --git a/gcc/rust/backend/rust-compile-expr.cc 
b/gcc/rust/backend/rust-compile-expr.cc
index e2fa6dda09e3..e23c691d1dbc 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -318,6 +318,10 @@ CompileExpr::visit (HIR::IfExpr &expr)
   ctx->add_statement (stmt);
 }
 
+void
+CompileExpr::visit (HIR::InlineAsm &expr)
+{}
+
 void
 CompileExpr::visit (HIR::IfExprConseqElse &expr)
 {
diff --git a/gcc/rust/backend/rust-compile-expr.h 
b/gcc/rust/backend/rust-compile-expr.h
index b257da5e59cb..ef907d1ca625 100644
--- a/gcc/rust/backend/rust-compile-expr.h
+++ b/gcc/rust/backend/rust-compile-expr.h
@@ -68,6 +68,7 @@ public:
   void visit (HIR::RangeFullExpr &expr) override;
   void visit (HIR::RangeFromToInclExpr &expr) override;
   void visit (HIR::ClosureExpr &expr) override;
+  void visit (HIR::InlineAsm &expr) override;
 
   // TODO
   void visit (HIR::ErrorPropagationExpr &) override {}
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc 
b/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
index 3515bdf030b6..8d4d90aab80c 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
@@ -21,6 +21,7 @@
 #include "rust-bir-builder-lazyboolexpr.h"
 #include "rust-bir-builder-pattern.h"
 #include "rust-bir-builder-struct.h"
+#include "rust-hir-expr.h"
 
 namespace Rust {
 namespace BIR {
@@ -317,6 +318,10 @@ ExprStmtBuilder::visit (HIR::CallExpr &expr)
   expr.get_locus (), true);
 }
 
+void
+ExprStmtBuilder::visit (HIR::InlineAsm &expr)
+{}
+
 void
 ExprStmtBuilder::visit (HIR::MethodCallExpr &expr)
 {}
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.h 
b/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.h
index 3a58611e338c..574f0f36fdd7 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.h
@@ -99,6 +99,7 @@ protected: // Expr
   void visit (HIR::WhileLetLoopExpr &expr) override;
   void visit (HIR::IfExpr &expr) override

[gcc r15-8343] gccrs: Refactor compile-asm for first round review

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:a438e47eeddb5e56dbcb3387417f334a582b5764

commit r15-8343-ga438e47eeddb5e56dbcb3387417f334a582b5764
Author: badumbatish 
Date:   Sun Jul 7 22:03:12 2024 -0700

gccrs: Refactor compile-asm for first round review

gcc/rust/ChangeLog:

* backend/rust-compile-asm.cc (strip_double_quotes):
Refactor compile-asm for first round review
(CompileAsm::asm_build_asm_stmt): Likewise.
(CompileAsm::asm_build_expr): Likewise.
(CompileAsm::asm_get_locus): Likewise.
(CompileAsm::asm_construct_string_tree): Likewise.
(CompileAsm::asm_construct_outputs): Likewise.
(CompileAsm::asm_construct_inputs): Likewise.
(CompileAsm::asm_construct_clobber_tree): Likewise.
(CompileAsm::asm_construct_label_tree): Likewise.
(CompileAsm::asm_is_simple): Likewise.
(CompileAsm::asm_is_inline): Likewise.
* backend/rust-compile-asm.h (strip_double_quotes): Likewise.
(class CompileAsm): Likewise.

Diff:
---
 gcc/rust/backend/rust-compile-asm.cc | 251 +++
 gcc/rust/backend/rust-compile-asm.h  | 127 +-
 2 files changed, 107 insertions(+), 271 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-asm.cc 
b/gcc/rust/backend/rust-compile-asm.cc
index fe080f6aa6b9..8fd62dd48c9d 100644
--- a/gcc/rust/backend/rust-compile-asm.cc
+++ b/gcc/rust/backend/rust-compile-asm.cc
@@ -1,72 +1,57 @@
 #include "rust-compile-asm.h"
 
-#include "rust-tree.h"
 #include "rust-system.h"
-#include 
 namespace Rust {
 namespace Compile {
 
+std::string
+strip_double_quotes (const std::string &str)
+{
+  // Helper function strips the beginning and ending double quotes from a
+  // string.
+  std::string result = str;
+
+  rust_assert (result.size () >= 3);
+  result.erase (0, 1);
+  result.erase (result.size () - 1, 1);
+  return result;
+}
+
 CompileAsm::CompileAsm (Context *ctx)
   : HIRCompileBase (ctx), translated (error_mark_node)
 {}
 void
 CompileAsm::visit (HIR::InlineAsm &expr)
 {
-  return ctx->add_statement (asm_build_expr (expr));
-}
-tree
-CompileAsm::asm_build_asm_stmt (HIR::InlineAsm &expr)
-{
-  // From the implementation of c-typeck.cc
-  // tree
-  // build_asm_stmt (bool is_volatile, tree args)
-  //{
-  //   if (is_volatile)
-  // ASM_VOLATILE_P (args) = 1;
-  //   return add_stmt (args);
-  // }
-  //
-  return NULL_TREE;
+  ctx->add_statement (asm_build_expr (expr));
 }
+
 tree
 CompileAsm::asm_build_expr (HIR::InlineAsm &expr)
 {
-  auto asm_expr = asm_build_stmt (asm_get_locus (expr), ASM_EXPR,
- {asm_construct_string_tree (expr),
-  asm_construct_outputs (expr),
-  asm_construct_inputs (expr),
-  asm_construct_clobber_tree (expr),
-  asm_construct_label_tree (expr)});
+  auto asm_expr
+= asm_build_stmt (expr.get_locus (), {asm_construct_string_tree (expr),
+ asm_construct_outputs (expr),
+ asm_construct_inputs (expr),
+ asm_construct_clobber_tree (expr),
+ asm_construct_label_tree (expr)});
 
   ASM_BASIC_P (asm_expr) = CompileAsm::asm_is_simple (expr);
-  ASM_VOLATILE_P (asm_expr) = (false);
+  ASM_VOLATILE_P (asm_expr) = false;
   ASM_INLINE_P (asm_expr) = CompileAsm::asm_is_inline (expr);
   return asm_expr;
-  // return build_asm_expr (CompileAsm::asm_get_locus (expr),
-  //CompileAsm::asm_construct_string_tree (expr),
-  //CompileAsm::asm_construct_outputs (expr),
-  //CompileAsm::asm_construct_inputs (expr),
-  //CompileAsm::asm_construct_clobber_tree (expr),
-  //CompileAsm::asm_construct_label_tree (expr),
-  //CompileAsm::asm_is_simple (expr),
-  //CompileAsm::asm_is_inline (expr));
 }
 
 tree
 CompileAsm::asm_build_stmt (
-  location_t loc, enum tree_code code,
+  location_t loc,
   const std::array &trees)
 {
+  // Prototype functiion for building an ASM_EXPR tree.
   tree ret;
-  //  va_list p;
   bool side_effects;
 
-  /* This function cannot be used to construct variably-sized nodes.  */
-  gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
-
-  // va_start (p, code);
-
-  ret = make_node (code);
+  ret = make_node (ASM_EXPR);
   TREE_TYPE (ret) = void_type_node;
   SET_EXPR_LOCATION (ret, loc);
 
@@ -75,6 +60,8 @@ CompileAsm::asm_build_stmt (
  expressions by checking whether the parameters have side
  effects.  */
 
+  // This is here because of c-typeck.cc's code
+  // I'm not sure what kind of effects it has
   side_effects = false;
   for (size_t i = 0; i < trees.size (); i++)
 {
@@ -86,213 +73,65 @@ Compil

[gcc r15-8362] gccrs: Use FreeRegions inplace of `std::vector`

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:e7a76ba9176304fab0924e429ae7ca1fa0ee434e

commit r15-8362-ge7a76ba9176304fab0924e429ae7ca1fa0ee434e
Author: Kushal Pal 
Date:   Thu Aug 8 07:12:00 2024 +

gccrs: Use FreeRegions inplace of `std::vector`

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder-internal.h: Use
FreeRegions instead of making a temporary vector of FreeRegion.
* checks/errors/borrowck/rust-bir-builder.h: Likewise.
* checks/errors/borrowck/rust-bir-fact-collector.h (class 
FactCollector):
Likewise.
(points): Likewise.
* checks/errors/borrowck/rust-bir-free-region.h: Remove obsolete
set_from() helpers, add push_back().
* checks/errors/borrowck/rust-bir-place.h: Use FreeRegions
instead of making a temporary vector of Origin.
* typecheck/rust-tyty-variance-analysis-private.h: Change type
of `regions`.
* typecheck/rust-tyty-variance-analysis.cc 
(CrateCtx::query_type_regions):
Use new type.
(GenericTyPerCrateCtx::query_generic_variance): Likewise.
(TyVisitorCtx::add_constraints_from_generic_args): Likewise.
(FieldVisitorCtx::add_constraints_from_region): Likewise.
(FieldVisitorCtx::add_constrints_from_param): Likewise.
* typecheck/rust-tyty-variance-analysis.h: Likewise.

Signed-off-by: Kushal Pal 

Diff:
---
 .../errors/borrowck/rust-bir-builder-internal.h|  6 ++---
 gcc/rust/checks/errors/borrowck/rust-bir-builder.h |  6 ++---
 .../errors/borrowck/rust-bir-fact-collector.h  | 20 -
 .../checks/errors/borrowck/rust-bir-free-region.h  | 26 +-
 gcc/rust/checks/errors/borrowck/rust-bir-place.h   |  9 +---
 .../rust-tyty-variance-analysis-private.h  | 11 +
 gcc/rust/typecheck/rust-tyty-variance-analysis.cc  | 10 -
 gcc/rust/typecheck/rust-tyty-variance-analysis.h   |  7 +++---
 8 files changed, 38 insertions(+), 57 deletions(-)

diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h 
b/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h
index afaeb12d458a..b27f7717cd0c 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h
@@ -206,7 +206,7 @@ protected:
   FreeRegions bind_regions (std::vector regions,
FreeRegions parent_free_regions)
   {
-std::vector free_regions;
+FreeRegions free_regions;
 for (auto ®ion : regions)
   {
if (region.is_early_bound ())
@@ -231,9 +231,7 @@ protected:
rust_unreachable ();
  }
   }
-// This is necesarry because of clash of current gcc and gcc4.8.
-FreeRegions free_regions_final{std::move (free_regions)};
-return free_regions_final;
+return free_regions;
   }
 
 protected: // Helpers to add BIR statements
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder.h 
b/gcc/rust/checks/errors/borrowck/rust-bir-builder.h
index 4e48ced32993..63d326278c7f 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-builder.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder.h
@@ -68,15 +68,15 @@ private:
   /** Instantiate `num_lifetime_params` free regions. */
   void handle_lifetime_params (size_t num_lifetime_params)
   {
-std::vector function_free_regions;
+FreeRegions regions;
 for (size_t i = 0; i < num_lifetime_params; i++)
   {
-   function_free_regions.push_back (ctx.place_db.get_next_free_region ());
+   regions.push_back (ctx.place_db.get_next_free_region ());
   }
 
 rust_debug ("\tctx.fn_free_region={%s}",
ctx.fn_free_regions.to_string ().c_str ());
-ctx.fn_free_regions.set_from (std::move (function_free_regions));
+ctx.fn_free_regions = regions;
   }
 
   void handle_lifetime_param_constraints (
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h 
b/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h
index ed2133a361bf..ebf8eec70538 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h
@@ -65,11 +65,11 @@ class FactCollector : public Visitor
 
   FreeRegions make_fresh_regions (size_t size)
   {
-std::vector free_regions;
+FreeRegions free_regions;
 for (size_t i = 0; i < size; i++)
   free_regions.push_back (region_binder.get_next_free_region ());
 
-return FreeRegions (std::move (free_regions));
+return free_regions;
   }
 
 public:
@@ -179,12 +179,12 @@ protected: // Main collection entry points (for different 
categories).
 
 rust_debug ("\tSanitize deref of %s", base.tyty->as_string ().c_str ());
 
-std::vector regions;
-regions.insert (regions.end (), base.regions.begin () + 1,
-   base.regions.end ());
-FreeRegions r;
-r.set

[gcc r15-8330] rust: Add checking for union patterns

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:b7e79e38fe97e9f41008f0a48bd41ffdd7a2895c

commit r15-8330-gb7e79e38fe97e9f41008f0a48bd41ffdd7a2895c
Author: Raiki Tamura 
Date:   Wed Jul 31 16:09:30 2024 +0900

rust: Add checking for union patterns

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-pattern.cc 
(TypeCheckPattern::visit):
Add check for union patterns.

gcc/testsuite/ChangeLog:

* rust/compile/match8.rs: New test.

Signed-off-by: Raiki Tamura 

Diff:
---
 gcc/rust/typecheck/rust-hir-type-check-pattern.cc | 82 ---
 gcc/testsuite/rust/compile/match8.rs  | 19 ++
 2 files changed, 76 insertions(+), 25 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-pattern.cc 
b/gcc/rust/typecheck/rust-hir-type-check-pattern.cc
index 1a3d0ecd1859..2b0b02ad5ef0 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-pattern.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-pattern.cc
@@ -222,10 +222,6 @@ TypeCheckPattern::visit (HIR::StructPattern &pattern)
   return;
 }
 
-  // check the elements
-  // error[E0027]: pattern does not mention fields `x`, `y`
-  // error[E0026]: variant `Foo::D` does not have a field named `b`
-
   std::vector named_fields;
   auto &struct_pattern_elems = pattern.get_struct_pattern_elems ();
   for (auto &field : struct_pattern_elems.get_struct_pattern_fields ())
@@ -279,31 +275,67 @@ TypeCheckPattern::visit (HIR::StructPattern &pattern)
}
 }
 
-  if (named_fields.size () != variant->num_fields ())
+  // check the elements
+  if (adt->is_union ())
 {
-  std::map missing_names;
+  auto &struct_pattern_elems = pattern.get_struct_pattern_elems ();
+  if (struct_pattern_elems.get_struct_pattern_fields ().size () != 1)
+   rust_error_at (pattern.get_locus (),
+  "union patterns should have exactly one field");
 
-  // populate with all fields
-  for (auto &field : variant->get_fields ())
-   missing_names[field->get_name ()] = true;
-
-  // then eliminate with named_fields
-  for (auto &named : named_fields)
-   missing_names.erase (named);
-
-  // then get the list of missing names
-  size_t i = 0;
-  std::string missing_fields_str;
-  for (auto it = missing_names.begin (); it != missing_names.end (); it++)
+  else
+   {
+ switch (struct_pattern_elems.get_struct_pattern_fields ()
+   .at (0)
+   ->get_item_type ())
+   {
+   case HIR::StructPatternField::ItemType::IDENT:
+   case HIR::StructPatternField::ItemType::IDENT_PAT:
+ break;
+ default: {
+   auto first_elem
+ = struct_pattern_elems.get_struct_pattern_fields ()
+ .at (0)
+ ->as_string ();
+   rust_error_at (pattern.get_locus (),
+  "%qs cannot be used in union patterns",
+  first_elem.c_str ());
+ }
+   }
+   }
+}
+  else
+{
+  // Expects enum struct or struct struct.
+  // error[E0027]: pattern does not mention fields `x`, `y`
+  // error[E0026]: variant `Foo::D` does not have a field named `b`
+  if (named_fields.size () != variant->num_fields ())
{
- bool has_next = (i + 1) < missing_names.size ();
- missing_fields_str += it->first + (has_next ? ", " : "");
- i++;
+ std::map missing_names;
+
+ // populate with all fields
+ for (auto &field : variant->get_fields ())
+   missing_names[field->get_name ()] = true;
+
+ // then eliminate with named_fields
+ for (auto &named : named_fields)
+   missing_names.erase (named);
+
+ // then get the list of missing names
+ size_t i = 0;
+ std::string missing_fields_str;
+ for (auto it = missing_names.begin (); it != missing_names.end ();
+  it++)
+   {
+ bool has_next = (i + 1) < missing_names.size ();
+ missing_fields_str += it->first + (has_next ? ", " : "");
+ i++;
+   }
+
+ rust_error_at (pattern.get_locus (), ErrorCode::E0027,
+"pattern does not mention fields %s",
+missing_fields_str.c_str ());
}
-
-  rust_error_at (pattern.get_locus (), ErrorCode::E0027,
-"pattern does not mention fields %s",
-missing_fields_str.c_str ());
 }
 }
 
diff --git a/gcc/testsuite/rust/compile/match8.rs 
b/gcc/testsuite/rust/compile/match8.rs
new file mode 100644
index ..336b313cde3e
--- /dev/null
+++ b/gcc/testsuite/rust/compile/match8.rs
@@ -0,0 +1,19 @@
+union MyUnion {
+f1: u32,
+f2: f32,
+}
+
+fn f(u: MyUnion) -> i32 {
+unsafe {
+match u {
+MyUnion { f1: 10 } => 0,
+MyUnion { f2 } 

[gcc r15-8335] gccrs: Fix the parser's operand and flags storage

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:9996b8ef849cb5626e14d0747dd45f10541807d0

commit r15-8335-g9996b8ef849cb5626e14d0747dd45f10541807d0
Author: badumbatish 
Date:   Tue Jul 23 22:17:12 2024 -0700

gccrs: Fix the parser's operand and flags storage

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-asm.cc (parse_reg_operand):
Fix parsing logic & reassignment logic
(parse_reg_operand_in): Fix parsing
(parse_reg_operand_out): Fix parsing
(parse_reg_operand_inout): Fix parsing
(parse_reg_operand_unexpected): Remove rust_unreachable()
(parse_asm_arg): Fix parsing logic

Diff:
---
 gcc/rust/expand/rust-macro-builtins-asm.cc | 21 +++--
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index 7f0498fdef4b..492bcfe31727 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -226,10 +226,12 @@ parse_reg_operand (InlineAsmContext inline_asm_ctx)
   // Loop over and execute the parsing functions, if the parser successfullly
   // parses or if the parser fails to parse while it has committed to a token,
   // we propogate the result.
+  int count = 0;
   tl::expected parsing_operand (
 inline_asm_ctx);
   for (auto &parse_func : parse_funcs)
 {
+  count++;
   auto result = parsing_operand.and_then (parse_func);
 
   // Per rust's asm.rs's structure
@@ -238,8 +240,7 @@ parse_reg_operand (InlineAsmContext inline_asm_ctx)
 
   if (result.has_value ())
{
- //
- inline_asm_ctx = *result;
+ inline_asm_ctx = result.value ();
  break;
}
   else if (result.error () == COMMITTED)
@@ -687,7 +688,9 @@ parse_asm_arg (InlineAsmContext inline_asm_ctx)
{
  auto expected = parse_clobber_abi (inline_asm_ctx);
  if (expected.has_value ())
-   continue;
+   {
+ continue;
+   }
  else if (expected.error () == COMMITTED)
return expected;
 
@@ -699,7 +702,9 @@ parse_asm_arg (InlineAsmContext inline_asm_ctx)
{
  auto expected = parse_options (inline_asm_ctx);
  if (expected.has_value ())
-   continue;
+   {
+ continue;
+   }
  else if (expected.error () == COMMITTED)
return expected;
 
@@ -712,9 +717,13 @@ parse_asm_arg (InlineAsmContext inline_asm_ctx)
 
   auto expected = parse_reg_operand (inline_asm_ctx);
   if (expected.has_value ())
-   continue;
+   {
+ continue;
+   }
   else if (expected.error () == COMMITTED)
-   return expected;
+   {
+ return expected;
+   }
 
   // Since parse_reg_operand is the last thing we've considered,
   // The non-committed parse error type means that we have exhausted our


[gcc r15-8361] gccrs: Strong type FreeRegion

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:f5e05755e91e7b32c79dc8c371557cf0049b4277

commit r15-8361-gf5e05755e91e7b32c79dc8c371557cf0049b4277
Author: Kushal Pal 
Date:   Wed Aug 7 05:19:28 2024 +

gccrs: Strong type FreeRegion

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder-internal.h: Use
STATIC_FREE_REGION, use value of FreeRegion for origin.
* checks/errors/borrowck/rust-bir-builder.h: Use free region
value.
* checks/errors/borrowck/rust-bir-dump.cc (Dump::visit_scope):
Likewise.
* checks/errors/borrowck/rust-bir-fact-collector.h (points):
Likewise.
* checks/errors/borrowck/rust-bir-free-region.h (struct FreeRegion):
Make FreeRegion a struct.
* checks/errors/borrowck/rust-bir-place.h: Use FreeRegion
instead of Origin in PlaceDB.
* typecheck/rust-tyty-variance-analysis.cc 
(FieldVisitorCtx::add_constraints_from_region):
Use value of FreeRegion for origin.
(FieldVisitorCtx::add_constrints_from_param): Likewise.
(Term::make_transform): Likewise.

Signed-off-by: Kushal Pal 

Diff:
---
 .../errors/borrowck/rust-bir-builder-internal.h| 11 ---
 gcc/rust/checks/errors/borrowck/rust-bir-builder.h |  6 ++--
 gcc/rust/checks/errors/borrowck/rust-bir-dump.cc   |  2 +-
 .../errors/borrowck/rust-bir-fact-collector.h  | 36 --
 .../checks/errors/borrowck/rust-bir-free-region.h  | 30 +++---
 gcc/rust/checks/errors/borrowck/rust-bir-place.h   | 14 ++---
 gcc/rust/typecheck/rust-tyty-variance-analysis.cc  |  6 ++--
 7 files changed, 68 insertions(+), 37 deletions(-)

diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h 
b/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h
index 74be02b90f68..afaeb12d458a 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h
@@ -215,7 +215,7 @@ protected:
  }
else if (region.is_static ())
  {
-   free_regions.push_back (0);
+   free_regions.push_back (STATIC_FREE_REGION);
  }
else if (region.is_anonymous ())
  {
@@ -314,9 +314,10 @@ protected: // Helpers to add BIR statements
   {
 auto mutability = ty->as ()->mutability ();
 auto loan = ctx.place_db.add_loan ({mutability, place_id, location});
-push_tmp_assignment (new BorrowExpr (place_id, loan,
-ctx.place_db.get_next_free_region ()),
-ty, location);
+push_tmp_assignment (
+  new BorrowExpr (place_id, loan,
+ ctx.place_db.get_next_free_region ().value),
+  ty, location);
 return translated;
   }
 
@@ -609,7 +610,7 @@ protected:
   {ty->as ()->mutability (), place_id,
location});
 return_expr (new BorrowExpr (place_id, loan,
-ctx.place_db.get_next_free_region ()),
+ctx.place_db.get_next_free_region ().value),
 ty, location);
 return translated;
   }
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder.h 
b/gcc/rust/checks/errors/borrowck/rust-bir-builder.h
index e3d61b5b36e8..4e48ced32993 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-builder.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder.h
@@ -94,8 +94,8 @@ private:
  ctx.fn_free_regions[bound.second.get_index ()]);
 
auto last_bound = universal_region_bounds.back ();
-   rust_debug ("\t\t %lu: %lu", (unsigned long) last_bound.first,
-   (unsigned long) last_bound.second);
+   rust_debug ("\t\t %lu: %lu", (unsigned long) last_bound.first.value,
+   (unsigned long) last_bound.second.value);
   }
 
 // TODO: handle type_region constraints
@@ -178,7 +178,7 @@ private:
if (generic_param->get_kind ()
== HIR::GenericParam::GenericKind::LIFETIME)
  {
-   result[regions[region_index++]]
+   result[regions[region_index++].value]
  = static_cast (generic_param.get ());
  }
   }
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc 
b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
index 924c7d9a6e8a..e69c0002b3c2 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
@@ -380,7 +380,7 @@ Dump::visit_scope (ScopeId id, size_t depth)
   print_comma_separated (stream,
 func.place_db[local].regions.get_regions (),
 [this] (FreeRegion region_id) {
-  stream << "'?" << region_id;
+  stream << "'?" << region_id.value;
 });
   stream << "]\n";
 }
diff --git a/gcc/rust/checks/errors/borrowck/

[gcc r15-8337] gccrs: Make sure CompileExpr::visit is reached

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:86c8894ab896ffc29bbed5fc7faeff022e86ad22

commit r15-8337-g86c8894ab896ffc29bbed5fc7faeff022e86ad22
Author: jjasmine 
Date:   Sat Jun 22 14:33:47 2024 -0700

gccrs: Make sure CompileExpr::visit is reached

gcc/rust/ChangeLog:

* hir/tree/rust-hir.cc (InlineAsm::accept_vis):
Make sure CompileExpr::visit is reached
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
Likewise
gcc/testsuite/ChangeLog:

* rust/compile/inline_asm_compile_nop.rs: New test.

Diff:
---
 gcc/rust/hir/tree/rust-hir.cc|  4 +++-
 gcc/rust/typecheck/rust-hir-type-check-expr.cc   |  4 +---
 gcc/testsuite/rust/compile/inline_asm_compile_nop.rs | 12 
 3 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/hir/tree/rust-hir.cc b/gcc/rust/hir/tree/rust-hir.cc
index 8e0d444ce152..f05e5065e625 100644
--- a/gcc/rust/hir/tree/rust-hir.cc
+++ b/gcc/rust/hir/tree/rust-hir.cc
@@ -3833,7 +3833,9 @@ BorrowExpr::accept_vis (HIRFullVisitor &vis)
 
 void
 InlineAsm::accept_vis (HIRExpressionVisitor &vis)
-{}
+{
+  vis.visit (*this);
+}
 
 void
 InlineAsm::accept_vis (HIRFullVisitor &vis)
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc 
b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index 6635f13ea040..1197916d1f5d 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -777,9 +777,7 @@ TypeCheckExpr::visit (HIR::RangeToExpr &expr)
 
 void
 TypeCheckExpr::visit (HIR::InlineAsm &expr)
-{
-  return;
-}
+{}
 
 void
 TypeCheckExpr::visit (HIR::RangeFullExpr &expr)
diff --git a/gcc/testsuite/rust/compile/inline_asm_compile_nop.rs 
b/gcc/testsuite/rust/compile/inline_asm_compile_nop.rs
new file mode 100644
index ..c49667c879de
--- /dev/null
+++ b/gcc/testsuite/rust/compile/inline_asm_compile_nop.rs
@@ -0,0 +1,12 @@
+#![feature(rustc_attrs)]
+
+#[rustc_builtin_macro]
+macro_rules! asm {
+() => {}
+}
+
+fn main() {
+unsafe {
+asm!("nop");
+}
+}
\ No newline at end of file


[gcc r15-8341] gccrs: Scaffolding code

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:c4e0e96cdc5e7c9ae32bcb55e2907ba8d0fa0407

commit r15-8341-gc4e0e96cdc5e7c9ae32bcb55e2907ba8d0fa0407
Author: badumbatish 
Date:   Fri Jul 5 10:03:56 2024 -0700

gccrs: Scaffolding code

gcc/rust/ChangeLog:

* backend/rust-compile-asm.cc (CompileAsm::add_stmt):
Scaffolding code.
(CompileAsm::asm_build_asm_stmt): Likewise.
(CompileAsm::asm_build_expr): Likewise.
(CompileAsm::asm_construct_string_tree): Likewise.
* backend/rust-compile-asm.h: Likewise.
* backend/rust-compile-expr.cc (CompileExpr::visit): Likewise.

Diff:
---
 gcc/rust/backend/rust-compile-asm.cc  | 92 ++-
 gcc/rust/backend/rust-compile-asm.h   |  5 ++
 gcc/rust/backend/rust-compile-expr.cc |  1 +
 3 files changed, 97 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/backend/rust-compile-asm.cc 
b/gcc/rust/backend/rust-compile-asm.cc
index 5bc7bce07e66..bc11696ed101 100644
--- a/gcc/rust/backend/rust-compile-asm.cc
+++ b/gcc/rust/backend/rust-compile-asm.cc
@@ -5,10 +5,60 @@
 namespace Rust {
 namespace Compile {
 
+tree
+CompileAsm::add_stmt (tree t)
+{
+  enum tree_code code = TREE_CODE (t);
+
+  if (EXPR_P (t) && code != LABEL_EXPR)
+{
+  if (!EXPR_HAS_LOCATION (t))
+   SET_EXPR_LOCATION (t, input_location);
+
+  /* When we expand a statement-tree, we must know whether or not the
+statements are full-expressions.  We record that fact here.  */
+  if (STATEMENT_CODE_P (TREE_CODE (t)))
+   STMT_IS_FULL_EXPR_P (t) = stmts_are_full_exprs_p ();
+}
+
+  if (code == LABEL_EXPR || code == CASE_LABEL_EXPR)
+STATEMENT_LIST_HAS_LABEL (cur_stmt_list) = 1;
+
+  /* Add T to the statement-tree.  Non-side-effect statements need to be
+ recorded during statement expressions.  */
+  gcc_checking_assert (!stmt_list_stack->is_empty ());
+  append_to_statement_list_force (t, &cur_stmt_list);
+
+  return t;
+}
+tree
+CompileAsm::asm_build_asm_stmt (HIR::InlineAsm &expr)
+{
+  // From the implementation of c-typeck.cc
+  // tree
+  // build_asm_stmt (bool is_volatile, tree args)
+  //{
+  //   if (is_volatile)
+  // ASM_VOLATILE_P (args) = 1;
+  //   return add_stmt (args);
+  // }
+  //
+  return add_stmt (asm_build_expr (expr));
+}
 tree
 CompileAsm::asm_build_expr (HIR::InlineAsm &expr)
 {
-  return NULL_TREE;
+  auto asm_expr = asm_build_stmt (asm_get_locus (expr), ASM_EXPR,
+ {asm_construct_string_tree (expr),
+  asm_construct_outputs (expr),
+  asm_construct_inputs (expr),
+  asm_construct_clobber_tree (expr),
+  asm_construct_label_tree (expr)});
+
+  ASM_BASIC_P (asm_expr) = CompileAsm::asm_is_simple (expr);
+  ASM_VOLATILE_P (asm_expr) = (false);
+  ASM_INLINE_P (asm_expr) = CompileAsm::asm_is_inline (expr);
+  return asm_expr;
   // return build_asm_expr (CompileAsm::asm_get_locus (expr),
   //CompileAsm::asm_construct_string_tree (expr),
   //CompileAsm::asm_construct_outputs (expr),
@@ -19,6 +69,43 @@ CompileAsm::asm_build_expr (HIR::InlineAsm &expr)
   //CompileAsm::asm_is_inline (expr));
 }
 
+tree
+CompileAsm::asm_build_stmt (
+  location_t loc, enum tree_code code,
+  const std::array &trees)
+{
+  tree ret;
+  //  va_list p;
+  bool side_effects;
+
+  /* This function cannot be used to construct variably-sized nodes.  */
+  gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
+
+  // va_start (p, code);
+
+  ret = make_node (code);
+  TREE_TYPE (ret) = void_type_node;
+  SET_EXPR_LOCATION (ret, loc);
+
+  /* TREE_SIDE_EFFECTS will already be set for statements with
+ implicit side effects.  Here we make sure it is set for other
+ expressions by checking whether the parameters have side
+ effects.  */
+
+  side_effects = false;
+  for (size_t i = 0; i < trees.size (); i++)
+{
+  tree t = trees[i];
+  if (t && !TYPE_P (t))
+   side_effects |= TREE_SIDE_EFFECTS (t);
+  TREE_OPERAND (ret, i) = t;
+}
+
+  TREE_SIDE_EFFECTS (ret) |= side_effects;
+
+  // va_end (p);
+  return ret;
+}
 location_t
 CompileAsm::asm_get_locus (HIR::InlineAsm &expr)
 {
@@ -40,6 +127,9 @@ CompileAsm::asm_construct_string_tree (HIR::InlineAsm &expr)
   string_chain = tree_cons (NULL_TREE, string_tree, string_chain);
 }
   // Reverse the chain before returning
+
+  string_chain = nreverse (string_chain);
+
   return nreverse (string_chain);
 }
 tree
diff --git a/gcc/rust/backend/rust-compile-asm.h 
b/gcc/rust/backend/rust-compile-asm.h
index 58f0f51e9cf4..fd25090cf982 100644
--- a/gcc/rust/backend/rust-compile-asm.h
+++ b/gcc/rust/backend/rust-compile-asm.h
@@ -29,7 +29,12 @@ namespace Compile {
 class CompileAsm
 {
 public:
+  static const int ASM_TREE_ARRAY_LENGTH = 5;
+  static tree add_stmt (tree);
+  static tree asm

[gcc r15-8332] gccrs: emit error code for E0758

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:bb0abd09cf8038bb8c1c0184f2d7ae83b6527540

commit r15-8332-gbb0abd09cf8038bb8c1c0184f2d7ae83b6527540
Author: Raiki Tamura 
Date:   Thu Aug 29 02:48:29 2024 +0900

gccrs: emit error code for E0758

gcc/rust/ChangeLog:

* lex/rust-lex.cc (Lexer::build_token): Emit error code.
* lex/rust-lex.h: Fix comment.

Signed-off-by: Raiki Tamura 

Diff:
---
 gcc/rust/lex/rust-lex.cc | 9 ++---
 gcc/rust/lex/rust-lex.h  | 9 +
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc
index f4b8861adcc6..849063824dcf 100644
--- a/gcc/rust/lex/rust-lex.cc
+++ b/gcc/rust/lex/rust-lex.cc
@@ -589,7 +589,8 @@ Lexer::build_token ()
  if (current_char.is_eof ())
{
  rust_error_at (
-   loc, "unexpected EOF while looking for end of comment");
+   loc, ErrorCode::E0758,
+   "unexpected EOF while looking for end of comment");
  break;
}
  str += current_char;
@@ -644,7 +645,8 @@ Lexer::build_token ()
  if (current_char.is_eof ())
{
  rust_error_at (
-   loc, "unexpected EOF while looking for end of comment");
+   loc, ErrorCode::E0758,
+   "unexpected EOF while looking for end of comment");
  break;
}
 
@@ -708,7 +710,8 @@ Lexer::build_token ()
  if (current_char.is_eof ())
{
  rust_error_at (
-   loc, "unexpected EOF while looking for end of comment");
+   loc, ErrorCode::E0758,
+   "unexpected EOF while looking for end of comment");
  break;
}
 
diff --git a/gcc/rust/lex/rust-lex.h b/gcc/rust/lex/rust-lex.h
index 8265ca8239f8..10293e0a8122 100644
--- a/gcc/rust/lex/rust-lex.h
+++ b/gcc/rust/lex/rust-lex.h
@@ -115,14 +115,15 @@ private:
   // Request new Location for current column in line_table
   location_t get_current_location ();
 
-  // Skips the current input char.
+  // Skips the current input character.
   void skip_input ();
-  // Advances current input char to n + 1 chars ahead of current position.
+  // Advances current input character to n + 1 characters ahead of current
+  // position.
   void skip_input (int n);
 
-  // Peeks the current char.
+  // Peeks the current character.
   Codepoint peek_input ();
-  // Returns char n bytes ahead of current position.
+  // Returns character n characters ahead of current position.
   Codepoint peek_input (int n);
 
   // Classifies keyword (i.e. gets id for keyword).


[gcc r15-8333] gccrs: Fix warnings from const auto& to const auto

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:e2126a193567e97e57c854ef59952c6df3063bbf

commit r15-8333-ge2126a193567e97e57c854ef59952c6df3063bbf
Author: badumbatish 
Date:   Sun Aug 4 12:43:09 2024 -0700

gccrs: Fix warnings from const auto& to const auto

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve.cc (NameResolution::go):
Fix warnings from const auto& to const auto

Diff:
---
 gcc/rust/resolve/rust-ast-resolve.cc | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/resolve/rust-ast-resolve.cc 
b/gcc/rust/resolve/rust-ast-resolve.cc
index a467d1e38b4c..a093ef7f444d 100644
--- a/gcc/rust/resolve/rust-ast-resolve.cc
+++ b/gcc/rust/resolve/rust-ast-resolve.cc
@@ -63,7 +63,10 @@ NameResolution::go (AST::Crate &crate)
 {
   // lookup current crate name
   CrateNum cnum = mappings.get_current_crate ();
-  const auto &crate_name = mappings.get_crate_name (cnum).value ();
+
+  // Clones the crate name instead of references due to gcc's possibly
+  // dangling references warnings
+  const auto crate_name = mappings.get_crate_name (cnum).value ();
 
   // setup the ribs
   NodeId scope_node_id = crate.get_node_id ();


[gcc r15-8347] gccrs: Start work on expand inline asm

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:1398473b12863138325f2884fa13d77c311fb1db

commit r15-8347-g1398473b12863138325f2884fa13d77c311fb1db
Author: badumbatish 
Date:   Thu Jul 25 23:07:00 2024 -0700

gccrs: Start work on expand inline asm

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-asm.cc (parse_reg_operand):
Remove warnings
(parse_reg_operand_out): Remove warnings
(expand_inline_asm): New function for eventual expansion
(parse_asm): Use expand_inline_asm

gcc/testsuite/ChangeLog:

* rust/execute/torture/inline_asm_mov_x_5.rs: New test.

Diff:
---
 gcc/rust/expand/rust-macro-builtins-asm.cc | 33 --
 .../rust/execute/torture/inline_asm_mov_x_5.rs | 19 +
 2 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index 492bcfe31727..bbb8fff180ff 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -21,6 +21,7 @@
 #include "rust-macro-builtins-asm.h"
 #include "rust-ast-fragment.h"
 #include "rust-ast.h"
+#include "rust-fmt.h"
 #include "rust-stmt.h"
 
 namespace Rust {
@@ -240,7 +241,7 @@ parse_reg_operand (InlineAsmContext inline_asm_ctx)
 
   if (result.has_value ())
{
- inline_asm_ctx = result.value ();
+ inline_asm_ctx = *result;
  break;
}
   else if (result.error () == COMMITTED)
@@ -741,6 +742,31 @@ parse_asm_arg (InlineAsmContext inline_asm_ctx)
   return tl::expected (inline_asm_ctx);
 }
 
+tl::expected
+expand_inline_asm (InlineAsmContext &inline_asm_ctx)
+{
+  auto &inline_asm = inline_asm_ctx.inline_asm;
+
+  auto str_vec = inline_asm.get_template_strs ();
+  for (auto &template_str : str_vec)
+{
+  std::cout << template_str.symbol << std::endl;
+
+  auto pieces = Fmt::Pieces::collect (template_str.symbol, false,
+ Fmt::ffi::ParseMode::Format)
+ .get_pieces ();
+
+  for (size_t i = 0; i < pieces.size (); i++)
+   {
+ auto piece = pieces[i];
+ if (piece.tag == Fmt::ffi::Piece::Tag::String)
+   std::cout << "   " << i << ": " << piece.string._0.to_string ()
+ << std::endl;
+   }
+}
+
+  return inline_asm_ctx;
+}
 tl::optional
 parse_asm (location_t invoc_locus, AST::MacroInvocData &invoc,
   AST::InvocKind semicolon, AST::AsmKind is_global_asm)
@@ -770,7 +796,10 @@ parse_asm (location_t invoc_locus, AST::MacroInvocData 
&invoc,
   // here Per Arthur's advice we would actually do the validation in a 
different
   // stage. and visit on the InlineAsm AST instead of it's context.
   auto is_valid = (bool) resulting_context;
-
+  if (is_valid)
+{
+  expand_inline_asm (resulting_context.value ());
+}
   if (is_valid)
 {
   auto node = inline_asm_ctx.inline_asm.clone_expr_without_block ();
diff --git a/gcc/testsuite/rust/execute/torture/inline_asm_mov_x_5.rs 
b/gcc/testsuite/rust/execute/torture/inline_asm_mov_x_5.rs
new file mode 100644
index ..18bc87ab554c
--- /dev/null
+++ b/gcc/testsuite/rust/execute/torture/inline_asm_mov_x_5.rs
@@ -0,0 +1,19 @@
+#![feature(rustc_attrs)]
+
+#[rustc_builtin_macro]
+macro_rules! asm {
+() => {};
+}
+extern "C" {
+fn printf(s: *const i8, ...);
+}
+
+fn main() {
+let mut _x: i32 = 0;
+unsafe {
+asm!(
+"mov {}, 5",
+out(reg) _x
+);
+}
+}


[gcc r15-8345] gccrs: Added new test for prep of output {}

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:8a56194dd27fda4c3b87f025f386a82780392692

commit r15-8345-g8a56194dd27fda4c3b87f025f386a82780392692
Author: badumbatish 
Date:   Sun Jul 21 15:13:25 2024 -0700

gccrs: Added new test for prep of output {}

gcc/testsuite/ChangeLog:

* rust/compile/inline_asm_parse_output_operand.rs: New test.

Diff:
---
 .../rust/compile/inline_asm_parse_output_operand.rs| 18 ++
 1 file changed, 18 insertions(+)

diff --git a/gcc/testsuite/rust/compile/inline_asm_parse_output_operand.rs 
b/gcc/testsuite/rust/compile/inline_asm_parse_output_operand.rs
new file mode 100644
index ..3134c73b3c29
--- /dev/null
+++ b/gcc/testsuite/rust/compile/inline_asm_parse_output_operand.rs
@@ -0,0 +1,18 @@
+#![feature(rustc_attrs)]
+
+#[rustc_builtin_macro]
+macro_rules! asm {
+() => {};
+}
+
+fn main() {
+let mut _num1: i32 = 10;
+let mut _num2: i32 = 10;
+unsafe {
+asm!(
+"mov {0}, 4",
+out(reg) _num1,
+out(reg) _num2,
+);
+}
+}


[gcc r15-8375] gccrs: Emit error on auto-traits

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:5aedc53315387276070e36a5dac4e768f7540cf2

commit r15-8375-g5aedc53315387276070e36a5dac4e768f7540cf2
Author: benjamin.thos 
Date:   Wed Sep 11 14:31:20 2024 +

gccrs: Emit error on auto-traits

Throw an error when auto-traits used without feature attribute.

gcc/rust/ChangeLog:

* checks/errors/rust-feature-gate.cc (FeatureGate::visit): Emit 
error
on trait when auto field member true.
* checks/errors/rust-feature-gate.h: add prototype of trait visitor.
* checks/errors/rust-feature.cc (Feature::create): add
optin_builtin_traits in match of feature.

gcc/testsuite/ChangeLog:

* rust/compile/auto_trait_super_trait.rs: Add feature attribute.
* rust/compile/generic_auto_trait.rs: likewise.
* rust/compile/auto_trait.rs: add test for error without
feature attribute

Signed-off-by: benjamin.thos 

Diff:
---
 gcc/rust/checks/errors/rust-feature-gate.cc  | 9 +
 gcc/rust/checks/errors/rust-feature-gate.h   | 1 +
 gcc/rust/checks/errors/rust-feature.cc   | 3 +++
 gcc/testsuite/rust/compile/auto_trait.rs | 1 +
 gcc/testsuite/rust/compile/auto_trait_super_trait.rs | 1 +
 gcc/testsuite/rust/compile/generic_auto_trait.rs | 1 +
 6 files changed, 16 insertions(+)

diff --git a/gcc/rust/checks/errors/rust-feature-gate.cc 
b/gcc/rust/checks/errors/rust-feature-gate.cc
index 4ab614e88537..f3daa61f170b 100644
--- a/gcc/rust/checks/errors/rust-feature-gate.cc
+++ b/gcc/rust/checks/errors/rust-feature-gate.cc
@@ -173,6 +173,15 @@ FeatureGate::visit (AST::TraitImpl &impl)
   AST::DefaultASTVisitor::visit (impl);
 }
 
+void
+FeatureGate::visit (AST::Trait &trait)
+{
+  if (trait.is_auto ())
+gate (Feature::Name::AUTO_TRAITS, trait.get_locus (),
+ "auto traits are experimental and possibly buggy");
+  AST::DefaultASTVisitor::visit (trait);
+}
+
 void
 FeatureGate::visit (AST::BoxExpr &expr)
 {
diff --git a/gcc/rust/checks/errors/rust-feature-gate.h 
b/gcc/rust/checks/errors/rust-feature-gate.h
index 7ffb6ef9d667..f1011e532245 100644
--- a/gcc/rust/checks/errors/rust-feature-gate.h
+++ b/gcc/rust/checks/errors/rust-feature-gate.h
@@ -42,6 +42,7 @@ public:
   void visit (AST::UseTreeGlob &use_tree) override;
   void visit (AST::Function &function) override;
   void visit (AST::TraitImpl &impl) override;
+  void visit (AST::Trait &trait) override;
   void visit (AST::ExternalTypeItem &item) override;
   void visit (AST::ExternBlock &block) override;
   void visit (AST::MacroRulesDefinition &rules_def) override;
diff --git a/gcc/rust/checks/errors/rust-feature.cc 
b/gcc/rust/checks/errors/rust-feature.cc
index 6900bb834dbe..25af46cbed81 100644
--- a/gcc/rust/checks/errors/rust-feature.cc
+++ b/gcc/rust/checks/errors/rust-feature.cc
@@ -55,6 +55,9 @@ Feature::create (Feature::Name f)
  "1.11.0", 37854);
 case Feature::Name::PRELUDE_IMPORT:
   return Feature (f, Feature::State::ACTIVE, "prelude_import", "1.0.0");
+case Feature::Name::AUTO_TRAITS:
+  return Feature (f, Feature::State::ACTIVE, "optin_builtin_traits",
+ "1.0.0", 13231);
 default:
   rust_unreachable ();
 }
diff --git a/gcc/testsuite/rust/compile/auto_trait.rs 
b/gcc/testsuite/rust/compile/auto_trait.rs
new file mode 100644
index ..47bd119ba36b
--- /dev/null
+++ b/gcc/testsuite/rust/compile/auto_trait.rs
@@ -0,0 +1 @@
+auto trait Valid {} // { dg-error "auto traits are experimental and possibly 
buggy" }
diff --git a/gcc/testsuite/rust/compile/auto_trait_super_trait.rs 
b/gcc/testsuite/rust/compile/auto_trait_super_trait.rs
index 1080afb5124d..06746e914979 100644
--- a/gcc/testsuite/rust/compile/auto_trait_super_trait.rs
+++ b/gcc/testsuite/rust/compile/auto_trait_super_trait.rs
@@ -1,3 +1,4 @@
+#![feature(optin_builtin_traits)]
 trait Cold {}
 
 auto trait IsCool: Cold {}
diff --git a/gcc/testsuite/rust/compile/generic_auto_trait.rs 
b/gcc/testsuite/rust/compile/generic_auto_trait.rs
index ae6a51d0244c..a0a414cdbbd4 100644
--- a/gcc/testsuite/rust/compile/generic_auto_trait.rs
+++ b/gcc/testsuite/rust/compile/generic_auto_trait.rs
@@ -1,2 +1,3 @@
+#![feature(optin_builtin_traits)]
 auto trait IsCooler {}
 // { dg-error "auto traits cannot have generic parameters .E0567." "" { target 
*-*-* } .-1 }


[gcc r15-8380] gccrs: Check if the type has been correctly resolved

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:a8bebc3bdd41fb86a3b4fa534820456719eaa79f

commit r15-8380-ga8bebc3bdd41fb86a3b4fa534820456719eaa79f
Author: Pierre-Emmanuel Patry 
Date:   Thu Sep 19 14:38:48 2024 +0200

gccrs: Check if the type has been correctly resolved

We did not check the optional was valid, this lead to rogue dereference
and undefined behaviors.

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add optional
check.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/resolve/rust-late-name-resolver-2.0.cc | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
index 9ac09456fbd0..068d231c6fb3 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -23,6 +23,7 @@
 #include "rust-default-resolver.h"
 #include "rust-name-resolution-context.h"
 #include "rust-path.h"
+#include "rust-system.h"
 #include "rust-tyty.h"
 #include "rust-hir-type-check.h"
 
@@ -223,9 +224,11 @@ Late::visit (AST::TypePath &type)
   // typepath-like path resolution? that sounds good
 
   auto resolved = ctx.types.get (type.get_segments ().back ()->as_string ());
-
-  ctx.map_usage (Usage (type.get_node_id ()),
-Definition (resolved->get_node_id ()));
+  if (resolved)
+ctx.map_usage (Usage (type.get_node_id ()),
+  Definition (resolved->get_node_id ()));
+  else
+rust_unreachable ();
 }
 
 void


[gcc r15-8385] gccrs: Remove some overloaded methods from DefaultResolver.

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:88524c5314967f013f1596cdd935da4d9dc27500

commit r15-8385-g88524c5314967f013f1596cdd935da4d9dc27500
Author: Owen Avery 
Date:   Mon Sep 23 17:44:19 2024 -0400

gccrs: Remove some overloaded methods from DefaultResolver.

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc
(DefaultResolver::visit): Remove some empty overloads which
DefaultASTVisitor::visit should be able to handle.
* resolve/rust-default-resolver.h
(DefaultResolver::visit): Likewise.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/resolve/rust-default-resolver.cc | 84 ---
 gcc/rust/resolve/rust-default-resolver.h  | 21 
 gcc/testsuite/rust/compile/nr2/exclude| 16 --
 3 files changed, 121 deletions(-)

diff --git a/gcc/rust/resolve/rust-default-resolver.cc 
b/gcc/rust/resolve/rust-default-resolver.cc
index 6de694f48f48..89e7e39f5bb8 100644
--- a/gcc/rust/resolve/rust-default-resolver.cc
+++ b/gcc/rust/resolve/rust-default-resolver.cc
@@ -548,70 +548,6 @@ void
 DefaultResolver::visit (AST::MetaListNameValueStr &)
 {}
 
-void
-DefaultResolver::visit (AST::RangePatternBoundPath &)
-{}
-
-void
-DefaultResolver::visit (AST::RangePatternBoundQualPath &)
-{}
-
-void
-DefaultResolver::visit (AST::RangePattern &)
-{}
-
-void
-DefaultResolver::visit (AST::ReferencePattern &)
-{}
-
-void
-DefaultResolver::visit (AST::StructPatternFieldTuplePat &)
-{}
-
-void
-DefaultResolver::visit (AST::StructPatternFieldIdentPat &)
-{}
-
-void
-DefaultResolver::visit (AST::StructPatternFieldIdent &)
-{}
-
-void
-DefaultResolver::visit (AST::StructPattern &)
-{}
-
-void
-DefaultResolver::visit (AST::TupleStructItemsNoRange &)
-{}
-
-void
-DefaultResolver::visit (AST::TupleStructItemsRange &)
-{}
-
-void
-DefaultResolver::visit (AST::TupleStructPattern &)
-{}
-
-void
-DefaultResolver::visit (AST::TuplePatternItemsMultiple &)
-{}
-
-void
-DefaultResolver::visit (AST::TuplePatternItemsRanged &)
-{}
-
-void
-DefaultResolver::visit (AST::TuplePattern &)
-{}
-
-void
-DefaultResolver::visit (AST::GroupedPattern &)
-{}
-
-void
-DefaultResolver::visit (AST::SlicePattern &)
-{}
-
 void
 DefaultResolver::visit (AST::AltPattern &)
 {}
@@ -632,10 +568,6 @@ void
 DefaultResolver::visit (AST::TraitObjectType &)
 {}
 
-void
-DefaultResolver::visit (AST::ParenthesisedType &)
-{}
-
 void
 DefaultResolver::visit (AST::ImplTraitTypeOneBound &)
 {}
@@ -644,22 +576,6 @@ void
 DefaultResolver::visit (AST::TraitObjectTypeOneBound &)
 {}
 
-void
-DefaultResolver::visit (AST::TupleType &)
-{}
-
-void
-DefaultResolver::visit (AST::ReferenceType &)
-{}
-
-void
-DefaultResolver::visit (AST::ArrayType &)
-{}
-
-void
-DefaultResolver::visit (AST::SliceType &)
-{}
-
 void
 DefaultResolver::visit (AST::BareFunctionType &)
 {}
diff --git a/gcc/rust/resolve/rust-default-resolver.h 
b/gcc/rust/resolve/rust-default-resolver.h
index 6bca8b7b6a1f..3774603daaa5 100644
--- a/gcc/rust/resolve/rust-default-resolver.h
+++ b/gcc/rust/resolve/rust-default-resolver.h
@@ -126,34 +126,13 @@ public:
   void visit (AST::MetaItemSeq &);
   void visit (AST::MetaListPaths &);
   void visit (AST::MetaListNameValueStr &);
-  void visit (AST::RangePatternBoundPath &);
-  void visit (AST::RangePatternBoundQualPath &);
-  void visit (AST::RangePattern &);
-  void visit (AST::ReferencePattern &);
-  void visit (AST::StructPatternFieldTuplePat &);
-  void visit (AST::StructPatternFieldIdentPat &);
-  void visit (AST::StructPatternFieldIdent &);
-  void visit (AST::StructPattern &);
-  void visit (AST::TupleStructItemsNoRange &);
-  void visit (AST::TupleStructItemsRange &);
-  void visit (AST::TupleStructPattern &);
-  void visit (AST::TuplePatternItemsMultiple &);
-  void visit (AST::TuplePatternItemsRanged &);
-  void visit (AST::TuplePattern &);
-  void visit (AST::GroupedPattern &);
-  void visit (AST::SlicePattern &);
   void visit (AST::AltPattern &);
   void visit (AST::EmptyStmt &);
   void visit (AST::TraitBound &);
   void visit (AST::ImplTraitType &);
   void visit (AST::TraitObjectType &);
-  void visit (AST::ParenthesisedType &);
   void visit (AST::ImplTraitTypeOneBound &);
   void visit (AST::TraitObjectTypeOneBound &);
-  void visit (AST::TupleType &);
-  void visit (AST::ReferenceType &);
-  void visit (AST::ArrayType &);
-  void visit (AST::SliceType &);
   void visit (AST::BareFunctionType &);
   void visit (AST::FunctionParam &);
   void visit (AST::VariadicParam &);
diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index 3251921acd45..8993c6d57500 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -4,9 +4,6 @@ debug-diagnostics-on.rs
 
 # main list
 all-cast.rs
-array3.rs
-arrays1.rs
-arrays2.rs
 attr-mismatch-crate-name.rs
 attr_deprecated.rs
 attr_deprecated_2.rs
@@ -3

[gcc r15-8391] gccrs: early: Resolve imports and create import mappings

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:2f743673232dc87b85e802ea5256a36bb1988172

commit r15-8391-g2f743673232dc87b85e802ea5256a36bb1988172
Author: Arthur Cohen 
Date:   Thu Apr 4 16:25:30 2024 +0200

gccrs: early: Resolve imports and create import mappings

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc 
(Early::resolve_glob_import): New function.
(Early::resolve_simple_import): Likewise.
(Early::resolve_rebind_import): Likewise.
(Early::build_import_mapping): Likewise.
* resolve/rust-early-name-resolver-2.0.h: Add declarations and list 
of imports to
resolve.
* resolve/rust-toplevel-name-resolver-2.0.cc 
(TopLevel::handle_use_glob): Remove function,
which is now being handled by the Early name resolver.
(TopLevel::handle_use_dec): Likewise.
(TopLevel::handle_rebind): Likewise.
* resolve/rust-toplevel-name-resolver-2.0.h: Likewise, and add 
functions for creating
import list and fetching it.

Diff:
---
 gcc/rust/resolve/rust-early-name-resolver-2.0.cc   | 175 ++-
 gcc/rust/resolve/rust-early-name-resolver-2.0.h|  16 ++
 .../resolve/rust-toplevel-name-resolver-2.0.cc | 188 -
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h |  74 
 4 files changed, 229 insertions(+), 224 deletions(-)

diff --git a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
index 1b21e115aeeb..884c05a93c34 100644
--- a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
@@ -18,6 +18,7 @@
 
 #include "rust-early-name-resolver-2.0.h"
 #include "rust-ast-full.h"
+#include "rust-diagnostics.h"
 #include "rust-toplevel-name-resolver-2.0.h"
 #include "rust-attributes.h"
 
@@ -51,16 +52,182 @@ Early::go (AST::Crate &crate)
   auto toplevel = TopLevel (ctx);
   toplevel.go (crate);
 
-  textual_scope.push ();
+  // We start with resolving the list of imports that `TopLevel` has built for
+  // us
+  for (auto &&import : toplevel.get_imports_to_resolve ())
+build_import_mapping (std::move (import));
 
-  // Then we proceed to the proper "early" name resolution: Import and macro
-  // name resolution
+  // We now proceed with resolving macros, which can be nested in almost any
+  // items
+  textual_scope.push ();
   for (auto &item : crate.items)
 item->accept_vis (*this);
-
   textual_scope.pop ();
 }
 
+bool
+Early::resolve_glob_import (TopLevel::ImportKind &&glob)
+{
+  auto resolved = ctx.types.resolve_path (glob.to_resolve.get_segments ());
+  if (!resolved.has_value ())
+return false;
+
+  auto result
+= Analysis::Mappings::get ().lookup_ast_module (resolved->get_node_id ());
+  if (!result)
+return false;
+
+  // here, we insert the module's NodeId into the import_mappings and will look
+  // up the module proper in `FinalizeImports`
+  import_mappings.insert ({std::move (glob), resolved->get_node_id ()});
+
+  // FIXME: This needs to be done in `FinalizeImports`
+  // GlobbingVisitor gvisitor (ctx);
+  // gvisitor.go (result.value ());
+
+  return true;
+}
+
+bool
+Early::resolve_simple_import (TopLevel::ImportKind &&import)
+{
+  // TODO: Fix documentation - the function has changed slightly
+
+  const auto &path = import.to_resolve;
+  // auto locus = path.get_final_segment ().get_locus ();
+  // auto declared_name = path.get_final_segment ().as_string ();
+
+  // In that function, we only need to declare a new definition - the use path.
+  // the resolution needs to happpen in the EarlyNameResolver. So the
+  // definitions we'll add will be the path's NodeId - that makes sense, as we
+  // need one definition per path declared in a Use tree. so all good.
+  // alright, now in what namespace do we declare them? all of them? do we only
+  // declare them in the EarlyNameResolver? this is dodgy
+
+  // in what namespace do we perform path resolution? All of them? see which 
one
+  // matches? Error out on ambiguities?
+  // so, apparently, for each one that matches, add it to the proper namespace
+  // :(
+
+  return ctx.values.resolve_path (path.get_segments ())
+.or_else ([&] () { return ctx.types.resolve_path (path.get_segments ()); })
+.or_else ([&] () { return ctx.macros.resolve_path (path.get_segments ()); 
})
+.map ([&] (Rib::Definition def) {
+  import_mappings.insert ({std::move (import), def.get_node_id ()});
+})
+.has_value ();
+
+  //switch (ns)
+  //  {
+  //  case Namespace::Values:
+  // resolved = ctx.values.resolve_path (path.get_segments ());
+  // break;
+  //  case Namespace::Types:
+  // resolved = ctx.types.resolve_path (path.get_segments ());
+  // break;
+  //  case Namespace::Macros:
+  // resolved = ctx.macros.resolve_path (path.get_segments ());
+  // break;
+  //  case Namespace::Labels:
+  // // TODO: Is that okay?
+  // rust_unr

[gcc r15-8387] gccrs: rust fix ICE when hir lowering qualified path expressions without an as

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:0581e0d9a8b1e47d43f8a6477b0536392532b6d3

commit r15-8387-g0581e0d9a8b1e47d43f8a6477b0536392532b6d3
Author: Philip Herron 
Date:   Fri Sep 20 17:13:38 2024 +0100

gccrs: rust fix ICE when hir lowering qualified path expressions without an 
as

Qualified path expressions usually are ::... but the as is optional
this adds the extra checking in hir lowering to not hit that nullptr.

Fixes #3082

gcc/rust/ChangeLog:

* hir/rust-ast-lower-type.cc (ASTLowerQualifiedPathInType::visit):
check for valid as segment

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/issue-3082.rs: New test.

Signed-off-by: Philip Herron 

Diff:
---
 gcc/rust/hir/rust-ast-lower-type.cc  | 11 +--
 gcc/testsuite/rust/compile/issue-3082.rs |  9 +
 gcc/testsuite/rust/compile/nr2/exclude   |  1 +
 3 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/hir/rust-ast-lower-type.cc 
b/gcc/rust/hir/rust-ast-lower-type.cc
index 883af4adb47f..7d6ac5ddffa3 100644
--- a/gcc/rust/hir/rust-ast-lower-type.cc
+++ b/gcc/rust/hir/rust-ast-lower-type.cc
@@ -145,8 +145,15 @@ ASTLowerQualifiedPathInType::visit 
(AST::QualifiedPathInType &path)
 
   HIR::Type *qual_type
 = ASTLoweringType::translate (path.get_qualified_path_type ().get_type ());
-  HIR::TypePath *qual_trait = ASTLowerTypePath::translate (
-path.get_qualified_path_type ().get_as_type_path ());
+
+  HIR::TypePath *qual_trait = nullptr;
+  if (!path.get_qualified_path_type ().is_error ())
+{
+  AST::QualifiedPathType &qualifier = path.get_qualified_path_type ();
+  if (qualifier.has_as_clause ())
+   qual_trait
+ = ASTLowerTypePath::translate (qualifier.get_as_type_path ());
+}
 
   HIR::QualifiedPathType qual_path_type (
 qual_mappings, std::unique_ptr (qual_type),
diff --git a/gcc/testsuite/rust/compile/issue-3082.rs 
b/gcc/testsuite/rust/compile/issue-3082.rs
new file mode 100644
index ..4b873955dde1
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3082.rs
@@ -0,0 +1,9 @@
+#![allow(unused)]
+fn main() {
+trait Hello {
+type Who;
+
+fn hello() -> ::You;
+// { dg-error "failed to resolve return type" "" { target *-*-* } .-1 }
+}
+}
diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index 5f5863bde87a..3412617f7eb2 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -277,3 +277,4 @@ dropck_eyepatch_feature_gate.rs
 inline_asm_parse_output_operand.rs
 issue-3030.rs
 issue-3035.rs
+issue-3082.rs
\ No newline at end of file


[gcc r15-8358] gccrs: Fix v0-mangle1.rs test when run with ASAN

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:99cbcd7c45354e334f6c30a937c96cd9962b583d

commit r15-8358-g99cbcd7c45354e334f6c30a937c96cd9962b583d
Author: Owen Avery 
Date:   Tue Sep 3 22:49:15 2024 -0400

gccrs: Fix v0-mangle1.rs test when run with ASAN

gcc/rust/ChangeLog:

* util/rust-canonical-path.h
(CanonicalPath::CanonicalPath): Properly initialize crate_num
with copy constructor.

gcc/testsuite/ChangeLog:

* rust/compile/v0-mangle1.rs: Make v0-mangle test more crate_num
agnostic.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/util/rust-canonical-path.h  | 4 +++-
 gcc/testsuite/rust/compile/v0-mangle1.rs | 2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/util/rust-canonical-path.h 
b/gcc/rust/util/rust-canonical-path.h
index af151c2db697..4d8f9542c8b1 100644
--- a/gcc/rust/util/rust-canonical-path.h
+++ b/gcc/rust/util/rust-canonical-path.h
@@ -46,7 +46,9 @@ namespace Resolver {
 class CanonicalPath
 {
 public:
-  CanonicalPath (const CanonicalPath &other) : segs (other.segs) {}
+  CanonicalPath (const CanonicalPath &other)
+: segs (other.segs), crate_num (other.crate_num)
+  {}
 
   CanonicalPath &operator= (const CanonicalPath &other)
   {
diff --git a/gcc/testsuite/rust/compile/v0-mangle1.rs 
b/gcc/testsuite/rust/compile/v0-mangle1.rs
index a34f1a70112a..04c546e351af 100644
--- a/gcc/testsuite/rust/compile/v0-mangle1.rs
+++ b/gcc/testsuite/rust/compile/v0-mangle1.rs
@@ -36,7 +36,7 @@ fn main() {
 // cf. rustc 1.72.0: _RNvNtCshIBIgX6Bzox_10v0_mangle18module_a3bar
 module_a::bar();
 
-// { dg-final { scan-assembler 
"_R.*NvNtNtC10v0_mangle18module_a8module_b3baz" } }
+// { dg-final { scan-assembler 
"_R.*NvNtNtC.*10v0_mangle18module_a8module_b3baz" } }
 // cf. rustc 1.72.0: 
_RNvNtNtCshIBIgX6Bzox_10v0_mangle18module_a8module_b3baz
 module_a::module_b::baz();


[gcc r15-8379] gccrs: Create new test system for name resolution 2.0

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:506459fac4e1a4a8d8ed68711cf88bddb1bbf601

commit r15-8379-g506459fac4e1a4a8d8ed68711cf88bddb1bbf601
Author: Owen Avery 
Date:   Mon Sep 16 18:27:19 2024 -0400

gccrs: Create new test system for name resolution 2.0

This runs the standard compile/**.rs tests
with name resolution 2.0 enabled. The exclude file
can be used to exclude tests which are not yet working
with name resolution 2.0.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/compile.exp: New test.
* rust/compile/nr2/exclude: New.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/testsuite/rust/compile/nr2/compile.exp | 136 +
 gcc/testsuite/rust/compile/nr2/exclude | 293 +
 2 files changed, 429 insertions(+)

diff --git a/gcc/testsuite/rust/compile/nr2/compile.exp 
b/gcc/testsuite/rust/compile/nr2/compile.exp
new file mode 100644
index ..0afe36c3c403
--- /dev/null
+++ b/gcc/testsuite/rust/compile/nr2/compile.exp
@@ -0,0 +1,136 @@
+# Copyright (C) 2021-2024 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# .
+
+# Compile tests, no torture testing, for name resolution 2.0
+#
+# These tests raise errors in the front end; torture testing doesn't apply.
+
+# Load support procs.
+load_lib rust-dg.exp
+
+# Initialize `dg'.
+dg-init
+
+namespace eval rust-nr2-ns {
+# Exclude tests which aren't passing yet
+# These should be removed from the exclude file over time
+
+set exclude_fh [open $srcdir/$subdir/exclude r]
+set exclude_raw [lsort [split [read $exclude_fh] "\n"]]
+close $exclude_fh
+unset exclude_fh
+
+set exclude ""
+foreach ent $exclude_raw {
+if [regexp {^[^#].*} $ent] {
+lappend exclude $ent
+   }
+}
+unset exclude_raw
+
+# Run tests in directories
+# Manually specifying these, in case some other test file
+# does something weird
+set test_dirs {. compile macros/builtin macros/mbe macros/proc}
+
+set tests_expect_ok ""
+set tests_expect_err ""
+
+foreach test_dir $test_dirs {
+foreach test [lsort [glob -nocomplain -tails -directory 
$srcdir/$subdir/../$test_dir *.rs]] {
+   if {$test_dir == "."} {
+   set test_lbl $test
+   } else {
+   set test_lbl "$test_dir/$test"
+}
+   set idx [lsearch -exact -sorted $exclude $test_lbl]
+   if {$idx == -1} {
+   lappend tests_expect_ok $srcdir/$subdir/../$test_dir/$test
+   } else {
+   lappend tests_expect_err $srcdir/$subdir/../$test_dir/$test
+   set exclude [lreplace $exclude $idx $idx]
+   }
+   }
+}
+
+# Generate failures for unmatched tests in the exclude list
+foreach ent $exclude {
+fail "$ent: could not exclude test"
+}
+unset exclude
+
+# run a test while catching record_test calls
+set record_test_out ""
+proc try_test { test } {
+variable record_test_out
+   rename ::record_test record_test_old
+
+   proc ::record_test { type msg args } {
+   namespace eval ::rust-nr2-ns {
+   set type [uplevel 1 {set type}]
+   set msg [uplevel 1 {set msg}]
+   variable record_test_out
+   switch $type {
+   FAIL {
+   lappend record_test_out "$type: $msg"
+   }
+   XPASS {
+   lappend record_test_out "$type: $msg"
+   }
+   }
+}
+   }
+
+namespace eval :: {
+   set saved-dg-do-what-default ${dg-do-what-default}
+   set dg-do-what-default "compile"
+dg-runtest [list [uplevel 1 {set test}]] 
"-frust-name-resolution-2.0" ""
+   set dg-do-what-default ${saved-dg-do-what-default}
+   }
+
+rename ::record_test ""
+   rename record_test_old ::record_test
+
+   set record_test_cache $record_test_out
+set record_test_out ""
+   return $record_test_cache
+}
+
+# check for unexpected failures
+foreach test $tests_expect_ok {
+set fails [try_test $test]
+   if {[llength $fails] != 0} {
+   foreach ent $fails {
+   record_test FAIL "$test: nr2 failure: $ent"
+   }
+ 

[gcc r15-8376] gccrs: session-manager: Fix typos in -frust-incomplete message

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:da48816297db523cac4bd69aceafb7cafc7478e2

commit r15-8376-gda48816297db523cac4bd69aceafb7cafc7478e2
Author: Arthur Cohen 
Date:   Thu Sep 5 16:17:57 2024 +0200

gccrs: session-manager: Fix typos in -frust-incomplete message

gcc/rust/ChangeLog:

* rust-session-manager.cc (Session::compile_crate): Use less 
repetition,
fix a typo in `reports`, fix word order.

Diff:
---
 gcc/rust/rust-session-manager.cc | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc
index 74f55103328a..a5cd97f18d76 100644
--- a/gcc/rust/rust-session-manager.cc
+++ b/gcc/rust/rust-session-manager.cc
@@ -477,10 +477,11 @@ Session::compile_crate (const char *filename)
 rust_fatal_error (
   UNDEF_LOCATION, "%s",
   "gccrs is not yet able to compile Rust code "
-  "properly. Most of the errors produced will be gccrs' fault and not the "
-  "crate you are trying to compile. Because of this, please reports issues 
"
-  "to us directly instead of opening issues on said crate's "
-  "repository.\n\nOur github repository: "
+  "properly. Most of the errors produced will be the fault of gccrs and "
+  "not the crate you are trying to compile. Because of this, please report 
"
+  "errors directly to us instead of opening issues on said crate's "
+  "repository.\n\n"
+  "Our github repository: "
   "https://github.com/rust-gcc/gccrs\nOur bugzilla tracker: "
   "https://gcc.gnu.org/bugzilla/";
   "buglist.cgi?bug_status=__open__&component=rust&product=gcc\n\n"


[gcc r15-8383] gccrs: adjust hir dump of BlockExpr

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:f4abaf6ec159b96f600d11eca311a3b8a34ece42

commit r15-8383-gf4abaf6ec159b96f600d11eca311a3b8a34ece42
Author: Marc Poulhiès 
Date:   Sat Sep 21 10:44:12 2024 +0200

gccrs: adjust hir dump of BlockExpr

Add tail_reachable and label fields to the dump.

gcc/rust/ChangeLog:

* hir/rust-hir-dump.cc (Dump::visit): Add missing fields.

Signed-off-by: Marc Poulhiès 

Diff:
---
 gcc/rust/hir/rust-hir-dump.cc | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/gcc/rust/hir/rust-hir-dump.cc b/gcc/rust/hir/rust-hir-dump.cc
index 67749de49a68..b44137732348 100644
--- a/gcc/rust/hir/rust-hir-dump.cc
+++ b/gcc/rust/hir/rust-hir-dump.cc
@@ -1270,6 +1270,8 @@ Dump::visit (BlockExpr &e)
   begin ("BlockExpr");
   do_expr (e);
   do_inner_attrs (e);
+  put_field ("tail_reachable", std::to_string (e.is_tail_reachable ()));
+  put_field ("label", e.get_label ().as_string ());
 
   visit_collection ("statements", e.get_statements ());


[gcc r15-8384] gccrs: Add extra assertions to tl::optional

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:70228a4ba99cdb5a152dceb10aa754bc0acb4aea

commit r15-8384-g70228a4ba99cdb5a152dceb10aa754bc0acb4aea
Author: Owen Avery 
Date:   Wed Sep 18 16:05:31 2024 -0400

gccrs: Add extra assertions to tl::optional

gcc/rust/ChangeLog:

* util/optional.h
(optional): Add assertions to dereference operator overloads
when C++14 is available.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/util/optional.h | 86 
 1 file changed, 79 insertions(+), 7 deletions(-)

diff --git a/gcc/rust/util/optional.h b/gcc/rust/util/optional.h
index b2011b784b76..2c59459cb940 100644
--- a/gcc/rust/util/optional.h
+++ b/gcc/rust/util/optional.h
@@ -1249,19 +1249,56 @@ public:
 
   /// Returns a pointer to the stored value
   constexpr const T *operator->() const {
+// constexpr function must only contain a return statement in C++11
+#ifdef TL_OPTIONAL_CXX14
+// undefined behavior if we don't have a value
+rust_assert(has_value ());
+#endif
+
 return std::addressof(this->m_value);
   }
 
   TL_OPTIONAL_11_CONSTEXPR T *operator->() {
+// constexpr function must only contain a return statement in C++11
+#ifdef TL_OPTIONAL_CXX14
+// undefined behavior if we don't have a value
+rust_assert(has_value ());
+#endif
+
 return std::addressof(this->m_value);
   }
 
   /// Returns the stored value
-  TL_OPTIONAL_11_CONSTEXPR T &operator*() & { return this->m_value; }
+  TL_OPTIONAL_11_CONSTEXPR T &operator*() &
+  {
+// constexpr function must only contain a return statement in C++11
+#ifdef TL_OPTIONAL_CXX14
+// undefined behavior if we don't have a value
+rust_assert(has_value ());
+#endif
 
-  constexpr const T &operator*() const & { return this->m_value; }
+return this->m_value;
+  }
+
+  constexpr const T &operator*() const &
+  {
+// constexpr function must only contain a return statement in C++11
+#ifdef TL_OPTIONAL_CXX14
+// undefined behavior if we don't have a value
+rust_assert(has_value ());
+#endif
+
+return this->m_value;
+  }
+
+  TL_OPTIONAL_11_CONSTEXPR T &&operator*() &&
+  {
+// constexpr function must only contain a return statement in C++11
+#ifdef TL_OPTIONAL_CXX14
+// undefined behavior if we don't have a value
+rust_assert(has_value ());
+#endif
 
-  TL_OPTIONAL_11_CONSTEXPR T &&operator*() && {
 return std::move(this->m_value);
   }
 
@@ -1988,14 +2025,49 @@ public:
   void swap(optional &rhs) noexcept { std::swap(m_value, rhs.m_value); }
 
   /// Returns a pointer to the stored value
-  constexpr const T *operator->() const noexcept { return m_value; }
+  constexpr const T *operator->() const noexcept
+  {
+// constexpr function must only contain a return statement in C++11
+#ifdef TL_OPTIONAL_CXX14
+// undefined behavior if we don't have a value
+rust_assert(has_value ());
+#endif
+
+return m_value;
+  }
 
-  TL_OPTIONAL_11_CONSTEXPR T *operator->() noexcept { return m_value; }
+  TL_OPTIONAL_11_CONSTEXPR T *operator->() noexcept
+  {
+// constexpr function must only contain a return statement in C++11
+#ifdef TL_OPTIONAL_CXX14
+// undefined behavior if we don't have a value
+rust_assert(has_value ());
+#endif
+
+return m_value;
+  }
 
   /// Returns the stored value
-  TL_OPTIONAL_11_CONSTEXPR T &operator*() noexcept { return *m_value; }
+  TL_OPTIONAL_11_CONSTEXPR T &operator*() noexcept {
+// constexpr function must only contain a return statement in C++11
+#ifdef TL_OPTIONAL_CXX14
+// undefined behavior if we don't have a value
+rust_assert(has_value ());
+#endif
+
+return *m_value;
+  }
 
-  constexpr const T &operator*() const noexcept { return *m_value; }
+  constexpr const T &operator*() const noexcept
+  {
+// constexpr function must only contain a return statement in C++11
+#ifdef TL_OPTIONAL_CXX14
+// undefined behavior if we don't have a value
+rust_assert(has_value ());
+#endif
+
+return *m_value;
+  }
 
   constexpr bool has_value() const noexcept { return m_value != nullptr; }


[gcc r15-8389] gccrs: toplevel: Add note for resolving use declarations

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:ca285a61c35df7da6ff652a2b2fbba8eef7d246b

commit r15-8389-gca285a61c35df7da6ff652a2b2fbba8eef7d246b
Author: Arthur Cohen 
Date:   Wed Apr 3 17:41:47 2024 +0200

gccrs: toplevel: Add note for resolving use declarations

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc 
(TopLevel::handle_use_dec):
Add notes on the problem.
* resolve/rust-toplevel-name-resolver-2.0.h: Likewise.

Diff:
---
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc | 11 +++
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h  |  2 +-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
index 746b2240d4b7..b18b86ca8218 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -452,6 +452,13 @@ TopLevel::handle_use_dec (AST::SimplePath &path)
   auto locus = path.get_final_segment ().get_locus ();
   auto declared_name = path.get_final_segment ().as_string ();
 
+  // In that function, we only need to declare a new definition - the use path.
+  // the resolution needs to happpen in the EarlyNameResolver. So the
+  // definitions we'll add will be the path's NodeId - that makes sense, as we
+  // need one definition per path declared in a Use tree. so all good.
+  // alright, now in what namespace do we declare them? all of them? do we only
+  // declare them in the EarlyNameResolver? this is dodgy
+
   // in what namespace do we perform path resolution? All of them? see which 
one
   // matches? Error out on ambiguities?
   // so, apparently, for each one that matches, add it to the proper namespace
@@ -464,6 +471,10 @@ TopLevel::handle_use_dec (AST::SimplePath &path)
 const AST::SimplePath &path) {
tl::optional resolved = tl::nullopt;
 
+   insert_or_error_out (declared_name, locus, path.get_node_id (), ns);
+   // what do we do here with the full simplepath? do we add it to an extra
+   // map?
+
// FIXME: resolve_path needs to return an `expected` so
// that we can improve it with hints or location or w/ever. and maybe
// only emit it the first time.
diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
index 095037042658..affddb97d50c 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
@@ -84,7 +84,7 @@ private:
   std::unordered_map node_locations;
 
   // Store node forwarding for use declaration, the link between a
-  // "new" local name and its definition.
+  // definition and its new local name.
   std::unordered_map node_forwarding;
 
   void visit (AST::Module &module) override;


[gcc r15-8386] rust: fix ICE when compiling impl block for !

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:d007ce87451f75134ccf38a3d760cbdc6720e608

commit r15-8386-gd007ce87451f75134ccf38a3d760cbdc6720e608
Author: Philip Herron 
Date:   Fri Sep 20 18:45:12 2024 +0100

rust: fix ICE when compiling impl block for !

We need to resolve the never type which is its own special AST node so it
doesnt magically get handled like the regular builtin type paths such as
i32.

Fixes #3035

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-type.cc (ResolveType::visit):
handle never type
(ResolveTypeToCanonicalPath::visit): likewise
* resolve/rust-ast-resolve-type.h: missing never type
* resolve/rust-name-resolver.cc (Resolver::generate_builtins):
track never type node_id
(Resolver::setup_builtin): likewise
* resolve/rust-name-resolver.h: new never type getter

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/issue-3035.rs: New test.

Signed-off-by: Philip Herron 

Diff:
---
 gcc/rust/resolve/rust-ast-resolve-type.cc |  8 +++-
 gcc/rust/resolve/rust-ast-resolve-type.h  |  2 ++
 gcc/rust/resolve/rust-name-resolver.cc|  9 +++--
 gcc/rust/resolve/rust-name-resolver.h |  7 ++-
 gcc/testsuite/rust/compile/issue-3035.rs  | 25 +
 gcc/testsuite/rust/compile/nr2/exclude|  3 ++-
 6 files changed, 49 insertions(+), 5 deletions(-)

diff --git a/gcc/rust/resolve/rust-ast-resolve-type.cc 
b/gcc/rust/resolve/rust-ast-resolve-type.cc
index 934d6ea3fbdc..cee259cceb45 100644
--- a/gcc/rust/resolve/rust-ast-resolve-type.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-type.cc
@@ -69,7 +69,7 @@ ResolveType::visit (AST::InferredType &)
 void
 ResolveType::visit (AST::NeverType &)
 {
-  // FIXME
+  resolved_node = resolver->get_never_type_node_id ();
 }
 
 void
@@ -501,6 +501,12 @@ ResolveTypeToCanonicalPath::visit (AST::TraitObjectType &)
   rust_unreachable ();
 }
 
+void
+ResolveTypeToCanonicalPath::visit (AST::NeverType &type)
+{
+  result = CanonicalPath::new_seg (type.get_node_id (), "!");
+}
+
 ResolveTypeToCanonicalPath::ResolveTypeToCanonicalPath ()
   : ResolverBase (), result (CanonicalPath::create_empty ())
 {}
diff --git a/gcc/rust/resolve/rust-ast-resolve-type.h 
b/gcc/rust/resolve/rust-ast-resolve-type.h
index 0076424ef51d..5e382445a148 100644
--- a/gcc/rust/resolve/rust-ast-resolve-type.h
+++ b/gcc/rust/resolve/rust-ast-resolve-type.h
@@ -246,6 +246,8 @@ public:
 
   void visit (AST::TraitObjectType &type) override;
 
+  void visit (AST::NeverType &type) override;
+
 private:
   ResolveTypeToCanonicalPath ();
 
diff --git a/gcc/rust/resolve/rust-name-resolver.cc 
b/gcc/rust/resolve/rust-name-resolver.cc
index ee52e5cc3d10..21147bd86fa5 100644
--- a/gcc/rust/resolve/rust-name-resolver.cc
+++ b/gcc/rust/resolve/rust-name-resolver.cc
@@ -429,7 +429,10 @@ Resolver::generate_builtins ()
   setup_builtin ("isize", isize);
   setup_builtin ("char", char_tyty);
   setup_builtin ("str", str);
-  setup_builtin ("!", never);
+
+  // never type
+  NodeId never_node_id = setup_builtin ("!", never);
+  set_never_type_node_id (never_node_id);
 
   // unit type ()
   TyTy::TupleType *unit_tyty
@@ -443,7 +446,7 @@ Resolver::generate_builtins ()
   set_unit_type_node_id (unit_type->get_node_id ());
 }
 
-void
+NodeId
 Resolver::setup_builtin (const std::string &name, TyTy::BaseType *tyty)
 {
   AST::PathIdentSegment seg (name, BUILTINS_LOCATION);
@@ -459,6 +462,8 @@ Resolver::setup_builtin (const std::string &name, 
TyTy::BaseType *tyty)
   mappings.insert_canonical_path (
 builtin_type->get_node_id (),
 CanonicalPath::new_seg (builtin_type->get_node_id (), name));
+
+  return builtin_type->get_node_id ();
 }
 
 void
diff --git a/gcc/rust/resolve/rust-name-resolver.h 
b/gcc/rust/resolve/rust-name-resolver.h
index c34002eb18e9..43b79e510050 100644
--- a/gcc/rust/resolve/rust-name-resolver.h
+++ b/gcc/rust/resolve/rust-name-resolver.h
@@ -163,9 +163,13 @@ public:
   Scope &get_macro_scope () { return macro_scope; }
 
   NodeId get_global_type_node_id () { return global_type_node_id; }
+
   void set_unit_type_node_id (NodeId id) { unit_ty_node_id = id; }
   NodeId get_unit_type_node_id () { return unit_ty_node_id; }
 
+  void set_never_type_node_id (NodeId id) { never_ty_node_id = id; }
+  NodeId get_never_type_node_id () { return never_ty_node_id; }
+
   void push_new_module_scope (NodeId module_id)
   {
 current_module_stack.push_back (module_id);
@@ -208,7 +212,7 @@ private:
   Resolver ();
 
   void generate_builtins ();
-  void setup_builtin (const std::string &name, TyTy::BaseType *tyty);
+  NodeId setup_builtin (const std::string &name, TyTy::BaseType *tyty);
 
   Analysis::Mappings &mappings;
   TypeCheckContext *tyctx;
@@ -222,6 +226,7 @@ private:
 
   NodeId global_type_node_id;
   NodeId unit_ty_node_id;
+  NodeId never_ty_node_id;
 
   // map a AST N

[gcc r15-8371] gccrs: Use `IndexVec` for bb_fold_map

2025-03-19 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:152ecf846f65c760c73ea77e8612eeeb4531fde4

commit r15-8371-g152ecf846f65c760c73ea77e8612eeeb4531fde4
Author: Kushal Pal 
Date:   Wed Aug 28 06:16:11 2024 +

gccrs: Use `IndexVec` for bb_fold_map

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-dump.cc (simplify_cfg):
Used `IndexVec` for bb_fold_map.
(Dump::go): Use strong type as index instead of value as now we
are using `IndexVec`.
(Dump::visit): Likewise.
* checks/errors/borrowck/rust-bir-dump.h (class Dump): Use
`IndexVec` for bb_fold_map.
* checks/errors/borrowck/rust-bir-place.h: Add constructor for
`IndexVec` that can reserve size.

Signed-off-by: Kushal Pal 

Diff:
---
 gcc/rust/checks/errors/borrowck/rust-bir-dump.cc | 27 
 gcc/rust/checks/errors/borrowck/rust-bir-dump.h  |  2 +-
 gcc/rust/checks/errors/borrowck/rust-bir-place.h |  3 +++
 3 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc 
b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
index b01d08a0456c..c9e01545c6aa 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
@@ -71,7 +71,7 @@ renumber_places (const Function &func, std::vector 
&place_map)
 }
 
 void
-simplify_cfg (Function &func, std::vector &bb_fold_map)
+simplify_cfg (Function &func, IndexVec 
&bb_fold_map)
 {
   // The BIR builder can generate many useless basic blocks, which contain only
   // a goto.
@@ -84,11 +84,11 @@ simplify_cfg (Function &func, std::vector 
&bb_fold_map)
   // BB0 cannot be folded as it is an entry block.
   for (BasicBlockId i = {1}; i.value < func.basic_blocks.size (); 
++i.value)
{
- const BasicBlock &bb = func.basic_blocks[bb_fold_map[i.value]];
+ const BasicBlock &bb = func.basic_blocks[bb_fold_map[i]];
  if (bb.statements.empty () && bb.is_goto_terminated ())
{
  auto dst = bb.successors.at (0);
- if (bb_fold_map[dst.value] != dst)
+ if (bb_fold_map[dst] != dst)
{
  rust_error_at (
UNKNOWN_LOCATION,
@@ -100,12 +100,12 @@ simplify_cfg (Function &func, std::vector 
&bb_fold_map)
  for (BasicBlockId i = ENTRY_BASIC_BLOCK;
   i.value < bb_fold_map.size (); ++i.value)
{
- bb_fold_map[i.value] = i;
+ bb_fold_map[i] = i;
}
  stabilized = true;
  break;
}
- bb_fold_map[i.value] = dst;
+ bb_fold_map[i] = dst;
  stabilized = false;
}
}
@@ -119,7 +119,7 @@ Dump::go (bool enable_simplify_cfg)
   for (BasicBlockId i = ENTRY_BASIC_BLOCK; i.value < bb_fold_map.size ();
++i.value)
 {
-  bb_fold_map[i.value] = i;
+  bb_fold_map[i] = i;
 }
   for (size_t i = 0; i < place_map.size (); ++i)
 {
@@ -146,7 +146,7 @@ Dump::go (bool enable_simplify_cfg)
   for (statement_bb = ENTRY_BASIC_BLOCK;
statement_bb.value < func.basic_blocks.size (); ++statement_bb.value)
 {
-  if (bb_fold_map[statement_bb.value] != statement_bb)
+  if (bb_fold_map[statement_bb] != statement_bb)
continue; // This BB was folded.
 
   if (func.basic_blocks[statement_bb].statements.empty ()
@@ -157,7 +157,7 @@ Dump::go (bool enable_simplify_cfg)
 
   BasicBlock &bb = func.basic_blocks[statement_bb];
   stream << "\n";
-  stream << indentation << "bb" << bb_fold_map[statement_bb.value].value
+  stream << indentation << "bb" << bb_fold_map[statement_bb].value
 << ": {\n";
   size_t i = 0;
   for (auto &stmt : bb.statements)
@@ -168,8 +168,8 @@ Dump::go (bool enable_simplify_cfg)
}
   if (!bb_terminated)
stream << indentation << indentation << "goto -> bb"
-  << bb_fold_map[bb.successors.at (0).value].value << ";\t\t"
-  << i++ << "\n";
+  << bb_fold_map[bb.successors.at (0)].value << ";\t\t" << i++
+  << "\n";
 
   stream << indentation << "}\n";
 }
@@ -194,7 +194,7 @@ Dump::visit (const Statement &stmt)
   stream << ") -> [";
   print_comma_separated (stream, 
func.basic_blocks[statement_bb].successors,
 [this] (BasicBlockId succ) {
-  stream << "bb" << bb_fold_map[succ.value].value;
+  stream << "bb" << bb_fold_map[succ].value;
 });
   stream << "]";
   bb_terminated = true;
@@ -206,8 +206,7 @@ Dump::visit (const Statement &stmt)
 case Statement::Kind::GOTO:
   stream
<< "goto -> bb"
-   << bb_fold_map[func.basic_blocks[statement_bb].successors.at (0).value]
-.valu

  1   2   >