[gcc r15-4407] testsuite: Add -march=x86-64-v3 to AVX10 testcases to slience warning for GCC built with AVX512 arch

2024-10-17 Thread Haochen Jiang via Gcc-cvs
https://gcc.gnu.org/g:8b9b696c98def874139effc0380929df4a4356f0

commit r15-4407-g8b9b696c98def874139effc0380929df4a4356f0
Author: Haochen Jiang 
Date:   Wed Oct 16 15:40:12 2024 +0800

testsuite: Add -march=x86-64-v3 to AVX10 testcases to slience warning for 
GCC built with AVX512 arch

Currently, when build GCC with config --with-arch=native on AVX512
machines, if we run AVX10.2 testcases, we will get vector size warnings.
It is expected but annoying. Simply add -march=x86-64-v3 to override
--with-arch=native to slience all the warnings.

gcc/testsuite/ChangeLog:

* gcc.target/i386/avx10_1-25.c: Add -march=x86-64-v3.
* gcc.target/i386/avx10_1-26.c: Ditto.
* gcc.target/i386/avx10_2-512-bf-vector-cmpp-1.c: Ditto.
* gcc.target/i386/avx10_2-512-bf-vector-fma-1.c: Ditto.
* gcc.target/i386/avx10_2-512-bf-vector-operations-1.c: Ditto.
* gcc.target/i386/avx10_2-512-bf-vector-smaxmin-1.c: Ditto.
* gcc.target/i386/avx10_2-512-bf16-1.c: Ditto.
* gcc.target/i386/avx10_2-512-convert-1.c: Ditto.
* gcc.target/i386/avx10_2-512-media-1.c: Ditto.
* gcc.target/i386/avx10_2-512-minmax-1.c: Ditto.
* gcc.target/i386/avx10_2-512-satcvt-1.c: Ditto.
* gcc.target/i386/avx10_2-512-vaddnepbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcmppbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvt2ps2phx-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvtbiasph2bf8-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvtbiasph2bf8s-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvtbiasph2hf8-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvtbiasph2hf8s-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvthf82ph-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvtne2ph2bf8-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvtne2ph2bf8s-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvtne2ph2hf8-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvtne2ph2hf8s-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvtnebf162ibs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvtnebf162iubs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvtneph2bf8-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvtneph2bf8s-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvtneph2hf8-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvtneph2hf8s-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvtph2ibs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvtph2iubs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvtps2ibs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvtps2iubs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvttnebf162ibs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvttnebf162iubs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvttpd2dqs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvttpd2qqs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvttpd2udqs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvttpd2uqqs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvttph2ibs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvttph2iubs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvttps2dqs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvttps2ibs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvttps2iubs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvttps2qqs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvttps2udqs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvttps2uqqs-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vdivnepbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vdpphps-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vfmaddXXXnepbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vfmsubXXXnepbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vfnmaddXXXnepbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vfnmsubXXXnepbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vfpclasspbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vgetexppbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vgetmantpbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vmaxpbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vminmaxnepbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vminmaxpd-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vminmaxph-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vminmaxps-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vminpbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vmpsadbw-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vmulnepbf16-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vpdpbssd-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vpdpbssds-2.c: Ditto.
  

[gcc r15-4406] The detailed explanation from PR116550:

2024-10-17 Thread Denis Chertykov via Gcc-cvs
https://gcc.gnu.org/g:e7393cbb5f2cae50b42713e71984064073aa378a

commit r15-4406-ge7393cbb5f2cae50b42713e71984064073aa378a
Author: Denis Chertykov 
Date:   Thu Oct 17 11:12:38 2024 +0400

The detailed explanation from PR116550:

Test file: udivmoddi.c
problem insn: 484

Before LRA pass we have:
(insn 484 483 485 72 (parallel [
(set (reg/v:SI 143 [ __q1 ])
(plus:SI (reg/v:SI 143 [ __q1 ])
(const_int -2 [0xfffe])))
(clobber (scratch:QI))
]) "udivmoddi.c":163:405 discrim 5 186 {addsi3}
 (nil))

LRA substitute all scratches with new pseudos, so we have:
(insn 484 483 485 72 (parallel [
(set (reg/v:SI 143 [ __q1 ])
(plus:SI (reg/v:SI 143 [ __q1 ])
(const_int -2 [0xfffe])))
(clobber (reg:QI 619))
]) "/mnt/d/avr-lra/udivmoddi.c":163:405 discrim 5 186 {addsi3}
 (expr_list:REG_UNUSED (reg:QI 619)
(nil)))

Pseudo 619 is a special scratch register generated by LRA which is marked 
in `scratch_bitmap' and can be tested by call `ira_former_scratch_p(regno)'.

In dump file (udivmoddi.c.317r.reload) we have:
  Creating newreg=619
Removing SCRATCH to p619 in insn #484 (nop 3)
rescanning insn with uid = 484.

After that LRA tries to spill (reg:QI 619)
It's a bug because (reg:QI 619) is an output scratch register which is 
already something like spill register.

Fragment from udivmoddi.c.317r.reload:
  Choosing alt 2 in insn 484:  (0) r  (1) 0  (2) nYnn  (3) &d {addsi3}
  Creating newreg=728 from oldreg=619, assigning class LD_REGS to r728

IMHO: the bug is in lra-constraints.cc in function `get_reload_reg'
fragment of `get_reload_reg':
  if (type == OP_OUT)
{
  /* Output reload registers tend to start out with a conservative
 choice of register class.  Usually this is ALL_REGS, although
 a target might narrow it (for performance reasons) through
 targetm.preferred_reload_class.  It's therefore quite common
 for a reload instruction to require a more restrictive class
 than the class that was originally assigned to the reload register.

 In these situations, it's more efficient to refine the choice
 of register class rather than create a second reload register.
 This also helps to avoid cycling for registers that are only
 used by reload instructions.  */
  if (REG_P (original)
  && (int) REGNO (original) >= new_regno_start
  && INSN_UID (curr_insn) >= new_insn_uid_start
__^^
  && in_class_p (original, rclass, &new_class, true))
{
  unsigned int regno = REGNO (original);
  if (lra_dump_file != NULL)
{
  fprintf (lra_dump_file, "  Reuse r%d for output ", regno);
  dump_value_slim (lra_dump_file, original, 1);
}

This condition incorrectly limits register reuse to ONLY newly generated 
instructions.
i.e. LRA can reuse registers only from insns generated by himself.

IMHO:It's wrong.
Scratch registers generated by LRA also have to be reused.

The patch is very simple.
On x86_64, it bootstraps+regtests fine.

gcc/
PR target/116550
* lra-constraints.cc (get_reload_reg): Reuse scratch registers
generated by LRA.

Diff:
---
 gcc/lra-constraints.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/lra-constraints.cc b/gcc/lra-constraints.cc
index fdcc07764a2e..1f63113f3210 100644
--- a/gcc/lra-constraints.cc
+++ b/gcc/lra-constraints.cc
@@ -680,7 +680,8 @@ get_reload_reg (enum op_type type, machine_mode mode, rtx 
original,
 used by reload instructions.  */
   if (REG_P (original)
  && (int) REGNO (original) >= new_regno_start
- && INSN_UID (curr_insn) >= new_insn_uid_start
+ && (INSN_UID (curr_insn) >= new_insn_uid_start
+ || ira_former_scratch_p (REGNO (original)))
  && in_class_p (original, rclass, &new_class, true))
{
  unsigned int regno = REGNO (original);


[gcc/devel/rust/master] Change lookup_hir_extern_item return type

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:fa24d0d08eb385df313beab7dd7c8a1091c216c4

commit fa24d0d08eb385df313beab7dd7c8a1091c216c4
Author: Pierre-Emmanuel Patry 
Date:   Thu May 2 13:44:10 2024 +0200

Change lookup_hir_extern_item return type

Wrap the return type with an optional and make the return type a pair
with the parent hid.

gcc/rust/ChangeLog:

* backend/rust-compile-resolve-path.cc 
(HIRCompileBase::query_compile):
Adapt code around new return type.
* checks/errors/rust-const-checker.cc 
(ConstChecker::check_function_call):
Likewise.
* checks/errors/rust-unsafe-checker.cc 
(UnsafeChecker::check_use_of_static):
Likewise.
(UnsafeChecker::check_function_call): Likewise.
* typecheck/rust-type-util.cc (query_type): Likewise.
* util/rust-hir-map.cc (Mappings::insert_hir_extern_item): Likewise.
(Mappings::lookup_hir_extern_item): Change return type.
* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/backend/rust-compile-resolve-path.cc |  8 +++-
 gcc/rust/checks/errors/rust-const-checker.cc  |  9 -
 gcc/rust/checks/errors/rust-unsafe-checker.cc | 18 ++
 gcc/rust/typecheck/rust-type-util.cc  | 11 ---
 gcc/rust/util/rust-hir-map.cc | 12 +---
 gcc/rust/util/rust-hir-map.h  |  5 -
 6 files changed, 26 insertions(+), 37 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc 
b/gcc/rust/backend/rust-compile-resolve-path.cc
index 6ca4d62972cd..a1188e978443 100644
--- a/gcc/rust/backend/rust-compile-resolve-path.cc
+++ b/gcc/rust/backend/rust-compile-resolve-path.cc
@@ -201,10 +201,6 @@ HIRCompileBase::query_compile (HirId ref, TyTy::BaseType 
*lookup,
   const Analysis::NodeMapping &mappings,
   location_t expr_locus, bool is_qualified_path)
 {
-  HirId parent_block;
-  HIR::ExternalItem *resolved_extern_item
-= ctx->get_mappings ().lookup_hir_extern_item (ref, &parent_block);
-  bool is_hir_extern_item = resolved_extern_item != nullptr;
   bool is_fn = lookup->get_kind () == TyTy::TypeKind::FNDEF;
   if (auto resolved_item = ctx->get_mappings ().lookup_hir_item (ref))
 {
@@ -215,8 +211,10 @@ HIRCompileBase::query_compile (HirId ref, TyTy::BaseType 
*lookup,
return CompileItem::compile (*resolved_item, ctx, lookup, true,
 expr_locus);
 }
-  else if (is_hir_extern_item)
+  else if (auto hir_extern_item
+  = ctx->get_mappings ().lookup_hir_extern_item (ref))
 {
+  HIR::ExternalItem *resolved_extern_item = hir_extern_item->first;
   if (!lookup->has_substitutions_defined ())
return CompileExternItem::compile (resolved_extern_item, ctx, nullptr,
   true, expr_locus);
diff --git a/gcc/rust/checks/errors/rust-const-checker.cc 
b/gcc/rust/checks/errors/rust-const-checker.cc
index 7e881abc9fcc..172540ecebb5 100644
--- a/gcc/rust/checks/errors/rust-const-checker.cc
+++ b/gcc/rust/checks/errors/rust-const-checker.cc
@@ -315,11 +315,9 @@ ConstChecker::check_function_call (HirId fn_id, location_t 
locus)
   // There are const extern functions (intrinsics)
   // TODO: Should we check the ABI is only "rust intrinsics"? Is that handled
   // elsewhere?
-  HirId parent_block;
-  auto maybe_extern_item
-= mappings.lookup_hir_extern_item (fn_id, &parent_block);
+  auto maybe_extern_item = mappings.lookup_hir_extern_item (fn_id);
   if (maybe_extern_item
-  && maybe_extern_item->get_extern_kind ()
+  && maybe_extern_item->first->get_extern_kind ()
   != ExternalItem::ExternKind::Function)
 return;
 
@@ -334,7 +332,8 @@ ConstChecker::check_function_call (HirId fn_id, location_t 
locus)
   if (maybe_extern_item)
 {
   {
-   auto fn = static_cast (maybe_extern_item);
+   auto fn
+ = static_cast (maybe_extern_item->first);
if (!is_const_extern_fn (*fn))
  is_error = true;
   }
diff --git a/gcc/rust/checks/errors/rust-unsafe-checker.cc 
b/gcc/rust/checks/errors/rust-unsafe-checker.cc
index 4a2bb0fc87e4..9e2ffa981998 100644
--- a/gcc/rust/checks/errors/rust-unsafe-checker.cc
+++ b/gcc/rust/checks/errors/rust-unsafe-checker.cc
@@ -70,15 +70,12 @@ UnsafeChecker::check_use_of_static (HirId node_id, 
location_t locus)
   if (unsafe_context.is_in_context ())
 return;
 
-  HirId extern_block;
-  auto maybe_extern_static
-= mappings.lookup_hir_extern_item (node_id, &extern_block);
-
   if (auto maybe_static_mut = mappings.lookup_hir_item (node_id))
 check_static_mut (*maybe_static_mut, locus);
 
-  if (maybe_extern_static)
-check_extern_static (static_cast (maybe_extern_static),
+  if (auto maybe_extern_static = mappings.lookup_hir_extern_item (node_id))
+check_ex

[gcc/devel/rust/master] Change return type of lookup trait defid functions.

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:310081b7d629e4640d0b962f727ac4249bd51e25

commit 310081b7d629e4640d0b962f727ac4249bd51e25
Author: Pierre-Emmanuel Patry 
Date:   Thu May 2 12:33:20 2024 +0200

Change return type of lookup trait defid functions.

Wrap the return type with an optional.

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc 
(HIRCompileBase::resolve_method_address):
Update code around lookup return type.
* typecheck/rust-tyty-bounds.cc 
(TypeCheckBase::get_predicate_from_bound):
Likewise.
* typecheck/rust-tyty.cc (ClosureType::setup_fn_once_output):
Likewise.
* util/rust-hir-map.cc (Mappings::insert_defid_mapping): Likewise.
(Mappings::lookup_trait_item_defid): Update return type with an
optional.
(Mappings::get_lang_item): Likewise.
* util/rust-hir-map.h: Update the functions prototype.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/backend/rust-compile-base.cc  |  2 +-
 gcc/rust/typecheck/rust-tyty-bounds.cc |  7 +--
 gcc/rust/typecheck/rust-tyty.cc|  4 ++--
 gcc/rust/util/rust-hir-map.cc  | 10 +-
 gcc/rust/util/rust-hir-map.h   |  6 +++---
 5 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-base.cc 
b/gcc/rust/backend/rust-compile-base.cc
index 56665a575b5b..e3b27f6bc0e8 100644
--- a/gcc/rust/backend/rust-compile-base.cc
+++ b/gcc/rust/backend/rust-compile-base.cc
@@ -887,7 +887,7 @@ HIRCompileBase::resolve_method_address (TyTy::FnType 
*fntype,
 
   // it might be resolved to a trait item
   HIR::TraitItem *trait_item
-= ctx->get_mappings ().lookup_trait_item_defid (id);
+= ctx->get_mappings ().lookup_trait_item_defid (id).value ();
   HIR::Trait *trait = ctx->get_mappings ().lookup_trait_item_mapping (
 trait_item->get_mappings ().get_hirid ());
 
diff --git a/gcc/rust/typecheck/rust-tyty-bounds.cc 
b/gcc/rust/typecheck/rust-tyty-bounds.cc
index 03ba622704e4..cc97016704d6 100644
--- a/gcc/rust/typecheck/rust-tyty-bounds.cc
+++ b/gcc/rust/typecheck/rust-tyty-bounds.cc
@@ -245,8 +245,11 @@ TypeCheckBase::get_predicate_from_bound (HIR::TypePath 
&type_path,
rust_assert (fn.has_return_type ());
TypeCheckType::Resolve (fn.get_return_type ().get ());
 
-   HIR::TraitItem *trait_item = mappings.lookup_trait_item_lang_item (
- LangItem::Kind::FN_ONCE_OUTPUT, final_seg->get_locus ());
+   HIR::TraitItem *trait_item
+ = mappings
+ .lookup_trait_item_lang_item (LangItem::Kind::FN_ONCE_OUTPUT,
+   final_seg->get_locus ())
+ .value ();
 
std::vector bindings;
location_t output_locus = fn.get_return_type ()->get_locus ();
diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index dc4fac956d1c..9839ff72f4fe 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -2238,8 +2238,8 @@ ClosureType::setup_fn_once_output () const
   rust_assert (!trait_ref->is_error ());
 
   // resolve to trait item
-  HIR::TraitItem *trait_item = mappings.lookup_trait_item_defid 
(trait_item_id);
-  rust_assert (trait_item != nullptr);
+  HIR::TraitItem *trait_item
+= mappings.lookup_trait_item_defid (trait_item_id).value ();
   rust_assert (trait_item->get_item_kind ()
   == HIR::TraitItem::TraitItemKind::TYPE);
   std::string item_identifier = trait_item->trait_identifier ();
diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index 798f457fea8a..80b7b1de1f86 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -314,7 +314,7 @@ Mappings::insert_defid_mapping (DefId id, HIR::Item *item)
 
   rust_assert (!lookup_defid (id));
   rust_assert (!lookup_local_defid (crate_num, local_def_id));
-  rust_assert (lookup_trait_item_defid (id) == nullptr);
+  rust_assert (!lookup_trait_item_defid (id));
 
   defIdMappings[id] = item;
   insert_local_defid_mapping (crate_num, local_def_id, item);
@@ -338,17 +338,17 @@ Mappings::insert_defid_mapping (DefId id, HIR::TraitItem 
*item)
 
   rust_assert (!lookup_defid (id));
   rust_assert (!lookup_local_defid (crate_num, local_def_id));
-  rust_assert (lookup_trait_item_defid (id) == nullptr);
+  rust_assert (!lookup_trait_item_defid (id));
 
   defIdTraitItemMappings[id] = item;
 }
 
-HIR::TraitItem *
+tl::optional
 Mappings::lookup_trait_item_defid (DefId id)
 {
   auto it = defIdTraitItemMappings.find (id);
   if (it == defIdTraitItemMappings.end ())
-return nullptr;
+return tl::nullopt;
 
   return it->second;
 }
@@ -1264,7 +1264,7 @@ Mappings::get_lang_item (LangItem::Kind item_type, 
location_t locus)
   return item;
 }
 
-HIR::TraitItem *
+tl::optional
 Mappings::lookup_trait_item_lang_item (LangItem::Kind item, location_t locus)
 {
   DefId trait_item_id = get_lang_item (item, locus)

[gcc/devel/rust/master] Change lookup_module function return type

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:395aab37873f0f988450f31323e7748ae500745c

commit 395aab37873f0f988450f31323e7748ae500745c
Author: Pierre-Emmanuel Patry 
Date:   Fri May 3 13:25:20 2024 +0200

Change lookup_module function return type

Wrap the return type into an optional.

gcc/rust/ChangeLog:

* checks/errors/privacy/rust-visibility-resolver.cc: Update function
call to match the new return type.
* typecheck/rust-hir-type-check-path.cc 
(TypeCheckExpr::resolve_root_path):
Likewise.
* typecheck/rust-hir-type-check-type.cc 
(TypeCheckType::resolve_root_path):
Likewise.
* util/rust-hir-map.cc (Mappings::insert_module): Likewise.
(Mappings::lookup_module): Change the function's return type.
* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 .../checks/errors/privacy/rust-visibility-resolver.cc| 16 +++-
 gcc/rust/typecheck/rust-hir-type-check-path.cc   |  2 +-
 gcc/rust/typecheck/rust-hir-type-check-type.cc   |  2 +-
 gcc/rust/util/rust-hir-map.cc|  6 +++---
 gcc/rust/util/rust-hir-map.h |  2 +-
 5 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc 
b/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc
index 5854b46562d3..7110883750f5 100644
--- a/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc
+++ b/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc
@@ -85,17 +85,15 @@ VisibilityResolver::resolve_module_path (const 
HIR::SimplePath &restriction,
 // these items as private?
 return true;
 
-  auto module = mappings.lookup_module (ref);
-  if (!module)
+  if (auto module = mappings.lookup_module (ref))
 {
-  invalid_path.emit ();
-  return false;
-}
+  // Fill in the resolved `DefId`
+  id = module.value ()->get_mappings ().get_defid ();
 
-  // Fill in the resolved `DefId`
-  id = module->get_mappings ().get_defid ();
-
-  return true;
+  return true;
+}
+  invalid_path.emit ();
+  return false;
 }
 
 bool
diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc 
b/gcc/rust/typecheck/rust-hir-type-check-path.cc
index 9e284f247fc3..d2962e6c2f19 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-path.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc
@@ -243,7 +243,7 @@ TypeCheckExpr::resolve_root_path (HIR::PathInExpression 
&expr, size_t *offset,
}
   auto ref = hid.value ();
 
-  auto seg_is_module = (nullptr != mappings.lookup_module (ref));
+  auto seg_is_module = mappings.lookup_module (ref).has_value ();
   auto seg_is_crate = mappings.is_local_hirid_crate (ref);
   if (seg_is_module || seg_is_crate)
{
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc 
b/gcc/rust/typecheck/rust-hir-type-check-type.cc
index c7bfee520976..36f64a770e90 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc
@@ -391,7 +391,7 @@ TypeCheckType::resolve_root_path (HIR::TypePath &path, 
size_t *offset,
}
   auto ref = hid.value ();
 
-  auto seg_is_module = (nullptr != mappings.lookup_module (ref));
+  auto seg_is_module = mappings.lookup_module (ref).has_value ();
   auto seg_is_crate = mappings.is_local_hirid_crate (ref);
   if (seg_is_module || seg_is_crate)
{
diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index aee3ef87baec..97d7abfe290c 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -489,18 +489,18 @@ void
 Mappings::insert_module (HIR::Module *module)
 {
   auto id = module->get_mappings ().get_hirid ();
-  rust_assert (lookup_module (id) == nullptr);
+  rust_assert (!lookup_module (id));
 
   hirModuleMappings[id] = module;
   insert_node_to_hir (module->get_mappings ().get_nodeid (), id);
 }
 
-HIR::Module *
+tl::optional
 Mappings::lookup_module (HirId id)
 {
   auto it = hirModuleMappings.find (id);
   if (it == hirModuleMappings.end ())
-return nullptr;
+return tl::nullopt;
 
   return it->second;
 }
diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h
index 1171945ef557..b18c60c0e526 100644
--- a/gcc/rust/util/rust-hir-map.h
+++ b/gcc/rust/util/rust-hir-map.h
@@ -138,7 +138,7 @@ public:
   tl::optional lookup_impl_block_type (HirId id);
 
   void insert_module (HIR::Module *module);
-  HIR::Module *lookup_module (HirId id);
+  tl::optional lookup_module (HirId id);
 
   void insert_hir_implitem (HirId parent_impl_id, HIR::ImplItem *item);
   HIR::ImplItem *lookup_hir_implitem (HirId id, HirId *parent_impl_id);


[gcc/devel/rust/master] Change lookup_hir_implitem return type

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:1fcb7198e46212a1689e190aca0e4803d9762e68

commit 1fcb7198e46212a1689e190aca0e4803d9762e68
Author: Pierre-Emmanuel Patry 
Date:   Fri May 3 16:30:06 2024 +0200

Change lookup_hir_implitem return type

Wrap the return type within an optional. Now return the parent id within
a pair instead of taking an out reference.

gcc/rust/ChangeLog:

* backend/rust-compile-item.cc (CompileItem::visit): Change call 
site
to accept new return type.
* backend/rust-compile-resolve-path.cc 
(HIRCompileBase::query_compile):
Likewise.
* backend/rust-mangle-v0.cc (v0_path): Likewise.
* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit):
Likewise.
* checks/lints/rust-lint-marklive.cc (MarkLive::go): Likewise.
(MarkLive::visit): Likewise.
* typecheck/rust-type-util.cc (query_type): Likewise.
* util/rust-hir-map.cc (Mappings::insert_hir_implitem): Likewise.
(Mappings::lookup_hir_implitem): Change return type.
* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/backend/rust-compile-item.cc |  7 ++
 gcc/rust/backend/rust-compile-resolve-path.cc | 12 --
 gcc/rust/backend/rust-mangle-v0.cc| 10 
 gcc/rust/checks/errors/rust-unsafe-checker.cc |  6 ++---
 gcc/rust/checks/lints/rust-lint-marklive.cc   | 33 ++-
 gcc/rust/typecheck/rust-type-util.cc  | 16 +
 gcc/rust/util/rust-hir-map.cc | 14 
 gcc/rust/util/rust-hir-map.h  | 10 
 8 files changed, 35 insertions(+), 73 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-item.cc 
b/gcc/rust/backend/rust-compile-item.cc
index 7f96694b759f..8380d8a857fa 100644
--- a/gcc/rust/backend/rust-compile-item.cc
+++ b/gcc/rust/backend/rust-compile-item.cc
@@ -152,15 +152,12 @@ CompileItem::visit (HIR::Function &function)
 {
   // if this is part of a trait impl block which is not generic we need to
   // ensure associated types are setup
-  HirId parent_impl_block = UNKNOWN_HIRID;
   HirId id = function.get_mappings ().get_hirid ();
-  HIR::ImplItem *impl_item
-   = ctx->get_mappings ().lookup_hir_implitem (id, &parent_impl_block);
-  if (impl_item != nullptr)
+  if (auto impl_item = ctx->get_mappings ().lookup_hir_implitem (id))
{
  Resolver::AssociatedImplTrait *impl = nullptr;
  bool found = ctx->get_tyctx ()->lookup_associated_trait_impl (
-   parent_impl_block, &impl);
+   impl_item->second, &impl);
  if (found)
impl->setup_raw_associated_types ();
}
diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc 
b/gcc/rust/backend/rust-compile-resolve-path.cc
index a1188e978443..58d9e8e3b100 100644
--- a/gcc/rust/backend/rust-compile-resolve-path.cc
+++ b/gcc/rust/backend/rust-compile-resolve-path.cc
@@ -238,18 +238,14 @@ HIRCompileBase::query_compile (HirId ref, TyTy::BaseType 
*lookup,
}
}
 
-  HirId parent_impl_id = UNKNOWN_HIRID;
-  HIR::ImplItem *resolved_item
-   = ctx->get_mappings ().lookup_hir_implitem (ref, &parent_impl_id);
-  bool is_impl_item = resolved_item != nullptr;
-  if (is_impl_item)
+  if (auto resolved_item = ctx->get_mappings ().lookup_hir_implitem (ref))
{
  if (!lookup->has_substitutions_defined ())
-   return CompileInherentImplItem::Compile (resolved_item, ctx,
+   return CompileInherentImplItem::Compile (resolved_item->first, ctx,
 nullptr, true, expr_locus);
  else
-   return CompileInherentImplItem::Compile (resolved_item, ctx, lookup,
-true, expr_locus);
+   return CompileInherentImplItem::Compile (resolved_item->first, ctx,
+lookup, true, expr_locus);
}
   else
{
diff --git a/gcc/rust/backend/rust-mangle-v0.cc 
b/gcc/rust/backend/rust-mangle-v0.cc
index 4c0319afbb60..6d9a59ab7931 100644
--- a/gcc/rust/backend/rust-mangle-v0.cc
+++ b/gcc/rust/backend/rust-mangle-v0.cc
@@ -384,17 +384,15 @@ v0_path (Rust::Compile::Context *ctx, const 
TyTy::BaseType *ty,
 
 auto hir_id = hid.value ();
 
-HirId parent_impl_id = UNKNOWN_HIRID;
-HIR::ImplItem *impl_item
-  = mappings.lookup_hir_implitem (hir_id, &parent_impl_id);
 HIR::Expr *expr = mappings.lookup_hir_expr (hir_id);
 
-if (impl_item != nullptr)
+if (auto impl_item = mappings.lookup_hir_implitem (hir_id))
   {
-   switch (impl_item->get_impl_item_type ())
+   switch (impl_item->first->get_impl_item_type ())
  {
case HIR::ImplItem::FUNCTION: {
- HIR::Function *fn =

[gcc/devel/rust/master] Change lookup_local_defid return type to optional

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:a83bc198e19a99d9f266dbb77deb5a7a5200f53f

commit a83bc198e19a99d9f266dbb77deb5a7a5200f53f
Author: Pierre-Emmanuel Patry 
Date:   Thu May 2 11:43:02 2024 +0200

Change lookup_local_defid return type to optional

Make the API more convenient by changing the function's return type. We
can now differentiate between a stored null pointer and a missing value.

gcc/rust/ChangeLog:

* util/rust-hir-map.cc (Mappings::insert_defid_mapping): Adapt call
to new return type.
(Mappings::insert_local_defid_mapping): Likewise.
(Mappings::lookup_local_defid): Change return type to wrap it with 
an
optional.
* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/util/rust-hir-map.cc | 12 ++--
 gcc/rust/util/rust-hir-map.h  |  3 ++-
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index 64f2f5c2bfdb..798f457fea8a 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -313,7 +313,7 @@ Mappings::insert_defid_mapping (DefId id, HIR::Item *item)
   LocalDefId local_def_id = id.localDefId;
 
   rust_assert (!lookup_defid (id));
-  rust_assert (lookup_local_defid (crate_num, local_def_id) == nullptr);
+  rust_assert (!lookup_local_defid (crate_num, local_def_id));
   rust_assert (lookup_trait_item_defid (id) == nullptr);
 
   defIdMappings[id] = item;
@@ -337,7 +337,7 @@ Mappings::insert_defid_mapping (DefId id, HIR::TraitItem 
*item)
   LocalDefId local_def_id = id.localDefId;
 
   rust_assert (!lookup_defid (id));
-  rust_assert (lookup_local_defid (crate_num, local_def_id) == nullptr);
+  rust_assert (!lookup_local_defid (crate_num, local_def_id));
   rust_assert (lookup_trait_item_defid (id) == nullptr);
 
   defIdTraitItemMappings[id] = item;
@@ -718,20 +718,20 @@ void
 Mappings::insert_local_defid_mapping (CrateNum crateNum, LocalDefId id,
  HIR::Item *item)
 {
-  rust_assert (lookup_local_defid (crateNum, id) == nullptr);
+  rust_assert (!lookup_local_defid (crateNum, id));
   localDefIdMappings[crateNum][id] = item;
 }
 
-HIR::Item *
+tl::optional
 Mappings::lookup_local_defid (CrateNum crateNum, LocalDefId id)
 {
   auto it = localDefIdMappings.find (crateNum);
   if (it == localDefIdMappings.end ())
-return nullptr;
+return tl::nullopt;
 
   auto iy = it->second.find (id);
   if (iy == it->second.end ())
-return nullptr;
+return tl::nullopt;
 
   return iy->second;
 }
diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h
index f7d99d18c447..e4e7f55f5880 100644
--- a/gcc/rust/util/rust-hir-map.h
+++ b/gcc/rust/util/rust-hir-map.h
@@ -112,7 +112,8 @@ public:
 
   void insert_local_defid_mapping (CrateNum crateNum, LocalDefId id,
   HIR::Item *item);
-  HIR::Item *lookup_local_defid (CrateNum crateNum, LocalDefId id);
+  tl::optional lookup_local_defid (CrateNum crateNum,
+   LocalDefId id);
 
   void insert_hir_item (HIR::Item *item);
   tl::optional lookup_hir_item (HirId id);


[gcc/devel/rust/master] Change return type of lookup_defid

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:d1f2064d643cf9e8865641746e3cf907b276d234

commit d1f2064d643cf9e8865641746e3cf907b276d234
Author: Pierre-Emmanuel Patry 
Date:   Fri Apr 26 12:02:53 2024 +0200

Change return type of lookup_defid

Change the return type to an optional.

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc 
(HIRCompileBase::resolve_method_address):
Change calling code to accomodate new return type.
* checks/errors/privacy/rust-privacy-reporter.cc:
Likewise.
* typecheck/rust-hir-type-check-base.cc 
(TypeCheckBase::get_marker_predicate):
Likewise.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
Likewise.
* typecheck/rust-tyty-bounds.cc 
(TypeBoundsProbe::assemble_builtin_candidate):
Likewise.
* typecheck/rust-tyty.cc (ClosureType::setup_fn_once_output): 
Likewise.
* util/rust-hir-map.cc (Mappings::lookup_defid): Change function's
return type.
* util/rust-hir-map.h: Update function's prototype.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/backend/rust-compile-base.cc   |  7 +++
 gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc |  3 +--
 gcc/rust/typecheck/rust-hir-type-check-base.cc  |  3 +--
 gcc/rust/typecheck/rust-hir-type-check-expr.cc  | 17 ++---
 gcc/rust/typecheck/rust-tyty-bounds.cc  |  5 +++--
 gcc/rust/typecheck/rust-tyty.cc |  2 +-
 gcc/rust/util/rust-hir-map.cc   |  8 
 gcc/rust/util/rust-hir-map.h|  2 +-
 8 files changed, 20 insertions(+), 27 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-base.cc 
b/gcc/rust/backend/rust-compile-base.cc
index 5cf9ed948e50..56665a575b5b 100644
--- a/gcc/rust/backend/rust-compile-base.cc
+++ b/gcc/rust/backend/rust-compile-base.cc
@@ -877,13 +877,12 @@ HIRCompileBase::resolve_method_address (TyTy::FnType 
*fntype,
   // Now we can try and resolve the address since this might be a forward
   // declared function, generic function which has not be compiled yet or
   // its an not yet trait bound function
-  HIR::Item *resolved_item = ctx->get_mappings ().lookup_defid (id);
-  if (resolved_item != nullptr)
+  if (auto resolved_item = ctx->get_mappings ().lookup_defid (id))
 {
   if (!fntype->has_substitutions_defined ())
-   return CompileItem::compile (resolved_item, ctx);
+   return CompileItem::compile (*resolved_item, ctx);
 
-  return CompileItem::compile (resolved_item, ctx, fntype);
+  return CompileItem::compile (*resolved_item, ctx, fntype);
 }
 
   // it might be resolved to a trait item
diff --git a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc 
b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
index 1ce47fda1a9c..c1e217d59987 100644
--- a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
+++ b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
@@ -146,8 +146,7 @@ PrivacyReporter::check_for_privacy_violation (const NodeId 
&use_id,
if (!current_module.has_value ())
  return;
 
-   auto module = mappings.lookup_defid (vis.get_module_id ());
-   rust_assert (module != nullptr);
+   auto module = mappings.lookup_defid (vis.get_module_id ()).value ();
 
auto mod_node_id = module->get_mappings ().get_nodeid ();
 
diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.cc 
b/gcc/rust/typecheck/rust-hir-type-check-base.cc
index 4d92f0c2b4fe..82782c68f418 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-base.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-base.cc
@@ -414,8 +414,7 @@ TyTy::TypeBoundPredicate
 TypeCheckBase::get_marker_predicate (LangItem::Kind item_type, location_t 
locus)
 {
   DefId item_id = mappings.get_lang_item (item_type, locus);
-  HIR::Item *item = mappings.lookup_defid (item_id);
-  rust_assert (item != nullptr);
+  HIR::Item *item = mappings.lookup_defid (item_id).value ();
   rust_assert (item->get_item_kind () == HIR::Item::ItemKind::Trait);
 
   HIR::Trait &trait = *static_cast (item);
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc 
b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index 57739e560259..2565a57b09c2 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -642,8 +642,7 @@ TypeCheckExpr::visit (HIR::RangeFromToExpr &expr)
 }
 
   // look it up and it _must_ be a struct definition
-  HIR::Item *item = mappings.lookup_defid (respective_lang_item_id);
-  rust_assert (item != nullptr);
+  HIR::Item *item = mappings.lookup_defid (respective_lang_item_id).value ();
 
   TyTy::BaseType *item_type = nullptr;
   bool ok
@@ -697,8 +696,7 @@ TypeCheckExpr::visit (HIR::RangeFromExpr &expr)
 }
 
   // look it up and it _must_ be a struct definition
-  HIR::Item *item = m

[gcc/devel/rust/master] Change return type to optional in get_lang_item

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:6f0e06c04f9278057a927f45a72db18602bd0f6e

commit 6f0e06c04f9278057a927f45a72db18602bd0f6e
Author: Pierre-Emmanuel Patry 
Date:   Fri May 3 14:54:06 2024 +0200

Change return type to optional in get_lang_item

Wrap the function's return type with an optional.

gcc/rust/ChangeLog:

* typecheck/rust-autoderef.cc: Adapt calling code to new return 
type.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
Likewise.
(TypeCheckExpr::resolve_operator_overload): Likewise.
* typecheck/rust-tyty-bounds.cc 
(TypeBoundsProbe::assemble_builtin_candidate):
Likewise.
* typecheck/rust-tyty.cc (ClosureType::setup_fn_once_output): 
Likewise.
* util/rust-hir-map.cc (Mappings::get_lang_item): Change return 
type.
* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/typecheck/rust-autoderef.cc   |  5 ++-
 gcc/rust/typecheck/rust-hir-type-check-expr.cc | 42 +-
 gcc/rust/typecheck/rust-tyty-bounds.cc |  6 ++--
 gcc/rust/typecheck/rust-tyty.cc| 12 ++--
 gcc/rust/util/rust-hir-map.cc  | 10 +++---
 gcc/rust/util/rust-hir-map.h   |  7 ++---
 6 files changed, 30 insertions(+), 52 deletions(-)

diff --git a/gcc/rust/typecheck/rust-autoderef.cc 
b/gcc/rust/typecheck/rust-autoderef.cc
index 1d0e7ad70aa1..285857323225 100644
--- a/gcc/rust/typecheck/rust-autoderef.cc
+++ b/gcc/rust/typecheck/rust-autoderef.cc
@@ -129,12 +129,11 @@ resolve_operator_overload_fn (
 
   // look up lang item for arithmetic type
   std::string associated_item_name = LangItem::ToString (lang_item_type);
-  DefId respective_lang_item_id = UNKNOWN_DEFID;
-  bool lang_item_defined
-= mappings.lookup_lang_item (lang_item_type, &respective_lang_item_id);
+  auto lang_item_defined = mappings.lookup_lang_item (lang_item_type);
 
   if (!lang_item_defined)
 return false;
+  DefId &respective_lang_item_id = lang_item_defined.value ();
 
   // we might be in a static or const context and unknown is fine
   TypeCheckContextItem current_context = TypeCheckContextItem::get_error ();
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc 
b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index 2565a57b09c2..8485f9c3acfa 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -628,10 +628,7 @@ TypeCheckExpr::visit (HIR::RangeFromToExpr &expr)
 {
   auto lang_item_type = LangItem::Kind::RANGE;
 
-  DefId respective_lang_item_id = UNKNOWN_DEFID;
-  bool lang_item_defined
-= mappings.lookup_lang_item (lang_item_type, &respective_lang_item_id);
-
+  auto lang_item_defined = mappings.lookup_lang_item (lang_item_type);
   // we need to have it maybe
   if (!lang_item_defined)
 {
@@ -640,6 +637,7 @@ TypeCheckExpr::visit (HIR::RangeFromToExpr &expr)
  LangItem::ToString (lang_item_type).c_str ());
   return;
 }
+  DefId respective_lang_item_id = lang_item_defined.value ();
 
   // look it up and it _must_ be a struct definition
   HIR::Item *item = mappings.lookup_defid (respective_lang_item_id).value ();
@@ -682,10 +680,7 @@ TypeCheckExpr::visit (HIR::RangeFromExpr &expr)
 {
   auto lang_item_type = LangItem::Kind::RANGE_FROM;
 
-  DefId respective_lang_item_id = UNKNOWN_DEFID;
-  bool lang_item_defined
-= mappings.lookup_lang_item (lang_item_type, &respective_lang_item_id);
-
+  auto lang_item_defined = mappings.lookup_lang_item (lang_item_type);
   // we need to have it maybe
   if (!lang_item_defined)
 {
@@ -694,6 +689,7 @@ TypeCheckExpr::visit (HIR::RangeFromExpr &expr)
  LangItem::ToString (lang_item_type).c_str ());
   return;
 }
+  DefId &respective_lang_item_id = lang_item_defined.value ();
 
   // look it up and it _must_ be a struct definition
   HIR::Item *item = mappings.lookup_defid (respective_lang_item_id).value ();
@@ -729,10 +725,7 @@ TypeCheckExpr::visit (HIR::RangeToExpr &expr)
 {
   auto lang_item_type = LangItem::Kind::RANGE_TO;
 
-  DefId respective_lang_item_id = UNKNOWN_DEFID;
-  bool lang_item_defined
-= mappings.lookup_lang_item (lang_item_type, &respective_lang_item_id);
-
+  auto lang_item_defined = mappings.lookup_lang_item (lang_item_type);
   // we need to have it maybe
   if (!lang_item_defined)
 {
@@ -742,6 +735,7 @@ TypeCheckExpr::visit (HIR::RangeToExpr &expr)
   return;
 }
 
+  DefId &respective_lang_item_id = lang_item_defined.value ();
   // look it up and it _must_ be a struct definition
   HIR::Item *item = mappings.lookup_defid (respective_lang_item_id).value ();
 
@@ -775,10 +769,7 @@ TypeCheckExpr::visit (HIR::RangeFullExpr &expr)
 {
   auto lang_item_type = LangItem::Kind::RANGE_FULL;
 
-  DefId respective_lang_item_id = UNKNOWN_DEFID;
-  bool l

[gcc/devel/rust/master] Change lookup_hir_path_expr_seg return type

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:d1dad032ded0c9c9cace45d0211ccd68ec6af755

commit d1dad032ded0c9c9cace45d0211ccd68ec6af755
Author: Pierre-Emmanuel Patry 
Date:   Fri May 3 19:49:44 2024 +0200

Change lookup_hir_path_expr_seg return type

Make the function's return type optional in order to differentiate
between null pointers and missing value.

gcc/rust/ChangeLog:

* util/rust-hir-map.cc (Mappings::insert_hir_path_expr_seg): Change
call site to accomodate the new return type.
(Mappings::lookup_hir_path_expr_seg): Wrap the function's return 
type
with an optional.
* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/util/rust-hir-map.cc | 6 +++---
 gcc/rust/util/rust-hir-map.h  | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index cfd2a58f482f..02e24bedfec6 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -550,19 +550,19 @@ void
 Mappings::insert_hir_path_expr_seg (HIR::PathExprSegment *expr)
 {
   auto id = expr->get_mappings ().get_hirid ();
-  rust_assert (lookup_hir_path_expr_seg (id) == nullptr);
+  rust_assert (!lookup_hir_path_expr_seg (id));
 
   hirPathSegMappings[id] = expr;
   insert_node_to_hir (expr->get_mappings ().get_nodeid (), id);
   insert_location (id, expr->get_locus ());
 }
 
-HIR::PathExprSegment *
+tl::optional
 Mappings::lookup_hir_path_expr_seg (HirId id)
 {
   auto it = hirPathSegMappings.find (id);
   if (it == hirPathSegMappings.end ())
-return nullptr;
+return tl::nullopt;
 
   return it->second;
 }
diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h
index 654493524459..dbfc8c05b7df 100644
--- a/gcc/rust/util/rust-hir-map.h
+++ b/gcc/rust/util/rust-hir-map.h
@@ -149,7 +149,7 @@ public:
   tl::optional lookup_hir_expr (HirId id);
 
   void insert_hir_path_expr_seg (HIR::PathExprSegment *expr);
-  HIR::PathExprSegment *lookup_hir_path_expr_seg (HirId id);
+  tl::optional lookup_hir_path_expr_seg (HirId id);
 
   void insert_hir_generic_param (HIR::GenericParam *expr);
   HIR::GenericParam *lookup_hir_generic_param (HirId id);


[gcc/devel/rust/master] Change lookup_hir_expr return type to optional

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:478c227c864f108a49ffa9bc695c0413e159c15c

commit 478c227c864f108a49ffa9bc695c0413e159c15c
Author: Pierre-Emmanuel Patry 
Date:   Fri May 3 19:40:18 2024 +0200

Change lookup_hir_expr return type to optional

Wrap the function's return type with an optional in order to
differentiate missing values from null pointers.

gcc/rust/ChangeLog:

* backend/rust-mangle-v0.cc (v0_path): Adapt call site to new 
returned
type.
* util/rust-hir-map.cc (Mappings::lookup_hir_expr): Change the
function's return type.
* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/backend/rust-mangle-v0.cc | 6 ++
 gcc/rust/util/rust-hir-map.cc  | 4 ++--
 gcc/rust/util/rust-hir-map.h   | 2 +-
 3 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/gcc/rust/backend/rust-mangle-v0.cc 
b/gcc/rust/backend/rust-mangle-v0.cc
index 6d9a59ab7931..685236b2da49 100644
--- a/gcc/rust/backend/rust-mangle-v0.cc
+++ b/gcc/rust/backend/rust-mangle-v0.cc
@@ -384,8 +384,6 @@ v0_path (Rust::Compile::Context *ctx, const TyTy::BaseType 
*ty,
 
 auto hir_id = hid.value ();
 
-HIR::Expr *expr = mappings.lookup_hir_expr (hir_id);
-
 if (auto impl_item = mappings.lookup_hir_implitem (hir_id))
   {
switch (impl_item->first->get_impl_item_type ())
@@ -467,9 +465,9 @@ v0_path (Rust::Compile::Context *ctx, const TyTy::BaseType 
*ty,
  cpath.get ().c_str ());
  break;
}
-else if (expr != nullptr)
+else if (auto expr = mappings.lookup_hir_expr (hir_id))
   {
-   rust_assert (expr->get_expression_type ()
+   rust_assert (expr.value ()->get_expression_type ()
 == HIR::Expr::ExprType::Closure);
// Use HIR ID as disambiguator.
v0path = v0_closure (v0path, hir_id);
diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index 597c5745ed6c..cfd2a58f482f 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -536,12 +536,12 @@ Mappings::insert_hir_expr (HIR::Expr *expr)
   insert_location (id, expr->get_locus ());
 }
 
-HIR::Expr *
+tl::optional
 Mappings::lookup_hir_expr (HirId id)
 {
   auto it = hirExprMappings.find (id);
   if (it == hirExprMappings.end ())
-return nullptr;
+return tl::nullopt;
 
   return it->second;
 }
diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h
index ec299767ebb1..654493524459 100644
--- a/gcc/rust/util/rust-hir-map.h
+++ b/gcc/rust/util/rust-hir-map.h
@@ -146,7 +146,7 @@ public:
   lookup_hir_implitem (HirId id);
 
   void insert_hir_expr (HIR::Expr *expr);
-  HIR::Expr *lookup_hir_expr (HirId id);
+  tl::optional lookup_hir_expr (HirId id);
 
   void insert_hir_path_expr_seg (HIR::PathExprSegment *expr);
   HIR::PathExprSegment *lookup_hir_path_expr_seg (HirId id);


[gcc/devel/rust/master] Change lookup_hir_generic_param return type

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:1e6a3ee55ed907f6e71e6fccbd872b6f80e8298e

commit 1e6a3ee55ed907f6e71e6fccbd872b6f80e8298e
Author: Pierre-Emmanuel Patry 
Date:   Fri May 3 19:59:43 2024 +0200

Change lookup_hir_generic_param return type

Wrap the function's return type with an optional.

gcc/rust/ChangeLog:

* util/rust-hir-map.cc (Mappings::insert_hir_generic_param): Change
call site to accomodate the new return type.
(Mappings::lookup_hir_generic_param): Wrap the function's return 
type
with an optional.
* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/util/rust-hir-map.cc | 6 +++---
 gcc/rust/util/rust-hir-map.h  | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index 02e24bedfec6..457e8af8ef01 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -571,19 +571,19 @@ void
 Mappings::insert_hir_generic_param (HIR::GenericParam *param)
 {
   auto id = param->get_mappings ().get_hirid ();
-  rust_assert (lookup_hir_generic_param (id) == nullptr);
+  rust_assert (!lookup_hir_generic_param (id));
 
   hirGenericParamMappings[id] = param;
   insert_node_to_hir (param->get_mappings ().get_nodeid (), id);
   insert_location (id, param->get_locus ());
 }
 
-HIR::GenericParam *
+tl::optional
 Mappings::lookup_hir_generic_param (HirId id)
 {
   auto it = hirGenericParamMappings.find (id);
   if (it == hirGenericParamMappings.end ())
-return nullptr;
+return tl::nullopt;
 
   return it->second;
 }
diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h
index dbfc8c05b7df..2c15097e0ce4 100644
--- a/gcc/rust/util/rust-hir-map.h
+++ b/gcc/rust/util/rust-hir-map.h
@@ -152,7 +152,7 @@ public:
   tl::optional lookup_hir_path_expr_seg (HirId id);
 
   void insert_hir_generic_param (HIR::GenericParam *expr);
-  HIR::GenericParam *lookup_hir_generic_param (HirId id);
+  tl::optional lookup_hir_generic_param (HirId id);
 
   void insert_hir_type (HIR::Type *type);
   HIR::Type *lookup_hir_type (HirId id);


[gcc/devel/rust/master] Change lookup_canonical_path's return path

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:291068b42e9ef3a23af89f33b0a72f5b8651b38d

commit 291068b42e9ef3a23af89f33b0a72f5b8651b38d
Author: Pierre-Emmanuel Patry 
Date:   Fri May 3 23:17:43 2024 +0200

Change lookup_canonical_path's return path

Change the function's return type to wrap it within an optional.

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc: Change call site to accomodate new
return type.
* backend/rust-compile-base.h: Change parameter to use a reference.
* backend/rust-compile-extern.h: Likewise.
* backend/rust-compile-implitem.cc (CompileTraitItem::visit):
Change call site for new return type.
* backend/rust-compile-item.cc (CompileItem::visit): Likewise.
* resolve/rust-ast-resolve-type.cc 
(ResolveTypeToCanonicalPath::visit):
Likewise.
* typecheck/rust-hir-type-check-enumitem.cc 
(TypeCheckEnumItem::visit):
Likewise.
* typecheck/rust-hir-type-check-implitem.cc 
(TypeCheckImplItem::visit):
Likewise.
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit):
Likewise.
* typecheck/rust-hir-type-check.cc 
(TraitItemReference::get_type_from_fn):
Likewise.
* util/rust-hir-map.h: Update the function's prototype and change 
the
function's return type.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/backend/rust-compile-base.cc  | 10 ++---
 gcc/rust/backend/rust-compile-base.h   |  4 +-
 gcc/rust/backend/rust-compile-extern.h |  6 +--
 gcc/rust/backend/rust-compile-implitem.cc  | 16 +++
 gcc/rust/backend/rust-compile-item.cc  | 26 +---
 gcc/rust/resolve/rust-ast-resolve-type.cc  |  3 +-
 gcc/rust/typecheck/rust-hir-type-check-enumitem.cc | 24 ---
 gcc/rust/typecheck/rust-hir-type-check-implitem.cc |  7 +---
 gcc/rust/typecheck/rust-hir-type-check-item.cc | 49 --
 gcc/rust/typecheck/rust-hir-type-check.cc  |  6 +--
 gcc/rust/util/rust-hir-map.h   | 11 +++--
 11 files changed, 61 insertions(+), 101 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-base.cc 
b/gcc/rust/backend/rust-compile-base.cc
index e3b27f6bc0e8..11129bcb86be 100644
--- a/gcc/rust/backend/rust-compile-base.cc
+++ b/gcc/rust/backend/rust-compile-base.cc
@@ -650,11 +650,11 @@ HIRCompileBase::compile_function (
   std::vector &function_params,
   const HIR::FunctionQualifiers &qualifiers, HIR::Visibility &visibility,
   AST::AttrVec &outer_attrs, location_t locus, HIR::BlockExpr *function_body,
-  const Resolver::CanonicalPath *canonical_path, TyTy::FnType *fntype)
+  const Resolver::CanonicalPath &canonical_path, TyTy::FnType *fntype)
 {
   tree compiled_fn_type = TyTyResolveCompile::compile (ctx, fntype);
   std::string ir_symbol_name
-= canonical_path->get () + fntype->subst_as_string ();
+= canonical_path.get () + fntype->subst_as_string ();
 
   // we don't mangle the main fn since we haven't implemented the main shim
   bool is_main_fn = fn_name.compare ("main") == 0;
@@ -677,7 +677,7 @@ HIRCompileBase::compile_function (
   // conditionally mangle the function name
   bool should_mangle = should_mangle_item (fndecl);
   if (!is_main_fn && should_mangle)
-asm_name = ctx->mangle_item (fntype, *canonical_path);
+asm_name = ctx->mangle_item (fntype, canonical_path);
   SET_DECL_ASSEMBLER_NAME (fndecl,
   get_identifier_with_length (asm_name.data (),
   asm_name.length ()));
@@ -767,10 +767,10 @@ HIRCompileBase::compile_function (
 
 tree
 HIRCompileBase::compile_constant_item (
-  TyTy::BaseType *resolved_type, const Resolver::CanonicalPath *canonical_path,
+  TyTy::BaseType *resolved_type, const Resolver::CanonicalPath &canonical_path,
   HIR::Expr *const_value_expr, location_t locus)
 {
-  const std::string &ident = canonical_path->get ();
+  const std::string &ident = canonical_path.get ();
 
   tree type = TyTyResolveCompile::compile (ctx, resolved_type);
   tree const_type = build_qualified_type (type, TYPE_QUAL_CONST);
diff --git a/gcc/rust/backend/rust-compile-base.h 
b/gcc/rust/backend/rust-compile-base.h
index c303d9f021a8..22d4ae6c6f66 100644
--- a/gcc/rust/backend/rust-compile-base.h
+++ b/gcc/rust/backend/rust-compile-base.h
@@ -91,7 +91,7 @@ protected:
  TyTy::BaseType *fn_return_ty);
 
   tree compile_constant_item (TyTy::BaseType *resolved_type,
- const Resolver::CanonicalPath *canonical_path,
+ const Resolver::CanonicalPath &canonical_path,
  HIR::Expr *const_value_expr, location_t locus);
 
   tree compile_function (const std::string &fn_name, HIR::SelfParam 
&self_param,
@@ -99,7 +99,7 @@ protected:
   

[gcc/devel/rust/master] Change lookup_macro_invocation's return type

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:435f227c2501d1d5a72905d30a5a90848be11481

commit 435f227c2501d1d5a72905d30a5a90848be11481
Author: Pierre-Emmanuel Patry 
Date:   Sat May 4 03:21:27 2024 +0200

Change lookup_macro_invocation's return type

Wrap the function's return type within an optional and remove the out
reference argument.

gcc/rust/ChangeLog:

* expand/rust-macro-expand.cc (MacroExpander::expand_invoc): Adapt
the function call to match its new prototype.
* resolve/rust-early-name-resolver-2.0.cc (Early::insert_once):
Likewise.
(Early::visit): Likewise.
* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
Likewise.
* util/rust-hir-map.cc (Mappings::lookup_macro_invocation): Change 
the
function's return type.
* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/expand/rust-macro-expand.cc | 18 +-
 gcc/rust/resolve/rust-early-name-resolver-2.0.cc |  8 ++--
 gcc/rust/resolve/rust-early-name-resolver.cc |  3 +--
 gcc/rust/util/rust-hir-map.cc| 10 --
 gcc/rust/util/rust-hir-map.h |  4 ++--
 5 files changed, 18 insertions(+), 25 deletions(-)

diff --git a/gcc/rust/expand/rust-macro-expand.cc 
b/gcc/rust/expand/rust-macro-expand.cc
index d95665d8d4a0..1efc81a8b3f3 100644
--- a/gcc/rust/expand/rust-macro-expand.cc
+++ b/gcc/rust/expand/rust-macro-expand.cc
@@ -272,25 +272,25 @@ MacroExpander::expand_invoc (AST::MacroInvocation &invoc, 
bool has_semicolon)
   invoc_data.set_expander (this);
 
   // lookup the rules
-  AST::MacroRulesDefinition *rules_def = nullptr;
-  bool ok = mappings.lookup_macro_invocation (invoc, &rules_def);
+  auto rules_def = mappings.lookup_macro_invocation (invoc);
 
   // If there's no rule associated with the invocation, we can simply return
   // early. The early name resolver will have already emitted an error.
-  if (!ok)
+  if (!rules_def)
 return;
 
+  auto rdef = rules_def.value ();
+
   // We store the last expanded invocation and macro definition for error
   // reporting in case the recursion limit is reached
   last_invoc = *invoc.clone_macro_invocation_impl ();
-  last_def = *rules_def;
+  last_def = *rdef;
 
-  if (rules_def->is_builtin ())
-fragment
-  = rules_def->get_builtin_transcriber () (invoc.get_locus (), invoc_data)
- .value_or (AST::Fragment::create_empty ());
+  if (rdef->is_builtin ())
+fragment = rdef->get_builtin_transcriber () (invoc.get_locus (), 
invoc_data)
+.value_or (AST::Fragment::create_empty ());
   else
-fragment = expand_decl_macro (invoc.get_locus (), invoc_data, *rules_def,
+fragment = expand_decl_macro (invoc.get_locus (), invoc_data, *rdef,
  has_semicolon);
 
   set_expanded_fragment (std::move (fragment));
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 473cdc4e317e..bcbe3bd75e33 100644
--- a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
@@ -32,10 +32,7 @@ Early::insert_once (AST::MacroInvocation &invocation, NodeId 
resolved)
   // TODO: Should we use `ctx.mark_resolved()`?
   auto definition = ctx.mappings.lookup_macro_def (resolved);
 
-  AST::MacroRulesDefinition *existing;
-  auto exists = ctx.mappings.lookup_macro_invocation (invocation, &existing);
-
-  if (!exists)
+  if (!ctx.mappings.lookup_macro_invocation (invocation))
 ctx.mappings.insert_macro_invocation (invocation, definition.value ());
 }
 
@@ -176,8 +173,7 @@ Early::visit (AST::MacroInvocation &invoc)
   if (!rules_def)
 return;
 
-  AST::MacroRulesDefinition *tmp_def = nullptr;
-  if (mappings.lookup_macro_invocation (invoc, &tmp_def))
+  if (mappings.lookup_macro_invocation (invoc))
 return;
 
   mappings.insert_macro_invocation (invoc, rules_def.value ());
diff --git a/gcc/rust/resolve/rust-early-name-resolver.cc 
b/gcc/rust/resolve/rust-early-name-resolver.cc
index 4021f5d56129..14d204150408 100644
--- a/gcc/rust/resolve/rust-early-name-resolver.cc
+++ b/gcc/rust/resolve/rust-early-name-resolver.cc
@@ -503,8 +503,7 @@ EarlyNameResolver::visit (AST::MacroInvocation &invoc)
* we could be inserting the same macro def over and over again until we
* implement some optimizations */
   // FIXME: ARTHUR: Remove that lookup and add proper optimizations instead
-  AST::MacroRulesDefinition *tmp_def = nullptr;
-  if (mappings.lookup_macro_invocation (invoc, &tmp_def))
+  if (mappings.lookup_macro_invocation (invoc))
 return;
 
   mappings.insert_macro_invocation (invoc, *rules_def);
diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index 5d46fc49af27..f7975fa9537a 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util

[gcc/devel/rust/master] Change lookup_visibility's return type

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:f13cb854c049ff9bb2ea0911ddc1b1b6282ffe88

commit f13cb854c049ff9bb2ea0911ddc1b1b6282ffe88
Author: Pierre-Emmanuel Patry 
Date:   Sat May 4 03:44:35 2024 +0200

Change lookup_visibility's return type

Wrap the return type within an optional.

gcc/rust/ChangeLog:

* checks/errors/privacy/rust-privacy-reporter.cc: Change call site
to accomodate new return type.
* checks/errors/privacy/rust-pub-restricted-visitor.cc: Likewise.
* util/rust-hir-map.cc (Mappings::lookup_visibility): Change the
function's return type.
* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc   | 8 
 gcc/rust/checks/errors/privacy/rust-pub-restricted-visitor.cc | 6 +++---
 gcc/rust/util/rust-hir-map.cc | 9 -
 gcc/rust/util/rust-hir-map.h  | 2 +-
 4 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc 
b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
index c1e217d59987..d2e448c41f4f 100644
--- a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
+++ b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
@@ -128,15 +128,15 @@ PrivacyReporter::check_for_privacy_violation (const 
NodeId &use_id,
   if (ref_node_id == UNKNOWN_NODEID)
 return;
 
-  ModuleVisibility vis;
+  auto vis = mappings.lookup_visibility (ref_node_id);
 
   // FIXME: Can we really return here if the item has no visibility?
-  if (!mappings.lookup_visibility (ref_node_id, vis))
+  if (!vis)
 return;
 
   auto valid = true;
 
-  switch (vis.get_kind ())
+  switch (vis->get_kind ())
 {
 case ModuleVisibility::Public:
   break;
@@ -146,7 +146,7 @@ PrivacyReporter::check_for_privacy_violation (const NodeId 
&use_id,
if (!current_module.has_value ())
  return;
 
-   auto module = mappings.lookup_defid (vis.get_module_id ()).value ();
+   auto module = mappings.lookup_defid (vis->get_module_id ()).value ();
 
auto mod_node_id = module->get_mappings ().get_nodeid ();
 
diff --git a/gcc/rust/checks/errors/privacy/rust-pub-restricted-visitor.cc 
b/gcc/rust/checks/errors/privacy/rust-pub-restricted-visitor.cc
index 907479071b74..7b26a953bdee 100644
--- a/gcc/rust/checks/errors/privacy/rust-pub-restricted-visitor.cc
+++ b/gcc/rust/checks/errors/privacy/rust-pub-restricted-visitor.cc
@@ -27,16 +27,16 @@ bool
 PubRestrictedVisitor::is_restriction_valid (NodeId item_id,
const location_t locus)
 {
-  ModuleVisibility visibility;
+  auto visibility = mappings.lookup_visibility (item_id);
 
   // If there is no visibility in the mappings, then the item is private and
   // does not contain any restriction
   // FIXME: Is that correct?
-  if (!mappings.lookup_visibility (item_id, visibility))
+  if (!visibility)
 return true;
 
   for (auto mod = module_stack.rbegin (); mod != module_stack.rend (); mod++)
-if (*mod == visibility.get_module_id ())
+if (*mod == visibility->get_module_id ())
   return true;
 
   rust_error_at (locus, "restricted path is not an ancestor of the "
diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index f7975fa9537a..26d24ee631f5 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -1102,15 +1102,14 @@ Mappings::insert_visibility (NodeId id, 
Privacy::ModuleVisibility visibility)
   visibility_map.insert ({id, visibility});
 }
 
-bool
-Mappings::lookup_visibility (NodeId id, Privacy::ModuleVisibility &def)
+tl::optional
+Mappings::lookup_visibility (NodeId id)
 {
   auto it = visibility_map.find (id);
   if (it == visibility_map.end ())
-return false;
+return tl::nullopt;
 
-  def = it->second;
-  return true;
+  return it->second;
 }
 
 void
diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h
index 34500474dc53..cc170dca4f39 100644
--- a/gcc/rust/util/rust-hir-map.h
+++ b/gcc/rust/util/rust-hir-map.h
@@ -326,7 +326,7 @@ public:
   AttributeProcMacro def);
 
   void insert_visibility (NodeId id, Privacy::ModuleVisibility visibility);
-  bool lookup_visibility (NodeId id, Privacy::ModuleVisibility &def);
+  tl::optional lookup_visibility (NodeId id);
 
   void insert_ast_module (AST::Module *);
   tl::optional lookup_ast_module (NodeId id);


[gcc/devel/rust/master] Change lookup_macro_def return type

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:c3493829b74bade43a6a9bc83520066c9a3c9e09

commit c3493829b74bade43a6a9bc83520066c9a3c9e09
Author: Pierre-Emmanuel Patry 
Date:   Sat May 4 02:42:10 2024 +0200

Change lookup_macro_def return type

Wrap the function's return type within an optional.

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc (Early::insert_once): 
Change
call site to accomodate the new return type.
(Early::visit): Likewise.
* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
Likewise.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit):
Likewise.
* util/rust-hir-map.cc (Mappings::lookup_macro_def): Change the
function's return type.
* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/resolve/rust-early-name-resolver-2.0.cc   | 25 --
 gcc/rust/resolve/rust-early-name-resolver.cc   | 17 ++-
 .../resolve/rust-toplevel-name-resolver-2.0.cc |  3 +--
 gcc/rust/util/rust-hir-map.cc  |  9 
 gcc/rust/util/rust-hir-map.h   |  2 +-
 5 files changed, 22 insertions(+), 34 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 8af4b0246792..473cdc4e317e 100644
--- a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
@@ -30,26 +30,20 @@ void
 Early::insert_once (AST::MacroInvocation &invocation, NodeId resolved)
 {
   // TODO: Should we use `ctx.mark_resolved()`?
-  AST::MacroRulesDefinition *definition;
-  auto ok = ctx.mappings.lookup_macro_def (resolved, &definition);
-
-  rust_assert (ok);
+  auto definition = ctx.mappings.lookup_macro_def (resolved);
 
   AST::MacroRulesDefinition *existing;
   auto exists = ctx.mappings.lookup_macro_invocation (invocation, &existing);
 
   if (!exists)
-ctx.mappings.insert_macro_invocation (invocation, definition);
+ctx.mappings.insert_macro_invocation (invocation, definition.value ());
 }
 
 void
 Early::insert_once (AST::MacroRulesDefinition &def)
 {
   // TODO: Should we use `ctx.mark_resolved()`?
-  AST::MacroRulesDefinition *definition;
-  auto exists = ctx.mappings.lookup_macro_def (def.get_node_id (), 
&definition);
-
-  if (!exists)
+  if (!ctx.mappings.lookup_macro_def (def.get_node_id ()))
 ctx.mappings.insert_macro_def (&def);
 }
 
@@ -176,18 +170,17 @@ Early::visit (AST::MacroInvocation &invoc)
   // now do we need to keep mappings or something? or insert "uses" into our
   // ForeverStack? can we do that? are mappings simpler?
   auto &mappings = Analysis::Mappings::get ();
-  AST::MacroRulesDefinition *rules_def = nullptr;
-  if (!mappings.lookup_macro_def (definition->get_node_id (), &rules_def))
-{
-  // Macro definition not found, maybe it is not expanded yet.
-  return;
-}
+  auto rules_def = mappings.lookup_macro_def (definition->get_node_id ());
+
+  // Macro definition not found, maybe it is not expanded yet.
+  if (!rules_def)
+return;
 
   AST::MacroRulesDefinition *tmp_def = nullptr;
   if (mappings.lookup_macro_invocation (invoc, &tmp_def))
 return;
 
-  mappings.insert_macro_invocation (invoc, rules_def);
+  mappings.insert_macro_invocation (invoc, rules_def.value ());
 }
 
 void
diff --git a/gcc/rust/resolve/rust-early-name-resolver.cc 
b/gcc/rust/resolve/rust-early-name-resolver.cc
index 83b6576fe69a..4021f5d56129 100644
--- a/gcc/rust/resolve/rust-early-name-resolver.cc
+++ b/gcc/rust/resolve/rust-early-name-resolver.cc
@@ -425,8 +425,7 @@ EarlyNameResolver::visit (AST::MacroRulesDefinition 
&rules_def)
* we could be inserting the same macro def over and over again until we
* implement some optimizations */
   // FIXME: ARTHUR: Remove that lookup and add proper optimizations instead
-  AST::MacroRulesDefinition *tmp = nullptr;
-  if (mappings.lookup_macro_def (rules_def.get_node_id (), &tmp))
+  if (mappings.lookup_macro_def (rules_def.get_node_id ()))
 return;
 
   mappings.insert_macro_def (&rules_def);
@@ -481,11 +480,9 @@ EarlyNameResolver::visit (AST::MacroInvocation &invoc)
 }
 
   // lookup the rules
-  AST::MacroRulesDefinition *rules_def = nullptr;
-  bool ok = mappings.lookup_macro_def (resolved_node, &rules_def);
-  rust_assert (ok);
+  auto rules_def = mappings.lookup_macro_def (resolved_node);
 
-  auto &outer_attrs = rules_def->get_outer_attrs ();
+  auto &outer_attrs = rules_def.value ()->get_outer_attrs ();
   bool is_builtin
 = std::any_of (outer_attrs.begin (), outer_attrs.end (),
   [] (AST::Attribute attr) {
@@ -495,12 +492,12 @@ EarlyNameResolver::visit (AST::MacroInvocation &invoc)
 
   if (is_builtin)
 {
-  auto builtin_kind
-   = builtin_macro_from_string (rules_def->get_rule_name ().as_

[gcc/devel/rust/master] Change lookup_hir_param return type with optional

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:b4927ee8b13e2f7501bc258c14f67b2b6bb42a0e

commit b4927ee8b13e2f7501bc258c14f67b2b6bb42a0e
Author: Pierre-Emmanuel Patry 
Date:   Fri May 3 20:34:58 2024 +0200

Change lookup_hir_param return type with optional

Wrap the function's return type within an optional to differentiate
between a null ppointer and a missing value.

gcc/rust/ChangeLog:

* util/rust-hir-map.cc (Mappings::insert_hir_param): Change call 
site
to accomodate new return type.
(Mappings::lookup_hir_param): Change the function's return type.
* util/rust-hir-map.h: Updat ethe function's prototype.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/util/rust-hir-map.cc | 6 +++---
 gcc/rust/util/rust-hir-map.h  | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index 3083f2c4d6f3..3fb649603739 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -632,18 +632,18 @@ void
 Mappings::insert_hir_param (HIR::FunctionParam *param)
 {
   auto id = param->get_mappings ().get_hirid ();
-  rust_assert (lookup_hir_param (id) == nullptr);
+  rust_assert (!lookup_hir_param (id));
 
   hirParamMappings[id] = param;
   insert_node_to_hir (param->get_mappings ().get_nodeid (), id);
 }
 
-HIR::FunctionParam *
+tl::optional
 Mappings::lookup_hir_param (HirId id)
 {
   auto it = hirParamMappings.find (id);
   if (it == hirParamMappings.end ())
-return nullptr;
+return tl::nullopt;
 
   return it->second;
 }
diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h
index 15b114244711..f8c3cb1809c4 100644
--- a/gcc/rust/util/rust-hir-map.h
+++ b/gcc/rust/util/rust-hir-map.h
@@ -161,7 +161,7 @@ public:
   tl::optional lookup_hir_stmt (HirId id);
 
   void insert_hir_param (HIR::FunctionParam *type);
-  HIR::FunctionParam *lookup_hir_param (HirId id);
+  tl::optional lookup_hir_param (HirId id);
 
   void insert_hir_self_param (HIR::SelfParam *type);
   HIR::SelfParam *lookup_hir_self_param (HirId id);


[gcc/devel/rust/master] Change lookup_hir_smt's return type with optional

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:0e7cff81b25b43a7a94de591ea03484e60334879

commit 0e7cff81b25b43a7a94de591ea03484e60334879
Author: Pierre-Emmanuel Patry 
Date:   Fri May 3 20:17:16 2024 +0200

Change lookup_hir_smt's return type with optional

Wrap the function's return type within an optional in order to
differentiate missing values from null pointers.

gcc/rust/ChangeLog:

* util/rust-hir-map.cc (Mappings::insert_hir_stmt): Change call site
to accomodate new return type.
(Mappings::lookup_hir_stmt): Change the function's return type.
(Mappings::resolve_nodeid_to_stmt): Adapt call site to new return 
type.
* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/util/rust-hir-map.cc | 8 
 gcc/rust/util/rust-hir-map.h  | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index de6cb4d28b91..3083f2c4d6f3 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -612,18 +612,18 @@ void
 Mappings::insert_hir_stmt (HIR::Stmt *stmt)
 {
   auto id = stmt->get_mappings ().get_hirid ();
-  rust_assert (lookup_hir_stmt (id) == nullptr);
+  rust_assert (!lookup_hir_stmt (id));
 
   hirStmtMappings[id] = stmt;
   insert_node_to_hir (stmt->get_mappings ().get_nodeid (), id);
 }
 
-HIR::Stmt *
+tl::optional
 Mappings::lookup_hir_stmt (HirId id)
 {
   auto it = hirStmtMappings.find (id);
   if (it == hirStmtMappings.end ())
-return nullptr;
+return tl::nullopt;
 
   return it->second;
 }
@@ -796,7 +796,7 @@ Mappings::resolve_nodeid_to_stmt (NodeId id)
 return tl::nullopt;
 
   HirId resolved = it->second;
-  return {lookup_hir_stmt (resolved)};
+  return lookup_hir_stmt (resolved);
 }
 
 void
diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h
index 583f63029b83..15b114244711 100644
--- a/gcc/rust/util/rust-hir-map.h
+++ b/gcc/rust/util/rust-hir-map.h
@@ -158,7 +158,7 @@ public:
   tl::optional lookup_hir_type (HirId id);
 
   void insert_hir_stmt (HIR::Stmt *stmt);
-  HIR::Stmt *lookup_hir_stmt (HirId id);
+  tl::optional lookup_hir_stmt (HirId id);
 
   void insert_hir_param (HIR::FunctionParam *type);
   HIR::FunctionParam *lookup_hir_param (HirId id);


[gcc/devel/rust/master] Change lookup_hir_self_param return type

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:1d8efec4f7b85e8d73eebe24a4667c702b7fb6f2

commit 1d8efec4f7b85e8d73eebe24a4667c702b7fb6f2
Author: Pierre-Emmanuel Patry 
Date:   Fri May 3 20:42:06 2024 +0200

Change lookup_hir_self_param return type

Wrap the function's return type within an optional in order to
differentiate null pointers from missing value.

gcc/rust/ChangeLog:

* util/rust-hir-map.cc (Mappings::insert_hir_self_param): Adapt call
site to new return type.
(Mappings::lookup_hir_self_param): Change the function's return 
type.
* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/util/rust-hir-map.cc | 6 +++---
 gcc/rust/util/rust-hir-map.h  | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index 3fb649603739..c2c75abeb801 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -652,18 +652,18 @@ void
 Mappings::insert_hir_self_param (HIR::SelfParam *param)
 {
   auto id = param->get_mappings ().get_hirid ();
-  rust_assert (lookup_hir_self_param (id) == nullptr);
+  rust_assert (!lookup_hir_self_param (id));
 
   hirSelfParamMappings[id] = param;
   insert_node_to_hir (param->get_mappings ().get_nodeid (), id);
 }
 
-HIR::SelfParam *
+tl::optional
 Mappings::lookup_hir_self_param (HirId id)
 {
   auto it = hirSelfParamMappings.find (id);
   if (it == hirSelfParamMappings.end ())
-return nullptr;
+return tl::nullopt;
 
   return it->second;
 }
diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h
index f8c3cb1809c4..7e1f644b11ec 100644
--- a/gcc/rust/util/rust-hir-map.h
+++ b/gcc/rust/util/rust-hir-map.h
@@ -164,7 +164,7 @@ public:
   tl::optional lookup_hir_param (HirId id);
 
   void insert_hir_self_param (HIR::SelfParam *type);
-  HIR::SelfParam *lookup_hir_self_param (HirId id);
+  tl::optional lookup_hir_self_param (HirId id);
 
   void insert_hir_struct_field (HIR::StructExprField *type);
   HIR::StructExprField *lookup_hir_struct_field (HirId id);


[gcc/devel/rust/master] Change lookup_hir_struct_field return type

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:e956f3a7bbf0d1e31d15bc46bd3451172a9b8869

commit e956f3a7bbf0d1e31d15bc46bd3451172a9b8869
Author: Pierre-Emmanuel Patry 
Date:   Fri May 3 20:48:10 2024 +0200

Change lookup_hir_struct_field return type

Wrap the function's return type within an optional to differentiate
between a null pointer and a missing value.

gcc/rust/ChangeLog:

* util/rust-hir-map.cc (Mappings::insert_hir_struct_field): Change
call site to accomodate new return type.
(Mappings::lookup_hir_struct_field): Change the function's return
type.
* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/util/rust-hir-map.cc | 6 +++---
 gcc/rust/util/rust-hir-map.h  | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index c2c75abeb801..1e5d3221f2eb 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -672,18 +672,18 @@ void
 Mappings::insert_hir_struct_field (HIR::StructExprField *field)
 {
   auto id = field->get_mappings ().get_hirid ();
-  rust_assert (lookup_hir_struct_field (id) == nullptr);
+  rust_assert (!lookup_hir_struct_field (id));
 
   hirStructFieldMappings[id] = field;
   insert_node_to_hir (field->get_mappings ().get_nodeid (), id);
 }
 
-HIR::StructExprField *
+tl::optional
 Mappings::lookup_hir_struct_field (HirId id)
 {
   auto it = hirStructFieldMappings.find (id);
   if (it == hirStructFieldMappings.end ())
-return nullptr;
+return tl::nullopt;
 
   return it->second;
 }
diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h
index 7e1f644b11ec..d613d7f5c59a 100644
--- a/gcc/rust/util/rust-hir-map.h
+++ b/gcc/rust/util/rust-hir-map.h
@@ -167,7 +167,7 @@ public:
   tl::optional lookup_hir_self_param (HirId id);
 
   void insert_hir_struct_field (HIR::StructExprField *type);
-  HIR::StructExprField *lookup_hir_struct_field (HirId id);
+  tl::optional lookup_hir_struct_field (HirId id);
 
   void insert_hir_pattern (HIR::Pattern *pattern);
   HIR::Pattern *lookup_hir_pattern (HirId id);


[gcc/devel/rust/master] Change lookup_hir_pattern return type

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:36518ef25d5f3d625ff9501f66d8c300f076e748

commit 36518ef25d5f3d625ff9501f66d8c300f076e748
Author: Pierre-Emmanuel Patry 
Date:   Fri May 3 20:55:01 2024 +0200

Change lookup_hir_pattern return type

Wrap the function's return type within an optional in order to
differentiate between a null pointer and a missing value.

gcc/rust/ChangeLog:

* util/rust-hir-map.cc (Mappings::insert_hir_pattern): Change call 
site
in order to accomodate new return type.
(Mappings::lookup_hir_pattern): Change the function's return type.
* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/util/rust-hir-map.cc | 6 +++---
 gcc/rust/util/rust-hir-map.h  | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index 1e5d3221f2eb..c0d9a65d393f 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -692,18 +692,18 @@ void
 Mappings::insert_hir_pattern (HIR::Pattern *pattern)
 {
   auto id = pattern->get_mappings ().get_hirid ();
-  rust_assert (lookup_hir_pattern (id) == nullptr);
+  rust_assert (!lookup_hir_pattern (id));
 
   hirPatternMappings[id] = pattern;
   insert_node_to_hir (pattern->get_mappings ().get_nodeid (), id);
 }
 
-HIR::Pattern *
+tl::optional
 Mappings::lookup_hir_pattern (HirId id)
 {
   auto it = hirPatternMappings.find (id);
   if (it == hirPatternMappings.end ())
-return nullptr;
+return tl::nullopt;
 
   return it->second;
 }
diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h
index d613d7f5c59a..86769646ee25 100644
--- a/gcc/rust/util/rust-hir-map.h
+++ b/gcc/rust/util/rust-hir-map.h
@@ -170,7 +170,7 @@ public:
   tl::optional lookup_hir_struct_field (HirId id);
 
   void insert_hir_pattern (HIR::Pattern *pattern);
-  HIR::Pattern *lookup_hir_pattern (HirId id);
+  tl::optional lookup_hir_pattern (HirId id);
 
   void walk_local_defids_for_crate (CrateNum crateNum,
std::function cb);


[gcc/devel/rust/master] Change lookup_hir_type return type with an optional

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:1746979fc55534bd8a2b26ac6d9fdf6b5fdca66e

commit 1746979fc55534bd8a2b26ac6d9fdf6b5fdca66e
Author: Pierre-Emmanuel Patry 
Date:   Fri May 3 20:08:14 2024 +0200

Change lookup_hir_type return type with an optional

Wrap the function's return type with an optional in order to tell
appart a null pointer from a missing value.

gcc/rust/ChangeLog:

* util/rust-hir-map.cc (Mappings::insert_hir_type): Change call site
to accomodate the new return type.
(Mappings::lookup_hir_type): Change the function's return type.
* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/util/rust-hir-map.cc | 6 +++---
 gcc/rust/util/rust-hir-map.h  | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index 457e8af8ef01..de6cb4d28b91 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -592,18 +592,18 @@ void
 Mappings::insert_hir_type (HIR::Type *type)
 {
   auto id = type->get_mappings ().get_hirid ();
-  rust_assert (lookup_hir_type (id) == nullptr);
+  rust_assert (!lookup_hir_type (id));
 
   hirTypeMappings[id] = type;
   insert_node_to_hir (type->get_mappings ().get_nodeid (), id);
 }
 
-HIR::Type *
+tl::optional
 Mappings::lookup_hir_type (HirId id)
 {
   auto it = hirTypeMappings.find (id);
   if (it == hirTypeMappings.end ())
-return nullptr;
+return tl::nullopt;
 
   return it->second;
 }
diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h
index 2c15097e0ce4..583f63029b83 100644
--- a/gcc/rust/util/rust-hir-map.h
+++ b/gcc/rust/util/rust-hir-map.h
@@ -155,7 +155,7 @@ public:
   tl::optional lookup_hir_generic_param (HirId id);
 
   void insert_hir_type (HIR::Type *type);
-  HIR::Type *lookup_hir_type (HirId id);
+  tl::optional lookup_hir_type (HirId id);
 
   void insert_hir_stmt (HIR::Stmt *stmt);
   HIR::Stmt *lookup_hir_stmt (HirId id);


[gcc/devel/rust/master] Corrected access specifiers

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:9ade15d37ee0b09270fe0d0fbc9b000c943f2614

commit 9ade15d37ee0b09270fe0d0fbc9b000c943f2614
Author: Kushal Pal 
Date:   Mon May 27 03:16:03 2024 +

Corrected access specifiers

gcc/rust/ChangeLog:

* ast/rust-expr.h (class OperatorExpr):
Location should be private.
* hir/tree/rust-hir-expr.h (class OperatorExpr): Likewise.

Signed-off-by: Kushal Pal 

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

diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index b990358df299..015680b2af46 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -302,7 +302,7 @@ protected:
 class OperatorExpr : public ExprWithoutBlock
 {
   // TODO: create binary and unary operator subclasses?
-public:
+private:
   location_t locus;
 
 protected:
diff --git a/gcc/rust/hir/tree/rust-hir-expr.h 
b/gcc/rust/hir/tree/rust-hir-expr.h
index 0e3e909e15ce..1a40ea537721 100644
--- a/gcc/rust/hir/tree/rust-hir-expr.h
+++ b/gcc/rust/hir/tree/rust-hir-expr.h
@@ -160,7 +160,7 @@ protected:
 class OperatorExpr : public ExprWithoutBlock
 {
   // TODO: create binary and unary operator subclasses?
-public:
+private:
   location_t locus;
 
 protected:


[gcc/devel/rust/master] Allow rustc_const_stable and rustc_const_unstable

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:646046091b703621c4ba63adb76179c11a1dbb92

commit 646046091b703621c4ba63adb76179c11a1dbb92
Author: Owen Avery 
Date:   Wed Feb 28 21:00:08 2024 -0500

Allow rustc_const_stable and rustc_const_unstable

gcc/rust/ChangeLog:

* expand/rust-macro-builtins.cc
(MacroBuiltin::builtin_transcribers):
Add entries for "rustc_const_stable" and "rustc_const_unstable".
* util/rust-attributes.cc
(__definitions): Add entries for RUSTC_CONST_STABLE and
RUSTC_CONST_UNSTABLE.
* util/rust-attribute-values.h
(Attributes::RUSTC_CONST_STABLE): New.
(Attributes::RUSTC_CONST_UNSTABLE): New.

gcc/testsuite/ChangeLog:

* rust/compile/rustc_const_stable.rs:
Enable feature rustc_attrs, expect no errors.
* rust/compile/rustc_const_unstable.rs: New test.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/expand/rust-macro-builtins.cc | 2 ++
 gcc/rust/util/rust-attribute-values.h  | 2 ++
 gcc/rust/util/rust-attributes.cc   | 5 -
 gcc/testsuite/rust/compile/rustc_const_stable.rs   | 4 +++-
 gcc/testsuite/rust/compile/rustc_const_unstable.rs | 4 
 5 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/expand/rust-macro-builtins.cc 
b/gcc/rust/expand/rust-macro-builtins.cc
index bc5bc944e772..a6816cf1603a 100644
--- a/gcc/rust/expand/rust-macro-builtins.cc
+++ b/gcc/rust/expand/rust-macro-builtins.cc
@@ -123,6 +123,8 @@ std::unordered_map
 {"test_case", MacroBuiltin::sorry},
 {"global_allocator", MacroBuiltin::sorry},
 {"cfg_accessible", MacroBuiltin::sorry},
+{"rustc_const_stable", MacroBuiltin::sorry},
+{"rustc_const_unstable", MacroBuiltin::sorry},
 /* Derive builtins do not need a real transcriber, but still need one. It
should however never be called since builtin derive macros get expanded
differently, and benefit from knowing on what kind of items they are
diff --git a/gcc/rust/util/rust-attribute-values.h 
b/gcc/rust/util/rust-attribute-values.h
index a8551c07dba6..a7eaf9ffa70c 100644
--- a/gcc/rust/util/rust-attribute-values.h
+++ b/gcc/rust/util/rust-attribute-values.h
@@ -53,6 +53,8 @@ public:
 = "rustc_inherit_overflow_checks";
   static constexpr auto &STABLE = "stable";
   static constexpr auto &UNSTABLE = "unstable";
+  static constexpr auto &RUSTC_CONST_STABLE = "rustc_const_stable";
+  static constexpr auto &RUSTC_CONST_UNSTABLE = "rustc_const_unstable";
 };
 } // namespace Values
 } // namespace Rust
diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc
index 84d1781d0b36..33166673c28a 100644
--- a/gcc/rust/util/rust-attributes.cc
+++ b/gcc/rust/util/rust-attributes.cc
@@ -61,7 +61,10 @@ static const BuiltinAttrDefinition __definitions[]
  {Attrs::RUSTC_DEPRECATED, STATIC_ANALYSIS},
  {Attrs::RUSTC_INHERIT_OVERFLOW_CHECKS, CODE_GENERATION},
  {Attrs::STABLE, STATIC_ANALYSIS},
- {Attrs::UNSTABLE, STATIC_ANALYSIS}};
+ {Attrs::UNSTABLE, STATIC_ANALYSIS},
+ // assuming we keep these for static analysis
+ {Attrs::RUSTC_CONST_STABLE, STATIC_ANALYSIS},
+ {Attrs::RUSTC_CONST_UNSTABLE, STATIC_ANALYSIS}};
 
 BuiltinAttributeMappings *
 BuiltinAttributeMappings::get ()
diff --git a/gcc/testsuite/rust/compile/rustc_const_stable.rs 
b/gcc/testsuite/rust/compile/rustc_const_stable.rs
index 9208b1ab3b62..a45355de6b37 100644
--- a/gcc/testsuite/rust/compile/rustc_const_stable.rs
+++ b/gcc/testsuite/rust/compile/rustc_const_stable.rs
@@ -1,2 +1,4 @@
+#![feature(rustc_attrs)]
+
 #[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = 
"1.47.0")]
-pub fn foo() {} // { dg-error "macro not found" "" { target *-*-* } .-1 }
+pub fn foo() {}
diff --git a/gcc/testsuite/rust/compile/rustc_const_unstable.rs 
b/gcc/testsuite/rust/compile/rustc_const_unstable.rs
new file mode 100644
index ..6cedefade720
--- /dev/null
+++ b/gcc/testsuite/rust/compile/rustc_const_unstable.rs
@@ -0,0 +1,4 @@
+#![feature(rustc_attrs)]
+
+#[rustc_const_unstable(feature = "const_ascii_ctype_on_intrinsics", issue = 
"1234")]
+pub fn foo() {}


[gcc/devel/rust/master] Remove useless cstddef header from rust-fmt

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:9ff8ac927533ea04b97349d9a8998851a75f239c

commit 9ff8ac927533ea04b97349d9a8998851a75f239c
Author: jjasmine 
Date:   Sat May 18 19:58:51 2024 -0700

Remove useless cstddef header from rust-fmt

gcc/rust/ChangeLog:

* ast/rust-fmt.h:  Remove useless cstddef header from rust-fmt

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

diff --git a/gcc/rust/ast/rust-fmt.h b/gcc/rust/ast/rust-fmt.h
index 6a0c116b841b..317db93dc1f0 100644
--- a/gcc/rust/ast/rust-fmt.h
+++ b/gcc/rust/ast/rust-fmt.h
@@ -20,7 +20,6 @@
 #define RUST_FMT_H
 
 #include "rust-system.h"
-#include 
 
 // FIXME: How to encode Option?


[gcc/devel/rust/master] Add call and method call default visitors

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:80e0560b54241dc0d1d86063f482f222e5aa9cd7

commit 80e0560b54241dc0d1d86063f482f222e5aa9cd7
Author: Owen Avery 
Date:   Wed Feb 28 20:18:14 2024 -0500

Add call and method call default visitors

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc
(DefaultResolver::visit):
New for AST::CallExpr and AST::MethodCallExpr.
* resolve/rust-default-resolver.h
(DefaultResolver::visit): Likewise.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/resolve/rust-default-resolver.cc | 30 ++
 gcc/rust/resolve/rust-default-resolver.h  |  2 ++
 2 files changed, 32 insertions(+)

diff --git a/gcc/rust/resolve/rust-default-resolver.cc 
b/gcc/rust/resolve/rust-default-resolver.cc
index ca831840298e..d9fe9eef36be 100644
--- a/gcc/rust/resolve/rust-default-resolver.cc
+++ b/gcc/rust/resolve/rust-default-resolver.cc
@@ -236,6 +236,36 @@ void
 DefaultResolver::visit (AST::ReturnExpr &expr)
 {}
 
+void
+DefaultResolver::visit (AST::CallExpr &expr)
+{
+  expr.get_function_expr ().accept_vis (*this);
+
+  for (auto ¶m : expr.get_params ())
+param->accept_vis (*this);
+}
+
+void
+DefaultResolver::visit (AST::MethodCallExpr &expr)
+{
+  expr.get_receiver_expr ().accept_vis (*this);
+
+  if (expr.get_method_name ().has_generic_args ())
+{
+  auto &args = expr.get_method_name ().get_generic_args ();
+  for (auto &arg : args.get_generic_args ())
+   arg.accept_vis (*this);
+  for (auto &arg : args.get_binding_args ())
+   if (!arg.is_error ())
+ arg.get_type ().accept_vis (*this);
+  for (auto &arg : args.get_lifetime_args ())
+   arg.accept_vis (*this);
+}
+
+  for (auto ¶m : expr.get_params ())
+param->accept_vis (*this);
+}
+
 void
 DefaultResolver::visit (AST::LoopExpr &expr)
 {}
diff --git a/gcc/rust/resolve/rust-default-resolver.h 
b/gcc/rust/resolve/rust-default-resolver.h
index 547b5376bfc8..5ae4e12f65ce 100644
--- a/gcc/rust/resolve/rust-default-resolver.h
+++ b/gcc/rust/resolve/rust-default-resolver.h
@@ -66,6 +66,8 @@ public:
   void visit (AST::RangeFromToInclExpr &);
   void visit (AST::RangeToInclExpr &);
   void visit (AST::ReturnExpr &);
+  void visit (AST::CallExpr &);
+  void visit (AST::MethodCallExpr &);
   void visit (AST::LoopExpr &);
   void visit (AST::WhileLoopExpr &);
   void visit (AST::WhileLetLoopExpr &);


[gcc/devel/rust/master] Change lookup_ast_item's return type

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:06bc336010c68d09061533a0f717ce2938236cb4

commit 06bc336010c68d09061533a0f717ce2938236cb4
Author: Pierre-Emmanuel Patry 
Date:   Sat May 4 04:10:08 2024 +0200

Change lookup_ast_item's return type

Wrap the function's return type within an optional.

gcc/rust/ChangeLog:

* metadata/rust-export-metadata.cc (ExportContext::emit_trait):
Adapt call site to the new return type.
(ExportContext::emit_function): Likewise.
(ExportContext::emit_macro): Likewise.
* util/rust-hir-map.cc (Mappings::lookup_ast_item): Change the
function's return type.
* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/metadata/rust-export-metadata.cc | 15 +--
 gcc/rust/util/rust-hir-map.cc |  9 -
 gcc/rust/util/rust-hir-map.h  |  2 +-
 3 files changed, 10 insertions(+), 16 deletions(-)

diff --git a/gcc/rust/metadata/rust-export-metadata.cc 
b/gcc/rust/metadata/rust-export-metadata.cc
index 16f94018e9d3..8fde137c763a 100644
--- a/gcc/rust/metadata/rust-export-metadata.cc
+++ b/gcc/rust/metadata/rust-export-metadata.cc
@@ -56,10 +56,8 @@ void
 ExportContext::emit_trait (const HIR::Trait &trait)
 {
   // lookup the AST node for this
-  AST::Item *item = nullptr;
-  bool ok
-= mappings.lookup_ast_item (trait.get_mappings ().get_nodeid (), &item);
-  rust_assert (ok);
+  AST::Item *item
+= mappings.lookup_ast_item (trait.get_mappings ().get_nodeid ()).value ();
 
   std::stringstream oss;
   AST::Dump dumper (oss);
@@ -72,9 +70,8 @@ void
 ExportContext::emit_function (const HIR::Function &fn)
 {
   // lookup the AST node for this
-  AST::Item *item = nullptr;
-  bool ok = mappings.lookup_ast_item (fn.get_mappings ().get_nodeid (), &item);
-  rust_assert (ok);
+  AST::Item *item
+= mappings.lookup_ast_item (fn.get_mappings ().get_nodeid ()).value ();
 
   // is this a CFG macro or not
   if (item->is_marked_for_strip ())
@@ -119,9 +116,7 @@ ExportContext::emit_macro (NodeId macro)
   std::stringstream oss;
   AST::Dump dumper (oss);
 
-  AST::Item *item;
-  auto ok = mappings.lookup_ast_item (macro, &item);
-  rust_assert (ok);
+  AST::Item *item = mappings.lookup_ast_item (macro).value ();
 
   dumper.go (*item);
 
diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index 26d24ee631f5..16a838d9c07c 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -1225,15 +1225,14 @@ Mappings::insert_ast_item (AST::Item *item)
   ast_item_mappings[item->get_node_id ()] = item;
 }
 
-bool
-Mappings::lookup_ast_item (NodeId id, AST::Item **result)
+tl::optional
+Mappings::lookup_ast_item (NodeId id)
 {
   auto it = ast_item_mappings.find (id);
   if (it == ast_item_mappings.end ())
-return false;
+return tl::nullopt;
 
-  *result = it->second;
-  return true;
+  return it->second;
 }
 
 HIR::ImplBlock *
diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h
index cc170dca4f39..c07f254a020d 100644
--- a/gcc/rust/util/rust-hir-map.h
+++ b/gcc/rust/util/rust-hir-map.h
@@ -345,7 +345,7 @@ public:
   bool node_is_module (NodeId query);
 
   void insert_ast_item (AST::Item *item);
-  bool lookup_ast_item (NodeId id, AST::Item **result);
+  tl::optional lookup_ast_item (NodeId id);
 
   HIR::ImplBlock *lookup_builtin_marker ();


[gcc/devel/rust/master] Add system include to `gcc/rust/rust-system.h`

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:219cea788152068895ece969d0462c7b6a102a69

commit 219cea788152068895ece969d0462c7b6a102a69
Author: SIGMazer 
Date:   Tue Apr 23 17:33:17 2024 +0200

Add system include to `gcc/rust/rust-system.h`

gcc/rust/ChangeLog:

* rust-system.h: Add system include 

Signed-off-by: SIGMazer 

Diff:
---
 gcc/rust/rust-system.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/rust/rust-system.h b/gcc/rust/rust-system.h
index 2382e5b1fb4e..5c260ee9944d 100644
--- a/gcc/rust/rust-system.h
+++ b/gcc/rust/rust-system.h
@@ -46,6 +46,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 


[gcc/devel/rust/master] Add dropck_eyepatch feature gate for may_dangle

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:85967c878147b3dc77f969f18adddfe2d5c3676d

commit 85967c878147b3dc77f969f18adddfe2d5c3676d
Author: Pierre-Emmanuel Patry 
Date:   Mon May 20 13:26:43 2024 +0200

Add dropck_eyepatch feature gate for may_dangle

Add a new feature gate for may_dangle generic param outer attributes.

gcc/rust/ChangeLog:

* checks/errors/rust-feature-gate.cc: Visit and gate may_dangle
attributes.
* checks/errors/rust-feature-gate.h: Update visit function prototype
and add a new member function to check on a set of attributes 
whether
one is may_dangle.
* checks/errors/rust-feature.cc (Feature::create): Add new
dropck_eyepatch feature.
* checks/errors/rust-feature.h: Likewise.
* util/rust-attribute-values.h: Add new may_dangle attribute value.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/checks/errors/rust-feature-gate.cc | 37 +
 gcc/rust/checks/errors/rust-feature-gate.h  |  8 ---
 gcc/rust/checks/errors/rust-feature.cc  |  4 
 gcc/rust/checks/errors/rust-feature.h   |  1 +
 gcc/rust/util/rust-attribute-values.h   |  1 +
 5 files changed, 48 insertions(+), 3 deletions(-)

diff --git a/gcc/rust/checks/errors/rust-feature-gate.cc 
b/gcc/rust/checks/errors/rust-feature-gate.cc
index 33b038745cc1..847122f70d98 100644
--- a/gcc/rust/checks/errors/rust-feature-gate.cc
+++ b/gcc/rust/checks/errors/rust-feature-gate.cc
@@ -18,6 +18,7 @@
 
 #include "rust-feature-gate.h"
 #include "rust-abi.h"
+#include "rust-attribute-values.h"
 #include "rust-ast-visitor.h"
 #include "rust-feature.h"
 
@@ -123,6 +124,19 @@ FeatureGate::check_rustc_attri (const 
std::vector &attributes)
 }
 }
 
+void
+FeatureGate::check_may_dangle_attribute (
+  const std::vector &attributes)
+{
+  for (const AST::Attribute &attr : attributes)
+{
+  if (attr.get_path ().as_string () == Values::Attributes::MAY_DANGLE)
+   gate (Feature::Name::DROPCK_EYEPATCH, attr.get_locus (),
+ "`may_dangle` has unstable semantics and may be removed in the "
+ "future");
+}
+}
+
 void
 FeatureGate::visit (AST::MacroRulesDefinition &rules_def)
 {
@@ -153,6 +167,8 @@ FeatureGate::visit (AST::TraitImpl &impl)
   if (impl.is_exclam ())
 gate (Feature::Name::NEGATIVE_IMPLS, impl.get_locus (),
  "negative_impls are not yet implemented");
+
+  AST::DefaultASTVisitor::visit (impl);
 };
 
 void
@@ -164,4 +180,25 @@ FeatureGate::visit (AST::BoxExpr &expr)
   AST::DefaultASTVisitor::visit (expr);
 }
 
+void
+FeatureGate::visit (AST::LifetimeParam &lifetime_param)
+{
+  check_may_dangle_attribute (lifetime_param.get_outer_attrs ());
+  AST::DefaultASTVisitor::visit (lifetime_param);
+}
+
+void
+FeatureGate::visit (AST::ConstGenericParam &const_param)
+{
+  check_may_dangle_attribute (const_param.get_outer_attrs ());
+  AST::DefaultASTVisitor::visit (const_param);
+}
+
+void
+FeatureGate::visit (AST::TypeParam ¶m)
+{
+  check_may_dangle_attribute (param.get_outer_attrs ());
+  AST::DefaultASTVisitor::visit (param);
+}
+
 } // namespace Rust
diff --git a/gcc/rust/checks/errors/rust-feature-gate.h 
b/gcc/rust/checks/errors/rust-feature-gate.h
index aa90ae2092b9..5801c0d5da77 100644
--- a/gcc/rust/checks/errors/rust-feature-gate.h
+++ b/gcc/rust/checks/errors/rust-feature-gate.h
@@ -40,8 +40,8 @@ public:
   void visit (AST::AttrInputMetaItemContainer &input) override {}
   void visit (AST::IdentifierExpr &ident_expr) override {}
   void visit (AST::Lifetime &lifetime) override {}
-  void visit (AST::LifetimeParam &lifetime_param) override {}
-  void visit (AST::ConstGenericParam &const_param) override {}
+  void visit (AST::LifetimeParam &lifetime_param) override;
+  void visit (AST::ConstGenericParam &const_param) override;
   void visit (AST::PathInExpression &path) override {}
   void visit (AST::TypePathSegment &segment) override {}
   void visit (AST::TypePathSegmentGeneric &segment) override {}
@@ -104,7 +104,7 @@ public:
   void visit (AST::MatchExpr &expr) override {}
   void visit (AST::AwaitExpr &expr) override {}
   void visit (AST::AsyncBlockExpr &expr) override {}
-  void visit (AST::TypeParam ¶m) override {}
+  void visit (AST::TypeParam ¶m) override;
   void visit (AST::LifetimeWhereClauseItem &item) override {}
   void visit (AST::TypeBoundWhereClauseItem &item) override {}
   void visit (AST::Module &module) override {}
@@ -188,6 +188,8 @@ public:
 private:
   void gate (Feature::Name name, location_t loc, const std::string &error_msg);
   void check_rustc_attri (const std::vector &attributes);
+  void
+  check_may_dangle_attribute (const std::vector &attributes);
   std::set valid_features;
 };
 } // namespace Rust
diff --git a/gcc/rust/checks/errors/rust-feature.cc 
b/gcc/rust/checks/errors/rust-feature.cc
index 18cfa33e1e56..0af3209e338f 100644
--- a/gcc/rust/checks/errors/rust-feature.cc
+++ b/gcc/rust/c

[gcc/devel/rust/master] Add outer attributes to struct expr fields

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:8de769bfc570c2fe6392f54092aaf17b90e22813

commit 8de769bfc570c2fe6392f54092aaf17b90e22813
Author: Pierre-Emmanuel Patry 
Date:   Mon May 20 15:28:19 2024 +0200

Add outer attributes to struct expr fields

Struct fields can have outer attributes on their field for various
purpose, this behavior should be reflected upon struct expr fields.

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): Output field
attributes.
* ast/rust-expr.h (class StructExprField): Add outer attributes 
member.
* parse/rust-parse-impl.h (Parser::parse_struct_expr_field): Parse
outer attributes and store them in the appropriate AST node.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/ast/rust-ast-collector.cc |  9 +++-
 gcc/rust/ast/rust-expr.h   | 44 +-
 gcc/rust/parse/rust-parse-impl.h   |  5 +
 3 files changed, 42 insertions(+), 16 deletions(-)

diff --git a/gcc/rust/ast/rust-ast-collector.cc 
b/gcc/rust/ast/rust-ast-collector.cc
index f0d743840ed8..6e60ea376103 100644
--- a/gcc/rust/ast/rust-ast-collector.cc
+++ b/gcc/rust/ast/rust-ast-collector.cc
@@ -1099,8 +1099,7 @@ TokenCollector::visit (StructExprStruct &expr)
 void
 TokenCollector::visit (StructExprFieldIdentifier &expr)
 {
-  // TODO: Add attributes
-  // visit_items_as_lines (expr.get_attrs ());
+  visit_items_as_lines (expr.get_outer_attrs ());
   auto id = expr.get_field_name ().as_string ();
   push (Rust::Token::make_identifier (expr.get_locus (), std::move (id)));
 }
@@ -1108,8 +1107,7 @@ TokenCollector::visit (StructExprFieldIdentifier &expr)
 void
 TokenCollector::visit (StructExprFieldIdentifierValue &expr)
 {
-  // TODO: Add attributes
-  // visit_items_as_lines (expr.get_attrs ());
+  visit_items_as_lines (expr.get_outer_attrs ());
   auto id = expr.get_field_name ();
   push (Rust::Token::make_identifier (expr.get_locus (), std::move (id)));
   push (Rust::Token::make (COLON, UNDEF_LOCATION));
@@ -1119,8 +1117,7 @@ TokenCollector::visit (StructExprFieldIdentifierValue 
&expr)
 void
 TokenCollector::visit (StructExprFieldIndexValue &expr)
 {
-  // TODO: Add attributes
-  // visit_items_as_lines (expr.get_attrs ());
+  visit_items_as_lines (expr.get_outer_attrs ());
   push (Rust::Token::make_int (expr.get_locus (),
   std::to_string (expr.get_index (;
   push (Rust::Token::make (COLON, UNDEF_LOCATION));
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index c3b93d4dc0d2..50c0cb146ed8 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -1758,6 +1758,13 @@ public:
 
   NodeId get_node_id () const { return node_id; }
 
+  const std::vector &get_outer_attrs () const
+  {
+return outer_attrs;
+  }
+
+  std::vector &get_outer_attrs () { return outer_attrs; }
+
 protected:
   // pure virtual clone implementation
   virtual StructExprField *clone_struct_expr_field_impl () const = 0;
@@ -1765,6 +1772,12 @@ protected:
   StructExprField () : node_id (Analysis::Mappings::get ().get_next_node_id ())
   {}
 
+  StructExprField (AST::AttrVec outer_attrs)
+: outer_attrs (std::move (outer_attrs)),
+  node_id (Analysis::Mappings::get ().get_next_node_id ())
+  {}
+
+  AST::AttrVec outer_attrs;
   NodeId node_id;
 };
 
@@ -1775,9 +1788,10 @@ class StructExprFieldIdentifier : public StructExprField
   location_t locus;
 
 public:
-  StructExprFieldIdentifier (Identifier field_identifier, location_t locus)
-: StructExprField (), field_name (std::move (field_identifier)),
-  locus (locus)
+  StructExprFieldIdentifier (Identifier field_identifier,
+AST::AttrVec outer_attrs, location_t locus)
+: StructExprField (std::move (outer_attrs)),
+  field_name (std::move (field_identifier)), locus (locus)
   {}
 
   std::string as_string () const override { return field_name.as_string (); }
@@ -1804,19 +1818,22 @@ class StructExprFieldWithVal : public StructExprField
   std::unique_ptr value;
 
 protected:
-  StructExprFieldWithVal (std::unique_ptr field_value)
-: StructExprField (), value (std::move (field_value))
+  StructExprFieldWithVal (std::unique_ptr field_value,
+ AST::AttrVec outer_attrs)
+: StructExprField (std::move (outer_attrs)), value (std::move 
(field_value))
   {}
 
   // Copy constructor requires clone
   StructExprFieldWithVal (StructExprFieldWithVal const &other)
-: value (other.value->clone_expr ())
+: StructExprField (other.get_outer_attrs ()),
+  value (other.value->clone_expr ())
   {}
 
   // Overload assignment operator to clone unique_ptr
   StructExprFieldWithVal &operator= (StructExprFieldWithVal const &other)
   {
 value = other.value->clone_expr ();
+outer_attrs = other.get_outer_attrs ();
 
 return *this;
   }
@@ -1843,10 +1860,17 @@ class StructExprFieldIdentifierValue : public 
St

[gcc/devel/rust/master] Add feature gate for box syntax

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:ca178958c4bb599da331f62cc5cc8a480ea5371e

commit ca178958c4bb599da331f62cc5cc8a480ea5371e
Author: Pierre-Emmanuel Patry 
Date:   Sun May 19 02:44:42 2024 +0200

Add feature gate for box syntax

The box syntax is experimental even though it is used in the standard
library. It should be feature gated to prevent anyone from using it in
stable rust.

gcc/rust/ChangeLog:

* checks/errors/rust-feature-gate.cc (FeatureGate::visit): Allow
visitor recursion in functions. Also add the gate for the box 
syntax.
* checks/errors/rust-feature-gate.h: Remove several recursion fences
in the feature gate visitor.
* checks/errors/rust-feature.cc (Feature::create): Add a new 
feature.
(Feature::as_name): Likewise.
* checks/errors/rust-feature.h: Add box_syntax gate.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/checks/errors/rust-feature-gate.cc | 11 +++
 gcc/rust/checks/errors/rust-feature-gate.h  |  3 +--
 gcc/rust/checks/errors/rust-feature.cc  |  6 +-
 gcc/rust/checks/errors/rust-feature.h   |  3 ++-
 4 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/checks/errors/rust-feature-gate.cc 
b/gcc/rust/checks/errors/rust-feature-gate.cc
index eb23192e11fe..33b038745cc1 100644
--- a/gcc/rust/checks/errors/rust-feature-gate.cc
+++ b/gcc/rust/checks/errors/rust-feature-gate.cc
@@ -134,6 +134,8 @@ FeatureGate::visit (AST::Function &function)
 {
   if (!function.is_external ())
 check_rustc_attri (function.get_outer_attrs ());
+
+  AST::DefaultASTVisitor::visit (function);
 }
 
 void
@@ -153,4 +155,13 @@ FeatureGate::visit (AST::TraitImpl &impl)
  "negative_impls are not yet implemented");
 };
 
+void
+FeatureGate::visit (AST::BoxExpr &expr)
+{
+  gate (
+Feature::Name::BOX_SYNTAX, expr.get_locus (),
+"box expression syntax is experimental; you can call `Box::new` instead");
+  AST::DefaultASTVisitor::visit (expr);
+}
+
 } // namespace Rust
diff --git a/gcc/rust/checks/errors/rust-feature-gate.h 
b/gcc/rust/checks/errors/rust-feature-gate.h
index d7c84a5b72e5..aa90ae2092b9 100644
--- a/gcc/rust/checks/errors/rust-feature-gate.h
+++ b/gcc/rust/checks/errors/rust-feature-gate.h
@@ -81,7 +81,6 @@ public:
   void visit (AST::MethodCallExpr &expr) override {}
   void visit (AST::FieldAccessExpr &expr) override {}
   void visit (AST::ClosureExprInner &expr) override {}
-  void visit (AST::BlockExpr &expr) override {}
   void visit (AST::ClosureExprInnerTyped &expr) override {}
   void visit (AST::ContinueExpr &expr) override {}
   void visit (AST::BreakExpr &expr) override {}
@@ -92,6 +91,7 @@ public:
   void visit (AST::RangeFromToInclExpr &expr) override {}
   void visit (AST::RangeToInclExpr &expr) override {}
   void visit (AST::ReturnExpr &expr) override {}
+  void visit (AST::BoxExpr &expr) override;
   void visit (AST::UnsafeBlockExpr &expr) override {}
   void visit (AST::LoopExpr &expr) override {}
   void visit (AST::WhileLoopExpr &expr) override {}
@@ -166,7 +166,6 @@ public:
   void visit (AST::SlicePattern &pattern) override {}
   void visit (AST::AltPattern &pattern) override {}
   void visit (AST::EmptyStmt &stmt) override {}
-  void visit (AST::LetStmt &stmt) override {}
   void visit (AST::ExprStmt &stmt) override {}
   void visit (AST::TraitBound &bound) override {}
   void visit (AST::ImplTraitType &type) override {}
diff --git a/gcc/rust/checks/errors/rust-feature.cc 
b/gcc/rust/checks/errors/rust-feature.cc
index 62497585575c..18cfa33e1e56 100644
--- a/gcc/rust/checks/errors/rust-feature.cc
+++ b/gcc/rust/checks/errors/rust-feature.cc
@@ -45,6 +45,9 @@ Feature::create (Feature::Name name)
 case Feature::Name::NEGATIVE_IMPLS:
   return Feature (Feature::Name::NEGATIVE_IMPLS, Feature::State::ACTIVE,
  "negative_impls", "1.0.0", 68318, tl::nullopt, "");
+case Feature::Name::BOX_SYNTAX:
+  return Feature (Feature::Name::BOX_SYNTAX, Feature::State::ACTIVE,
+ "box_syntax", "1.0.0", 49733, tl::nullopt, "");
 default:
   rust_unreachable ();
 }
@@ -62,6 +65,7 @@ const std::map 
Feature::name_hash_map = {
   {"extern_types", Feature::Name::EXTERN_TYPES},
   {"lang_items", Feature::Name::LANG_ITEMS},
   {"no_core", Feature::Name::NO_CORE},
+  {"box_syntax", Feature::Name::BOX_SYNTAX},
 }; // namespace Rust
 
 tl::optional
@@ -73,4 +77,4 @@ Feature::as_name (const std::string &name)
   return tl::nullopt;
 }
 
-} // namespace Rust
\ No newline at end of file
+} // namespace Rust
diff --git a/gcc/rust/checks/errors/rust-feature.h 
b/gcc/rust/checks/errors/rust-feature.h
index 306baf283981..238bf0792dca 100644
--- a/gcc/rust/checks/errors/rust-feature.h
+++ b/gcc/rust/checks/errors/rust-feature.h
@@ -46,6 +46,7 @@ public:
 EXTERN_TYPES,
 LANG_ITEMS,
 NO_CORE,
+BOX_SYNTAX,
   };
 
   const std::string &as_string () { return m_nam

[gcc/devel/rust/master] Allow multiple outer attributes on generic params

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:2a1e169956f9faa13928eda3f146ea0cc770b864

commit 2a1e169956f9faa13928eda3f146ea0cc770b864
Author: Pierre-Emmanuel Patry 
Date:   Mon May 20 12:00:11 2024 +0200

Allow multiple outer attributes on generic params

Previously generic params only allowed one outer attribute in front of
them.

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): Visit outer
attributes.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Change outer
attribute visit, we need to visit all of them.
* ast/rust-ast.cc (LifetimeParam::as_string): Change as_string
implementation to allow multiple outer attributes.
(TypeParam::as_string): Likewise.
* ast/rust-ast.h (class LifetimeParam): Allow multiple outer
attributes.
* ast/rust-item.h (class TypeParam): Likewise.
* ast/rust-path.h: Likewise.
* parse/rust-parse-impl.h (Parser::parse_generic_param): Change call
to outer attribute parsing to collect several attributes.
(Parser::parse_lifetime_param): Likewise.
(Parser::parse_type_param): Likewise.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/ast/rust-ast-collector.cc |  3 +++
 gcc/rust/ast/rust-ast-visitor.cc   |  6 +++---
 gcc/rust/ast/rust-ast.cc   | 12 ++--
 gcc/rust/ast/rust-ast.h| 13 ++---
 gcc/rust/ast/rust-item.h   | 14 +++---
 gcc/rust/ast/rust-path.h   | 10 +-
 gcc/rust/parse/rust-parse-impl.h   | 14 +++---
 7 files changed, 37 insertions(+), 35 deletions(-)

diff --git a/gcc/rust/ast/rust-ast-collector.cc 
b/gcc/rust/ast/rust-ast-collector.cc
index c0f4884f3c98..f0d743840ed8 100644
--- a/gcc/rust/ast/rust-ast-collector.cc
+++ b/gcc/rust/ast/rust-ast-collector.cc
@@ -476,6 +476,7 @@ TokenCollector::visit (LifetimeParam &lifetime_param)
 
   // TODO what to do with outer attr? They are not mentioned in the reference.
 
+  visit_items_as_lines (lifetime_param.get_outer_attrs ());
   auto lifetime = lifetime_param.get_lifetime ();
   visit (lifetime);
 
@@ -495,6 +496,7 @@ TokenCollector::visit (ConstGenericParam ¶m)
   // Syntax:
   // const IDENTIFIER : Type ( = Block | IDENTIFIER | -?LITERAL )?
 
+  visit_items_as_lines (param.get_outer_attrs ());
   push (Rust::Token::make (CONST, param.get_locus ()));
   auto id = param.get_name ().as_string ();
   push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (id)));
@@ -1509,6 +1511,7 @@ TokenCollector::visit (TypeParam ¶m)
   // TypeParamBounds :
   //TypeParamBound ( + TypeParamBound )* +?
 
+  visit_items_as_lines (param.get_outer_attrs ());
   auto id = param.get_type_representation ().as_string ();
   push (Rust::Token::make_identifier (param.get_locus (), std::move (id)));
   if (param.has_type_param_bounds ())
diff --git a/gcc/rust/ast/rust-ast-visitor.cc b/gcc/rust/ast/rust-ast-visitor.cc
index c9ccbfc2ceff..65a92bbf1e70 100644
--- a/gcc/rust/ast/rust-ast-visitor.cc
+++ b/gcc/rust/ast/rust-ast-visitor.cc
@@ -69,7 +69,7 @@ DefaultASTVisitor::visit (AST::Lifetime &lifetime)
 void
 DefaultASTVisitor::visit (AST::LifetimeParam &lifetime_param)
 {
-  visit (lifetime_param.get_outer_attribute ());
+  visit_outer_attrs (lifetime_param);
   visit (lifetime_param.get_lifetime ());
   for (auto &lifetime_bound : lifetime_param.get_lifetime_bounds ())
 visit (lifetime_bound);
@@ -78,7 +78,7 @@ DefaultASTVisitor::visit (AST::LifetimeParam &lifetime_param)
 void
 DefaultASTVisitor::visit (AST::ConstGenericParam &const_param)
 {
-  visit (const_param.get_outer_attribute ());
+  visit_outer_attrs (const_param);
   if (const_param.has_type ())
 visit (const_param.get_type ());
   if (const_param.has_default_value ())
@@ -665,7 +665,7 @@ DefaultASTVisitor::visit (AST::AsyncBlockExpr &expr)
 void
 DefaultASTVisitor::visit (AST::TypeParam ¶m)
 {
-  visit (param.get_outer_attribute ());
+  visit_outer_attrs (param);
   for (auto &bound : param.get_type_param_bounds ())
 visit (bound);
   if (param.has_type ())
diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc
index 4e6e1668f5fe..9ecbd686a835 100644
--- a/gcc/rust/ast/rust-ast.cc
+++ b/gcc/rust/ast/rust-ast.cc
@@ -2399,11 +2399,11 @@ LifetimeParam::as_string () const
 {
   std::string str ("LifetimeParam: ");
 
-  str += "\n Outer attribute: ";
+  str += "\n Outer attribute:";
   if (!has_outer_attribute ())
 str += "none";
-  else
-str += outer_attr.as_string ();
+  for (auto &attr : outer_attrs)
+str += " " + attr.as_string ();
 
   str += "\n Lifetime: " + lifetime.as_string ();
 
@@ -2495,11 +2495,11 @@ TypeParam::as_string () const
 {
   std::string str ("TypeParam: ");
 
-  str += "\n Outer attribute: ";
+  str += "\n Outer attribute:";
   if (!has_outer_attribute ())
 str += "none";
-  else
-str += outer_attr.as_string ();
+  for (aut

[gcc/devel/rust/master] Improve handling of ConstantItem during name resolution 2.0

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:75049a3bfee8c3f888994bce3b741a805c631c2a

commit 75049a3bfee8c3f888994bce3b741a805c631c2a
Author: Owen Avery 
Date:   Wed Feb 28 20:19:04 2024 -0500

Improve handling of ConstantItem during name resolution 2.0

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc
(DefaultResolver::visit):
Scope with Rib::Kind::ConstantItem instead
of Rib::Kind::Item.
* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Remove redundancy in override of
ConstantItem visitor.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/resolve/rust-default-resolver.cc   | 2 +-
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc | 5 +
 2 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/gcc/rust/resolve/rust-default-resolver.cc 
b/gcc/rust/resolve/rust-default-resolver.cc
index d9fe9eef36be..8138a8949004 100644
--- a/gcc/rust/resolve/rust-default-resolver.cc
+++ b/gcc/rust/resolve/rust-default-resolver.cc
@@ -487,7 +487,7 @@ DefaultResolver::visit (AST::ConstantItem &item)
   };
 
   // FIXME: Why do we need a Rib here?
-  ctx.scoped (Rib::Kind::Item, item.get_node_id (), expr_vis);
+  ctx.scoped (Rib::Kind::ConstantItem, item.get_node_id (), expr_vis);
 }
 }
 
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 b991145c4d4a..6524a303061b 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -424,10 +424,7 @@ TopLevel::visit (AST::ConstantItem &const_item)
   insert_or_error_out (const_item.get_identifier (), const_item,
   Namespace::Values);
 
-  auto expr_vis
-= [this, &const_item] () { const_item.get_expr ().accept_vis (*this); };
-
-  ctx.scoped (Rib::Kind::ConstantItem, const_item.get_node_id (), expr_vis);
+  DefaultResolver::visit (const_item);
 }
 
 bool


[gcc/devel/rust/master] Add two new tests related to may_dangle attribute

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:14c4c2f142d1908e8e93aa15d49f61f97f060727

commit 14c4c2f142d1908e8e93aa15d49f61f97f060727
Author: Pierre-Emmanuel Patry 
Date:   Mon May 20 13:29:51 2024 +0200

Add two new tests related to may_dangle attribute

First test checks the may_dangle outer atttribute on generic params can
be parsed. The second one tests whether may_dangle attributes are
correctly feature gated.

gcc/testsuite/ChangeLog:

* rust/compile/dropck_eyepatch_feature_gate.rs: New test.
* rust/compile/may_dangle.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/testsuite/rust/compile/dropck_eyepatch_feature_gate.rs |  8 
 gcc/testsuite/rust/compile/may_dangle.rs   | 10 ++
 2 files changed, 18 insertions(+)

diff --git a/gcc/testsuite/rust/compile/dropck_eyepatch_feature_gate.rs 
b/gcc/testsuite/rust/compile/dropck_eyepatch_feature_gate.rs
new file mode 100644
index ..3c3174f93bba
--- /dev/null
+++ b/gcc/testsuite/rust/compile/dropck_eyepatch_feature_gate.rs
@@ -0,0 +1,8 @@
+// { dg-options "-frust-compile-until=lowering" }
+struct Test {
+_inner: T,
+}
+
+trait Action {}
+
+unsafe impl<#[may_dangle] T> Action for Test {} //{ dg-error ".may_dangle. 
has unstable semantics and may be removed in the future." "" { target *-*-* }  }
diff --git a/gcc/testsuite/rust/compile/may_dangle.rs 
b/gcc/testsuite/rust/compile/may_dangle.rs
new file mode 100644
index ..6b81b53aa596
--- /dev/null
+++ b/gcc/testsuite/rust/compile/may_dangle.rs
@@ -0,0 +1,10 @@
+// { dg-options "-fsyntax-only" }
+
+#![feature(dropck_eyepatch)]
+struct Test {
+_inner: T,
+}
+
+trait Action {}
+
+unsafe impl<#[may_dangle] T> Action for Test {}


[gcc/devel/rust/master] Parse box expressions

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:32ccdf41a087e1027e4ba26cbe71c39d9e44b4d3

commit 32ccdf41a087e1027e4ba26cbe71c39d9e44b4d3
Author: Pierre-Emmanuel Patry 
Date:   Sat May 18 23:53:42 2024 +0200

Parse box expressions

Add support for old box expression syntax.

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): Add visit 
member
function for BoxExpr nodes.
* ast/rust-ast-collector.h: Add visit function prototype.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Add visit 
member
function to default ast visitor.
* ast/rust-ast-visitor.h: Add visit function's prototype.
* ast/rust-ast.cc (BoxExpr::as_string): Add as_string function
implementation for BoxExpr.
(BoxExpr::accept_vis): Add accept_vis implementation to BoxExpr.
* ast/rust-expr.h (class BoxExpr): Add BoxExpr class to represent 
boxed
expressions.
* expand/rust-derive.h: Add BoxExpr visit function prototype.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Add BoxExpr
visitor implementation.
* hir/rust-ast-lower-base.h: Add visit function's prototype.
* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Add BoxExpr
visitor implementation.
* hir/rust-ast-lower-expr.h: Add visit function's prototype.
* parse/rust-parse-impl.h (Parser::parse_box_expr): Add 
parse_box_expr
function's implementation.
* parse/rust-parse.h: Add parse_box_expr function's prototype.
* resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Add 
resolver
visit implementation.
* resolve/rust-ast-resolve-base.h: Add resolver's visit function
prototype.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/ast/rust-ast-collector.cc|  8 
 gcc/rust/ast/rust-ast-collector.h |  1 +
 gcc/rust/ast/rust-ast-visitor.cc  |  7 +++
 gcc/rust/ast/rust-ast-visitor.h   |  2 +
 gcc/rust/ast/rust-ast.cc  | 12 +
 gcc/rust/ast/rust-expr.h  | 73 +++
 gcc/rust/expand/rust-derive.h |  1 +
 gcc/rust/hir/rust-ast-lower-base.cc   |  5 +++
 gcc/rust/hir/rust-ast-lower-base.h|  1 +
 gcc/rust/hir/rust-ast-lower-expr.cc   |  8 
 gcc/rust/hir/rust-ast-lower-expr.h|  1 +
 gcc/rust/parse/rust-parse-impl.h  | 23 ++
 gcc/rust/parse/rust-parse.h   |  3 ++
 gcc/rust/resolve/rust-ast-resolve-base.cc |  4 ++
 gcc/rust/resolve/rust-ast-resolve-base.h  |  1 +
 15 files changed, 150 insertions(+)

diff --git a/gcc/rust/ast/rust-ast-collector.cc 
b/gcc/rust/ast/rust-ast-collector.cc
index a2cb506805be..c0f4884f3c98 100644
--- a/gcc/rust/ast/rust-ast-collector.cc
+++ b/gcc/rust/ast/rust-ast-collector.cc
@@ -20,6 +20,7 @@
 #include "rust-diagnostics.h"
 #include "rust-item.h"
 #include "rust-keyword-values.h"
+#include "rust-token.h"
 
 namespace Rust {
 namespace AST {
@@ -1315,6 +1316,13 @@ TokenCollector::visit (RangeToInclExpr &expr)
   visit (expr.get_to_expr ());
 }
 
+void
+TokenCollector::visit (BoxExpr &expr)
+{
+  push (Rust::Token::make (BOX, expr.get_locus ()));
+  visit (expr.get_boxed_expr ());
+}
+
 void
 TokenCollector::visit (ReturnExpr &expr)
 {
diff --git a/gcc/rust/ast/rust-ast-collector.h 
b/gcc/rust/ast/rust-ast-collector.h
index fdc99bb70860..2873053c5f52 100644
--- a/gcc/rust/ast/rust-ast-collector.h
+++ b/gcc/rust/ast/rust-ast-collector.h
@@ -288,6 +288,7 @@ public:
   void visit (RangeFromToInclExpr &expr);
   void visit (RangeToInclExpr &expr);
   void visit (ReturnExpr &expr);
+  void visit (BoxExpr &expr);
   void visit (UnsafeBlockExpr &expr);
   void visit (LoopExpr &expr);
   void visit (WhileLoopExpr &expr);
diff --git a/gcc/rust/ast/rust-ast-visitor.cc b/gcc/rust/ast/rust-ast-visitor.cc
index de4242afeb55..c9ccbfc2ceff 100644
--- a/gcc/rust/ast/rust-ast-visitor.cc
+++ b/gcc/rust/ast/rust-ast-visitor.cc
@@ -531,6 +531,13 @@ DefaultASTVisitor::visit (AST::ReturnExpr &expr)
 visit (expr.get_returned_expr ());
 }
 
+void
+DefaultASTVisitor::visit (AST::BoxExpr &expr)
+{
+  visit_outer_attrs (expr);
+  visit (expr.get_boxed_expr ());
+}
+
 void
 DefaultASTVisitor::visit (AST::UnsafeBlockExpr &expr)
 {
diff --git a/gcc/rust/ast/rust-ast-visitor.h b/gcc/rust/ast/rust-ast-visitor.h
index 622e7f766a38..2bc58d57a9c6 100644
--- a/gcc/rust/ast/rust-ast-visitor.h
+++ b/gcc/rust/ast/rust-ast-visitor.h
@@ -112,6 +112,7 @@ public:
   virtual void visit (RangeFromToInclExpr &expr) = 0;
   virtual void visit (RangeToInclExpr &expr) = 0;
   virtual void visit (ReturnExpr &expr) = 0;
+  virtual void visit (BoxExpr &expr) = 0;
   virtual void visit (UnsafeBlockExpr &expr) = 0;
   virtual void visit (LoopExpr &expr) = 0;
   virtual void visit (WhileLoopExpr &expr) = 0;
@@ -297,6 +298,

[gcc/devel/rust/master] Fix generic parameter parsing

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:50862befdb2c33ad6b71f0c4c8ce3d455c92cffd

commit 50862befdb2c33ad6b71f0c4c8ce3d455c92cffd
Author: Pierre-Emmanuel Patry 
Date:   Mon May 20 11:02:53 2024 +0200

Fix generic parameter parsing

Generic parameter parsing failed when an outer attribute was used on it.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_generic_param): Change 
token
reference to be the last token after all outer attributes have been
parsed.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/parse/rust-parse-impl.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index e22ad6d3c7c8..b501c8ecc8bd 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -3093,9 +3093,9 @@ template 
 std::unique_ptr
 Parser::parse_generic_param (EndTokenPred is_end_token)
 {
-  auto token = lexer.peek_token ();
   auto outer_attrs = parse_outer_attribute ();
   std::unique_ptr param;
+  auto token = lexer.peek_token ();
 
   switch (token->get_id ())
 {


[gcc/devel/rust/master] Make gccrs recognize negative_impls

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:84666c6eecc0d32019f03169b2ba242ead1e2d49

commit 84666c6eecc0d32019f03169b2ba242ead1e2d49
Author: jjasmine 
Date:   Wed May 15 12:44:15 2024 -0700

Make gccrs recognize negative_impls

gcc/rust/ChangeLog:

* checks/errors/rust-feature-gate.cc (FeatureGate::visit): make
gccrs recognize negative_impls
* checks/errors/rust-feature-gate.h: likewise.
* checks/errors/rust-feature.cc (Feature::create): likewise.
* checks/errors/rust-feature.h: likewise.

gcc/testsuite/ChangeLog:

* rust/compile/negative_impls.rs: New test.
* rust/compile/negative_impls_2.rs: New test.

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 |  4 
 gcc/rust/checks/errors/rust-feature.h  |  1 +
 gcc/testsuite/rust/compile/negative_impls.rs   |  8 
 gcc/testsuite/rust/compile/negative_impls_2.rs | 16 
 6 files changed, 39 insertions(+)

diff --git a/gcc/rust/checks/errors/rust-feature-gate.cc 
b/gcc/rust/checks/errors/rust-feature-gate.cc
index 33bbfa1ec51b..eb23192e11fe 100644
--- a/gcc/rust/checks/errors/rust-feature-gate.cc
+++ b/gcc/rust/checks/errors/rust-feature-gate.cc
@@ -19,6 +19,7 @@
 #include "rust-feature-gate.h"
 #include "rust-abi.h"
 #include "rust-ast-visitor.h"
+#include "rust-feature.h"
 
 namespace Rust {
 
@@ -144,4 +145,12 @@ FeatureGate::visit (AST::ExternalTypeItem &item)
"extern types are experimental");
 }
 
+void
+FeatureGate::visit (AST::TraitImpl &impl)
+{
+  if (impl.is_exclam ())
+gate (Feature::Name::NEGATIVE_IMPLS, impl.get_locus (),
+ "negative_impls are not yet implemented");
+};
+
 } // namespace Rust
diff --git a/gcc/rust/checks/errors/rust-feature-gate.h 
b/gcc/rust/checks/errors/rust-feature-gate.h
index 481b5a530613..d7c84a5b72e5 100644
--- a/gcc/rust/checks/errors/rust-feature-gate.h
+++ b/gcc/rust/checks/errors/rust-feature-gate.h
@@ -127,6 +127,7 @@ public:
   void visit (AST::StaticItem &static_item) override {}
   void visit (AST::TraitItemConst &item) override {}
   void visit (AST::TraitItemType &item) override {}
+  void visit (AST::TraitImpl &impl) override;
   void visit (AST::Trait &trait) override {}
   void visit (AST::ExternalTypeItem &item) override;
   void visit (AST::ExternalStaticItem &item) override {}
diff --git a/gcc/rust/checks/errors/rust-feature.cc 
b/gcc/rust/checks/errors/rust-feature.cc
index c12710ae2e17..62497585575c 100644
--- a/gcc/rust/checks/errors/rust-feature.cc
+++ b/gcc/rust/checks/errors/rust-feature.cc
@@ -42,6 +42,9 @@ Feature::create (Feature::Name name)
 case Feature::Name::EXTERN_TYPES:
   return Feature (Feature::Name::EXTERN_TYPES, Feature::State::ACTIVE,
  "extern_types", "1.23.0", 43467, tl::nullopt, "");
+case Feature::Name::NEGATIVE_IMPLS:
+  return Feature (Feature::Name::NEGATIVE_IMPLS, Feature::State::ACTIVE,
+ "negative_impls", "1.0.0", 68318, tl::nullopt, "");
 default:
   rust_unreachable ();
 }
@@ -52,6 +55,7 @@ const std::map 
Feature::name_hash_map = {
   {"intrinsics", Feature::Name::INTRINSICS},
   {"rustc_attrs", Feature::Name::RUSTC_ATTRS},
   {"decl_macro", Feature::Name::DECL_MACRO},
+  {"negative_impls", Feature::Name::NEGATIVE_IMPLS},
   // TODO: Rename to "auto_traits" when supporting
   // later Rust versions
   {"optin_builtin_traits", Feature::Name::AUTO_TRAITS},
diff --git a/gcc/rust/checks/errors/rust-feature.h 
b/gcc/rust/checks/errors/rust-feature.h
index e6bc2362e39e..306baf283981 100644
--- a/gcc/rust/checks/errors/rust-feature.h
+++ b/gcc/rust/checks/errors/rust-feature.h
@@ -39,6 +39,7 @@ public:
   {
 ASSOCIATED_TYPE_BOUNDS,
 INTRINSICS,
+NEGATIVE_IMPLS,
 RUSTC_ATTRS,
 DECL_MACRO,
 AUTO_TRAITS,
diff --git a/gcc/testsuite/rust/compile/negative_impls.rs 
b/gcc/testsuite/rust/compile/negative_impls.rs
new file mode 100644
index ..949a3906cdc4
--- /dev/null
+++ b/gcc/testsuite/rust/compile/negative_impls.rs
@@ -0,0 +1,8 @@
+#![feature(negative_impls)]
+
+trait ExampleTrait {}
+
+impl !ExampleTrait for i32 {}
+
+
+fn main() {}
diff --git a/gcc/testsuite/rust/compile/negative_impls_2.rs 
b/gcc/testsuite/rust/compile/negative_impls_2.rs
new file mode 100644
index ..d66fbc9c36b4
--- /dev/null
+++ b/gcc/testsuite/rust/compile/negative_impls_2.rs
@@ -0,0 +1,16 @@
+// This test case should error out since we haven't included the 
negative_impls feature
+// Output from  online rust compiler 2021 ver
+// Compiling playground v0.0.1 (/playground)
+// error[E0658]: negative trait bounds are not yet fully implemented; use 
marker types for now
+//  --> src/main.rs:8:6
+//   |
+// 8 | impl !ExampleTrait for i32 {}//
+//   |  ^
+//   |
+//   = note: see issue #68318 

[gcc/devel/rust/master] Add new test for box syntax

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:36a21ef17c09dccc03d6d84a4f37b06b1b9cf716

commit 36a21ef17c09dccc03d6d84a4f37b06b1b9cf716
Author: Pierre-Emmanuel Patry 
Date:   Sun May 19 02:11:36 2024 +0200

Add new test for box syntax

Add a new test to prevent regressions on the box syntax as well as its
feature gate.

gcc/testsuite/ChangeLog:

* rust/compile/box_syntax.rs: New test.
* rust/compile/box_syntax_feature_gate.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/testsuite/rust/compile/box_syntax.rs  | 6 ++
 gcc/testsuite/rust/compile/box_syntax_feature_gate.rs | 5 +
 2 files changed, 11 insertions(+)

diff --git a/gcc/testsuite/rust/compile/box_syntax.rs 
b/gcc/testsuite/rust/compile/box_syntax.rs
new file mode 100644
index ..c63284b5163d
--- /dev/null
+++ b/gcc/testsuite/rust/compile/box_syntax.rs
@@ -0,0 +1,6 @@
+// { dg-options "-fsyntax-only" }
+#![feature(box_syntax)]
+
+fn main() {
+let x: Box<_> = box 1;
+}
diff --git a/gcc/testsuite/rust/compile/box_syntax_feature_gate.rs 
b/gcc/testsuite/rust/compile/box_syntax_feature_gate.rs
new file mode 100644
index ..8eb5503dde6c
--- /dev/null
+++ b/gcc/testsuite/rust/compile/box_syntax_feature_gate.rs
@@ -0,0 +1,5 @@
+// { dg-options "-frust-compile-until=lowering" }
+
+fn main() {
+let x: Box<_> = box 1; //{ dg-error "box expression syntax is 
experimental." "" { target *-*-* }  }
+}


[gcc/devel/rust/master] rust: Do not link with libdl and libpthread unconditionally

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:a45362e582e24f7997edc25dde660297bde710f5

commit a45362e582e24f7997edc25dde660297bde710f5
Author: Arthur Cohen 
Date:   Fri Apr 12 13:52:18 2024 +0200

rust: Do not link with libdl and libpthread unconditionally

ChangeLog:

* Makefile.tpl: Add CRAB1_LIBS variable.
* Makefile.in: Regenerate.
* configure: Regenerate.
* configure.ac: Check if -ldl and -lpthread are needed, and if so, 
add
them to CRAB1_LIBS.

gcc/rust/ChangeLog:

* Make-lang.in: Remove overazealous LIBS = -ldl -lpthread line, link
crab1 against CRAB1_LIBS.

Diff:
---
 Makefile.in   |   3 +
 Makefile.tpl  |   3 +
 configure | 154 ++
 configure.ac  |  41 ++
 gcc/rust/Make-lang.in |   6 +-
 5 files changed, 203 insertions(+), 4 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index edb0c8a9a427..1753fb6b8625 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -197,6 +197,7 @@ HOST_EXPORTS = \
$(BASE_EXPORTS) \
CC="$(CC)"; export CC; \
ADA_CFLAGS="$(ADA_CFLAGS)"; export ADA_CFLAGS; \
+   CRAB1_LIBS="$(CRAB1_LIBS)"; export CRAB1_LIBS; \
CFLAGS="$(CFLAGS)"; export CFLAGS; \
CONFIG_SHELL="$(SHELL)"; export CONFIG_SHELL; \
CXX="$(CXX)"; export CXX; \
@@ -450,6 +451,8 @@ GOCFLAGS = $(CFLAGS)
 GDCFLAGS = @GDCFLAGS@
 GM2FLAGS = $(CFLAGS)
 
+CRAB1_LIBS = @CRAB1_LIBS@
+
 PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
 
 GUILE = guile
diff --git a/Makefile.tpl b/Makefile.tpl
index adbcbdd1d572..4aeaad3c1a5f 100644
--- a/Makefile.tpl
+++ b/Makefile.tpl
@@ -200,6 +200,7 @@ HOST_EXPORTS = \
$(BASE_EXPORTS) \
CC="$(CC)"; export CC; \
ADA_CFLAGS="$(ADA_CFLAGS)"; export ADA_CFLAGS; \
+   CRAB1_LIBS="$(CRAB1_LIBS)"; export CRAB1_LIBS; \
CFLAGS="$(CFLAGS)"; export CFLAGS; \
CONFIG_SHELL="$(SHELL)"; export CONFIG_SHELL; \
CXX="$(CXX)"; export CXX; \
@@ -453,6 +454,8 @@ GOCFLAGS = $(CFLAGS)
 GDCFLAGS = @GDCFLAGS@
 GM2FLAGS = $(CFLAGS)
 
+CRAB1_LIBS = @CRAB1_LIBS@
+
 PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
 
 GUILE = guile
diff --git a/configure b/configure
index 02b435c1163b..a9ea5258f0f6 100755
--- a/configure
+++ b/configure
@@ -690,6 +690,7 @@ extra_host_zlib_configure_flags
 extra_host_libiberty_configure_flags
 stage1_languages
 host_libs_picflag
+CRAB1_LIBS
 PICFLAG
 host_shared
 gcc_host_pie
@@ -8826,6 +8827,139 @@ fi
 
 
 
+# Rust requires -ldl and -lpthread if you are using an old glibc that does not 
include them by
+# default, so we check for them here
+
+missing_rust_dynlibs=none
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing 
dlopen" >&5
+$as_echo_n "checking for library containing dlopen... " >&6; }
+if ${ac_cv_search_dlopen+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_func_search_save_LIBS=$LIBS
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char dlopen ();
+int
+main ()
+{
+return dlopen ();
+  ;
+  return 0;
+}
+_ACEOF
+for ac_lib in '' dl; do
+  if test -z "$ac_lib"; then
+ac_res="none required"
+  else
+ac_res=-l$ac_lib
+LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
+  fi
+  if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_search_dlopen=$ac_res
+fi
+rm -f core conftest.err conftest.$ac_objext \
+conftest$ac_exeext
+  if ${ac_cv_search_dlopen+:} false; then :
+  break
+fi
+done
+if ${ac_cv_search_dlopen+:} false; then :
+
+else
+  ac_cv_search_dlopen=no
+fi
+rm conftest.$ac_ext
+LIBS=$ac_func_search_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_dlopen" >&5
+$as_echo "$ac_cv_search_dlopen" >&6; }
+ac_res=$ac_cv_search_dlopen
+if test "$ac_res" != no; then :
+  test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
+
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing 
pthread_create" >&5
+$as_echo_n "checking for library containing pthread_create... " >&6; }
+if ${ac_cv_search_pthread_create+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_func_search_save_LIBS=$LIBS
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char pthread_create ();
+int
+main ()
+{
+return pthread_create ();
+  ;
+  return 0;
+}
+_ACEOF
+for ac_lib in '' pthread; do
+  if test -z "$ac_lib"; then
+ac_res="none required"
+  else
+ac_res=-l$ac_lib
+LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
+  fi
+  if ac_fn_c_try_link "$LINENO"; then 

[gcc/devel/rust/master] Add a new regression test over struct expr field

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:53a857ac945f0acc8c8db93f534656acca4cbd71

commit 53a857ac945f0acc8c8db93f534656acca4cbd71
Author: Pierre-Emmanuel Patry 
Date:   Mon May 20 17:57:52 2024 +0200

Add a new regression test over struct expr field

We want to prevent regressions on struct expr field attribute parsing.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry 

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

diff --git a/gcc/testsuite/rust/compile/struct_expr_field_attributes.rs 
b/gcc/testsuite/rust/compile/struct_expr_field_attributes.rs
new file mode 100644
index ..b5d65dc4bb65
--- /dev/null
+++ b/gcc/testsuite/rust/compile/struct_expr_field_attributes.rs
@@ -0,0 +1,22 @@
+pub struct Test {
+#[cfg(not(any(
+target_os = "solaris",
+target_os = "illumos",
+target_os = "fuchsia",
+target_os = "redox",
+)))]
+value: bool,
+// { dg-warning "field is never read" "" { target *-*-* } .-1 }
+}
+
+pub fn test() -> Test {
+Test {
+#[cfg(not(any(
+target_os = "solaris",
+target_os = "illumos",
+target_os = "fuchsia",
+target_os = "redox",
+)))]
+value: false,
+}
+}


[gcc/devel/rust/master] Parse raw ref operator

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:a8e63c472f8169ef8e9ca8e7216dbdb0ddabb7ef

commit a8e63c472f8169ef8e9ca8e7216dbdb0ddabb7ef
Author: Pierre-Emmanuel Patry 
Date:   Tue May 21 10:23:55 2024 +0200

Parse raw ref operator

The raw ref operator is an unstable feature required to obtain a pointer
to unaligned adresses (mainly unaligned struct fields) without UB.

gcc/rust/ChangeLog:

* ast/rust-ast-builder.cc (Builder::ref): Adapt constructor to the 
new
API.
* ast/rust-ast-collector.cc (TokenCollector::visit): Emit a raw weak
keyword when required.
* ast/rust-ast.cc (BorrowExpr::as_string): Change as_string
representation to handle raw ref operator.
* ast/rust-expr.h (class BorrowExpr): Add raw discriminant.
* expand/rust-macro-builtins-include.cc: Adapt constructor to the 
new
API.
* parse/rust-parse-impl.h: Handle the raw weak keyword.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/ast/rust-ast-builder.cc   |  5 ++-
 gcc/rust/ast/rust-ast-collector.cc | 17 --
 gcc/rust/ast/rust-ast.cc   | 18 +++---
 gcc/rust/ast/rust-expr.h   | 16 +
 gcc/rust/expand/rust-macro-builtins-include.cc |  7 ++--
 gcc/rust/parse/rust-parse-impl.h   | 46 ++
 6 files changed, 86 insertions(+), 23 deletions(-)

diff --git a/gcc/rust/ast/rust-ast-builder.cc b/gcc/rust/ast/rust-ast-builder.cc
index 1138d3dc2b2c..381501498bd3 100644
--- a/gcc/rust/ast/rust-ast-builder.cc
+++ b/gcc/rust/ast/rust-ast-builder.cc
@@ -19,6 +19,7 @@
 #include "rust-ast-builder.h"
 #include "rust-ast-full-decls.h"
 #include "rust-ast-full.h"
+#include "rust-common.h"
 #include "rust-expr.h"
 #include "rust-token.h"
 #include "rust-make-unique.h"
@@ -122,8 +123,10 @@ Builder::let (std::unique_ptr pattern, 
std::unique_ptr type,
 std::unique_ptr
 Builder::ref (std::unique_ptr &&of, bool mut) const
 {
+  auto mutability = mut ? Mutability::Mut : Mutability::Imm;
   return std::unique_ptr (
-new BorrowExpr (std::move (of), mut, /* is double */ false, {}, loc));
+new BorrowExpr (std::move (of), mutability,
+   /* raw */ false, /* is double */ false, {}, loc));
 }
 
 std::unique_ptr
diff --git a/gcc/rust/ast/rust-ast-collector.cc 
b/gcc/rust/ast/rust-ast-collector.cc
index 6e60ea376103..341b31857237 100644
--- a/gcc/rust/ast/rust-ast-collector.cc
+++ b/gcc/rust/ast/rust-ast-collector.cc
@@ -843,8 +843,21 @@ TokenCollector::visit (BorrowExpr &expr)
   push (Rust::Token::make (AMP, expr.get_locus ()));
   if (expr.get_is_double_borrow ())
 push (Rust::Token::make (AMP, UNDEF_LOCATION));
-  if (expr.get_is_mut ())
-push (Rust::Token::make (MUT, UNDEF_LOCATION));
+
+  if (expr.is_raw_borrow ())
+{
+  push (Rust::Token::make_identifier (expr.get_locus (),
+ Values::WeakKeywords::RAW));
+  if (expr.get_is_mut ())
+   push (Rust::Token::make (MUT, UNDEF_LOCATION));
+  else
+   push (Rust::Token::make (CONST, UNDEF_LOCATION));
+}
+  else
+{
+  if (expr.get_is_mut ())
+   push (Rust::Token::make (MUT, UNDEF_LOCATION));
+}
 
   visit (expr.get_borrowed_expr ());
 }
diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc
index 9ecbd686a835..5dd8537aee6d 100644
--- a/gcc/rust/ast/rust-ast.cc
+++ b/gcc/rust/ast/rust-ast.cc
@@ -20,6 +20,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "rust-ast.h"
 #include "optional.h"
 #include "rust-builtin-ast-nodes.h"
+#include "rust-common.h"
 #include "rust-system.h"
 #include "rust-ast-full.h"
 #include "rust-diagnostics.h"
@@ -1570,12 +1571,19 @@ BorrowExpr::as_string () const
 
   std::string str ("&");
 
-  if (double_borrow)
-str += "&";
-
-  if (is_mut)
-str += "mut ";
+  if (raw_borrow)
+{
+  str += "raw ";
+  str += get_is_mut () ? "const " : "mut ";
+}
+  else
+{
+  if (double_borrow)
+   str += "&";
 
+  if (get_is_mut ())
+   str += "mut ";
+}
   str += main_or_left_expr->as_string ();
 
   return str;
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index 50c0cb146ed8..6609ad80b37e 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -2,6 +2,7 @@
 #define RUST_AST_EXPR_H
 
 #include "rust-ast.h"
+#include "rust-common.h"
 #include "rust-path.h"
 #include "rust-macro.h"
 #include "rust-operators.h"
@@ -370,18 +371,20 @@ public:
  * overloaded. */
 class BorrowExpr : public OperatorExpr
 {
-  bool is_mut;
+  Mutability mutability;
+  bool raw_borrow;
   bool double_borrow;
 
 public:
   std::string as_string () const override;
 
-  BorrowExpr (std::unique_ptr borrow_lvalue, bool is_mut_borrow,
- bool is_double_borrow, std::vector outer_attribs,
- location_t locus)
+  BorrowExpr (std::unique_ptr borrow_lvalue, Mutabi

[gcc/devel/rust/master] Parse exclusive range pattern

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:a178a07e4322fca9bd3c4b12d3d1da32bedfe198

commit a178a07e4322fca9bd3c4b12d3d1da32bedfe198
Author: Pierre-Emmanuel Patry 
Date:   Tue May 21 17:45:34 2024 +0200

Parse exclusive range pattern

Exclusive range pattern were not handled by the parser as this an
experimental feature.

gcc/rust/ChangeLog:

* ast/rust-pattern.cc (tokenid_to_rangekind): Add a new function to
get a range kind from the current token type.
(RangePattern::as_string): Change the string representation for 
range
pattern in order to handle excluded ranges.
* ast/rust-pattern.h (enum class): Add new enum class to 
differentiate
range kinds.
(tokenid_to_rangekind): New prototype for a function that converts a
token id to it's corresponding range kind.
(class RangePattern): Change the class to accept a range kind 
instead
of an ellipsis boolean.
* hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::visit): Abort
when an excluded pattern has been found as we do not handle their
lowering yet.
* parse/rust-parse-impl.h (Parser::parse_literal_or_range_pattern):
Parse excluded range patterns.
(Parser::parse_pattern_no_alt): Likewise.
(Parser::parse_ident_leading_pattern): Likewise.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/ast/rust-pattern.cc   | 31 +++
 gcc/rust/ast/rust-pattern.h| 32 +++-
 gcc/rust/hir/rust-ast-lower-pattern.cc |  3 +++
 gcc/rust/parse/rust-parse-impl.h   | 33 +++--
 4 files changed, 72 insertions(+), 27 deletions(-)

diff --git a/gcc/rust/ast/rust-pattern.cc b/gcc/rust/ast/rust-pattern.cc
index 9091637c786b..59d736798ac0 100644
--- a/gcc/rust/ast/rust-pattern.cc
+++ b/gcc/rust/ast/rust-pattern.cc
@@ -30,6 +30,22 @@ along with GCC; see the file COPYING3.  If not see
 namespace Rust {
 namespace AST {
 
+RangeKind
+tokenid_to_rangekind (TokenId id)
+{
+  switch (id)
+{
+case DOT_DOT_EQ:
+  return RangeKind::INCLUDED;
+case ELLIPSIS:
+  return RangeKind::ELLIPSIS;
+case DOT_DOT:
+  return RangeKind::EXCLUDED;
+default:
+  rust_unreachable ();
+}
+}
+
 std::string
 LiteralPattern::as_string () const
 {
@@ -73,10 +89,17 @@ std::string
 RangePattern::as_string () const
 {
   // TODO: maybe rewrite to work with non-linearisable bounds
-  if (has_ellipsis_syntax)
-return lower->as_string () + "..." + upper->as_string ();
-  else
-return lower->as_string () + "..=" + upper->as_string ();
+  switch (range_kind)
+{
+case RangeKind::EXCLUDED:
+  return lower->as_string () + ".." + upper->as_string ();
+case RangeKind::INCLUDED:
+  return lower->as_string () + "..=" + upper->as_string ();
+case RangeKind::ELLIPSIS:
+  return lower->as_string () + "..." + upper->as_string ();
+default:
+  rust_unreachable ();
+}
 }
 
 std::string
diff --git a/gcc/rust/ast/rust-pattern.h b/gcc/rust/ast/rust-pattern.h
index eb80c730a9e2..53df7fc270ac 100644
--- a/gcc/rust/ast/rust-pattern.h
+++ b/gcc/rust/ast/rust-pattern.h
@@ -368,13 +368,22 @@ protected:
   }
 };
 
+enum class RangeKind
+{
+  INCLUDED,
+  ELLIPSIS,
+  EXCLUDED,
+};
+
+RangeKind
+tokenid_to_rangekind (TokenId id);
 // AST node for matching within a certain range (range pattern)
 class RangePattern : public Pattern
 {
   std::unique_ptr lower;
   std::unique_ptr upper;
 
-  bool has_ellipsis_syntax;
+  RangeKind range_kind;
 
   /* location only stored to avoid a dereference - lower pattern should give
* correct location so maybe change in future */
@@ -386,10 +395,10 @@ public:
 
   // Constructor
   RangePattern (std::unique_ptr lower,
-   std::unique_ptr upper, location_t locus,
-   bool has_ellipsis_syntax = false)
+   std::unique_ptr upper, RangeKind range_kind,
+   location_t locus)
 : lower (std::move (lower)), upper (std::move (upper)),
-  has_ellipsis_syntax (has_ellipsis_syntax), locus (locus),
+  range_kind (range_kind), locus (locus),
   node_id (Analysis::Mappings::get ().get_next_node_id ())
   {}
 
@@ -397,7 +406,7 @@ public:
   RangePattern (RangePattern const &other)
 : lower (other.lower->clone_range_pattern_bound ()),
   upper (other.upper->clone_range_pattern_bound ()),
-  has_ellipsis_syntax (other.has_ellipsis_syntax), locus (other.locus),
+  range_kind (other.range_kind), locus (other.locus),
   node_id (other.node_id)
   {}
 
@@ -406,7 +415,7 @@ public:
   {
 lower = other.lower->clone_range_pattern_bound ();
 upper = other.upper->clone_range_pattern_bound ();
-has_ellipsis_syntax = other.has_ellipsis_syntax;
+range_kind = other.range_kind;
 locus = other.locus;
 node_id = other.node_id;
 
@@

[gcc/devel/rust/master] Add exclusive_range_pattern feature gate

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:956542656fe2fc39c14b99b87ef2cae21928d6e6

commit 956542656fe2fc39c14b99b87ef2cae21928d6e6
Author: Pierre-Emmanuel Patry 
Date:   Tue May 21 18:09:14 2024 +0200

Add exclusive_range_pattern feature gate

This syntax is experimental and shall be explicitely enabled in the crate
attributes as it cannot be used in stable rust.

gcc/rust/ChangeLog:

* checks/errors/rust-feature-gate.cc (FeatureGate::visit): Gate the
excluded pattern.
* checks/errors/rust-feature-gate.h: Update the function prototype
and delete two empty implementations in order to use default visitor
behavior.
* checks/errors/rust-feature.cc (Feature::create): Add the new
exclusive range pattern feature gate.
* checks/errors/rust-feature.h: Add new feature enum variant for
exclusive range patterns.
* parse/rust-parse-impl.h (Parser::parse_pattern_no_alt): Forward 
the
token location to the AST.
(Parser::parse_ident_leading_pattern): Likewise.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/checks/errors/rust-feature-gate.cc | 8 
 gcc/rust/checks/errors/rust-feature-gate.h  | 4 +---
 gcc/rust/checks/errors/rust-feature.cc  | 5 +
 gcc/rust/checks/errors/rust-feature.h   | 1 +
 gcc/rust/parse/rust-parse-impl.h| 4 ++--
 5 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/gcc/rust/checks/errors/rust-feature-gate.cc 
b/gcc/rust/checks/errors/rust-feature-gate.cc
index d5b70635857f..0fe2edbce4fc 100644
--- a/gcc/rust/checks/errors/rust-feature-gate.cc
+++ b/gcc/rust/checks/errors/rust-feature-gate.cc
@@ -209,4 +209,12 @@ FeatureGate::visit (AST::BorrowExpr &expr)
  "raw address of syntax is experimental");
 }
 
+void
+FeatureGate::visit (AST::RangePattern &pattern)
+{
+  if (pattern.get_range_kind () == AST::RangeKind::EXCLUDED)
+gate (Feature::Name::EXCLUSIVE_RANGE_PATTERN, pattern.get_locus (),
+ "exclusive range pattern syntax is experimental");
+}
+
 } // namespace Rust
diff --git a/gcc/rust/checks/errors/rust-feature-gate.h 
b/gcc/rust/checks/errors/rust-feature-gate.h
index 0d53b40c151b..5a063ea5c8a1 100644
--- a/gcc/rust/checks/errors/rust-feature-gate.h
+++ b/gcc/rust/checks/errors/rust-feature-gate.h
@@ -99,9 +99,7 @@ public:
   void visit (AST::ForLoopExpr &expr) override {}
   void visit (AST::IfExpr &expr) override {}
   void visit (AST::IfExprConseqElse &expr) override {}
-  void visit (AST::IfLetExpr &expr) override {}
   void visit (AST::IfLetExprConseqElse &expr) override {}
-  void visit (AST::MatchExpr &expr) override {}
   void visit (AST::AwaitExpr &expr) override {}
   void visit (AST::AsyncBlockExpr &expr) override {}
   void visit (AST::TypeParam ¶m) override;
@@ -150,7 +148,7 @@ public:
   void visit (AST::RangePatternBoundLiteral &bound) override {}
   void visit (AST::RangePatternBoundPath &bound) override {}
   void visit (AST::RangePatternBoundQualPath &bound) override {}
-  void visit (AST::RangePattern &pattern) override {}
+  void visit (AST::RangePattern &pattern) override;
   void visit (AST::ReferencePattern &pattern) override {}
   void visit (AST::StructPatternFieldTuplePat &field) override {}
   void visit (AST::StructPatternFieldIdentPat &field) override {}
diff --git a/gcc/rust/checks/errors/rust-feature.cc 
b/gcc/rust/checks/errors/rust-feature.cc
index cb2b42cafaf0..cd2df0f96f6a 100644
--- a/gcc/rust/checks/errors/rust-feature.cc
+++ b/gcc/rust/checks/errors/rust-feature.cc
@@ -54,6 +54,10 @@ Feature::create (Feature::Name name)
 case Feature::Name::RAW_REF_OP:
   return Feature (Feature::Name::RAW_REF_OP, Feature::State::ACTIVE,
  "raw_ref_op", "1.41.0", 64490, tl::nullopt, "");
+case Feature::Name::EXCLUSIVE_RANGE_PATTERN:
+  return Feature (Feature::Name::EXCLUSIVE_RANGE_PATTERN,
+ Feature::State::ACTIVE, "exclusive_range_pattern",
+ "1.11.0", 37854, tl::nullopt, "");
 default:
   rust_unreachable ();
 }
@@ -74,6 +78,7 @@ const std::map 
Feature::name_hash_map = {
   {"box_syntax", Feature::Name::BOX_SYNTAX},
   {"dropck_eyepatch", Feature::Name::DROPCK_EYEPATCH},
   {"raw_ref_op", Feature::Name::RAW_REF_OP},
+  {"exclusive_range_pattern", Feature::Name::EXCLUSIVE_RANGE_PATTERN},
 }; // namespace Rust
 
 tl::optional
diff --git a/gcc/rust/checks/errors/rust-feature.h 
b/gcc/rust/checks/errors/rust-feature.h
index 5a1819912df2..89e58cf0ed1e 100644
--- a/gcc/rust/checks/errors/rust-feature.h
+++ b/gcc/rust/checks/errors/rust-feature.h
@@ -49,6 +49,7 @@ public:
 BOX_SYNTAX,
 DROPCK_EYEPATCH,
 RAW_REF_OP,
+EXCLUSIVE_RANGE_PATTERN,
   };
 
   const std::string &as_string () { return m_name_str; }
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index db5c3c00b596..0a20bf632fa7 100644
--- a/gcc/rust/parse/ru

[gcc/devel/rust/master] Add regression tests for exclusive range pattern

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:f88aa88faf491f6855e01da1062b8db184d74997

commit f88aa88faf491f6855e01da1062b8db184d74997
Author: Pierre-Emmanuel Patry 
Date:   Tue May 21 18:29:08 2024 +0200

Add regression tests for exclusive range pattern

Add a few test to check the exclusive range pattern feature. This feature
is experimental and shall not be enabled in stable rust.

gcc/testsuite/ChangeLog:

* rust/compile/exclusive_range_pattern.rs: New test.
* rust/compile/exclusive_range_pattern_feature_gate.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/testsuite/rust/compile/exclusive_range_pattern.rs   | 17 +
 .../compile/exclusive_range_pattern_feature_gate.rs |  8 
 2 files changed, 25 insertions(+)

diff --git a/gcc/testsuite/rust/compile/exclusive_range_pattern.rs 
b/gcc/testsuite/rust/compile/exclusive_range_pattern.rs
new file mode 100644
index ..4840abeab803
--- /dev/null
+++ b/gcc/testsuite/rust/compile/exclusive_range_pattern.rs
@@ -0,0 +1,17 @@
+// { dg-options "-fsyntax-only" }
+#![feature(exclusive_range_pattern)]
+
+const TEN: usize = 10;
+
+fn test(n: usize) {
+match n {
+0..TEN => (),
+TEN..20 => (),
+20..30 => (),
+_ => (),
+}
+}
+
+fn test2(t: usize) {
+if let 0..10 = t {}
+}
diff --git a/gcc/testsuite/rust/compile/exclusive_range_pattern_feature_gate.rs 
b/gcc/testsuite/rust/compile/exclusive_range_pattern_feature_gate.rs
new file mode 100644
index ..4530214c0a2a
--- /dev/null
+++ b/gcc/testsuite/rust/compile/exclusive_range_pattern_feature_gate.rs
@@ -0,0 +1,8 @@
+// { dg-options "-frust-compile-until=lowering" }
+
+fn test(n: usize) {
+match n {
+0..10 => (), //{ dg-error "exclusive range pattern syntax is 
experimental." "" { target *-*-* }  }
+_ => (),
+}
+}


[gcc/devel/rust/master] Add raw_ref_op feature gate

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:bd97356fbbbf889b049b25775b98dcace2d84885

commit bd97356fbbbf889b049b25775b98dcace2d84885
Author: Pierre-Emmanuel Patry 
Date:   Tue May 21 10:58:55 2024 +0200

Add raw_ref_op feature gate

Raw ref operators are still experimental and shall not slip within
stable rust, they should therefore be feature gated.

gcc/rust/ChangeLog:

* checks/errors/rust-feature-gate.cc (FeatureGate::visit): Gate raw
borrow.
* checks/errors/rust-feature-gate.h: Update function prototype.
* checks/errors/rust-feature.cc: Add raw_ref_op gate.
* checks/errors/rust-feature.h: Likewise.

Signed-off-by: Pierre-Emmanuel Patry 

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 +
 4 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/checks/errors/rust-feature-gate.cc 
b/gcc/rust/checks/errors/rust-feature-gate.cc
index 847122f70d98..d5b70635857f 100644
--- a/gcc/rust/checks/errors/rust-feature-gate.cc
+++ b/gcc/rust/checks/errors/rust-feature-gate.cc
@@ -201,4 +201,12 @@ FeatureGate::visit (AST::TypeParam ¶m)
   AST::DefaultASTVisitor::visit (param);
 }
 
+void
+FeatureGate::visit (AST::BorrowExpr &expr)
+{
+  if (expr.is_raw_borrow ())
+gate (Feature::Name::RAW_REF_OP, expr.get_locus (),
+ "raw address of syntax is experimental");
+}
+
 } // namespace Rust
diff --git a/gcc/rust/checks/errors/rust-feature-gate.h 
b/gcc/rust/checks/errors/rust-feature-gate.h
index 5801c0d5da77..0d53b40c151b 100644
--- a/gcc/rust/checks/errors/rust-feature-gate.h
+++ b/gcc/rust/checks/errors/rust-feature-gate.h
@@ -54,7 +54,7 @@ public:
   void visit (AST::AttrInputMacro &attr_input) override {}
   void visit (AST::MetaItemLitExpr &meta_item) override {}
   void visit (AST::MetaItemPathLit &meta_item) override {}
-  void visit (AST::BorrowExpr &expr) override {}
+  void visit (AST::BorrowExpr &expr) override;
   void visit (AST::DereferenceExpr &expr) override {}
   void visit (AST::ErrorPropagationExpr &expr) override {}
   void visit (AST::NegationExpr &expr) override {}
diff --git a/gcc/rust/checks/errors/rust-feature.cc 
b/gcc/rust/checks/errors/rust-feature.cc
index 0af3209e338f..cb2b42cafaf0 100644
--- a/gcc/rust/checks/errors/rust-feature.cc
+++ b/gcc/rust/checks/errors/rust-feature.cc
@@ -51,6 +51,9 @@ Feature::create (Feature::Name name)
 case Feature::Name::DROPCK_EYEPATCH:
   return Feature (Feature::Name::DROPCK_EYEPATCH, Feature::State::ACTIVE,
  "dropck_eyepatch", "1.10.0", 34761, tl::nullopt, "");
+case Feature::Name::RAW_REF_OP:
+  return Feature (Feature::Name::RAW_REF_OP, Feature::State::ACTIVE,
+ "raw_ref_op", "1.41.0", 64490, tl::nullopt, "");
 default:
   rust_unreachable ();
 }
@@ -70,6 +73,7 @@ const std::map 
Feature::name_hash_map = {
   {"no_core", Feature::Name::NO_CORE},
   {"box_syntax", Feature::Name::BOX_SYNTAX},
   {"dropck_eyepatch", Feature::Name::DROPCK_EYEPATCH},
+  {"raw_ref_op", Feature::Name::RAW_REF_OP},
 }; // namespace Rust
 
 tl::optional
diff --git a/gcc/rust/checks/errors/rust-feature.h 
b/gcc/rust/checks/errors/rust-feature.h
index abb8c551406c..5a1819912df2 100644
--- a/gcc/rust/checks/errors/rust-feature.h
+++ b/gcc/rust/checks/errors/rust-feature.h
@@ -48,6 +48,7 @@ public:
 NO_CORE,
 BOX_SYNTAX,
 DROPCK_EYEPATCH,
+RAW_REF_OP,
   };
 
   const std::string &as_string () { return m_name_str; }


[gcc/devel/rust/master] Add some test for raw_ref_op to prevent regressions

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:6fc8ad5340aa21110fe1655fef477aa5b94846f6

commit 6fc8ad5340aa21110fe1655fef477aa5b94846f6
Author: Pierre-Emmanuel Patry 
Date:   Tue May 21 11:36:55 2024 +0200

Add some test for raw_ref_op to prevent regressions

Add a test for the feature gate, as well as some test to ensure the raw
keyword stays weak. Also add some tests to check whether the raw_ref_op
syntax is parsed correctly.

gcc/testsuite/ChangeLog:

* rust/compile/not_raw_ref_op.rs: New test.
* rust/compile/raw_ref_op.rs: New test.
* rust/compile/raw_ref_op_feature_gate.rs: New test.
* rust/compile/raw_ref_op_invalid.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/testsuite/rust/compile/not_raw_ref_op.rs  |  9 +
 gcc/testsuite/rust/compile/raw_ref_op.rs  | 11 +++
 gcc/testsuite/rust/compile/raw_ref_op_feature_gate.rs |  8 
 gcc/testsuite/rust/compile/raw_ref_op_invalid.rs  | 12 
 4 files changed, 40 insertions(+)

diff --git a/gcc/testsuite/rust/compile/not_raw_ref_op.rs 
b/gcc/testsuite/rust/compile/not_raw_ref_op.rs
new file mode 100644
index ..f55f1846faba
--- /dev/null
+++ b/gcc/testsuite/rust/compile/not_raw_ref_op.rs
@@ -0,0 +1,9 @@
+// { dg-options "-frust-compile-until=lowering" }
+pub struct Toto {
+u: usize,
+}
+
+pub fn test(raw: Toto) {
+// Not raw ref op syntax, raw keyword is weak.
+let _c = &raw;
+}
diff --git a/gcc/testsuite/rust/compile/raw_ref_op.rs 
b/gcc/testsuite/rust/compile/raw_ref_op.rs
new file mode 100644
index ..a97e58c62b0f
--- /dev/null
+++ b/gcc/testsuite/rust/compile/raw_ref_op.rs
@@ -0,0 +1,11 @@
+// { dg-options "-fsyntax-only" }
+#![feature(raw_ref_op)]
+
+pub struct Toto {
+u: usize,
+}
+
+pub fn test(mut toto: Toto) {
+let _a = &raw mut toto.u;
+let _b = &raw const toto.u;
+}
diff --git a/gcc/testsuite/rust/compile/raw_ref_op_feature_gate.rs 
b/gcc/testsuite/rust/compile/raw_ref_op_feature_gate.rs
new file mode 100644
index ..256202b2da6a
--- /dev/null
+++ b/gcc/testsuite/rust/compile/raw_ref_op_feature_gate.rs
@@ -0,0 +1,8 @@
+// { dg-options "-frust-compile-until=lowering" }
+pub struct Toto {
+u: usize,
+}
+
+pub fn test(mut toto: Toto) {
+let _a = &raw mut toto.u; //{ dg-error "raw address of syntax is 
experimental." "" { target *-*-* }  }
+}
diff --git a/gcc/testsuite/rust/compile/raw_ref_op_invalid.rs 
b/gcc/testsuite/rust/compile/raw_ref_op_invalid.rs
new file mode 100644
index ..90e169f30f6b
--- /dev/null
+++ b/gcc/testsuite/rust/compile/raw_ref_op_invalid.rs
@@ -0,0 +1,12 @@
+// { dg-options "-fsyntax-only" }
+#![feature(raw_ref_op)]
+
+pub struct Toto {
+u: usize,
+}
+
+pub fn test(mut toto: Toto) {
+let _c = &raw toto.u; //{ dg-error "expecting .;. but .identifier. found" 
"" { target *-*-* }  }
+//{ dg-excess-errors "Additional errors for parent items" { target *-*-* } 
}
+
+}


[gcc/devel/rust/master] Almost done with top level parsing

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:3f23987dab049d63aa112d272c493562b1d122cf

commit 3f23987dab049d63aa112d272c493562b1d122cf
Author: jjasmine 
Date:   Wed May 8 11:06:00 2024 -0700

Almost done with top level parsing

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-asm.cc (struct AsmParseError): title.
(enum InlineAsmDirSpec): title.
(enum InlineAsmOptions): title.
(struct AsmArg): title.
(parseAsmArg): title.
(parse_global_asm): title.
(parse_nonglobal_asm): title.
(parse_asm): title.
(parseDirSpec): title.
(parse_format_string): title.
(MacroBuiltin::global_asm_handler): title.
(MacroBuiltin::nonglobal_asm_handler): title.
* expand/rust-macro-builtins.cc: title.
* expand/rust-macro-builtins.h: title.

Diff:
---
 gcc/rust/expand/rust-macro-builtins-asm.cc | 178 +
 gcc/rust/expand/rust-macro-builtins.cc |   6 +-
 gcc/rust/expand/rust-macro-builtins.h  |   6 +
 3 files changed, 186 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index 62bb59352801..c1076c1e55df 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -18,3 +18,181 @@
 
 #include "rust-macro-builtins.h"
 #include "rust-macro-builtins-helpers.h"
+#include "rust-macro-invoc-lexer.h"
+
+namespace Rust {
+
+struct AsmParseError
+{
+};
+
+// This is just an enum to hold some operands right now.
+enum InlineAsmDirSpec
+{
+  In,
+  Out,
+  InOut,
+  SplitInOut,
+  Const,
+  Sym,
+  Label,
+};
+
+enum InlineAsmOptions
+{
+
+};
+
+typedef std::string symbol_name;
+typedef std::vector Templates;
+typedef std::vector Operands;
+typedef std::map RegisterArgs;
+typedef std::map ClobberAbis;
+typedef std::map NamedValues;
+
+struct AsmArg
+{
+  Templates templates;
+  Operands operands;
+  std::map named_values;
+  RegisterArgs register_arguments;
+  ClobberAbis clobber_abis;
+  InlineAsmOptions options;
+  std::vector
+options_span; // TODO: @badumbatish @jjasmine I have no idea what span do, 
i
+ // copied it out of rustc_builtin_macros/src/asm.rs
+};
+
+tl::optional
+parseAsmArg (Parser &p, bool is_global_asm);
+static tl::optional
+parse_global_asm (location_t invoc_locus, AST::MacroInvocData &invoc);
+static tl::optional
+parse_nonglobal_asm (location_t invoc_locus, AST::MacroInvocData &invoc);
+static tl::optional
+parse_asm (location_t invoc_locus, AST::MacroInvocData &invoc,
+  bool is_global_asm);
+
+tl::optional
+parseDirSpec (Parser &p, TokenId last_token_id)
+{
+  return tl::nullopt;
+}
+tl::optional
+parseAsmArg (Parser &p, bool is_global_asm)
+{
+  return tl::nullopt;
+}
+
+tl::optional
+parse_format_string (Parser &parser, TokenId last_token_id)
+{
+  auto token = parser.peek_current_token ();
+
+  if (token->get_id () != last_token_id && token->get_id () == STRING_LITERAL)
+{
+  // very nice, we got a supposedly formatted string.
+  std::cout << token->get_token_description () << std::endl;
+  parser.skip_token ();
+  return "formatted string";
+}
+  else
+{
+  parser.skip_token ();
+  std::cout << token->get_token_description () << std::endl;
+
+  rust_error_at (token->get_locus (),
+"asm template must be a string literal");
+  return tl::nullopt;
+}
+}
+
+tl::optional
+MacroBuiltin::global_asm_handler (location_t invoc_locus,
+ AST::MacroInvocData &invoc)
+{
+  // Just to clarify the code
+  bool is_global_asm = true;
+  return parse_asm (invoc_locus, invoc, is_global_asm);
+}
+
+tl::optional
+MacroBuiltin::nonglobal_asm_handler (location_t invoc_locus,
+AST::MacroInvocData &invoc)
+{
+  // Just to clarify the code
+  bool is_global_asm = false;
+  return parse_asm (invoc_locus, invoc, is_global_asm);
+}
+
+static tl::optional
+parse_asm (location_t invoc_locus, AST::MacroInvocData &invoc,
+  bool is_global_asm)
+{
+  // From the rule of asm.
+  // We first peek and see if it is a format string or not.
+  // If yes, we process the first ever format string, and move on to the
+  // recurrent of format string Else we exit out
+
+  // After that, we peek and see if it is a reoccuring stream of format string
+  // or not. If it is, keep on going to do this format string. Else, move on
+
+  // After that, we peek and see if it is a reoccuring stream of operands or 
not
+  // If it is, keep on going to do this operand thingy.
+  // Else, move on
+
+  // We check if there is an optional "," at the end, per ABNF spec.
+  // If it is, consume it.
+
+  // Done
+  MacroInvocLexer lex (invoc.get_delim_tok_tree ().to_token_stream ());
+  Parser parser (lex);
+  auto last_token_id = macro_end_token (invoc.get_delim_tok_tree (), parser);
+
+  //

[gcc/devel/rust/master] Prevent raw reference from being lowered silently

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:ef8821745ee8755e948a2bce906c58216a6d6188

commit ef8821745ee8755e948a2bce906c58216a6d6188
Author: Pierre-Emmanuel Patry 
Date:   Tue May 21 10:38:16 2024 +0200

Prevent raw reference from being lowered silently

We do not handle those kind of references yet, we shall not let them
pass as a regular reference.

gcc/rust/ChangeLog:

* ast/rust-expr.h: Add a getter for mutability.
* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Panic when a
raw reference is met.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/ast/rust-expr.h|  2 ++
 gcc/rust/hir/rust-ast-lower-expr.cc | 13 +++--
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index 6609ad80b37e..a5afbffee99b 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -398,6 +398,8 @@ public:
 
   bool get_is_mut () const { return mutability == Mutability::Mut; }
 
+  Mutability get_mutability () const { return mutability; }
+
   bool get_is_double_borrow () const { return double_borrow; }
   bool is_raw_borrow () const { return raw_borrow; }
 
diff --git a/gcc/rust/hir/rust-ast-lower-expr.cc 
b/gcc/rust/hir/rust-ast-lower-expr.cc
index 3b462ee88a7d..063a5fb6d54c 100644
--- a/gcc/rust/hir/rust-ast-lower-expr.cc
+++ b/gcc/rust/hir/rust-ast-lower-expr.cc
@@ -628,6 +628,9 @@ ASTLoweringExpr::visit (AST::ContinueExpr &expr)
 void
 ASTLoweringExpr::visit (AST::BorrowExpr &expr)
 {
+  if (expr.is_raw_borrow ())
+rust_unreachable ();
+
   HIR::Expr *borrow_lvalue
 = ASTLoweringExpr::translate (expr.get_borrowed_expr ());
 
@@ -638,9 +641,8 @@ ASTLoweringExpr::visit (AST::BorrowExpr &expr)
 
   auto *borrow_expr
 = new HIR::BorrowExpr (mapping, std::unique_ptr (borrow_lvalue),
-  expr.get_is_mut () ? Mutability::Mut
- : Mutability::Imm,
-  expr.get_outer_attrs (), expr.get_locus ());
+  expr.get_mutability (), expr.get_outer_attrs (),
+  expr.get_locus ());
 
   if (expr.get_is_double_borrow ())
 {
@@ -652,9 +654,8 @@ ASTLoweringExpr::visit (AST::BorrowExpr &expr)
   borrow_expr
= new HIR::BorrowExpr (mapping,
   std::unique_ptr (borrow_expr),
-  expr.get_is_mut () ? Mutability::Mut
- : Mutability::Imm,
-  expr.get_outer_attrs (), expr.get_locus ());
+  expr.get_mutability (), expr.get_outer_attrs (),
+  expr.get_locus ());
 }
 
   translated = borrow_expr;


[gcc/devel/rust/master] Working on parse_options for a bit more

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:edd623c58ee47d0f7c42669b860bd98f22b59eef

commit edd623c58ee47d0f7c42669b860bd98f22b59eef
Author: jjasmine 
Date:   Mon May 20 23:02:59 2024 -0700

Working on parse_options for a bit more

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-asm.cc (parse_options): title.

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

diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index 8b9b47d51aa4..310131c5b311 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -98,7 +98,19 @@ parse_options (Parser &parser, TokenId 
last_token_id,
 {
   // Parse everything commitedly
   if (!p.skip_token (LEFT_PAREN))
-{}
+{
+  // We have shifted `options` to search for the left parenthesis next, we
+  // should error out if this is not possible.
+  // TODO: report some error.
+  return -1;
+}
+
+  auto token = parser.peek_current_token ();
+  while (token->get_id () != last_token_id && token->get_id () != RIGHT_PAREN)
+{
+  parser.skip_token ();
+  token = parser.peek_current_token ();
+}
 }
 bool
 check_identifier (Parser &p, std::string ident)


[gcc/devel/rust/master] Working on parseAsmArg

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:424224a0a4fb0547c01b9c315c682f90fc8755bd

commit 424224a0a4fb0547c01b9c315c682f90fc8755bd
Author: jjasmine 
Date:   Sat May 18 21:24:10 2024 -0700

Working on parseAsmArg

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-asm.cc (enum InlineAsmRegOrRegClass): 
title.
(parseAsmArg): title.
(check_identifier): title.
(parse_operand): title.
(parse_options): title.
(parse_reg): title.
(parseDirSpec): title.
(parse_asm): title.

Diff:
---
 gcc/rust/expand/rust-macro-builtins-asm.cc | 151 ++---
 gcc/rust/expand/rust-macro-builtins-asm.h  |  87 +
 2 files changed, 159 insertions(+), 79 deletions(-)

diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index c1076c1e55df..4d9f6af0ee90 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -16,74 +16,32 @@
 // along with GCC; see the file COPYING3.  If not see
 // .
 
-#include "rust-macro-builtins.h"
-#include "rust-macro-builtins-helpers.h"
-#include "rust-macro-invoc-lexer.h"
+#include "rust-macro-builtins-asm.h"
 
 namespace Rust {
 
-struct AsmParseError
-{
-};
-
-// This is just an enum to hold some operands right now.
-enum InlineAsmDirSpec
-{
-  In,
-  Out,
-  InOut,
-  SplitInOut,
-  Const,
-  Sym,
-  Label,
-};
-
-enum InlineAsmOptions
-{
-
-};
-
-typedef std::string symbol_name;
-typedef std::vector Templates;
-typedef std::vector Operands;
-typedef std::map RegisterArgs;
-typedef std::map ClobberAbis;
-typedef std::map NamedValues;
-
-struct AsmArg
-{
-  Templates templates;
-  Operands operands;
-  std::map named_values;
-  RegisterArgs register_arguments;
-  ClobberAbis clobber_abis;
-  InlineAsmOptions options;
-  std::vector
-options_span; // TODO: @badumbatish @jjasmine I have no idea what span do, 
i
- // copied it out of rustc_builtin_macros/src/asm.rs
-};
-
-tl::optional
-parseAsmArg (Parser &p, bool is_global_asm);
-static tl::optional
-parse_global_asm (location_t invoc_locus, AST::MacroInvocData &invoc);
-static tl::optional
-parse_nonglobal_asm (location_t invoc_locus, AST::MacroInvocData &invoc);
-static tl::optional
-parse_asm (location_t invoc_locus, AST::MacroInvocData &invoc,
-  bool is_global_asm);
-
 tl::optional
-parseDirSpec (Parser &p, TokenId last_token_id)
+parseDirSpec (Parser &parser, TokenId last_token_id)
 {
   return tl::nullopt;
 }
-tl::optional
-parseAsmArg (Parser &p, bool is_global_asm)
+
+bool
+check_identifier (Parser &p, std::string ident)
 {
-  return tl::nullopt;
-}
+  auto token = p.peek_current_token ();
 
+  if (token->get_id () == IDENTIFIER
+  && (token->as_string () == ident || ident == ""))
+{
+  p.skip_token ();
+  return true;
+}
+  else
+{
+  return false;
+}
+}
 tl::optional
 parse_format_string (Parser &parser, TokenId last_token_id)
 {
@@ -125,6 +83,59 @@ MacroBuiltin::nonglobal_asm_handler (location_t invoc_locus,
   return parse_asm (invoc_locus, invoc, is_global_asm);
 }
 
+tl::optional
+parseAsmArg (Parser &parser, TokenId last_token_id,
+bool is_global_asm)
+{
+  auto token = parser.peek_current_token ();
+  AsmArg arg;
+  tl::optional fm_string;
+  while (token->get_id () != last_token_id)
+{
+  std::cout << token->get_token_description () << std::endl;
+
+  token = parser.peek_current_token ();
+
+  // We accept a comma token here.
+  if (token->get_id () != COMMA)
+   {
+ break;
+   }
+  parser.skip_token ();
+
+  // And if that token comma is also the trailing comma, we break
+  // TODO: Check with mentor see what last_token_id means
+  token = parser.peek_current_token ();
+  if (token->get_id () == COMMA && token->get_id () == last_token_id)
+   {
+ parser.skip_token ();
+ break;
+   }
+
+  // Ok after the left paren is good, we better be parsing correctly
+  // everything in here, which is operand in ABNF
+
+  // TODO: Parse clobber abi
+  if (check_identifier (parser, "clobber_abi"))
+   {
+ std::cout << "Clobber abi tee hee" << std::endl;
+ continue;
+   }
+
+  // TODO: Parse options
+  if (check_identifier (parser, "options"))
+   {
+ std::cout << "Parse optoins" << std::endl;
+ continue;
+   }
+
+  // Ok after we have check that neither clobber_abi nor options works, the
+  // only other logical choice is reg_operand
+  fm_string = parse_format_string (parser, last_token_id);
+}
+  return tl::nullopt;
+}
+
 static tl::optional
 parse_asm (location_t invoc_locus, AST::MacroInvocData &invoc,
   bool is_global_asm)
@@ -171,26 +182,8 @@ parse_asm (location_t invoc_locus, AST::MacroInvocData 
&invoc,
   fm_string = parse_format_string (parser, 

[gcc/devel/rust/master] Introduce first implementation of parse_clobber_abi

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:68d60cf5388d6aa90ed6957e59b47215a31443d7

commit 68d60cf5388d6aa90ed6957e59b47215a31443d7
Author: jjasmine 
Date:   Mon May 20 17:01:43 2024 -0700

Introduce first implementation of parse_clobber_abi

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-asm.cc (parse_clobber_abi): title.
(parseAsmArg): title.
* expand/rust-macro-builtins-asm.h (parse_clobber_abi): title.

Diff:
---
 gcc/rust/expand/rust-macro-builtins-asm.cc | 76 +-
 gcc/rust/expand/rust-macro-builtins-asm.h  |  7 ++-
 2 files changed, 81 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index 4d9f6af0ee90..8b9b47d51aa4 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -26,6 +26,80 @@ parseDirSpec (Parser &parser, TokenId 
last_token_id)
   return tl::nullopt;
 }
 
+int
+parse_clobber_abi (Parser &parser, TokenId last_token_id,
+  AsmArg &args)
+{
+  // clobber_abi := "clobber_abi("  *("," ) [","] ")"
+
+  // PARSE EVERYTHING COMMITTEDLY IN THIS FUNCTION, WE CONFIRMED VIA 
clobber_abi
+  // identifier keyword
+
+  if (!parser.skip_token (LEFT_PAREN))
+{
+  // TODO: Raise error exactly like rustc if left parenthesis is not
+  // encountered.
+  return -1;
+}
+
+  if (parser.skip_token (RIGHT_PAREN))
+{
+  // TODO: We encountered a "clobber_abi()", which should be illegal?
+  // 
https://github.com/rust-lang/rust/blob/c00957a3e269219413041a4e3565f33b1f9d0779/compiler/rustc_builtin_macros/src/asm.rs#L381
+  return -1;
+}
+
+  ClobberAbis new_abis;
+
+  auto token = parser.peek_current_token ();
+
+  while (token->get_id () != last_token_id && token->get_id () != RIGHT_PAREN)
+{
+  // Check if it is a string literal or not, codename:  in ABNF
+  if (token->get_id () == STRING_LITERAL)
+   {
+ // TODO: Caring for span in here.
+ new_abis.push_back (token->as_string ());
+   }
+  else
+   {
+ // TODO: We encountered something that is not string literal, which
+ // should be illegal, please emit the correct error
+ // 
https://github.com/rust-lang/rust/blob/b92758a9aef1cef7b79e2b72c3d8ba113e547f89/compiler/rustc_builtin_macros/src/asm.rs#L387
+   }
+
+  if (parser.skip_token (RIGHT_PAREN))
+   {
+ break;
+   }
+
+  if (!parser.skip_token (COMMA))
+   {
+ // TODO: If the skip of comma is unsuccessful, which should be
+ // illegal, pleaes emit the correct error.
+ return -1;
+   }
+
+  // Done processing the local clobber abis, push that to the main Args in
+  // argument
+
+  for (auto abi : new_abis)
+   {
+ args.clobber_abis.push_back (abi);
+   }
+
+  return 0;
+}
+}
+
+int
+parse_options (Parser &parser, TokenId last_token_id,
+  AsmArg &args, bool is_global_asm)
+{
+  // Parse everything commitedly
+  if (!p.skip_token (LEFT_PAREN))
+{}
+}
 bool
 check_identifier (Parser &p, std::string ident)
 {
@@ -115,7 +189,7 @@ parseAsmArg (Parser &parser, TokenId 
last_token_id,
   // Ok after the left paren is good, we better be parsing correctly
   // everything in here, which is operand in ABNF
 
-  // TODO: Parse clobber abi
+  // TODO: Parse clobber abi, eat the identifier named "clobber_abi" if 
true
   if (check_identifier (parser, "clobber_abi"))
{
  std::cout << "Clobber abi tee hee" << std::endl;
diff --git a/gcc/rust/expand/rust-macro-builtins-asm.h 
b/gcc/rust/expand/rust-macro-builtins-asm.h
index 3a67c7e3152b..ebb939a05480 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.h
+++ b/gcc/rust/expand/rust-macro-builtins-asm.h
@@ -37,7 +37,7 @@ typedef std::string symbol_name;
 typedef std::vector Templates;
 typedef std::vector Operands;
 typedef std::map RegisterArgs;
-typedef std::map ClobberAbis;
+typedef std::vector ClobberAbis;
 typedef std::map NamedValues;
 
 struct AsmArg
@@ -84,4 +84,9 @@ parse_options (Parser &parser, TokenId 
last_token_id,
 tl::optional
 parse_reg (Parser &parser, TokenId last_token_id, AsmArg 
&args,
   bool is_explicit);
+
+int
+parse_clobber_abi (Parser &parser, TokenId last_token_id,
+  AsmArg &args);
+
 } // namespace Rust
\ No newline at end of file


[gcc/devel/rust/master] Replace scaffolded InlineAsm with real InlineAsm.

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:1e784746825d984dddc23cc75c5e6b80b2563d88

commit 1e784746825d984dddc23cc75c5e6b80b2563d88
Author: jjasmine 
Date:   Tue May 21 16:50:36 2024 -0700

Replace scaffolded InlineAsm with real InlineAsm.

Replace scaffolded InlineAsm with real InlineAsm node in rust-expr.h

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-asm.cc (parseDirSpec): replace
scaffolded InlineAsm with real InlineAsm.
(parse_clobber_abi): likewise.
(check_and_set): likewise.
(parse_options): likewise.
(parseAsmArg): likewise.
(parse_asm): likewise.
* expand/rust-macro-builtins-asm.h (struct AsmParseError): likewise.
(enum InlineAsmDirSpec): likewise.
(enum InlineAsmRegOrRegClass): likewise.
(struct AsmArg): likewise.
(parseAsmArg): likewise.
(check_and_set): likewise.
(parse_operand): likewise.
(parse_options): likewise.
(parse_reg): likewise.
(parse_clobber_abi): likewise.

Diff:
---
 gcc/rust/expand/rust-macro-builtins-asm.cc | 54 +---
 gcc/rust/expand/rust-macro-builtins-asm.h  | 66 +-
 2 files changed, 40 insertions(+), 80 deletions(-)

diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index eae194b56f2a..9d7c9d4b7c69 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -20,15 +20,15 @@
 
 namespace Rust {
 
-tl::optional
+int
 parseDirSpec (Parser &parser, TokenId last_token_id)
 {
-  return tl::nullopt;
+  return 0;
 }
 
 int
 parse_clobber_abi (Parser &parser, TokenId last_token_id,
-  AsmArg &args)
+  AST::InlineAsm &inlineAsm)
 {
   // clobber_abi := "clobber_abi("  *("," ) [","] ")"
 
@@ -49,7 +49,7 @@ parse_clobber_abi (Parser &parser, TokenId 
last_token_id,
   return -1;
 }
 
-  ClobberAbis new_abis;
+  std::vector new_abis;
 
   auto token = parser.peek_current_token ();
 
@@ -59,7 +59,7 @@ parse_clobber_abi (Parser &parser, TokenId 
last_token_id,
   if (token->get_id () == STRING_LITERAL)
{
  // TODO: Caring for span in here.
- new_abis.push_back (token->as_string ());
+ new_abis.push_back ({token->as_string (), token->get_locus ()});
}
   else
{
@@ -88,16 +88,17 @@ parse_clobber_abi (Parser &parser, TokenId 
last_token_id,
 
   for (auto abi : new_abis)
 {
-  args.clobber_abis.push_back (abi);
+  inlineAsm.clobber_abi.push_back (abi);
 }
 
   return 0;
 }
 
 void
-check_and_set (Parser &p, AsmArg &args, std::string option)
+check_and_set (Parser &p, AST::InlineAsm &inlineAsm,
+  std::string option)
 {
-  if (args.options.count (option) == 1)
+  if (inlineAsm.options.count (option) == 1)
 {
   // TODO: report an error of duplication
 
@@ -105,13 +106,14 @@ check_and_set (Parser &p, AsmArg &args, 
std::string option)
 }
   else
 {
-  args.options.insert (option);
+  inlineAsm.options.insert (option);
 }
 }
 int
 parse_options (Parser &parser, TokenId last_token_id,
-  AsmArg &args, bool is_global_asm)
+  AST::InlineAsm &inlineAsm)
 {
+  bool is_global_asm = inlineAsm.is_global_asm;
   // Parse everything commitedly
   if (!parser.skip_token (LEFT_PAREN))
 {
@@ -126,43 +128,43 @@ parse_options (Parser &parser, TokenId 
last_token_id,
 {
   if (!is_global_asm && check_identifier (parser, "pure"))
{
- check_and_set (parser, args, "pure");
+ check_and_set (parser, inlineAsm, "pure");
}
   else if (!is_global_asm && check_identifier (parser, "nomem"))
{
- check_and_set (parser, args, "nomem");
+ check_and_set (parser, inlineAsm, "nomem");
}
   else if (!is_global_asm && check_identifier (parser, "readonly"))
{
- check_and_set (parser, args, "readonly");
+ check_and_set (parser, inlineAsm, "readonly");
}
   else if (!is_global_asm && check_identifier (parser, "preserves_flags"))
{
- check_and_set (parser, args, "preserves_flags");
+ check_and_set (parser, inlineAsm, "preserves_flags");
}
   else if (!is_global_asm && check_identifier (parser, "noreturn"))
{
- check_and_set (parser, args, "noreturn");
+ check_and_set (parser, inlineAsm, "noreturn");
}
   else if (!is_global_asm && check_identifier (parser, "noreturn"))
{
- check_and_set (parser, args, "noreturn");
+ check_and_set (parser, inlineAsm, "noreturn");
}
   else if (!is_global_asm && check_identifier (parser, "nostack"))
{
- check_and_set (parser, args, "nostack");
+ check_and_set (parser, inlineAsm, "nostack");
}
   else if (!is_global_as

[gcc/devel/rust/master] Top level parsing test for asm!

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:2822845b16c2545c01a28328b81b642631d3e165

commit 2822845b16c2545c01a28328b81b642631d3e165
Author: jjasmine 
Date:   Tue May 21 17:54:57 2024 -0700

Top level parsing test for asm!

gcc/testsuite/ChangeLog:

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

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

diff --git a/gcc/testsuite/rust/compile/inline_asm_ident_first.rs 
b/gcc/testsuite/rust/compile/inline_asm_ident_first.rs
new file mode 100644
index ..9a4eb7ee4024
--- /dev/null
+++ b/gcc/testsuite/rust/compile/inline_asm_ident_first.rs
@@ -0,0 +1,10 @@
+#![feature(rustc_attrs)]
+
+#[rustc_builtin_macro]
+macro_rules! asm {
+() => {}
+}
+
+fn main() {
+asm!(i_am_a_dummy); // { dg-error "asm template must be a string literal" }
+}
\ No newline at end of file


[gcc/devel/rust/master] Add tests parsing with trailing commas inline asm

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:a4fe2a1016a8ebfd0d7a3b139f50b7b4fa258e6c

commit a4fe2a1016a8ebfd0d7a3b139f50b7b4fa258e6c
Author: jjasmine 
Date:   Tue May 21 18:06:30 2024 -0700

Add tests parsing with trailing commas inline asm

gcc/testsuite/ChangeLog:

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

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

diff --git a/gcc/testsuite/rust/compile/inline_asm_nop_2.rs 
b/gcc/testsuite/rust/compile/inline_asm_nop_2.rs
new file mode 100644
index ..8437e8fc66c3
--- /dev/null
+++ b/gcc/testsuite/rust/compile/inline_asm_nop_2.rs
@@ -0,0 +1,10 @@
+#![feature(rustc_attrs)]
+
+#[rustc_builtin_macro]
+macro_rules! asm {
+() => {}
+}
+
+fn main() {
+asm!("nop",);
+}


[gcc/devel/rust/master] First draft of parse_option finished

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:666e43bde81d41898d8cbde7edddb691a5c4a0f5

commit 666e43bde81d41898d8cbde7edddb691a5c4a0f5
Author: jjasmine 
Date:   Tue May 21 00:31:57 2024 -0700

First draft of parse_option finished

Finish up on parse_option, formatted parse_clobber_abi
gcc/rust/ChangeLog:

* expand/rust-macro-builtins-asm.cc (parse_clobber_abi): format
(check_and_set): helper function, is try_set_option equivalent
(parse_options): new function
* expand/rust-macro-builtins-asm.h (enum InlineAsmOptions):
removed
(check_and_set): decl of helper function

Diff:
---
 gcc/rust/expand/rust-macro-builtins-asm.cc | 84 +-
 gcc/rust/expand/rust-macro-builtins-asm.h  |  8 ++-
 2 files changed, 85 insertions(+), 7 deletions(-)

diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index cfe5906ba020..eae194b56f2a 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -79,6 +79,8 @@ parse_clobber_abi (Parser &parser, TokenId 
last_token_id,
  // illegal, pleaes emit the correct error.
  return -1;
}
+
+  token = parser.peek_current_token ();
 }
 
   // Done processing the local clobber abis, push that to the main Args in
@@ -92,12 +94,26 @@ parse_clobber_abi (Parser &parser, TokenId 
last_token_id,
   return 0;
 }
 
+void
+check_and_set (Parser &p, AsmArg &args, std::string option)
+{
+  if (args.options.count (option) == 1)
+{
+  // TODO: report an error of duplication
+
+  return;
+}
+  else
+{
+  args.options.insert (option);
+}
+}
 int
 parse_options (Parser &parser, TokenId last_token_id,
   AsmArg &args, bool is_global_asm)
 {
   // Parse everything commitedly
-  if (!p.skip_token (LEFT_PAREN))
+  if (!parser.skip_token (LEFT_PAREN))
 {
   // We have shifted `options` to search for the left parenthesis next, we
   // should error out if this is not possible.
@@ -108,9 +124,73 @@ parse_options (Parser &parser, TokenId 
last_token_id,
   auto token = parser.peek_current_token ();
   while (token->get_id () != last_token_id && token->get_id () != RIGHT_PAREN)
 {
-  parser.skip_token ();
+  if (!is_global_asm && check_identifier (parser, "pure"))
+   {
+ check_and_set (parser, args, "pure");
+   }
+  else if (!is_global_asm && check_identifier (parser, "nomem"))
+   {
+ check_and_set (parser, args, "nomem");
+   }
+  else if (!is_global_asm && check_identifier (parser, "readonly"))
+   {
+ check_and_set (parser, args, "readonly");
+   }
+  else if (!is_global_asm && check_identifier (parser, "preserves_flags"))
+   {
+ check_and_set (parser, args, "preserves_flags");
+   }
+  else if (!is_global_asm && check_identifier (parser, "noreturn"))
+   {
+ check_and_set (parser, args, "noreturn");
+   }
+  else if (!is_global_asm && check_identifier (parser, "noreturn"))
+   {
+ check_and_set (parser, args, "noreturn");
+   }
+  else if (!is_global_asm && check_identifier (parser, "nostack"))
+   {
+ check_and_set (parser, args, "nostack");
+   }
+  else if (!is_global_asm && check_identifier (parser, "may_unwind"))
+   {
+ check_and_set (parser, args, "may_unwind");
+   }
+  else if (check_identifier (parser, "att_syntax"))
+   {
+ check_and_set (parser, args, "att_syntax");
+   }
+  else if (check_identifier (parser, "raw"))
+   {
+ check_and_set (parser, args, "raw");
+   }
+  else
+   {
+ // TODO: Unexpected error, please return the correct error
+ rust_error_at (token->get_locus (),
+"Unexpected token encountered in parse_options");
+   }
+  if (!parser.skip_token (RIGHT_PAREN))
+   {
+ break;
+   }
+
+  if (!parser.skip_token (COMMA))
+   {
+ // TODO: If the skip of comma is unsuccessful, which should be
+ // illegal, pleaes emit the correct error.
+ return -1;
+   }
+
   token = parser.peek_current_token ();
 }
+
+  // TODO: Per rust asm.rs regarding options_spans
+  // I'm guessing this has to do with some error reporting.
+  // let new_span = span_start.to(p.prev_token.span);
+  // args.options_spans.push(new_span);
+
+  return 0;
 }
 bool
 check_identifier (Parser &p, std::string ident)
diff --git a/gcc/rust/expand/rust-macro-builtins-asm.h 
b/gcc/rust/expand/rust-macro-builtins-asm.h
index ebb939a05480..fd86c309c9a5 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.h
+++ b/gcc/rust/expand/rust-macro-builtins-asm.h
@@ -21,11 +21,6 @@ enum InlineAsmDirSpec
   Label, // TODO: This is not present in ABNF
 };
 
-enum InlineAsmOptions
-{
-
-};
-
 // Place holder for classes
 enum InlineAsmRegOrRegClass
 

[gcc/devel/rust/master] Make InlineAsm non-abstract for usage in parsing.

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:3c93736b8b898d48147488669b01338ffa09d47f

commit 3c93736b8b898d48147488669b01338ffa09d47f
Author: jjasmine 
Date:   Tue May 21 15:02:00 2024 -0700

Make InlineAsm non-abstract for usage in parsing.

gcc/rust/ChangeLog:

* ast/rust-expr.h: Make InlineAsm non-abstract for usage in parsing.

Diff:
---
 gcc/rust/ast/rust-expr.h | 44 
 1 file changed, 36 insertions(+), 8 deletions(-)

diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index 84fb5e8ab337..03336cdcc594 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -4809,11 +4809,8 @@ struct InlineAsmPlaceHolder
 struct InlineAsmTemplatePiece
 {
   bool is_placeholder;
-  union
-  {
-std::string string;
-InlineAsmPlaceHolder placeholder;
-  };
+  std::string string;
+  InlineAsmPlaceHolder placeholder;
 };
 
 struct TupleClobber
@@ -4832,16 +4829,47 @@ struct TupleTemplateStr
 };
 
 // Inline Assembly Node
-class InlineAsm : public ExprWithoutBlock
+class InlineAsm : private ExprWithoutBlock
 {
+private:
+  location_t locus;
+  // TODO: Not sure how outer_attrs plays with InlineAsm, I put it here in 
order
+  // to override, very hacky.
+  std::vector outer_attrs;
+
 public:
   std::vector template_;
   std::vector template_strs;
   std::vector operands;
-  TupleClobber clobber_abi;
-  InlineAsmOptions options;
+  std::vector clobber_abi;
+  // std::set options;
+  std::set options;
+
   std::vector line_spans;
+
   bool is_global_asm;
+
+  InlineAsm (location_t locus, bool is_global_asm)
+: locus (locus), is_global_asm (is_global_asm)
+  {}
+  void accept_vis (ASTVisitor &vis) override{};
+
+  std::string as_string () const override { return "InlineAsm AST Node"; }
+
+  location_t get_locus () const override { return locus; }
+
+  void mark_for_strip () override {}
+
+  bool is_marked_for_strip () const override { return false; }
+
+  std::vector &get_outer_attrs () override { return outer_attrs; }
+
+  void set_outer_attrs (std::vector v) override { outer_attrs = v; }
+
+  ExprWithoutBlock *clone_expr_without_block_impl () const override
+  {
+return nullptr;
+  }
 };
 
 } // namespace AST


[gcc/devel/rust/master] Add a simple no-op test for asm!

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:af74733fa97de1195f45ef5b1727cb933d736255

commit af74733fa97de1195f45ef5b1727cb933d736255
Author: jjasmine 
Date:   Tue May 21 17:48:30 2024 -0700

Add a simple no-op test for asm!

gcc/testsuite/ChangeLog:

* rust/compile/inline_asm_nop.rs: Simple test for asm!

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

diff --git a/gcc/testsuite/rust/compile/inline_asm_nop.rs 
b/gcc/testsuite/rust/compile/inline_asm_nop.rs
new file mode 100644
index ..ffe3161cd73c
--- /dev/null
+++ b/gcc/testsuite/rust/compile/inline_asm_nop.rs
@@ -0,0 +1,10 @@
+#![feature(rustc_attrs)]
+
+#[rustc_builtin_macro]
+macro_rules! asm {
+() => {}
+}
+
+fn main() {
+asm!("nop");
+}


[gcc/devel/rust/master] Added faulty tests for inline asm cloberring

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:de7dbe64f859ab67ee0160cff6f8463569dd9739

commit de7dbe64f859ab67ee0160cff6f8463569dd9739
Author: jjasmine 
Date:   Tue May 21 19:45:35 2024 -0700

Added faulty tests for inline asm cloberring

gcc/testsuite/ChangeLog:

* rust/compile/inline_asm_faulty_clobber.rs: New test.
* rust/compile/inline_asm_faulty_clobber_1.rs: New test.
* rust/compile/inline_asm_faulty_clobber_2.rs: New test.

Diff:
---
 gcc/testsuite/rust/compile/inline_asm_faulty_clobber.rs   | 10 ++
 gcc/testsuite/rust/compile/inline_asm_faulty_clobber_1.rs | 10 ++
 gcc/testsuite/rust/compile/inline_asm_faulty_clobber_2.rs | 10 ++
 3 files changed, 30 insertions(+)

diff --git a/gcc/testsuite/rust/compile/inline_asm_faulty_clobber.rs 
b/gcc/testsuite/rust/compile/inline_asm_faulty_clobber.rs
new file mode 100644
index ..8d040ea40b4f
--- /dev/null
+++ b/gcc/testsuite/rust/compile/inline_asm_faulty_clobber.rs
@@ -0,0 +1,10 @@
+#![feature(rustc_attrs)]
+
+#[rustc_builtin_macro]
+macro_rules! asm {
+() => {}
+}
+
+fn main() {
+asm!("nop", clobber_abi());  // { dg-error "at least one abi must be 
provided as an argument to `clobber_abi`" }
+}
\ No newline at end of file
diff --git a/gcc/testsuite/rust/compile/inline_asm_faulty_clobber_1.rs 
b/gcc/testsuite/rust/compile/inline_asm_faulty_clobber_1.rs
new file mode 100644
index ..77af10177c48
--- /dev/null
+++ b/gcc/testsuite/rust/compile/inline_asm_faulty_clobber_1.rs
@@ -0,0 +1,10 @@
+#![feature(rustc_attrs)]
+
+#[rustc_builtin_macro]
+macro_rules! asm {
+() => {}
+}
+
+fn main() {
+asm!("nop", clobber_abi);  // { dg-error "expected `\\(`, found end of 
macro arguments" }
+}
\ No newline at end of file
diff --git a/gcc/testsuite/rust/compile/inline_asm_faulty_clobber_2.rs 
b/gcc/testsuite/rust/compile/inline_asm_faulty_clobber_2.rs
new file mode 100644
index ..ae3607ffa778
--- /dev/null
+++ b/gcc/testsuite/rust/compile/inline_asm_faulty_clobber_2.rs
@@ -0,0 +1,10 @@
+#![feature(rustc_attrs)]
+
+#[rustc_builtin_macro]
+macro_rules! asm {
+() => {}
+}
+
+fn main() {
+asm!("nop", clobber_abi+);  // { dg-error "expected `\\(`, found `\\+`" }
+}
\ No newline at end of file


[gcc/devel/rust/master] Wraps inline_asm tests in unsafe {}

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:ed17ab77c334c0351f92805695640d9a57e2bbd4

commit ed17ab77c334c0351f92805695640d9a57e2bbd4
Author: jjasmine 
Date:   Wed May 22 01:23:40 2024 -0700

Wraps inline_asm tests in unsafe {}

gcc/testsuite/ChangeLog:

* rust/compile/inline_asm_faulty_clobber.rs:
Wraps inline_asm tests in unsafe {}
* rust/compile/inline_asm_faulty_clobber_1.rs: likewise.
* rust/compile/inline_asm_faulty_clobber_2.rs: likewise.
* rust/compile/inline_asm_ident_first.rs: likewise.
* rust/compile/inline_asm_nop.rs: likewise.
* rust/compile/inline_asm_nop_2.rs: likewise.

Diff:
---
 gcc/testsuite/rust/compile/inline_asm_faulty_clobber.rs   | 4 +++-
 gcc/testsuite/rust/compile/inline_asm_faulty_clobber_1.rs | 4 +++-
 gcc/testsuite/rust/compile/inline_asm_faulty_clobber_2.rs | 4 +++-
 gcc/testsuite/rust/compile/inline_asm_ident_first.rs  | 4 +++-
 gcc/testsuite/rust/compile/inline_asm_nop.rs  | 4 +++-
 gcc/testsuite/rust/compile/inline_asm_nop_2.rs| 4 +++-
 6 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/gcc/testsuite/rust/compile/inline_asm_faulty_clobber.rs 
b/gcc/testsuite/rust/compile/inline_asm_faulty_clobber.rs
index 8d040ea40b4f..67dc10bd75bc 100644
--- a/gcc/testsuite/rust/compile/inline_asm_faulty_clobber.rs
+++ b/gcc/testsuite/rust/compile/inline_asm_faulty_clobber.rs
@@ -6,5 +6,7 @@ macro_rules! asm {
 }
 
 fn main() {
-asm!("nop", clobber_abi());  // { dg-error "at least one abi must be 
provided as an argument to `clobber_abi`" }
+unsafe {
+asm!("nop", clobber_abi());  // { dg-error "at least one abi must be 
provided as an argument to `clobber_abi`" }
+}
 }
\ No newline at end of file
diff --git a/gcc/testsuite/rust/compile/inline_asm_faulty_clobber_1.rs 
b/gcc/testsuite/rust/compile/inline_asm_faulty_clobber_1.rs
index 77af10177c48..2906ea4292a5 100644
--- a/gcc/testsuite/rust/compile/inline_asm_faulty_clobber_1.rs
+++ b/gcc/testsuite/rust/compile/inline_asm_faulty_clobber_1.rs
@@ -6,5 +6,7 @@ macro_rules! asm {
 }
 
 fn main() {
-asm!("nop", clobber_abi);  // { dg-error "expected `\\(`, found end of 
macro arguments" }
+unsafe {
+asm!("nop", clobber_abi);  // { dg-error "expected `\\(`, found end of 
macro arguments" }
+}
 }
\ No newline at end of file
diff --git a/gcc/testsuite/rust/compile/inline_asm_faulty_clobber_2.rs 
b/gcc/testsuite/rust/compile/inline_asm_faulty_clobber_2.rs
index ae3607ffa778..e5bf1d1f7f62 100644
--- a/gcc/testsuite/rust/compile/inline_asm_faulty_clobber_2.rs
+++ b/gcc/testsuite/rust/compile/inline_asm_faulty_clobber_2.rs
@@ -6,5 +6,7 @@ macro_rules! asm {
 }
 
 fn main() {
-asm!("nop", clobber_abi+);  // { dg-error "expected `\\(`, found `\\+`" }
+unsafe {
+asm!("nop", clobber_abi+);  // { dg-error "expected `\\(`, found 
`\\+`" }
+}
 }
\ No newline at end of file
diff --git a/gcc/testsuite/rust/compile/inline_asm_ident_first.rs 
b/gcc/testsuite/rust/compile/inline_asm_ident_first.rs
index 9a4eb7ee4024..a425b8e5ad41 100644
--- a/gcc/testsuite/rust/compile/inline_asm_ident_first.rs
+++ b/gcc/testsuite/rust/compile/inline_asm_ident_first.rs
@@ -6,5 +6,7 @@ macro_rules! asm {
 }
 
 fn main() {
-asm!(i_am_a_dummy); // { dg-error "asm template must be a string literal" }
+unsafe {
+asm!(i_am_a_dummy); // { dg-error "asm template must be a string 
literal" }
+}
 }
\ No newline at end of file
diff --git a/gcc/testsuite/rust/compile/inline_asm_nop.rs 
b/gcc/testsuite/rust/compile/inline_asm_nop.rs
index ffe3161cd73c..7da9bef3e568 100644
--- a/gcc/testsuite/rust/compile/inline_asm_nop.rs
+++ b/gcc/testsuite/rust/compile/inline_asm_nop.rs
@@ -6,5 +6,7 @@ macro_rules! asm {
 }
 
 fn main() {
-asm!("nop");
+unsafe {
+asm!("nop");
+}
 }
diff --git a/gcc/testsuite/rust/compile/inline_asm_nop_2.rs 
b/gcc/testsuite/rust/compile/inline_asm_nop_2.rs
index 8437e8fc66c3..76f53fadbe3c 100644
--- a/gcc/testsuite/rust/compile/inline_asm_nop_2.rs
+++ b/gcc/testsuite/rust/compile/inline_asm_nop_2.rs
@@ -6,5 +6,7 @@ macro_rules! asm {
 }
 
 fn main() {
-asm!("nop",);
+unsafe {
+asm!("nop",);
+}
 }


[gcc/devel/rust/master] Add checks for duplicate options in inline asm

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:a4cbd38f06c2d4f6859b7bda3086cd62f9e0dfca

commit a4cbd38f06c2d4f6859b7bda3086cd62f9e0dfca
Author: jjasmine 
Date:   Wed May 22 02:00:09 2024 -0700

Add checks for duplicate options in inline asm

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-asm.cc (check_and_set):
Add checks for duplicate options in inline asm
(parse_options): likewise.

gcc/testsuite/ChangeLog:

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

Diff:
---
 gcc/rust/expand/rust-macro-builtins-asm.cc | 35 +++---
 .../rust/compile/inline_asm_illegal_options.rs | 13 
 2 files changed, 38 insertions(+), 10 deletions(-)

diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index a86d58ee69f9..185bf38259f5 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -19,6 +19,17 @@
 #include "rust-macro-builtins-asm.h"
 
 namespace Rust {
+std::map InlineAsmOptionsMap{
+  {AST::InlineAsmOptions::PURE, "pure"},
+  {AST::InlineAsmOptions::NOMEM, "nomem"},
+  {AST::InlineAsmOptions::READONLY, "readonly"},
+  {AST::InlineAsmOptions::PRESERVES_FLAGS, "preserves_flags"},
+  {AST::InlineAsmOptions::NORETURN, "noreturn"},
+  {AST::InlineAsmOptions::NOSTACK, "nostack"},
+  {AST::InlineAsmOptions::MAY_UNWIND, "may_unwind"},
+  {AST::InlineAsmOptions::ATT_SYNTAX, "att_syntax"},
+  {AST::InlineAsmOptions::RAW, "raw"},
+};
 
 int
 parseDirSpec (Parser &parser, TokenId last_token_id)
@@ -115,13 +126,15 @@ parse_clobber_abi (Parser &parser, 
TokenId last_token_id,
 }
 
 void
-check_and_set (Parser &p, AST::InlineAsm &inlineAsm,
+check_and_set (Parser &parser, AST::InlineAsm &inlineAsm,
   AST::InlineAsmOptions option)
 {
-  if (inlineAsm.options.count (option) == 1)
+  if (inlineAsm.options.count (option) != 0)
 {
   // TODO: report an error of duplication
-
+  rust_error_at (parser.peek_current_token ()->get_locus (),
+"the `%s` option was already provided",
+InlineAsmOptionsMap[option].c_str ());
   return;
 }
   else
@@ -189,20 +202,22 @@ parse_options (Parser &parser, TokenId 
last_token_id,
  rust_error_at (token->get_locus (),
 "Unexpected token encountered in parse_options");
}
-  if (!parser.skip_token (RIGHT_PAREN))
+  if (parser.skip_token (RIGHT_PAREN))
{
  break;
}
 
-  if (!parser.skip_token (COMMA))
+  // Parse comma as optional
+  if (parser.skip_token (COMMA))
{
- // TODO: If the skip of comma is unsuccessful, which should be
- // illegal, pleaes emit the correct error.
- std::cout << "Illegal comma" << std::endl;
+ continue;
+   }
+  else
+   {
+ std::cout << "Sum wrong here, check it out" << std::endl;
+ token = parser.peek_current_token ();
  return -1;
}
-
-  token = parser.peek_current_token ();
 }
 
   // TODO: Per rust asm.rs regarding options_spans
diff --git a/gcc/testsuite/rust/compile/inline_asm_illegal_options.rs 
b/gcc/testsuite/rust/compile/inline_asm_illegal_options.rs
new file mode 100644
index ..ee501941af3d
--- /dev/null
+++ b/gcc/testsuite/rust/compile/inline_asm_illegal_options.rs
@@ -0,0 +1,13 @@
+#![feature(rustc_attrs)]
+
+#[rustc_builtin_macro]
+macro_rules! asm {
+() => {}
+}
+
+fn main() {
+unsafe {
+asm!("nop", options(nomem, nomem)); // { dg-error "the `nomem` option 
was already provided" }
+asm!("nop", options(noreturn, noreturn)); // { dg-error "the 
`noreturn` option was already provided" }
+}
+}
\ No newline at end of file


[gcc/devel/rust/master] Resolve static decl warning

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:24fa822edf4a89c1fd272ef931c033958c5ca955

commit 24fa822edf4a89c1fd272ef931c033958c5ca955
Author: jjasmine 
Date:   Wed May 22 11:25:07 2024 -0700

Resolve static decl warning

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-asm.h (parseAsmArg):
Resolve static decl warning
(parse_nonglobal_asm):
Resolve static decl warning

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

diff --git a/gcc/rust/expand/rust-macro-builtins-asm.h 
b/gcc/rust/expand/rust-macro-builtins-asm.h
index 163ad161b5a4..469dc5ae9067 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.h
+++ b/gcc/rust/expand/rust-macro-builtins-asm.h
@@ -11,11 +11,11 @@ int
 parseAsmArg (Parser &p, TokenId last_token_id,
 AST::InlineAsm &inlineAsm,
 bool consumed_comma_without_formatted_string);
-static tl::optional
+tl::optional
 parse_global_asm (location_t invoc_locus, AST::MacroInvocData &invoc);
-static tl::optional
+tl::optional
 parse_nonglobal_asm (location_t invoc_locus, AST::MacroInvocData &invoc);
-static tl::optional
+tl::optional
 parse_asm (location_t invoc_locus, AST::MacroInvocData &invoc,
   bool is_global_asm);


[gcc/devel/rust/master] Introduced is_global_asm to InlineAsm AST

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:c3bdf2dda85db805ffc63c2d10850da544357405

commit c3bdf2dda85db805ffc63c2d10850da544357405
Author: jjasmine 
Date:   Tue May 21 14:53:52 2024 -0700

Introduced is_global_asm to InlineAsm AST

gcc/rust/ChangeLog:

* ast/rust-expr.h: Introduced is_global_asm to InlineAsm AST

Diff:
---
 gcc/rust/ast/rust-expr.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index a5afbffee99b..84fb5e8ab337 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -4841,6 +4841,7 @@ public:
   TupleClobber clobber_abi;
   InlineAsmOptions options;
   std::vector line_spans;
+  bool is_global_asm;
 };
 
 } // namespace AST


[gcc/devel/rust/master] Implemented parse_clobber_abi to pass new tests

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:4ca3eaaad71ffdce97ee550a7f95fee33ebb8184

commit 4ca3eaaad71ffdce97ee550a7f95fee33ebb8184
Author: jjasmine 
Date:   Tue May 21 19:46:18 2024 -0700

Implemented parse_clobber_abi to pass new tests

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-asm.cc (parse_clobber_abi):
implemented parse_clobber_abi
(parse_format_string): likewise.
(parseAsmArg): likewise.
(parse_asm): likewise.
* expand/rust-macro-builtins-asm.h (parseAsmArg): likewise.

Diff:
---
 gcc/rust/expand/rust-macro-builtins-asm.cc | 81 ++
 gcc/rust/expand/rust-macro-builtins-asm.h  |  3 +-
 2 files changed, 61 insertions(+), 23 deletions(-)

diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index 9d7c9d4b7c69..df65a8f1beb7 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -31,14 +31,31 @@ parse_clobber_abi (Parser &parser, TokenId 
last_token_id,
   AST::InlineAsm &inlineAsm)
 {
   // clobber_abi := "clobber_abi("  *("," ) [","] ")"
-
   // PARSE EVERYTHING COMMITTEDLY IN THIS FUNCTION, WE CONFIRMED VIA 
clobber_abi
   // identifier keyword
-
+  auto token = parser.peek_current_token ();
   if (!parser.skip_token (LEFT_PAREN))
 {
   // TODO: Raise error exactly like rustc if left parenthesis is not
   // encountered.
+  token = parser.peek_current_token ();
+
+  // TODO: Error reporting shifted to the left 1 character, I'm not sure
+  // why.
+  if (token->get_id () == last_token_id)
+   {
+ rust_error_at (parser.peek_current_token ()->get_locus (),
+"expected `(`, found end of macro arguments");
+ return -1;
+   }
+
+  else
+   {
+ rust_error_at (
+   parser.peek_current_token ()->get_locus (),
+   "expected `(`, found `%s`",
+   parser.peek_current_token ()->get_token_description ());
+   }
   return -1;
 }
 
@@ -46,12 +63,15 @@ parse_clobber_abi (Parser &parser, TokenId 
last_token_id,
 {
   // TODO: We encountered a "clobber_abi()", which should be illegal?
   // 
https://github.com/rust-lang/rust/blob/c00957a3e269219413041a4e3565f33b1f9d0779/compiler/rustc_builtin_macros/src/asm.rs#L381
+  rust_error_at (
+   parser.peek_current_token ()->get_locus (),
+   "at least one abi must be provided as an argument to `clobber_abi`");
   return -1;
 }
 
   std::vector new_abis;
 
-  auto token = parser.peek_current_token ();
+  token = parser.peek_current_token ();
 
   while (token->get_id () != last_token_id && token->get_id () != RIGHT_PAREN)
 {
@@ -198,7 +218,6 @@ bool
 check_identifier (Parser &p, std::string ident)
 {
   auto token = p.peek_current_token ();
-
   if (token->get_id () == IDENTIFIER
   && (token->as_string () == ident || ident == ""))
 {
@@ -218,17 +237,11 @@ parse_format_string (Parser &parser, 
TokenId last_token_id)
   if (token->get_id () != last_token_id && token->get_id () == STRING_LITERAL)
 {
   // very nice, we got a supposedly formatted string.
-  std::cout << token->get_token_description () << std::endl;
   parser.skip_token ();
-  return "formatted string";
+  return token->as_string ();
 }
   else
 {
-  parser.skip_token ();
-  std::cout << token->get_token_description () << std::endl;
-
-  rust_error_at (token->get_locus (),
-"asm template must be a string literal");
   return tl::nullopt;
 }
 }
@@ -253,22 +266,32 @@ MacroBuiltin::nonglobal_asm_handler (location_t 
invoc_locus,
 
 int
 parseAsmArg (Parser &parser, TokenId last_token_id,
-AST::InlineAsm &inlineAsm)
+AST::InlineAsm &inlineAsm,
+bool consumed_comma_without_formatted_string)
 {
   auto token = parser.peek_current_token ();
   tl::optional fm_string;
   while (token->get_id () != last_token_id)
 {
-  std::cout << token->get_token_description () << std::endl;
-
   token = parser.peek_current_token ();
 
   // We accept a comma token here.
-  if (token->get_id () != COMMA)
+  if (token->get_id () != COMMA && consumed_comma_without_formatted_string)
+   {
+ // if it is not a comma, but we consumed it previously, this is fine
+ // but we have to set it to false tho.
+ consumed_comma_without_formatted_string = false;
+   }
+  else if (token->get_id () == COMMA
+  && !consumed_comma_without_formatted_string)
+   {
+ consumed_comma_without_formatted_string = false;
+ parser.skip_token ();
+   }
+  else
{
  break;
}
-  parser.skip_token ();
 
   // And if that token comma is also the trailing comma, we break
   // TODO: Check with mentor see what last_token_id means
@@ -285,7 +308,7 @@ parse

[gcc/devel/rust/master] Safegaurd InlineAsm's clone_expr_...

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:69265253d17c6b190ee4e495c3782e007795248c

commit 69265253d17c6b190ee4e495c3782e007795248c
Author: jjasmine 
Date:   Fri May 24 15:35:16 2024 -0700

Safegaurd InlineAsm's clone_expr_...

Safegaurd InlineAsm's clone_expr_... with unreachable since
we would never use them.

gcc/rust/ChangeLog:

* ast/rust-expr.h:
Safegaurd InlineAsm's clone_expr_... with unreachable.

Diff:
---
 gcc/rust/ast/rust-expr.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index bceef827dfb0..1af72965a93e 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -4873,6 +4873,7 @@ public:
 
   ExprWithoutBlock *clone_expr_without_block_impl () const override
   {
+rust_unreachable ();
 return nullptr;
   }
 };


[gcc/devel/rust/master] Remove global_asm and non_global_asm handler

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:56c687a5f648ed581729bc8edd4f0802e71899af

commit 56c687a5f648ed581729bc8edd4f0802e71899af
Author: jjasmine 
Date:   Fri May 24 16:01:13 2024 -0700

Remove global_asm and non_global_asm handler

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-asm.cc
(MacroBuiltin::global_asm_handler):
Remove global_asm and non_global_asm handler
(MacroBuiltin::nonglobal_asm_handler): Likewise.
(MacroBuiltin::asm_handler): Likewise.
* expand/rust-macro-builtins.cc (enum class): Likewise.
(inline_asm_maker): Likewise.
* expand/rust-macro-builtins.h: Likewise.

Diff:
---
 gcc/rust/expand/rust-macro-builtins-asm.cc | 15 ++-
 gcc/rust/expand/rust-macro-builtins.cc | 20 ++--
 gcc/rust/expand/rust-macro-builtins.h  |  8 +++-
 3 files changed, 23 insertions(+), 20 deletions(-)

diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index 5734a4176c8d..268019c2da2b 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -307,20 +307,9 @@ parse_format_string (Parser &parser, 
TokenId last_token_id)
 }
 
 tl::optional
-MacroBuiltin::global_asm_handler (location_t invoc_locus,
- AST::MacroInvocData &invoc)
+MacroBuiltin::asm_handler (location_t invoc_locus, AST::MacroInvocData &invoc,
+  bool is_global_asm)
 {
-  // Just to clarify the code
-  bool is_global_asm = true;
-  return parse_asm (invoc_locus, invoc, is_global_asm);
-}
-
-tl::optional
-MacroBuiltin::nonglobal_asm_handler (location_t invoc_locus,
-AST::MacroInvocData &invoc)
-{
-  // Just to clarify the code
-  bool is_global_asm = false;
   return parse_asm (invoc_locus, invoc, is_global_asm);
 }
 
diff --git a/gcc/rust/expand/rust-macro-builtins.cc 
b/gcc/rust/expand/rust-macro-builtins.cc
index dc2482acf6ca..617202f43549 100644
--- a/gcc/rust/expand/rust-macro-builtins.cc
+++ b/gcc/rust/expand/rust-macro-builtins.cc
@@ -92,6 +92,22 @@ format_args_maker (AST::FormatArgs::Newline nl)
   };
 }
 
+enum class isGlobalAsm
+{
+  Yes,
+  No,
+};
+
+AST::MacroTranscriberFunc
+inline_asm_maker (isGlobalAsm is_global_asm)
+{
+  bool global_asm = is_global_asm == isGlobalAsm::Yes ? true : false;
+
+  return [global_asm] (location_t loc, AST::MacroInvocData &invoc) {
+return MacroBuiltin::asm_handler (loc, invoc, global_asm);
+  };
+}
+
 std::unordered_map
   MacroBuiltin::builtin_transcribers = {
 {"assert", MacroBuiltin::assert_handler},
@@ -108,8 +124,8 @@ std::unordered_map
 {"include", MacroBuiltin::include_handler},
 {"format_args", format_args_maker (AST::FormatArgs::Newline::No)},
 {"format_args_nl", format_args_maker (AST::FormatArgs::Newline::Yes)},
-{"asm", MacroBuiltin::nonglobal_asm_handler},
-{"global_asm", MacroBuiltin::global_asm_handler},
+{"asm", inline_asm_maker (isGlobalAsm::No)},
+{"global_asm", inline_asm_maker (isGlobalAsm::Yes)},
 /* Unimplemented macro builtins */
 {"option_env", MacroBuiltin::sorry},
 {"concat_idents", MacroBuiltin::sorry},
diff --git a/gcc/rust/expand/rust-macro-builtins.h 
b/gcc/rust/expand/rust-macro-builtins.h
index dbc838bf97fe..d9873c712099 100644
--- a/gcc/rust/expand/rust-macro-builtins.h
+++ b/gcc/rust/expand/rust-macro-builtins.h
@@ -159,11 +159,9 @@ public:
   static tl::optional line_handler (location_t invoc_locus,
   AST::MacroInvocData &invoc);
 
-  static tl::optional
-  nonglobal_asm_handler (location_t invoc_locus, AST::MacroInvocData &invoc);
-
-  static tl::optional
-  global_asm_handler (location_t invoc_locus, AST::MacroInvocData &invoc);
+  static tl::optional asm_handler (location_t invoc_locus,
+ AST::MacroInvocData &invoc,
+ bool is_global_asm);
 
   static tl::optional
   format_args_handler (location_t invoc_locus, AST::MacroInvocData &invoc,


[gcc/devel/rust/master] Rename InlineAsmOptions to InlineAsmOption

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:93e27fa1b2ef168a5831ebc3ac676b4a2a1c55c2

commit 93e27fa1b2ef168a5831ebc3ac676b4a2a1c55c2
Author: jjasmine 
Date:   Fri May 24 15:31:48 2024 -0700

Rename InlineAsmOptions to InlineAsmOption

Rename InlineAsmOptions to InlineAsmOption for clarity

gcc/rust/ChangeLog:

* ast/rust-ast-full-decls.h (enum class):
Rename InlineAsmOptions to InlineAsmOption for clarity
* ast/rust-expr.h (enum class): Likewise.
* expand/rust-macro-builtins-asm.cc (check_and_set): Likewise.
(parse_options): Likewise.
* expand/rust-macro-builtins-asm.h (check_and_set): Likewise.
* hir/tree/rust-hir-expr.h: Likewise.

Diff:
---
 gcc/rust/ast/rust-ast-full-decls.h |  2 +-
 gcc/rust/ast/rust-expr.h   |  5 ++--
 gcc/rust/expand/rust-macro-builtins-asm.cc | 42 +++---
 gcc/rust/expand/rust-macro-builtins-asm.h  |  2 +-
 gcc/rust/hir/tree/rust-hir-expr.h  |  2 +-
 5 files changed, 26 insertions(+), 27 deletions(-)

diff --git a/gcc/rust/ast/rust-ast-full-decls.h 
b/gcc/rust/ast/rust-ast-full-decls.h
index dd982c448e01..cf6bcbbc2ca8 100644
--- a/gcc/rust/ast/rust-ast-full-decls.h
+++ b/gcc/rust/ast/rust-ast-full-decls.h
@@ -145,7 +145,7 @@ struct MatchCase;
 class MatchExpr;
 class AwaitExpr;
 class AsyncBlockExpr;
-enum class InlineAsmOptions;
+enum class InlineAsmOption;
 struct AnonConst;
 struct InlineAsmRegOrRegClass;
 struct InlineAsmOperand;
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index 309174057c00..bceef827dfb0 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -4706,7 +4706,7 @@ protected:
 };
 
 // Inline-assembly specific options
-enum class InlineAsmOptions
+enum class InlineAsmOption
 {
   PURE = 1 << 0,
   NOMEM = 1 << 1,
@@ -4848,8 +4848,7 @@ public:
   std::vector template_strs;
   std::vector operands;
   std::vector clobber_abi;
-  // std::set options;
-  std::set options;
+  std::set options;
 
   std::vector line_spans;
 
diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index acdbd18342a5..5734a4176c8d 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -19,16 +19,16 @@
 #include "rust-macro-builtins-asm.h"
 
 namespace Rust {
-std::map InlineAsmOptionsMap{
-  {AST::InlineAsmOptions::PURE, "pure"},
-  {AST::InlineAsmOptions::NOMEM, "nomem"},
-  {AST::InlineAsmOptions::READONLY, "readonly"},
-  {AST::InlineAsmOptions::PRESERVES_FLAGS, "preserves_flags"},
-  {AST::InlineAsmOptions::NORETURN, "noreturn"},
-  {AST::InlineAsmOptions::NOSTACK, "nostack"},
-  {AST::InlineAsmOptions::MAY_UNWIND, "may_unwind"},
-  {AST::InlineAsmOptions::ATT_SYNTAX, "att_syntax"},
-  {AST::InlineAsmOptions::RAW, "raw"},
+std::map InlineAsmOptionMap{
+  {AST::InlineAsmOption::PURE, "pure"},
+  {AST::InlineAsmOption::NOMEM, "nomem"},
+  {AST::InlineAsmOption::READONLY, "readonly"},
+  {AST::InlineAsmOption::PRESERVES_FLAGS, "preserves_flags"},
+  {AST::InlineAsmOption::NORETURN, "noreturn"},
+  {AST::InlineAsmOption::NOSTACK, "nostack"},
+  {AST::InlineAsmOption::MAY_UNWIND, "may_unwind"},
+  {AST::InlineAsmOption::ATT_SYNTAX, "att_syntax"},
+  {AST::InlineAsmOption::RAW, "raw"},
 };
 
 int
@@ -174,14 +174,14 @@ parse_operand (Parser &parser, TokenId 
last_token_id,
 
 void
 check_and_set (Parser &parser, AST::InlineAsm &inlineAsm,
-  AST::InlineAsmOptions option)
+  AST::InlineAsmOption option)
 {
   if (inlineAsm.options.count (option) != 0)
 {
   // TODO: report an error of duplication
   rust_error_at (parser.peek_current_token ()->get_locus (),
 "the `%s` option was already provided",
-InlineAsmOptionsMap[option].c_str ());
+InlineAsmOptionMap[option].c_str ());
   return;
 }
   else
@@ -208,40 +208,40 @@ parse_options (Parser &parser, TokenId 
last_token_id,
 {
   if (!is_global_asm && check_identifier (parser, "pure"))
{
- check_and_set (parser, inlineAsm, AST::InlineAsmOptions::PURE);
+ check_and_set (parser, inlineAsm, AST::InlineAsmOption::PURE);
}
   else if (!is_global_asm && check_identifier (parser, "nomem"))
{
- check_and_set (parser, inlineAsm, AST::InlineAsmOptions::NOMEM);
+ check_and_set (parser, inlineAsm, AST::InlineAsmOption::NOMEM);
}
   else if (!is_global_asm && check_identifier (parser, "readonly"))
{
- check_and_set (parser, inlineAsm, AST::InlineAsmOptions::READONLY);
+ check_and_set (parser, inlineAsm, AST::InlineAsmOption::READONLY);
}
   else if (!is_global_asm && check_identifier (parser, "preserves_flags"))
{
  check_and_set (parser, inlineAsm,
-AST::InlineAsmOptions::PRESERVES_FLAGS);
+AST::InlineAsm

[gcc/devel/rust/master] Parsing of options(...) done.

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:0044275c34cdcf6e282c7dc65d54582611267186

commit 0044275c34cdcf6e282c7dc65d54582611267186
Author: jjasmine 
Date:   Wed May 22 01:18:48 2024 -0700

Parsing of options(...) done.

This is without any mutually exclusive options checked, or
any relationship with reg_operands. Very primitive.

gcc/rust/ChangeLog:

* ast/rust-expr.h: parsing of options(...)
* expand/rust-macro-builtins-asm.cc (check_and_set):
likewise.
(parse_options): likewise.
(parseAsmArg): likewise.
* expand/rust-macro-builtins-asm.h (check_and_set):
likewise.

gcc/testsuite/ChangeLog:

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

Diff:
---
 gcc/rust/ast/rust-expr.h   |  2 +-
 gcc/rust/expand/rust-macro-builtins-asm.cc | 30 ++
 gcc/rust/expand/rust-macro-builtins-asm.h  |  2 +-
 .../rust/compile/inline_asm_legal_options.rs   | 12 +
 4 files changed, 28 insertions(+), 18 deletions(-)

diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index 03336cdcc594..719a76cdbb3d 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -4843,7 +4843,7 @@ public:
   std::vector operands;
   std::vector clobber_abi;
   // std::set options;
-  std::set options;
+  std::set options;
 
   std::vector line_spans;
 
diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index df65a8f1beb7..a86d58ee69f9 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -116,7 +116,7 @@ parse_clobber_abi (Parser &parser, TokenId 
last_token_id,
 
 void
 check_and_set (Parser &p, AST::InlineAsm &inlineAsm,
-  std::string option)
+  AST::InlineAsmOptions option)
 {
   if (inlineAsm.options.count (option) == 1)
 {
@@ -148,43 +148,40 @@ parse_options (Parser &parser, TokenId 
last_token_id,
 {
   if (!is_global_asm && check_identifier (parser, "pure"))
{
- check_and_set (parser, inlineAsm, "pure");
+ check_and_set (parser, inlineAsm, AST::InlineAsmOptions::PURE);
}
   else if (!is_global_asm && check_identifier (parser, "nomem"))
{
- check_and_set (parser, inlineAsm, "nomem");
+ check_and_set (parser, inlineAsm, AST::InlineAsmOptions::NOMEM);
}
   else if (!is_global_asm && check_identifier (parser, "readonly"))
{
- check_and_set (parser, inlineAsm, "readonly");
+ check_and_set (parser, inlineAsm, AST::InlineAsmOptions::READONLY);
}
   else if (!is_global_asm && check_identifier (parser, "preserves_flags"))
{
- check_and_set (parser, inlineAsm, "preserves_flags");
+ check_and_set (parser, inlineAsm,
+AST::InlineAsmOptions::PRESERVES_FLAGS);
}
   else if (!is_global_asm && check_identifier (parser, "noreturn"))
{
- check_and_set (parser, inlineAsm, "noreturn");
-   }
-  else if (!is_global_asm && check_identifier (parser, "noreturn"))
-   {
- check_and_set (parser, inlineAsm, "noreturn");
+ check_and_set (parser, inlineAsm, AST::InlineAsmOptions::NORETURN);
}
   else if (!is_global_asm && check_identifier (parser, "nostack"))
{
- check_and_set (parser, inlineAsm, "nostack");
+ check_and_set (parser, inlineAsm, AST::InlineAsmOptions::NOSTACK);
}
   else if (!is_global_asm && check_identifier (parser, "may_unwind"))
{
- check_and_set (parser, inlineAsm, "may_unwind");
+ check_and_set (parser, inlineAsm, AST::InlineAsmOptions::MAY_UNWIND);
}
   else if (check_identifier (parser, "att_syntax"))
{
- check_and_set (parser, inlineAsm, "att_syntax");
+ check_and_set (parser, inlineAsm, AST::InlineAsmOptions::ATT_SYNTAX);
}
   else if (check_identifier (parser, "raw"))
{
- check_and_set (parser, inlineAsm, "raw");
+ check_and_set (parser, inlineAsm, AST::InlineAsmOptions::RAW);
}
   else
{
@@ -201,6 +198,7 @@ parse_options (Parser &parser, TokenId 
last_token_id,
{
  // TODO: If the skip of comma is unsuccessful, which should be
  // illegal, pleaes emit the correct error.
+ std::cout << "Illegal comma" << std::endl;
  return -1;
}
 
@@ -315,13 +313,13 @@ parseAsmArg (Parser &parser, TokenId 
last_token_id,
   // TODO: Parse options
   if (check_identifier (parser, "options"))
{
- std::cout << "Parse optoins" << std::endl;
+ parse_options (parser, last_token_id, inlineAsm);
  continue;
}
 
   // Ok after we have check that neither clobber_abi nor options works, the
   // only other logical choice is reg_operand
-  st

[gcc/devel/rust/master] Scaffolding parse_reg

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:387917381a467b50943d989669a206cea7fe02cc

commit 387917381a467b50943d989669a206cea7fe02cc
Author: jjasmine 
Date:   Fri May 24 15:18:45 2024 -0700

Scaffolding parse_reg

gcc/rust/ChangeLog:

* ast/rust-expr.h (struct InlineAsmRegOrRegClass):
Scaffolding parse_reg
* expand/rust-macro-builtins-asm.cc (parse_reg): Likewise.
(parse_operand): Likewise.
(parseAsmArg): Likewise.

Diff:
---
 gcc/rust/ast/rust-expr.h   |  6 +++
 .../checks/errors/borrowck/ffi-polonius/Cargo.lock | 39 +
 gcc/rust/expand/rust-macro-builtins-asm.cc | 49 +-
 3 files changed, 93 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index 719a76cdbb3d..309174057c00 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -4743,6 +4743,12 @@ struct InlineAsmRegOrRegClass
 std::string Symbol;
   };
 
+  Type type;
+  union
+  {
+struct Reg reg;
+struct RegClass regClass;
+  };
   Identifier name;
   location_t locus;
 };
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 ..55cc71157ae4
--- /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.21"
+source = "registry+https://github.com/rust-lang/crates.io-index";
+checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c"
+
+[[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/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index 185bf38259f5..acdbd18342a5 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -125,6 +125,53 @@ parse_clobber_abi (Parser &parser, 
TokenId last_token_id,
   return 0;
 }
 
+int
+parse_reg (Parser &parser, TokenId last_token_id,
+  AST::InlineAsm &inlineAsm, bool is_explicit)
+{
+  if (!parser.skip_token (LEFT_PAREN))
+{
+  // TODO: we expect a left parenthesis here, please return the correct
+  // error.
+  return 0;
+}
+
+  // after successful left parenthesis parsing, we should return ast of
+  // InlineAsmRegOrRegClass of reg or reg class
+  auto token = parser.peek_current_token ();
+  auto tok_id = token->get_id ();
+
+  if (tok_id == IDENTIFIER)
+{
+  // construct a InlineAsmRegOrRegClass
+}
+  else if (tok_id == STRING_LITERAL)
+{
+  // TODO: there is STRING_LITERAL, and BYTE_STRING_LITERAL, should we 
check
+  // for both?
+
+  // construct a InlineAsmRegOrRegClass
+}
+  else
+{
+  // TODO
+}
+  if (!parser.skip_token (RIGHT_PAREN))
+{
+  // we expect a left parenthesis here, please return the correct error.
+  return 0;
+}
+
+  return 0;
+}
+
+int
+parse_operand (Parser &parser, TokenId last_token_id,
+  AST::InlineAsm &inlineAsm)
+{
+  return 0;
+}
+
 void
 check_and_set (Parser &parser, AST::InlineAsm &inlineAsm,
   AST::InlineAsmOptions option)
@@ -340,7 +387,7 @@ parseAsmArg (Parser &parser, TokenId 
last_token_id,
   return 0;
 }
 
-static tl::optional
+tl::optional
 parse_asm (location_t invoc_locus, AST::MacroInvocData &invoc,
   bool is_global_asm)
 {


[gcc/devel/rust/master] Fix clobber_api brackets

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:b923da77f09ee7adcaff28eb7cc1b6d88e260cc2

commit b923da77f09ee7adcaff28eb7cc1b6d88e260cc2
Author: jjasmine 
Date:   Mon May 20 23:04:01 2024 -0700

Fix clobber_api brackets

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-asm.cc (parse_clobber_abi): title.

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

diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index 310131c5b311..cfe5906ba020 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -79,17 +79,17 @@ parse_clobber_abi (Parser &parser, TokenId 
last_token_id,
  // illegal, pleaes emit the correct error.
  return -1;
}
+}
 
-  // Done processing the local clobber abis, push that to the main Args in
-  // argument
-
-  for (auto abi : new_abis)
-   {
- args.clobber_abis.push_back (abi);
-   }
+  // Done processing the local clobber abis, push that to the main Args in
+  // argument
 
-  return 0;
+  for (auto abi : new_abis)
+{
+  args.clobber_abis.push_back (abi);
 }
+
+  return 0;
 }
 
 int


[gcc/devel/rust/master] Refactoring for inline asm pr

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:e63fba72a6544be08fec2edf0fe9011208e9bf8a

commit e63fba72a6544be08fec2edf0fe9011208e9bf8a
Author: jjasmine 
Date:   Fri May 31 02:01:18 2024 -0700

Refactoring for inline asm pr

gcc/rust/ChangeLog:

* ast/rust-expr.h (struct AnonConst):
major refactoring of inline asm, mostly concerns
naming convention, trinary conditionals, warnings,
adding rust_unreachables in not-yet supported errors.
(struct InlineAsmRegOrRegClass): Likewise.
(struct InlineAsmOperand): Likewise.
* expand/rust-macro-builtins-asm.cc (parse_clobber_abi): Likewise.
(parse_reg): Likewise.
(parse_operand): Likewise.
(parse_reg_operand): Likewise.
(check_and_set): Likewise.
(parse_options): Likewise.
(parse_format_string): Likewise.
(parse_asm_arg): Likewise.
(parse_asm): Likewise.
* expand/rust-macro-builtins-asm.h (parse_asm_arg): Likewise.
(check_identifier): Likewise.
(check_and_set): Likewise.
(parse_operand): Likewise.
(parse_reg_operand): Likewise.
(parse_options): Likewise.
(parse_reg): Likewise.
(parse_clobber_abi): Likewise.
* expand/rust-macro-builtins.cc (enum class): Likewise.
(inline_asm_maker): Likewise.
* checks/errors/borrowck/ffi-polonius/Cargo.lock: Removed. Likewise.

gcc/testsuite/ChangeLog:
* rust/compile/inline_asm_faulty_clobber.rs: Likewise.
* rust/compile/inline_asm_faulty_clobber_1.rs: Likewise.
* rust/compile/inline_asm_faulty_clobber_2.rs: Likewise.
* rust/compile/inline_asm_illegal_options.rs: Likewise.

Diff:
---
 gcc/rust/ast/rust-expr.h   |  88 ++---
 .../checks/errors/borrowck/ffi-polonius/Cargo.lock |  39 --
 gcc/rust/expand/rust-macro-builtins-asm.cc | 139 -
 gcc/rust/expand/rust-macro-builtins-asm.h  |  28 ++---
 gcc/rust/expand/rust-macro-builtins.cc |  10 +-
 .../rust/compile/inline_asm_faulty_clobber.rs  |   2 +-
 .../rust/compile/inline_asm_faulty_clobber_1.rs|   2 +-
 .../rust/compile/inline_asm_faulty_clobber_2.rs|   2 +-
 .../rust/compile/inline_asm_illegal_options.rs |   4 +-
 9 files changed, 142 insertions(+), 172 deletions(-)

diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index 1284c7367fef..ad742bfe85d6 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -6,7 +6,7 @@
 #include "rust-path.h"
 #include "rust-macro.h"
 #include "rust-operators.h"
-#include 
+#include "rust-system.h"
 
 namespace Rust {
 namespace AST {
@@ -4723,22 +4723,20 @@ enum class InlineAsmOption
 struct AnonConst
 {
   NodeId id;
-  std::unique_ptr value;
+  std::unique_ptr expr;
   AnonConst () {}
   AnonConst (const AnonConst &other)
   {
 id = other.id;
-value = other.value == nullptr
- ? nullptr
- : std::unique_ptr (other.value->clone_expr ());
+if (other.expr)
+  expr = other.expr->clone_expr ();
   }
 
   AnonConst operator= (const AnonConst &other)
   {
 id = other.id;
-value = other.value == nullptr
- ? nullptr
- : std::unique_ptr (other.value->clone_expr ());
+if (other.expr)
+  expr = other.expr->clone_expr ();
 return *this;
   }
 };
@@ -4763,7 +4761,7 @@ struct InlineAsmRegOrRegClass
 
   Type type;
   struct Reg reg;
-  struct RegClass regClass;
+  struct RegClass reg_class;
 
   Identifier name;
   location_t locus;
@@ -4790,17 +4788,15 @@ struct InlineAsmOperand
 In (const struct In &other)
 {
   reg = other.reg;
-  expr = other.expr == nullptr
-  ? nullptr
-  : std::unique_ptr (other.expr->clone_expr ());
+  if (other.expr)
+   expr = other.expr->clone_expr ();
 }
 
 In operator= (const struct In &other)
 {
   reg = other.reg;
-  expr = other.expr == nullptr
-  ? nullptr
-  : std::unique_ptr (other.expr->clone_expr ());
+  if (other.expr)
+   expr = other.expr->clone_expr ();
 
   return *this;
 }
@@ -4817,18 +4813,16 @@ struct InlineAsmOperand
 {
   reg = other.reg;
   late = other.late;
-  expr = other.expr == nullptr
-  ? nullptr
-  : std::unique_ptr (other.expr->clone_expr ());
+  if (other.expr)
+   expr = other.expr->clone_expr ();
 }
 
 Out operator= (const struct Out &other)
 {
   reg = other.reg;
   late = other.late;
-  expr = other.expr == nullptr
-  ? nullptr
-  : std::unique_ptr (other.expr->clone_expr ());
+  if (other.expr)
+   expr = other.expr->clone_expr ();
   return *this;
 }
   };
@@ -4844,18 +4838,17 @@ struct InlineAsmOperand
 {
   reg = other.

[gcc/devel/rust/master] Working towards parse_reg and parse_reg_operand

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:a5c3c7615fbf995a5788c622f65c752627d5dda1

commit a5c3c7615fbf995a5788c622f65c752627d5dda1
Author: jjasmine 
Date:   Tue May 28 01:21:07 2024 -0700

Working towards parse_reg and parse_reg_operand

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-asm.cc (parse_reg):
Working towards parse_reg and parse_reg_operand
(parse_reg_operand):
Working towards parse_reg and parse_reg_operand
(parse_asm_arg):
Add todo about errors
* expand/rust-macro-builtins-asm.h (parse_global_asm):
remove dead code.
(parse_nonglobal_asm):
remove dead code.

Diff:
---
 gcc/rust/expand/rust-macro-builtins-asm.cc | 29 -
 gcc/rust/expand/rust-macro-builtins-asm.h  |  4 
 2 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index 55d822d1f901..7293701bf04b 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -141,11 +141,10 @@ parse_reg (Parser &parser, TokenId 
last_token_id,
   // InlineAsmRegOrRegClass of reg or reg class
   auto token = parser.peek_current_token ();
   auto tok_id = token->get_id ();
-
-  if (tok_id == IDENTIFIER)
+  AST::InlineAsmRegOrRegClass regClass;
+  if (parser.skip_token (IDENTIFIER))
 {
   // construct a InlineAsmRegOrRegClass
-  AST::InlineAsmRegOrRegClass regClass;
   regClass.type = RegType::RegClass;
   regClass.regClass.Symbol = token->as_string ();
 }
@@ -156,18 +155,27 @@ parse_reg (Parser &parser, TokenId 
last_token_id,
 
   // construct a InlineAsmRegOrRegClass
   // parse_format_string
+  regClass.type = RegType::Reg;
+  inlineAsmCtx.is_explicit = true;
+  regClass.regClass.Symbol = token->as_string ();
 }
   else
 {
-  // TODO
+  // TODO: This should emit error
+  //  return
+  //  
Err(p.dcx().create_err(errors::ExpectedRegisterClassOrExplicitRegister
+  //  {
+  //   span: p.token.span,
+  //   }));
 }
   if (!parser.skip_token (RIGHT_PAREN))
 {
-  // we expect a left parenthesis here, please return the correct error.
+  // TODO: we expect a left parenthesis here, please return the correct
+  // error.
   return tl::nullopt;
 }
 
-  return tl::nullopt;
+  return regClass;
 }
 
 int
@@ -193,7 +201,7 @@ parse_reg_operand (Parser &parser, TokenId 
last_token_id,
   //   };
 
   using RegisterType = AST::InlineAsmOperand::RegisterType;
-
+  AST::InlineAsmOperand reg_operand;
   auto token = parser.peek_current_token ();
   auto iden_token = parser.peek_current_token ();
   auto &inlineAsm = inlineAsmCtx.inlineAsm;
@@ -221,8 +229,9 @@ parse_reg_operand (Parser &parser, TokenId 
last_token_id,
 {}
   else if (!is_global_asm && check_identifier (parser, "inlateout"))
 {}
-  else if (false && check_identifier (parser, "const"))
+  else if (parser.peek_current_token ()->get_id () == CONST)
 {
+  rust_unreachable ();
   // todo: Please handle const
 }
   else if (false && check_identifier (parser, "sym"))
@@ -237,7 +246,7 @@ parse_reg_operand (Parser &parser, TokenId 
last_token_id,
 {
   return tl::nullopt;
 }
-  return tl::nullopt;
+  return reg_operand;
 }
 void
 check_and_set (Parser &parser, InlineAsmContext &inlineAsmCtx,
@@ -410,6 +419,8 @@ parse_asm_arg (Parser &parser, TokenId 
last_token_id,
}
   else
{
+ // TODO: we consumed comma, and there happens to also be a comma
+ // error should be: expected expression, found `,`
  break;
}
 
diff --git a/gcc/rust/expand/rust-macro-builtins-asm.h 
b/gcc/rust/expand/rust-macro-builtins-asm.h
index a35d7707e6c9..c7fcf3017358 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.h
+++ b/gcc/rust/expand/rust-macro-builtins-asm.h
@@ -34,10 +34,6 @@ int
 parse_asm_arg (Parser &p, TokenId last_token_id,
   InlineAsmContext &inlineAsmCtx);
 
-tl::optional
-parse_global_asm (location_t invoc_locus, AST::MacroInvocData &invoc);
-tl::optional
-parse_nonglobal_asm (location_t invoc_locus, AST::MacroInvocData &invoc);
 tl::optional
 parse_asm (location_t invoc_locus, AST::MacroInvocData &invoc,
   bool is_global_asm);


[gcc/devel/rust/master] Got AST::Fragment to be created from InlineAsm

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:bfcebbf7e1d36a5b999ed41d0fc2e9acbbed4dbb

commit bfcebbf7e1d36a5b999ed41d0fc2e9acbbed4dbb
Author: jjasmine 
Date:   Tue May 28 21:56:19 2024 -0700

Got AST::Fragment to be created from InlineAsm

gcc/rust/ChangeLog:

* ast/rust-expr.h (struct AnonConst):
Got AST::Fragment to be created from InlineAsm.
(struct InlineAsmOperand): Likewise.
(class InlineAsm): Likewise.
* expand/rust-macro-builtins-asm.cc (parse_reg_operand): Likewise.
(parse_asm): likewise

Diff:
---
 gcc/rust/ast/rust-expr.h   | 129 -
 gcc/rust/expand/rust-macro-builtins-asm.cc |  31 +--
 2 files changed, 150 insertions(+), 10 deletions(-)

diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index 76e5fa7c4475..1284c7367fef 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -6,6 +6,7 @@
 #include "rust-path.h"
 #include "rust-macro.h"
 #include "rust-operators.h"
+#include 
 
 namespace Rust {
 namespace AST {
@@ -4723,6 +4724,23 @@ struct AnonConst
 {
   NodeId id;
   std::unique_ptr value;
+  AnonConst () {}
+  AnonConst (const AnonConst &other)
+  {
+id = other.id;
+value = other.value == nullptr
+ ? nullptr
+ : std::unique_ptr (other.value->clone_expr ());
+  }
+
+  AnonConst operator= (const AnonConst &other)
+  {
+id = other.id;
+value = other.value == nullptr
+ ? nullptr
+ : std::unique_ptr (other.value->clone_expr ());
+return *this;
+  }
 };
 
 struct InlineAsmRegOrRegClass
@@ -4767,6 +4785,25 @@ struct InlineAsmOperand
   {
 InlineAsmRegOrRegClass reg;
 std::unique_ptr expr;
+
+In () {}
+In (const struct In &other)
+{
+  reg = other.reg;
+  expr = other.expr == nullptr
+  ? nullptr
+  : std::unique_ptr (other.expr->clone_expr ());
+}
+
+In operator= (const struct In &other)
+{
+  reg = other.reg;
+  expr = other.expr == nullptr
+  ? nullptr
+  : std::unique_ptr (other.expr->clone_expr ());
+
+  return *this;
+}
   };
 
   struct Out
@@ -4774,6 +4811,26 @@ struct InlineAsmOperand
 InlineAsmRegOrRegClass reg;
 bool late;
 std::unique_ptr expr; // can be null
+
+Out () {}
+Out (const struct Out &other)
+{
+  reg = other.reg;
+  late = other.late;
+  expr = other.expr == nullptr
+  ? nullptr
+  : std::unique_ptr (other.expr->clone_expr ());
+}
+
+Out operator= (const struct Out &other)
+{
+  reg = other.reg;
+  late = other.late;
+  expr = other.expr == nullptr
+  ? nullptr
+  : std::unique_ptr (other.expr->clone_expr ());
+  return *this;
+}
   };
 
   struct InOut
@@ -4781,6 +4838,26 @@ struct InlineAsmOperand
 InlineAsmRegOrRegClass reg;
 bool late;
 std::unique_ptr expr; // this can't be null
+
+InOut () {}
+InOut (const struct InOut &other)
+{
+  reg = other.reg;
+  late = other.late;
+  expr = other.expr == nullptr
+  ? nullptr
+  : std::unique_ptr (other.expr->clone_expr ());
+}
+
+InOut operator= (const struct InOut &other)
+{
+  reg = other.reg;
+  late = other.late;
+  expr = other.expr == nullptr
+  ? nullptr
+  : std::unique_ptr (other.expr->clone_expr ());
+  return *this;
+}
   };
 
   struct SplitInOut
@@ -4789,6 +4866,33 @@ struct InlineAsmOperand
 bool late;
 std::unique_ptr in_expr;
 std::unique_ptr out_expr; // could be null
+
+SplitInOut () {}
+SplitInOut (const struct SplitInOut &other)
+{
+  reg = other.reg;
+  late = other.late;
+  in_expr = other.in_expr == nullptr
+ ? nullptr
+ : std::unique_ptr (other.in_expr->clone_expr ());
+  out_expr = other.out_expr == nullptr
+  ? nullptr
+  : std::unique_ptr (other.out_expr->clone_expr ());
+}
+
+SplitInOut operator= (const struct SplitInOut &other)
+{
+  reg = other.reg;
+  late = other.late;
+  in_expr = other.in_expr == nullptr
+ ? nullptr
+ : std::unique_ptr (other.in_expr->clone_expr ());
+  out_expr = other.out_expr == nullptr
+  ? nullptr
+  : std::unique_ptr (other.out_expr->clone_expr ());
+
+  return *this;
+}
   };
 
   struct Const
@@ -4799,6 +4903,18 @@ struct InlineAsmOperand
   struct Sym
   {
 std::unique_ptr sym;
+
+Sym () {}
+Sym (const struct Sym &other)
+{
+  sym = std::unique_ptr (other.sym->clone_expr ());
+}
+
+Sym operator= (const struct Sym &other)
+{
+  sym = std::unique_ptr (other.sym->clone_expr ());
+  return *this;
+}
   };
   RegisterType registerType;
 
@@ -4809,6 +4925,12 @@ struct InlineAsmOperand
   struct C

[gcc/devel/rust/master] Big Refactor after meeting

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:0eafcc27996564b3516cecbdcaa8b9c13e88836d

commit 0eafcc27996564b3516cecbdcaa8b9c13e88836d
Author: jjasmine 
Date:   Mon May 27 20:51:38 2024 -0700

Big Refactor after meeting

gcc/rust/ChangeLog:

* ast/rust-expr.h (struct InlineAsmRegOrRegClass):
Remove union
(struct InlineAsmOperand): Make instances of inside struct.
* expand/rust-macro-builtins-asm.cc (parse_clobber_abi):
Change signature with inlineAsmCtx.
(parse_reg): Likewise.
(parse_operand): Likewise.
(parse_reg_operand): Likewise.
(check_and_set): Likewise.
(parse_options): Likewise.
(parse_format_string): Likewise.
(parseAsmArg): Likewise.
(parse_asm): Likewise.
* expand/rust-macro-builtins-asm.h (class InlineAsmContext): 
Likewise.
(parseAsmArg): Likewise.
(check_and_set): Likewise.
(parse_reg_operand): Likewise.
(parse_options): Likewise.
(parse_reg): Likewise.
(parse_clobber_abi): Likewise.

Diff:
---
 gcc/rust/ast/rust-expr.h   |  17 +++-
 gcc/rust/expand/rust-macro-builtins-asm.cc | 152 +
 gcc/rust/expand/rust-macro-builtins-asm.h  |  44 +++--
 3 files changed, 157 insertions(+), 56 deletions(-)

diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index 1af72965a93e..76e5fa7c4475 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -4744,11 +4744,9 @@ struct InlineAsmRegOrRegClass
   };
 
   Type type;
-  union
-  {
-struct Reg reg;
-struct RegClass regClass;
-  };
+  struct Reg reg;
+  struct RegClass regClass;
+
   Identifier name;
   location_t locus;
 };
@@ -4802,6 +4800,15 @@ struct InlineAsmOperand
   {
 std::unique_ptr sym;
   };
+  RegisterType registerType;
+
+  struct In in;
+  struct Out out;
+  struct InOut inOut;
+  struct SplitInOut splitInOut;
+  struct Const cnst;
+  struct Sym sym;
+
   location_t locus;
 };
 
diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index 268019c2da2b..20a434c6c296 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -39,11 +39,12 @@ parseDirSpec (Parser &parser, TokenId 
last_token_id)
 
 int
 parse_clobber_abi (Parser &parser, TokenId last_token_id,
-  AST::InlineAsm &inlineAsm)
+  InlineAsmContext &inlineAsmCtx)
 {
   // clobber_abi := "clobber_abi("  *("," ) [","] ")"
   // PARSE EVERYTHING COMMITTEDLY IN THIS FUNCTION, WE CONFIRMED VIA 
clobber_abi
   // identifier keyword
+  auto &inlineAsm = inlineAsmCtx.inlineAsm;
   auto token = parser.peek_current_token ();
   if (!parser.skip_token (LEFT_PAREN))
 {
@@ -59,7 +60,6 @@ parse_clobber_abi (Parser &parser, TokenId 
last_token_id,
 "expected `(`, found end of macro arguments");
  return -1;
}
-
   else
{
  rust_error_at (
@@ -125,15 +125,16 @@ parse_clobber_abi (Parser &parser, 
TokenId last_token_id,
   return 0;
 }
 
-int
+tl::optional
 parse_reg (Parser &parser, TokenId last_token_id,
-  AST::InlineAsm &inlineAsm, bool is_explicit)
+  InlineAsmContext &inlineAsmCtx)
 {
+  using RegType = AST::InlineAsmRegOrRegClass::Type;
   if (!parser.skip_token (LEFT_PAREN))
 {
   // TODO: we expect a left parenthesis here, please return the correct
   // error.
-  return 0;
+  return tl::nullopt;
 }
 
   // after successful left parenthesis parsing, we should return ast of
@@ -144,6 +145,9 @@ parse_reg (Parser &parser, TokenId 
last_token_id,
   if (tok_id == IDENTIFIER)
 {
   // construct a InlineAsmRegOrRegClass
+  AST::InlineAsmRegOrRegClass regClass;
+  regClass.type = RegType::RegClass;
+  regClass.regClass.Symbol = token->as_string ();
 }
   else if (tok_id == STRING_LITERAL)
 {
@@ -151,6 +155,7 @@ parse_reg (Parser &parser, TokenId 
last_token_id,
   // for both?
 
   // construct a InlineAsmRegOrRegClass
+  // parse_format_string
 }
   else
 {
@@ -159,23 +164,86 @@ parse_reg (Parser &parser, TokenId 
last_token_id,
   if (!parser.skip_token (RIGHT_PAREN))
 {
   // we expect a left parenthesis here, please return the correct error.
-  return 0;
+  return tl::nullopt;
 }
 
-  return 0;
+  return tl::nullopt;
 }
 
 int
 parse_operand (Parser &parser, TokenId last_token_id,
-  AST::InlineAsm &inlineAsm)
+  InlineAsmContext &inlineAsmCtx)
 {
   return 0;
 }
 
+// From rustc
+tl::optional
+parse_reg_operand (Parser &parser, TokenId last_token_id,
+  InlineAsmContext &inlineAsmCtx)
+{
+  // let name = if p.token.is_ident() && p.look_ahead(1, |t| *t == token::Eq) {
+  //   let (ident, _) = p.token.ident().unwrap();
+  //   p.bump()

[gcc/devel/rust/master] Scaffolding ast visitor for InlineAsm

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:5075dee97b002a2c68e1476a1aca2468abe88341

commit 5075dee97b002a2c68e1476a1aca2468abe88341
Author: jjasmine 
Date:   Tue Jun 4 19:34:58 2024 -0700

Scaffolding ast visitor for InlineAsm

gcc/rust/ChangeLog:

* ast/rust-ast-visitor.h:
Scaffolding ast visitor for InlineAsm
* ast/rust-ast.cc (InlineAsm::accept_vis): Likewise.
* ast/rust-expr.h: Likewise.

Diff:
---
 gcc/rust/ast/rust-ast-visitor.h | 2 ++
 gcc/rust/ast/rust-ast.cc| 7 +++
 gcc/rust/ast/rust-expr.h| 2 +-
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/ast/rust-ast-visitor.h b/gcc/rust/ast/rust-ast-visitor.h
index 2bc58d57a9c6..6a2bb7a8aff6 100644
--- a/gcc/rust/ast/rust-ast-visitor.h
+++ b/gcc/rust/ast/rust-ast-visitor.h
@@ -23,6 +23,7 @@
 // full include not required - only forward decls
 #include "rust-ast-full-decls.h"
 #include "rust-ast.h"
+#include "rust-expr.h"
 #include "rust-item.h"
 #include "rust-system.h"
 
@@ -128,6 +129,7 @@ public:
   virtual void visit (MatchExpr &expr) = 0;
   virtual void visit (AwaitExpr &expr) = 0;
   virtual void visit (AsyncBlockExpr &expr) = 0;
+  virtual void visit (InlineAsm &expr){};
 
   // rust-item.h
   virtual void visit (TypeParam ¶m) = 0;
diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc
index 5dd8537aee6d..2a173c4610df 100644
--- a/gcc/rust/ast/rust-ast.cc
+++ b/gcc/rust/ast/rust-ast.cc
@@ -21,6 +21,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "optional.h"
 #include "rust-builtin-ast-nodes.h"
 #include "rust-common.h"
+#include "rust-expr.h"
 #include "rust-system.h"
 #include "rust-ast-full.h"
 #include "rust-diagnostics.h"
@@ -4655,6 +4656,12 @@ AsyncBlockExpr::accept_vis (ASTVisitor &vis)
   vis.visit (*this);
 }
 
+void
+InlineAsm::accept_vis (ASTVisitor &vis)
+{
+  vis.visit (*this);
+}
+
 void
 TypeParam::accept_vis (ASTVisitor &vis)
 {
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index cc8c6ea03500..5f60ec79b583 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -4980,8 +4980,8 @@ public:
   InlineAsm (location_t locus, bool is_global_asm)
 : locus (locus), is_global_asm (is_global_asm)
   {}
-  void accept_vis (ASTVisitor &vis) override{};
 
+  void accept_vis (ASTVisitor &vis) override;
   std::string as_string () const override { return "InlineAsm AST Node"; }
 
   location_t get_locus () const override { return locus; }


[gcc/devel/rust/master] Partial unsafe support for inline asm

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:914777653e9433c525e4b584aa0d5658c7eccddc

commit 914777653e9433c525e4b584aa0d5658c7eccddc
Author: jjasmine 
Date:   Fri May 31 16:09:40 2024 -0700

Partial unsafe support for inline asm

gcc/rust/ChangeLog:

* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit):
Partial unsafe support for inline asm
* checks/errors/rust-unsafe-checker.h: Likewise.
* hir/tree/rust-hir-expr.h: Likewise.
* hir/tree/rust-hir.cc (InlineAsm::accept_vis): Likewise.

Diff:
---
 gcc/rust/checks/errors/rust-unsafe-checker.cc | 11 +++
 gcc/rust/checks/errors/rust-unsafe-checker.h  |  1 +
 gcc/rust/hir/tree/rust-hir-expr.h |  4 ++--
 gcc/rust/hir/tree/rust-hir.cc |  9 +
 4 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/checks/errors/rust-unsafe-checker.cc 
b/gcc/rust/checks/errors/rust-unsafe-checker.cc
index 56ac26667529..ff307ae21134 100644
--- a/gcc/rust/checks/errors/rust-unsafe-checker.cc
+++ b/gcc/rust/checks/errors/rust-unsafe-checker.cc
@@ -636,6 +636,17 @@ UnsafeChecker::visit (AsyncBlockExpr &)
   // TODO: Visit block expression
 }
 
+void
+UnsafeChecker::visit (InlineAsm &expr)
+{
+  if (unsafe_context.is_in_context ())
+return;
+
+  rust_error_at (
+expr.get_locus (), ErrorCode::E0133,
+"use of inline assembly is unsafe and requires unsafe function or block");
+}
+
 void
 UnsafeChecker::visit (TypeParam &)
 {}
diff --git a/gcc/rust/checks/errors/rust-unsafe-checker.h 
b/gcc/rust/checks/errors/rust-unsafe-checker.h
index 27659f5141a5..3a1e715d2442 100644
--- a/gcc/rust/checks/errors/rust-unsafe-checker.h
+++ b/gcc/rust/checks/errors/rust-unsafe-checker.h
@@ -115,6 +115,7 @@ private:
   virtual void visit (MatchExpr &expr) override;
   virtual void visit (AwaitExpr &expr) override;
   virtual void visit (AsyncBlockExpr &expr) override;
+  virtual void visit (InlineAsm &expr);
   virtual void visit (TypeParam ¶m) override;
   virtual void visit (ConstGenericParam ¶m) override;
   virtual void visit (LifetimeWhereClauseItem &item) override;
diff --git a/gcc/rust/hir/tree/rust-hir-expr.h 
b/gcc/rust/hir/tree/rust-hir-expr.h
index 7dcb84e9050c..15a32cf989d7 100644
--- a/gcc/rust/hir/tree/rust-hir-expr.h
+++ b/gcc/rust/hir/tree/rust-hir-expr.h
@@ -3878,9 +3878,9 @@ public:
 
   std::vector line_spans;
 
-  void accept_vis (HIRExpressionVisitor &vis) override{};
+  void accept_vis (HIRExpressionVisitor &vis) override;
 
-  void accept_vis (HIRFullVisitor &vis) override{};
+  void accept_vis (HIRFullVisitor &vis) override;
 
   std::string as_string () const override { return "InlineAsm HIR Node"; }
 
diff --git a/gcc/rust/hir/tree/rust-hir.cc b/gcc/rust/hir/tree/rust-hir.cc
index 3eb8838eb9db..5e5d579e26b9 100644
--- a/gcc/rust/hir/tree/rust-hir.cc
+++ b/gcc/rust/hir/tree/rust-hir.cc
@@ -17,6 +17,7 @@
 // .
 
 #include "rust-ast-full.h"
+#include "rust-hir-expr.h"
 #include "rust-hir-full.h"
 #include "rust-hir-visitor.h"
 #include "rust-diagnostics.h"
@@ -3769,6 +3770,14 @@ BorrowExpr::accept_vis (HIRFullVisitor &vis)
   vis.visit (*this);
 }
 
+void
+InlineAsm::accept_vis (HIRExpressionVisitor &vis)
+{}
+
+void
+InlineAsm::accept_vis (HIRFullVisitor &vis)
+{}
+
 void
 BorrowExpr::accept_vis (HIRExpressionVisitor &vis)
 {


[gcc/devel/rust/master] Fix warnings

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:379670e7f685de8b4e8cb38e8dcc35b886e55a02

commit 379670e7f685de8b4e8cb38e8dcc35b886e55a02
Author: jjasmine 
Date:   Fri May 31 19:34:49 2024 -0700

Fix warnings

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-asm.cc (parse_reg_operand):
Fix compile warnings.
(parse_options): Likewise.
(parse_asm): Likewise.

gcc/testsuite/ChangeLog:

* rust/compile/inline_asm_illegal_options.rs:

Diff:
---
 gcc/rust/expand/rust-macro-builtins-asm.cc   | 10 +++---
 gcc/testsuite/rust/compile/inline_asm_illegal_options.rs |  3 +++
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index fd7da8c3d328..b979b34763d8 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -219,7 +219,6 @@ parse_reg_operand (Parser &parser, TokenId 
last_token_id,
 
   token = parser.peek_current_token ();
 
-  bool is_explicit_reg = false;
   bool is_global_asm = inline_asm.is_global_asm;
   if (!is_global_asm && check_identifier (parser, "in"))
 {
@@ -354,7 +353,12 @@ parse_options (Parser &parser, TokenId 
last_token_id,
{
  // TODO: Unexpected error, please return the correct error
  rust_error_at (token->get_locus (),
-"Unexpected token encountered in parse_options");
+"expected one of %qs, %qs, %qs, %qs, %qs, %qs, %qs, "
+"%qs, %qs, or %qs, found %qs",
+")", "att_syntax", "may_unwind", "nomem", "noreturn",
+"nostack", "preserves_flags", "pure", "raw",
+"readonly", token->as_string ().c_str ());
+ return -1;
}
   if (parser.skip_token (RIGHT_PAREN))
{
@@ -519,7 +523,7 @@ parse_asm (location_t invoc_locus, AST::MacroInvocData 
&invoc,
   if (fm_string == tl::nullopt)
 {
   rust_error_at (parser.peek_current_token ()->get_locus (),
-"asm template must be a string literal");
+"%s template must be a string literal", "asm");
   return tl::nullopt;
 }
 
diff --git a/gcc/testsuite/rust/compile/inline_asm_illegal_options.rs 
b/gcc/testsuite/rust/compile/inline_asm_illegal_options.rs
index bf34c4489f1c..2cf354d6d123 100644
--- a/gcc/testsuite/rust/compile/inline_asm_illegal_options.rs
+++ b/gcc/testsuite/rust/compile/inline_asm_illegal_options.rs
@@ -9,5 +9,8 @@ fn main() {
 unsafe {
 asm!("nop", options(nomem, nomem)); // { dg-error "the 'nomem' option 
was already provided" }
 asm!("nop", options(noreturn, noreturn)); // { dg-error "the 
'noreturn' option was already provided" }
+asm!("nop", options(xxx)); // { dg-error "expected one of '\\)', 
'att_syntax', 'may_unwind', 'nomem', 'noreturn', 'nostack', 'preserves_flags', 
'pure', 'raw', or 'readonly', found 'xxx'" }
+asm!("nop", options(+)); // { dg-error "expected one of '\\)', 
'att_syntax', 'may_unwind', 'nomem', 'noreturn', 'nostack', 'preserves_flags', 
'pure', 'raw', or 'readonly', found '\\+'" }
+
 }
 }
\ No newline at end of file


[gcc/devel/rust/master] Add support for AST to HIR inline asm translation

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:520d279b5d61643cc0f92aed25caf97f981c60b5

commit 520d279b5d61643cc0f92aed25caf97f981c60b5
Author: jjasmine 
Date:   Fri May 31 14:55:45 2024 -0700

Add support for AST to HIR inline asm translation

gcc/rust/ChangeLog:

* ast/rust-expr.h:
Add support for AST to HIR inline asm translation
* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise.
* hir/rust-ast-lower-base.h: Likewise.
* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise.
* hir/rust-ast-lower-expr.h: Likewise.
* hir/tree/rust-hir-expr.h (class InlineAsm): Likewise.

Diff:
---
 gcc/rust/ast/rust-expr.h| 10 +++
 gcc/rust/hir/rust-ast-lower-base.cc |  5 
 gcc/rust/hir/rust-ast-lower-base.h  |  1 +
 gcc/rust/hir/rust-ast-lower-expr.cc | 14 +
 gcc/rust/hir/rust-ast-lower-expr.h  |  1 +
 gcc/rust/hir/tree/rust-hir-expr.h   | 60 +++--
 6 files changed, 89 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index ad742bfe85d6..cc8c6ea03500 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -4994,6 +4994,16 @@ public:
 
   void set_outer_attrs (std::vector v) override { outer_attrs = v; }
 
+  std::vector get_template_ () { return template_; }
+
+  std::vector get_template_strs () { return template_strs; }
+
+  std::vector get_operands () { return operands; }
+
+  std::vector get_clobber_abi () { return clobber_abi; }
+
+  std::set get_options () { return options; }
+
   InlineAsm *clone_expr_without_block_impl () const override
   {
 return new InlineAsm (*this);
diff --git a/gcc/rust/hir/rust-ast-lower-base.cc 
b/gcc/rust/hir/rust-ast-lower-base.cc
index fc37b50f9ae3..5113880600ae 100644
--- a/gcc/rust/hir/rust-ast-lower-base.cc
+++ b/gcc/rust/hir/rust-ast-lower-base.cc
@@ -248,6 +248,11 @@ ASTLoweringBase::visit (AST::IfLetExpr &)
 void
 ASTLoweringBase::visit (AST::IfLetExprConseqElse &)
 {}
+
+void
+ASTLoweringBase::visit (AST::InlineAsm &)
+{}
+
 //  void ASTLoweringBase::visit(MatchCasematch_case) {}
 // void ASTLoweringBase:: (AST::MatchCaseBlockExpr &) {}
 // void ASTLoweringBase:: (AST::MatchCaseExpr &) {}
diff --git a/gcc/rust/hir/rust-ast-lower-base.h 
b/gcc/rust/hir/rust-ast-lower-base.h
index d477739bbc70..b197b4a1e0c2 100644
--- a/gcc/rust/hir/rust-ast-lower-base.h
+++ b/gcc/rust/hir/rust-ast-lower-base.h
@@ -148,6 +148,7 @@ public:
   virtual void visit (AST::IfExprConseqElse &expr);
   virtual void visit (AST::IfLetExpr &expr);
   virtual void visit (AST::IfLetExprConseqElse &expr);
+  virtual void visit (AST::InlineAsm &expr);
   //  virtual void visit(MatchCase& match_case);
   // virtual void visit (AST::MatchCaseBlockExpr &match_case);
   // virtual void visit (AST::MatchCaseExpr &match_case);
diff --git a/gcc/rust/hir/rust-ast-lower-expr.cc 
b/gcc/rust/hir/rust-ast-lower-expr.cc
index 063a5fb6d54c..fbb9f957ad17 100644
--- a/gcc/rust/hir/rust-ast-lower-expr.cc
+++ b/gcc/rust/hir/rust-ast-lower-expr.cc
@@ -829,6 +829,20 @@ ASTLoweringExpr::visit (AST::ClosureExprInnerTyped &expr)
expr.get_locus ());
 }
 
+void
+ASTLoweringExpr::visit (AST::InlineAsm &expr)
+{
+  auto crate_num = mappings.get_current_crate ();
+  Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
+mappings.get_next_hir_id (crate_num),
+mappings.get_next_localdef_id (crate_num));
+
+  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 (),
+ expr.get_options (), mapping);
+}
 void
 ASTLoweringExpr::visit (AST::FormatArgs &fmt)
 {
diff --git a/gcc/rust/hir/rust-ast-lower-expr.h 
b/gcc/rust/hir/rust-ast-lower-expr.h
index e145259ae8bc..12bb9b16c4d5 100644
--- a/gcc/rust/hir/rust-ast-lower-expr.h
+++ b/gcc/rust/hir/rust-ast-lower-expr.h
@@ -122,6 +122,7 @@ public:
   void visit (AST::RangeFromToInclExpr &expr) override;
   void visit (AST::ClosureExprInner &expr) override;
   void visit (AST::ClosureExprInnerTyped &expr) override;
+  void visit (AST::InlineAsm &expr) override;
 
   // Extra visitor for FormatArgs nodes
   void visit (AST::FormatArgs &fmt) override;
diff --git a/gcc/rust/hir/tree/rust-hir-expr.h 
b/gcc/rust/hir/tree/rust-hir-expr.h
index a319844c3033..7dcb84e9050c 100644
--- a/gcc/rust/hir/tree/rust-hir-expr.h
+++ b/gcc/rust/hir/tree/rust-hir-expr.h
@@ -24,7 +24,7 @@
 #include "rust-hir.h"
 #include "rust-hir-path.h"
 #include "rust-operators.h"
-
+#include "rust-expr.h"
 namespace Rust {
 namespace HIR {
 
@@ -3865,13 +3865,69 @@ struct InlineAsmRegOrRegClass
 class InlineAsm : public ExprWithoutBlock
 {
   NodeId id;
+  location_t locus;
 
 public:
+  bool is_global_asm;
+
   std::vector template

[gcc/devel/rust/master] Slim down the test cases

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:dd03ef700b718738955e53701b90a36f89588f28

commit dd03ef700b718738955e53701b90a36f89588f28
Author: jjasmine 
Date:   Fri May 31 02:06:18 2024 -0700

Slim down the test cases

gcc/testsuite/ChangeLog:

* rust/compile/inline_asm_faulty_clobber.rs: compress
the test
* rust/compile/inline_asm_nop.rs: compress
the test
* rust/compile/inline_asm_faulty_clobber_1.rs: Removed.
* rust/compile/inline_asm_faulty_clobber_2.rs: Removed.
* rust/compile/inline_asm_nop_2.rs: Removed.

Diff:
---
 gcc/testsuite/rust/compile/inline_asm_faulty_clobber.rs   |  2 ++
 gcc/testsuite/rust/compile/inline_asm_faulty_clobber_1.rs | 12 
 gcc/testsuite/rust/compile/inline_asm_faulty_clobber_2.rs | 12 
 gcc/testsuite/rust/compile/inline_asm_nop.rs  |  1 +
 gcc/testsuite/rust/compile/inline_asm_nop_2.rs| 12 
 5 files changed, 3 insertions(+), 36 deletions(-)

diff --git a/gcc/testsuite/rust/compile/inline_asm_faulty_clobber.rs 
b/gcc/testsuite/rust/compile/inline_asm_faulty_clobber.rs
index 1358b5eb4901..ea3dac7734e2 100644
--- a/gcc/testsuite/rust/compile/inline_asm_faulty_clobber.rs
+++ b/gcc/testsuite/rust/compile/inline_asm_faulty_clobber.rs
@@ -8,5 +8,7 @@ macro_rules! asm {
 fn main() {
 unsafe {
 asm!("nop", clobber_abi());  // { dg-error "at least one abi must be 
provided as an argument to 'clobber_abi'" }
+asm!("nop", clobber_abi+);  // { dg-error "expected '\\(', found 
'\\+'" }
+asm!("nop", clobber_abi);  // { dg-error "expected '\\(', found end of 
macro arguments" }
 }
 }
\ No newline at end of file
diff --git a/gcc/testsuite/rust/compile/inline_asm_faulty_clobber_1.rs 
b/gcc/testsuite/rust/compile/inline_asm_faulty_clobber_1.rs
deleted file mode 100644
index 568899239398..
--- a/gcc/testsuite/rust/compile/inline_asm_faulty_clobber_1.rs
+++ /dev/null
@@ -1,12 +0,0 @@
-#![feature(rustc_attrs)]
-
-#[rustc_builtin_macro]
-macro_rules! asm {
-() => {}
-}
-
-fn main() {
-unsafe {
-asm!("nop", clobber_abi);  // { dg-error "expected '\\(', found end of 
macro arguments" }
-}
-}
\ No newline at end of file
diff --git a/gcc/testsuite/rust/compile/inline_asm_faulty_clobber_2.rs 
b/gcc/testsuite/rust/compile/inline_asm_faulty_clobber_2.rs
deleted file mode 100644
index 98cd0525f559..
--- a/gcc/testsuite/rust/compile/inline_asm_faulty_clobber_2.rs
+++ /dev/null
@@ -1,12 +0,0 @@
-#![feature(rustc_attrs)]
-
-#[rustc_builtin_macro]
-macro_rules! asm {
-() => {}
-}
-
-fn main() {
-unsafe {
-asm!("nop", clobber_abi+);  // { dg-error "expected '\\(', found 
'\\+'" }
-}
-}
\ No newline at end of file
diff --git a/gcc/testsuite/rust/compile/inline_asm_nop.rs 
b/gcc/testsuite/rust/compile/inline_asm_nop.rs
index 7da9bef3e568..ba21d024079d 100644
--- a/gcc/testsuite/rust/compile/inline_asm_nop.rs
+++ b/gcc/testsuite/rust/compile/inline_asm_nop.rs
@@ -8,5 +8,6 @@ macro_rules! asm {
 fn main() {
 unsafe {
 asm!("nop");
+asm!("nop",);
 }
 }
diff --git a/gcc/testsuite/rust/compile/inline_asm_nop_2.rs 
b/gcc/testsuite/rust/compile/inline_asm_nop_2.rs
deleted file mode 100644
index 76f53fadbe3c..
--- a/gcc/testsuite/rust/compile/inline_asm_nop_2.rs
+++ /dev/null
@@ -1,12 +0,0 @@
-#![feature(rustc_attrs)]
-
-#[rustc_builtin_macro]
-macro_rules! asm {
-() => {}
-}
-
-fn main() {
-unsafe {
-asm!("nop",);
-}
-}


[gcc/devel/rust/master] Renamed parseAsmArg to conform to other function names

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:4b1fa28ff56288eea4c2657061ce9df839fc02ea

commit 4b1fa28ff56288eea4c2657061ce9df839fc02ea
Author: jjasmine 
Date:   Tue May 28 00:17:33 2024 -0700

Renamed parseAsmArg to conform to other function names

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-asm.cc (parseAsmArg):
Renamed parseAsmArg to conform to other function names
(parse_asm_arg): Likewise.
(parse_asm): Likewise.
* expand/rust-macro-builtins-asm.h (parseAsmArg): Likewise.
(parse_asm_arg): Likewise.

Diff:
---
 gcc/rust/expand/rust-macro-builtins-asm.cc | 6 +++---
 gcc/rust/expand/rust-macro-builtins-asm.h  | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index 20a434c6c296..55d822d1f901 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -385,8 +385,8 @@ MacroBuiltin::asm_handler (location_t invoc_locus, 
AST::MacroInvocData &invoc,
 }
 
 int
-parseAsmArg (Parser &parser, TokenId last_token_id,
-InlineAsmContext &inlineAsmCtx)
+parse_asm_arg (Parser &parser, TokenId last_token_id,
+  InlineAsmContext &inlineAsmCtx)
 {
   auto token = parser.peek_current_token ();
   tl::optional fm_string;
@@ -505,7 +505,7 @@ parse_asm (location_t invoc_locus, AST::MacroInvocData 
&invoc,
 }
 
   // operands stream, also handles the optional ","
-  parseAsmArg (parser, last_token_id, inlineAsmCtx);
+  parse_asm_arg (parser, last_token_id, inlineAsmCtx);
 
   return tl::nullopt;
 }
diff --git a/gcc/rust/expand/rust-macro-builtins-asm.h 
b/gcc/rust/expand/rust-macro-builtins-asm.h
index 65763780979c..a35d7707e6c9 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.h
+++ b/gcc/rust/expand/rust-macro-builtins-asm.h
@@ -31,8 +31,8 @@ public:
 };
 
 int
-parseAsmArg (Parser &p, TokenId last_token_id,
-InlineAsmContext &inlineAsmCtx);
+parse_asm_arg (Parser &p, TokenId last_token_id,
+  InlineAsmContext &inlineAsmCtx);
 
 tl::optional
 parse_global_asm (location_t invoc_locus, AST::MacroInvocData &invoc);


[gcc/devel/rust/master] Scaffolding validation of asm!

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:07a48d90e0f1d6be523a04270f7c1c42babadaa4

commit 07a48d90e0f1d6be523a04270f7c1c42babadaa4
Author: jjasmine 
Date:   Mon Jun 10 18:08:42 2024 -0700

Scaffolding validation of asm!

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-asm.cc (parse_asm):
Scaffolding validation of asm!
(validate): Likewise
* expand/rust-macro-builtins-asm.h (validate): Likewise

Diff:
---
 gcc/rust/expand/rust-macro-builtins-asm.cc | 31 --
 gcc/rust/expand/rust-macro-builtins-asm.h  |  3 ++-
 2 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index 01749a387288..005570f48c38 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -703,13 +703,26 @@ parse_asm (location_t invoc_locus, AST::MacroInvocData 
&invoc,
   // operands stream, also handles the optional ","
   parse_asm_arg (parser, last_token_id, inline_asm_ctx);
 
-  AST::SingleASTNode single = AST::SingleASTNode (
-inline_asm_ctx.inline_asm.clone_expr_without_block ());
-  std::vector single_vec = {single};
+  // TODO: I'm putting the validation here because the rust reference put it
+  // 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 = validate (inline_asm_ctx);
 
-  AST::Fragment fragment_ast
-= AST::Fragment (single_vec, std::vector> ());
-  return fragment_ast;
+  if (is_valid)
+{
+  AST::SingleASTNode single = AST::SingleASTNode (
+   inline_asm_ctx.inline_asm.clone_expr_without_block ());
+  std::vector single_vec = {single};
+
+  AST::Fragment fragment_ast
+   = AST::Fragment (single_vec,
+std::vector> ());
+  return fragment_ast;
+}
+  else
+{
+  return tl::nullopt;
+}
 }
 
 tl::optional
@@ -749,4 +762,10 @@ parse_label (Parser &parser, TokenId 
last_token_id,
   return tl::nullopt;
 }
 }
+
+bool
+validate (InlineAsmContext &inline_asm_ctx)
+{
+  return true;
+}
 } // namespace Rust
diff --git a/gcc/rust/expand/rust-macro-builtins-asm.h 
b/gcc/rust/expand/rust-macro-builtins-asm.h
index 267c1b609d91..293d790ca40c 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.h
+++ b/gcc/rust/expand/rust-macro-builtins-asm.h
@@ -75,7 +75,8 @@ parse_format_string (Parser &parser, TokenId 
last_token_id,
 tl::optional
 parse_label (Parser &parser, TokenId last_token_id,
 InlineAsmContext &inline_asm_ctx);
-
+bool
+validate (InlineAsmContext &inline_asm_ctx);
 std::set potentially_nonpromoted_keywords
   = {"in", "out", "lateout", "inout", "inlateout", "const", "sym", "label"};


[gcc/devel/rust/master] Add potentially_nonpromoted_keywords set str

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:4ec940e39cae459a7c26f9ee24a7145d277cc8bf

commit 4ec940e39cae459a7c26f9ee24a7145d277cc8bf
Author: jjasmine 
Date:   Wed Jun 5 08:24:50 2024 -0700

Add potentially_nonpromoted_keywords set str

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-asm.cc (parse_reg_operand):
Add potentially_nonpromoted_keywords set str
(check_identifier): likewise
* expand/rust-macro-builtins-asm.h (parse_format_string):
likewise

gcc/testsuite/ChangeLog:

* rust/compile/inline_asm_parse_operand.rs: fix warnings

Diff:
---
 gcc/rust/expand/rust-macro-builtins-asm.cc | 174 +++--
 gcc/rust/expand/rust-macro-builtins-asm.h  |   3 +
 .../rust/compile/inline_asm_parse_operand.rs   |  17 +-
 3 files changed, 110 insertions(+), 84 deletions(-)

diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index 02426c65825d..4e6193deb7bc 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -204,14 +204,14 @@ parse_reg_operand (Parser &parser, 
TokenId last_token_id,
   //   };
 
   AST::InlineAsmOperand reg_operand;
-  rust_debug("Enter parse_reg_operand");
+  rust_debug ("Enter parse_reg_operand");
   auto token = parser.peek_current_token ();
   auto iden_token = parser.peek_current_token ();
   auto &inline_asm = inline_asm_ctx.inline_asm;
   if (check_identifier (parser, ""))
 {
-
-  rust_debug("Didn't get passed identifier checking, %s", 
token->as_string().c_str());
+  rust_debug ("Didn't get passed identifier checking, %s",
+ token->as_string ().c_str ());
 
   auto equal_token = parser.peek_current_token ();
   if (!parser.skip_token (EQUAL))
@@ -222,36 +222,40 @@ parse_reg_operand (Parser &parser, 
TokenId last_token_id,
 }
 
   token = parser.peek_current_token ();
-  rust_debug_loc(token->get_locus(), "Got pass identifier checking with %s",  
token->as_string().c_str());
-
+  rust_debug_loc (token->get_locus (), "Got pass identifier checking with %s",
+ token->as_string ().c_str ());
 
   bool is_global_asm = inline_asm.is_global_asm;
 
-  // For the keyword IN, currently we count it as a seperate keyword called 
Rust::IN
-  // search for #define RS_TOKEN_LIST in code base.
-  if (!is_global_asm && parser.skip_token(IN))
+  // For the keyword IN, currently we count it as a seperate keyword called
+  // Rust::IN search for #define RS_TOKEN_LIST in code base.
+  if (!is_global_asm && parser.skip_token (IN))
 {
-  rust_debug("Enter parse_reg_operand in");
+  rust_debug ("Enter parse_reg_operand in");
 
-  auto reg = parse_reg(parser, last_token_id, inline_asm_ctx);
+  auto reg = parse_reg (parser, last_token_id, inline_asm_ctx);
 
-  if (parser.skip_token(UNDERSCORE)) {
-// We are sure to be failing a test here, based on asm.rs 
-// 
https://github.com/rust-lang/rust/blob/a330e49593ee890f9197727a3a558b6e6b37f843/compiler/rustc_builtin_macros/src/asm.rs#L112
-rust_unreachable();
-  }
+  if (parser.skip_token (UNDERSCORE))
+   {
+ // We are sure to be failing a test here, based on asm.rs
+ // 
https://github.com/rust-lang/rust/blob/a330e49593ee890f9197727a3a558b6e6b37f843/compiler/rustc_builtin_macros/src/asm.rs#L112
+ rust_unreachable ();
+   }
 
-  auto expr = parse_format_string(parser, last_token_id, inline_asm_ctx) ;
+  auto expr = parse_format_string (parser, last_token_id, inline_asm_ctx);
   reg_operand.register_type = AST::InlineAsmOperand::RegisterType::In;
-  
-  // Since reg is of type optional, we need to check if it is not 
optional first.
-  // TODO: We don't throw any errors since we should have throw any 
encountered parsing error in parse_reg
-  if (reg) {
-reg_operand.in.reg = reg.value();
-  }
-  
-  // Only clone_expr() if we know that we have parse an expression 
successfully
-  // if (expr) {
+
+  // Since reg is of type optional, we need to check if it is not
+  // optional first.
+  // TODO: We don't throw any errors since we should have throw any
+  // encountered parsing error in parse_reg
+  if (reg)
+   {
+ reg_operand.in.reg = reg.value ();
+   }
+
+  // Only clone_expr() if we know that we have parse an expression
+  // successfully if (expr) {
   //   reg_operand.in.expr = expr->clone_expr();
   // }
 
@@ -269,51 +273,58 @@ parse_reg_operand (Parser &parser, 
TokenId last_token_id,
 }
   else if (!is_global_asm && check_identifier (parser, "inout"))
 {
-  rust_debug("Enter parse_reg_operand inout");
-  
-  auto reg = parse_reg(parser, last_token_id, inline_asm_ctx);
+  rust_debug ("Enter parse_reg_operand inout");
+
+  auto reg = parse_reg (parser, last_token_id, inline_

[gcc/devel/rust/master] Fix visitor-related warnings

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:4eb63c929f8bd77e0afa463bfc8f45986e12d288

commit 4eb63c929f8bd77e0afa463bfc8f45986e12d288
Author: jjasmine 
Date:   Wed Jun 5 18:12:49 2024 -0700

Fix visitor-related warnings

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit):
Fix visitor-related warnings
* ast/rust-ast-collector.h: Likewise.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise.
* ast/rust-ast-visitor.h: Likewise.
* checks/errors/borrowck/rust-bir-builder-struct.h: Likewise.
* checks/errors/borrowck/rust-function-collector.h: Likewise.
* checks/errors/rust-const-checker.cc (ConstChecker::visit): 
Likewise.
* checks/errors/rust-const-checker.h: Likewise.
* expand/rust-derive.h: Likewise.
* expand/rust-macro-builtins-asm.cc (parse_reg_operand): Likewise.
* hir/rust-hir-dump.cc (Dump::visit): Likewise.
* hir/rust-hir-dump.h: Likewise.
* hir/tree/rust-hir-visitor.h: Likewise.
* resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise.
* resolve/rust-ast-resolve-base.h: Likewise.

Diff:
---
 gcc/rust/ast/rust-ast-collector.cc|  5 +
 gcc/rust/ast/rust-ast-collector.h |  2 +-
 gcc/rust/ast/rust-ast-visitor.cc  |  6 ++
 gcc/rust/ast/rust-ast-visitor.h   |  5 +++--
 .../checks/errors/borrowck/rust-bir-builder-struct.h  |  1 +
 .../checks/errors/borrowck/rust-function-collector.h  |  1 +
 gcc/rust/checks/errors/rust-const-checker.cc  |  4 
 gcc/rust/checks/errors/rust-const-checker.h   |  2 ++
 gcc/rust/expand/rust-derive.h |  1 +
 gcc/rust/expand/rust-macro-builtins-asm.cc| 19 +--
 gcc/rust/hir/rust-hir-dump.cc |  5 +
 gcc/rust/hir/rust-hir-dump.h  |  1 +
 gcc/rust/hir/tree/rust-hir-visitor.h  |  3 ++-
 gcc/rust/resolve/rust-ast-resolve-base.cc |  4 
 gcc/rust/resolve/rust-ast-resolve-base.h  |  1 +
 15 files changed, 54 insertions(+), 6 deletions(-)

diff --git a/gcc/rust/ast/rust-ast-collector.cc 
b/gcc/rust/ast/rust-ast-collector.cc
index 341b31857237..78a30afe0dd5 100644
--- a/gcc/rust/ast/rust-ast-collector.cc
+++ b/gcc/rust/ast/rust-ast-collector.cc
@@ -18,6 +18,7 @@
 #include "rust-ast-collector.h"
 #include "rust-ast.h"
 #include "rust-diagnostics.h"
+#include "rust-expr.h"
 #include "rust-item.h"
 #include "rust-keyword-values.h"
 #include "rust-token.h"
@@ -1511,6 +1512,10 @@ TokenCollector::visit (AsyncBlockExpr &expr)
   visit (expr.get_block_expr ());
 }
 
+void
+TokenCollector::visit (InlineAsm &expr)
+{}
+
 // rust-item.h
 
 void
diff --git a/gcc/rust/ast/rust-ast-collector.h 
b/gcc/rust/ast/rust-ast-collector.h
index 2873053c5f52..6a44669c14ff 100644
--- a/gcc/rust/ast/rust-ast-collector.h
+++ b/gcc/rust/ast/rust-ast-collector.h
@@ -303,7 +303,7 @@ public:
   void visit (MatchExpr &expr);
   void visit (AwaitExpr &expr);
   void visit (AsyncBlockExpr &expr);
-
+  void visit (InlineAsm &expr);
   // rust-item.h
   void visit (TypeParam ¶m);
   void visit (LifetimeWhereClauseItem &item);
diff --git a/gcc/rust/ast/rust-ast-visitor.cc b/gcc/rust/ast/rust-ast-visitor.cc
index 65a92bbf1e70..c645ade4772b 100644
--- a/gcc/rust/ast/rust-ast-visitor.cc
+++ b/gcc/rust/ast/rust-ast-visitor.cc
@@ -662,6 +662,12 @@ DefaultASTVisitor::visit (AST::AsyncBlockExpr &expr)
   visit (expr.get_block_expr ());
 }
 
+void
+DefaultASTVisitor::visit (AST::InlineAsm &expr)
+{
+  rust_unreachable ();
+}
+
 void
 DefaultASTVisitor::visit (AST::TypeParam ¶m)
 {
diff --git a/gcc/rust/ast/rust-ast-visitor.h b/gcc/rust/ast/rust-ast-visitor.h
index fc807db15585..c4ce57cb7a3c 100644
--- a/gcc/rust/ast/rust-ast-visitor.h
+++ b/gcc/rust/ast/rust-ast-visitor.h
@@ -23,7 +23,6 @@
 // full include not required - only forward decls
 #include "rust-ast-full-decls.h"
 #include "rust-ast.h"
-#include "rust-expr.h"
 #include "rust-item.h"
 #include "rust-system.h"
 
@@ -129,7 +128,7 @@ public:
   virtual void visit (MatchExpr &expr) = 0;
   virtual void visit (AwaitExpr &expr) = 0;
   virtual void visit (AsyncBlockExpr &expr) = 0;
-  virtual void visit (InlineAsm &expr) { rust_unreachable (); }
+  virtual void visit (InlineAsm &expr) = 0;
 
   // rust-item.h
   virtual void visit (TypeParam ¶m) = 0;
@@ -313,6 +312,8 @@ protected:
   virtual void visit (AST::MatchExpr &expr) override;
   virtual void visit (AST::AwaitExpr &expr) override;
   virtual void visit (AST::AsyncBlockExpr &expr) override;
+  virtual void visit (InlineAsm &expr) override;
+
   virtual void visit (AST::TypeParam ¶m) override;
   virtual void visit (AST::LifetimeWhereClauseItem &item) override;
   virtual void visit (AST::TypeBoundWhereClauseItem &item) override;
diff --git a/gcc/rust/che

[gcc/devel/rust/master] Refactoring and supporting more parse_reg_operand

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:57c1f3a0f0d974662ded3a48200318dde763e4c6

commit 57c1f3a0f0d974662ded3a48200318dde763e4c6
Author: jjasmine 
Date:   Mon Jun 10 14:04:11 2024 -0700

Refactoring and supporting more parse_reg_operand

gcc/rust/ChangeLog:

* ast/rust-expr.h (struct InlineAsmOperand):
Refactoring and supporting more parse_reg_operand
* expand/rust-macro-builtins-asm.cc (parse_reg_operand):
Likewise.
(rust_debug): Likewise.

Diff:
---
 gcc/rust/ast/rust-expr.h   |  75 +-
 gcc/rust/expand/rust-macro-builtins-asm.cc | 121 +
 2 files changed, 144 insertions(+), 52 deletions(-)

diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index 5f60ec79b583..30146b2d57cf 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -4781,10 +4781,15 @@ struct InlineAsmOperand
 
   struct In
   {
-InlineAsmRegOrRegClass reg;
+tl::optional reg;
 std::unique_ptr expr;
 
 In () {}
+In (tl::optional ®,
+   std::unique_ptr expr)
+  : reg (reg), expr (std::move (expr))
+{}
+
 In (const struct In &other)
 {
   reg = other.reg;
@@ -4804,11 +4809,17 @@ struct InlineAsmOperand
 
   struct Out
   {
-InlineAsmRegOrRegClass reg;
+tl::optional reg;
 bool late;
 std::unique_ptr expr; // can be null
 
 Out () {}
+
+Out (tl::optional ®, bool late,
+std::unique_ptr expr)
+  : reg (reg), late (late), expr (std::move (expr))
+{}
+
 Out (const struct Out &other)
 {
   reg = other.reg;
@@ -4829,11 +4840,16 @@ struct InlineAsmOperand
 
   struct InOut
   {
-InlineAsmRegOrRegClass reg;
+tl::optional reg;
 bool late;
 std::unique_ptr expr; // this can't be null
 
 InOut () {}
+InOut (tl::optional ®, bool late,
+  std::unique_ptr expr)
+  : reg (reg), late (late), expr (std::move (expr))
+{}
+
 InOut (const struct InOut &other)
 {
   reg = other.reg;
@@ -4855,12 +4871,19 @@ struct InlineAsmOperand
 
   struct SplitInOut
   {
-InlineAsmRegOrRegClass reg;
+tl::optional reg;
 bool late;
 std::unique_ptr in_expr;
 std::unique_ptr out_expr; // could be null
 
 SplitInOut () {}
+
+SplitInOut (tl::optional ®, bool late,
+   std::unique_ptr in_expr, std::unique_ptr out_expr)
+  : reg (reg), late (late), in_expr (std::move (in_expr)),
+   out_expr (std::move (out_expr))
+{}
+
 SplitInOut (const struct SplitInOut &other)
 {
   reg = other.reg;
@@ -4925,6 +4948,50 @@ struct InlineAsmOperand
   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 ();
+  }
+
+  void set_sym (const tl::optional ®)
+  {
+this->register_type = Sym;
+if (reg.has_value ())
+  this->sym = reg.value ();
+  }
+
   location_t locus;
 };
 
diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index 795c66aa917a..df63233eeea0 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -221,10 +221,6 @@ parse_reg_operand (Parser &parser, 
TokenId last_token_id,
}
 }
 
-  token = parser.peek_current_token ();
-  rust_debug_loc (token->get_locus (), "Got pass identifier checking with %s",
- token->as_string ().c_str ());
-
   bool is_global_asm = inline_asm.is_global_asm;
 
   // For the keyword IN, currently we count it as a seperate keyword called
@@ -243,21 +239,11 @@ parse_reg_operand (Parser &parser, 
TokenId last_token_id,
}
 
   auto expr = parse_format_string (parser, last_token_id, inline_asm_ctx);
-  reg_operand.register_type = AST::InlineAsmOperand::RegisterType::In;
-
-  // Since reg is of type optional, we need to check if it is not
-  // optional first.
-  // TODO: We don't throw any errors since we should have throw any
-  // encountered parsing error in parse_reg
-  if (reg)
-   {
- reg_operand.in.reg = reg.value ();
-   }
 
-  // Only clone_expr() if we know that we have parse an expression
-  // successfully if (expr) {
-  //   reg_operand.in.expr = expr-

[gcc/devel/rust/master] Move parser and last_token_id to InlineAsmCtx

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:da324bc6ee09a0f71ff6bc4ebcaa7e2989dbf39a

commit da324bc6ee09a0f71ff6bc4ebcaa7e2989dbf39a
Author: jjasmine 
Date:   Tue Jun 11 17:56:20 2024 -0700

Move parser and last_token_id to InlineAsmCtx

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-asm.cc (parse_clobber_abi):
Move parser and last_token_id to InlineAsmCtx to prepapre
for tl::expected.
(parse_reg): Likewise.
(parse_operand): Likewise.
(parse_reg_operand): Likewise.
(check_and_set): Likewise.
(parse_options): Likewise.
(parse_format_string): Likewise.
(parse_asm_arg): Likewise.
(parse_asm): Likewise.
* expand/rust-macro-builtins-asm.h (class InlineAsmParseError): 
Likewise.
(parse_asm_arg): Likewise.
(check_and_set): Likewise.
(parse_operand): Likewise.
(parse_reg_operand): Likewise.
(parse_options): Likewise.
(parse_reg): Likewise.
(parse_clobber_abi): Likewise.
(parse_format_string): Likewise.

Diff:
---
 gcc/rust/expand/rust-macro-builtins-asm.cc | 100 ++---
 gcc/rust/expand/rust-macro-builtins-asm.h  |  39 +--
 2 files changed, 70 insertions(+), 69 deletions(-)

diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index 2628e89ced03..19c842ff86d1 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -38,12 +38,13 @@ parseDirSpec (Parser &parser, TokenId 
last_token_id)
 }
 
 int
-parse_clobber_abi (Parser &parser, TokenId last_token_id,
-  InlineAsmContext &inline_asm_ctx)
+parse_clobber_abi (InlineAsmContext &inline_asm_ctx)
 {
   // clobber_abi := "clobber_abi("  *("," ) [","] ")"
   // PARSE EVERYTHING COMMITTEDLY IN THIS FUNCTION, WE CONFIRMED VIA 
clobber_abi
   // identifier keyword
+  auto &parser = inline_asm_ctx.parser;
+  auto last_token_id = inline_asm_ctx.last_token_id;
   auto &inline_asm = inline_asm_ctx.inline_asm;
   auto token = parser.peek_current_token ();
   if (!parser.skip_token (LEFT_PAREN))
@@ -126,10 +127,12 @@ parse_clobber_abi (Parser &parser, 
TokenId last_token_id,
 }
 
 tl::optional
-parse_reg (Parser &parser, TokenId last_token_id,
-  InlineAsmContext &inline_asm_ctx)
+parse_reg (InlineAsmContext &inline_asm_ctx)
 {
   using RegType = AST::InlineAsmRegOrRegClass::Type;
+  auto &parser = inline_asm_ctx.parser;
+  auto last_token_id = inline_asm_ctx.last_token_id;
+
   if (!parser.skip_token (LEFT_PAREN))
 {
   // TODO: we expect a left parenthesis here, please return the correct
@@ -182,16 +185,14 @@ parse_reg (Parser &parser, TokenId 
last_token_id,
 }
 
 int
-parse_operand (Parser &parser, TokenId last_token_id,
-  InlineAsmContext &inline_asm_ctx)
+parse_operand (InlineAsmContext &inline_asm_ctx)
 {
   return 0;
 }
 
 // From rustc
 tl::optional
-parse_reg_operand (Parser &parser, TokenId last_token_id,
-  InlineAsmContext &inline_asm_ctx)
+parse_reg_operand (InlineAsmContext &inline_asm_ctx)
 {
   // let name = if p.token.is_ident() && p.look_ahead(1, |t| *t == token::Eq) {
   //   let (ident, _) = p.token.ident().unwrap();
@@ -202,7 +203,8 @@ parse_reg_operand (Parser &parser, TokenId 
last_token_id,
   //   } else {
   //   None
   //   };
-
+  auto &parser = inline_asm_ctx.parser;
+  auto last_token_id = inline_asm_ctx.last_token_id;
   AST::InlineAsmOperand reg_operand;
   rust_debug ("Enter parse_reg_operand");
   auto token = parser.peek_current_token ();
@@ -229,7 +231,7 @@ parse_reg_operand (Parser &parser, TokenId 
last_token_id,
 {
   rust_debug ("Enter parse_reg_operand in");
 
-  auto reg = parse_reg (parser, last_token_id, inline_asm_ctx);
+  auto reg = parse_reg (inline_asm_ctx);
 
   if (parser.skip_token (UNDERSCORE))
{
@@ -238,7 +240,7 @@ parse_reg_operand (Parser &parser, TokenId 
last_token_id,
  rust_unreachable ();
}
 
-  auto expr = parse_format_string (parser, last_token_id, inline_asm_ctx);
+  auto expr = parse_format_string (inline_asm_ctx);
 
   // TODO: When we've succesfully parse an expr, remember to clone_expr()
   // instead of nullptr
@@ -251,9 +253,9 @@ parse_reg_operand (Parser &parser, TokenId 
last_token_id,
 {
   rust_debug ("Enter parse_reg_operand out");
 
-  auto reg = parse_reg (parser, last_token_id, inline_asm_ctx);
+  auto reg = parse_reg (inline_asm_ctx);
 
-  auto expr = parse_format_string (parser, last_token_id, inline_asm_ctx);
+  auto expr = parse_format_string (inline_asm_ctx);
 
   // TODO: When we've succesfully parse an expr, remember to clone_expr()
   // instead of nullptr
@@ -271,7 +273,7 @@ parse_reg_operand (Parser &parser, TokenId 
last_token_id,
 {
   rust_debug (

[gcc/devel/rust/master] Update parser to parse strings in the first stage

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:9202993a573985e8bbaad3a4078e5a876ecd67e5

commit 9202993a573985e8bbaad3a4078e5a876ecd67e5
Author: jjasmine 
Date:   Tue Jun 11 16:57:48 2024 -0700

Update parser to parse strings in the first stage

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-asm.cc (parse_reg_operand):
Update parser to parse strings in the first stage
(parse_label): not needed right now

Diff:
---
 gcc/rust/expand/rust-macro-builtins-asm.cc | 62 +++---
 1 file changed, 13 insertions(+), 49 deletions(-)

diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index 005570f48c38..2628e89ced03 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -385,21 +385,6 @@ parse_reg_operand (Parser &parser, 
TokenId last_token_id,
   rust_unreachable ();
   return tl::nullopt;
 }
-  else if (auto label_str = parse_label (parser, last_token_id, 
inline_asm_ctx))
-{
-  auto block = parser.parse_block_expr ();
-  struct AST::InlineAsmOperand::Label label (label_str,
-block ? block->clone_expr ()
-  : nullptr);
-  reg_operand.set_label (label);
-  return reg_operand;
-}
-  else if (inline_asm_ctx.allows_templates ())
-{
-  // TODO: If we allow templating, do sth here
-  rust_unreachable ();
-  return tl::nullopt;
-}
   else
 {
   // TODO: It is  weird that we can't seem to match any identifier,
@@ -725,43 +710,22 @@ parse_asm (location_t invoc_locus, AST::MacroInvocData 
&invoc,
 }
 }
 
-tl::optional
-parse_label (Parser &parser, TokenId last_token_id,
-InlineAsmContext &inline_asm_ctx)
-{
-  auto token = parser.peek_current_token ();
+// bool
+// is_label (const std::string &potential_label)
+// {
 
-  if (token->get_id () != last_token_id && token->get_id () == STRING_LITERAL)
-{
-  // very nice, we got a string.
-  auto label = token->as_string ();
+//   if (potential_label.empty () || potential_label.back () != ':')
+// return false;
 
-  bool flag = true;
-  if (label.empty () || label.back () != ':')
-   flag = false; // Check if string is empty or does not end with a colon
+//   // Check if all characters before the last colon are digits
+//   for (size_t i = 0; i < potential_label.length () - 1; i++)
+//   {
+// if (potential_label[i] < '0' || potential_label[i] > '9')
+//   return false;
+//   }
 
-  // Check if all characters before the last colon are digits
-  for (int i = 0; i < label.length () - 1 && flag == true; i++)
-   {
- if (label[i] < '0' || label[i] > '9')
-   flag = false;
-   }
-
-  if (flag == true)
-   {
- parser.skip_token ();
- return token->as_string ();
-   }
-  else
-   {
- return tl::nullopt;
-   }
-}
-  else
-{
-  return tl::nullopt;
-}
-}
+//   return true;
+// }
 
 bool
 validate (InlineAsmContext &inline_asm_ctx)


[gcc/devel/rust/master] Partial support for operand

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:9d812b8af76d7517f21060708deb060ccf8c7a8c

commit 9d812b8af76d7517f21060708deb060ccf8c7a8c
Author: jjasmine 
Date:   Mon Jun 10 16:54:34 2024 -0700

Partial support for operand

gcc/rust/ChangeLog:

* ast/rust-expr.h (struct InlineAsmOperand):
Partial support for operand
* expand/rust-macro-builtins-asm.cc (parse_reg_operand): Likewise.
(parse_label): Likewise.
* expand/rust-macro-builtins-asm.h (parse_label): Likewise.

Diff:
---
 gcc/rust/ast/rust-expr.h   | 38 ++
 gcc/rust/expand/rust-macro-builtins-asm.cc | 62 ++
 gcc/rust/expand/rust-macro-builtins-asm.h  |  4 ++
 3 files changed, 97 insertions(+), 7 deletions(-)

diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index 30146b2d57cf..ba413da95df2 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -7,6 +7,7 @@
 #include "rust-macro.h"
 #include "rust-operators.h"
 #include "rust-system.h"
+#include 
 
 namespace Rust {
 namespace AST {
@@ -4777,6 +4778,7 @@ struct InlineAsmOperand
 SplitInOut,
 Const,
 Sym,
+Label,
   };
 
   struct In
@@ -4933,6 +4935,34 @@ struct InlineAsmOperand
   return *this;
 }
   };
+
+  struct Label
+  {
+std::string label_name;
+std::unique_ptr expr;
+
+Label () {}
+
+Label (tl::optional label_name, std::unique_ptr expr)
+  : expr (std::move (expr))
+{
+  if (label_name.has_value ())
+   this->label_name = label_name.value ();
+}
+Label (const struct Label &other)
+{
+  if (other.expr)
+   expr = std::unique_ptr (other.expr->clone_expr ());
+}
+
+Label operator= (const struct Label &other)
+{
+  if (other.expr)
+   expr = std::unique_ptr (other.expr->clone_expr ());
+  return *this;
+}
+  };
+
   RegisterType register_type;
 
   struct In in;
@@ -4941,6 +4971,7 @@ struct InlineAsmOperand
   struct SplitInOut split_in_out;
   struct Const cnst;
   struct Sym sym;
+  struct Label label;
 
   InlineAsmOperand () {}
   InlineAsmOperand (const InlineAsmOperand &other)
@@ -4992,6 +5023,13 @@ struct InlineAsmOperand
   this->sym = reg.value ();
   }
 
+  void set_label (const tl::optional ®)
+  {
+this->register_type = Label;
+if (reg.has_value ())
+  this->label = reg.value ();
+  }
+
   location_t locus;
 };
 
diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index df63233eeea0..01749a387288 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -373,19 +373,30 @@ parse_reg_operand (Parser &parser, 
TokenId last_token_id,
 }
   else if (parser.peek_current_token ()->get_id () == CONST)
 {
-  // TODO: Please handle const
-  rust_unreachable ();
-  return tl::nullopt;
+  // TODO: Please handle const with parse_expr instead.
+  auto anon_const
+   = parse_format_string (parser, last_token_id, inline_asm_ctx);
+  reg_operand.set_cnst (tl::nullopt);
+  return reg_operand;
 }
-  else if (false && check_identifier (parser, "sym"))
+  else if (check_identifier (parser, "sym"))
 {
-  // TODO: Please handle sym
+  // TODO: Please handle sym, which needs ExprKind::Path in Rust's asm.rs
   rust_unreachable ();
   return tl::nullopt;
 }
-  else if (false && check_identifier (parser, "label"))
+  else if (auto label_str = parse_label (parser, last_token_id, 
inline_asm_ctx))
+{
+  auto block = parser.parse_block_expr ();
+  struct AST::InlineAsmOperand::Label label (label_str,
+block ? block->clone_expr ()
+  : nullptr);
+  reg_operand.set_label (label);
+  return reg_operand;
+}
+  else if (inline_asm_ctx.allows_templates ())
 {
-  // TODO: Please handle label
+  // TODO: If we allow templating, do sth here
   rust_unreachable ();
   return tl::nullopt;
 }
@@ -701,4 +712,41 @@ parse_asm (location_t invoc_locus, AST::MacroInvocData 
&invoc,
   return fragment_ast;
 }
 
+tl::optional
+parse_label (Parser &parser, TokenId last_token_id,
+InlineAsmContext &inline_asm_ctx)
+{
+  auto token = parser.peek_current_token ();
+
+  if (token->get_id () != last_token_id && token->get_id () == STRING_LITERAL)
+{
+  // very nice, we got a string.
+  auto label = token->as_string ();
+
+  bool flag = true;
+  if (label.empty () || label.back () != ':')
+   flag = false; // Check if string is empty or does not end with a colon
+
+  // Check if all characters before the last colon are digits
+  for (int i = 0; i < label.length () - 1 && flag == true; i++)
+   {
+ if (label[i] < '0' || label[i] > '9')
+   flag = false;
+   }
+
+  if (flag == true)
+   {
+ pa

[gcc/devel/rust/master] Successful parse of in and inout, albeit with str

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:d24c338399f75dbc8f6b9f0711746d891966c0d7

commit d24c338399f75dbc8f6b9f0711746d891966c0d7
Author: jjasmine 
Date:   Tue Jun 4 23:14:19 2024 -0700

Successful parse of in and inout, albeit with str

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-asm.cc (parse_reg_operand):
Successful parse of in and inout, albeit with str
(check_identifier): Likewise.
(parse_asm_arg): Likewise.
* expand/rust-macro-builtins-asm.h (parse_format_string): Likewise.

gcc/testsuite/ChangeLog:

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

Diff:
---
 gcc/rust/expand/rust-macro-builtins-asm.cc | 108 +++--
 gcc/rust/expand/rust-macro-builtins-asm.h  |   4 +
 .../rust/compile/inline_asm_parse_operand.rs   |  28 ++
 3 files changed, 130 insertions(+), 10 deletions(-)

diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index b979b34763d8..02426c65825d 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -204,11 +204,15 @@ parse_reg_operand (Parser &parser, 
TokenId last_token_id,
   //   };
 
   AST::InlineAsmOperand reg_operand;
+  rust_debug("Enter parse_reg_operand");
   auto token = parser.peek_current_token ();
   auto iden_token = parser.peek_current_token ();
   auto &inline_asm = inline_asm_ctx.inline_asm;
   if (check_identifier (parser, ""))
 {
+
+  rust_debug("Didn't get passed identifier checking, %s", 
token->as_string().c_str());
+
   auto equal_token = parser.peek_current_token ();
   if (!parser.skip_token (EQUAL))
{
@@ -218,12 +222,40 @@ parse_reg_operand (Parser &parser, 
TokenId last_token_id,
 }
 
   token = parser.peek_current_token ();
+  rust_debug_loc(token->get_locus(), "Got pass identifier checking with %s",  
token->as_string().c_str());
+
 
   bool is_global_asm = inline_asm.is_global_asm;
-  if (!is_global_asm && check_identifier (parser, "in"))
+
+  // For the keyword IN, currently we count it as a seperate keyword called 
Rust::IN
+  // search for #define RS_TOKEN_LIST in code base.
+  if (!is_global_asm && parser.skip_token(IN))
 {
-  rust_unreachable ();
-  return tl::nullopt;
+  rust_debug("Enter parse_reg_operand in");
+
+  auto reg = parse_reg(parser, last_token_id, inline_asm_ctx);
+
+  if (parser.skip_token(UNDERSCORE)) {
+// We are sure to be failing a test here, based on asm.rs 
+// 
https://github.com/rust-lang/rust/blob/a330e49593ee890f9197727a3a558b6e6b37f843/compiler/rustc_builtin_macros/src/asm.rs#L112
+rust_unreachable();
+  }
+
+  auto expr = parse_format_string(parser, last_token_id, inline_asm_ctx) ;
+  reg_operand.register_type = AST::InlineAsmOperand::RegisterType::In;
+  
+  // Since reg is of type optional, we need to check if it is not 
optional first.
+  // TODO: We don't throw any errors since we should have throw any 
encountered parsing error in parse_reg
+  if (reg) {
+reg_operand.in.reg = reg.value();
+  }
+  
+  // Only clone_expr() if we know that we have parse an expression 
successfully
+  // if (expr) {
+  //   reg_operand.in.expr = expr->clone_expr();
+  // }
+
+  return reg_operand;
 }
   else if (!is_global_asm && check_identifier (parser, "out"))
 {
@@ -237,8 +269,51 @@ parse_reg_operand (Parser &parser, 
TokenId last_token_id,
 }
   else if (!is_global_asm && check_identifier (parser, "inout"))
 {
-  rust_unreachable ();
+  rust_debug("Enter parse_reg_operand inout");
+  
+  auto reg = parse_reg(parser, last_token_id, inline_asm_ctx);
+
+  if (parser.skip_token(UNDERSCORE)) {
+// We are sure to be failing a test here, based on asm.rs 
+// 
https://github.com/rust-lang/rust/blob/a330e49593ee890f9197727a3a558b6e6b37f843/compiler/rustc_builtin_macros/src/asm.rs#L112
+rust_unreachable();
+  }
+
+  // TODO: Is error propogation our top priority, the ? in rust's asm.rs 
is doing a lot of work.
+  // TODO: Not sure how to use parse_expr
+  auto expr = parse_format_string(parser, last_token_id, inline_asm_ctx) ;
+
+  std::unique_ptr out_expr;
+
+  if (parser.skip_token(MATCH_ARROW)) {
+rust_debug("Matched MATCH_ARROW");
+if (!parser.skip_token(UNDERSCORE)) {
+  
+  parse_format_string(parser, last_token_id, inline_asm_ctx) ;
+  //out_expr = parser.parse_expr();
+}
+
+reg_operand.register_type = 
AST::InlineAsmOperand::RegisterType::SplitInOut;
+// reg_operand.split_in_out.in_expr = expr->clone_expr();
+// reg_operand.split_in_out.out_expr = out_expr->clone_expr();
+// reg_operand.split_in_out.late = false;
+return reg_operand;
+
+  } else {
+reg_operand.register_type = AST::

[gcc/devel/rust/master] Scaffolding HIRFullVisitor for inline asm

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:ba440238991674de23e51de786010a6f52084c25

commit ba440238991674de23e51de786010a6f52084c25
Author: jjasmine 
Date:   Tue Jun 4 20:17:23 2024 -0700

Scaffolding HIRFullVisitor for inline asm

gcc/rust/ChangeLog:

* ast/rust-ast-visitor.h:
Scaffolding HIRFullVisitor for inline asm
* ast/rust-ast.cc (InlineAsm::accept_vis): Likewise.
* hir/tree/rust-hir-visitor.h (RUST_HIR_VISITOR_H): Likewise.
* hir/tree/rust-hir.cc (InlineAsm::accept_vis): Likewise.

Diff:
---
 gcc/rust/ast/rust-ast-visitor.h  | 2 +-
 gcc/rust/ast/rust-ast.cc | 1 +
 gcc/rust/hir/tree/rust-hir-visitor.h | 2 ++
 gcc/rust/hir/tree/rust-hir.cc| 9 +++--
 4 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/gcc/rust/ast/rust-ast-visitor.h b/gcc/rust/ast/rust-ast-visitor.h
index 6a2bb7a8aff6..fc807db15585 100644
--- a/gcc/rust/ast/rust-ast-visitor.h
+++ b/gcc/rust/ast/rust-ast-visitor.h
@@ -129,7 +129,7 @@ public:
   virtual void visit (MatchExpr &expr) = 0;
   virtual void visit (AwaitExpr &expr) = 0;
   virtual void visit (AsyncBlockExpr &expr) = 0;
-  virtual void visit (InlineAsm &expr){};
+  virtual void visit (InlineAsm &expr) { rust_unreachable (); }
 
   // rust-item.h
   virtual void visit (TypeParam ¶m) = 0;
diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc
index 2a173c4610df..d94b7118d5e2 100644
--- a/gcc/rust/ast/rust-ast.cc
+++ b/gcc/rust/ast/rust-ast.cc
@@ -4659,6 +4659,7 @@ AsyncBlockExpr::accept_vis (ASTVisitor &vis)
 void
 InlineAsm::accept_vis (ASTVisitor &vis)
 {
+  rust_unreachable ();
   vis.visit (*this);
 }
 
diff --git a/gcc/rust/hir/tree/rust-hir-visitor.h 
b/gcc/rust/hir/tree/rust-hir-visitor.h
index ae9d23f2e005..80960fc03156 100644
--- a/gcc/rust/hir/tree/rust-hir-visitor.h
+++ b/gcc/rust/hir/tree/rust-hir-visitor.h
@@ -19,6 +19,7 @@
 #ifndef RUST_HIR_VISITOR_H
 #define RUST_HIR_VISITOR_H
 
+#include "rust-hir-expr.h"
 #include "rust-hir-full-decls.h"
 
 namespace Rust {
@@ -85,6 +86,7 @@ public:
   virtual void visit (MatchExpr &expr) = 0;
   virtual void visit (AwaitExpr &expr) = 0;
   virtual void visit (AsyncBlockExpr &expr) = 0;
+  virtual void visit (InlineAsm &expr) {}
   virtual void visit (TypeParam ¶m) = 0;
   virtual void visit (ConstGenericParam ¶m) = 0;
   virtual void visit (LifetimeWhereClauseItem &item) = 0;
diff --git a/gcc/rust/hir/tree/rust-hir.cc b/gcc/rust/hir/tree/rust-hir.cc
index 5e5d579e26b9..7ad0de85a6cd 100644
--- a/gcc/rust/hir/tree/rust-hir.cc
+++ b/gcc/rust/hir/tree/rust-hir.cc
@@ -3772,11 +3772,16 @@ BorrowExpr::accept_vis (HIRFullVisitor &vis)
 
 void
 InlineAsm::accept_vis (HIRExpressionVisitor &vis)
-{}
+{
+  rust_unreachable ();
+}
 
 void
 InlineAsm::accept_vis (HIRFullVisitor &vis)
-{}
+{
+  rust_unreachable ();
+  vis.visit (*this);
+}
 
 void
 BorrowExpr::accept_vis (HIRExpressionVisitor &vis)


[gcc/devel/rust/master] expand: Keep track of semicoloned builtin macros

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:fb906a41a4e911f7f0d7b506347286c7d942995e

commit fb906a41a4e911f7f0d7b506347286c7d942995e
Author: Arthur Cohen 
Date:   Fri Jun 14 16:45:34 2024 +0200

expand: Keep track of semicoloned builtin macros

This is quite a rough fix (like a lot of the macro expansion code...) but
it allows built-in macros to be treated as statements. I *think* asm!()
might be the only one where it really matters, but also doing something
like

{
line!();
}

will now work, whereas before the macro invocation would not get expanded
properly and would be ignored.

gcc/rust/ChangeLog:

* ast/rust-ast-fragment.h: Pass `is_semicolon` information to 
builtin
macro transcribers.
* ast/rust-macro.h: Pass semicolon information to transcriber..
* expand/rust-macro-builtins-asm.cc (MacroBuiltin::asm_handler): 
Likewise.
(parse_asm): Likewise.
* expand/rust-macro-builtins-asm.h (parse_asm): Likewise.
* expand/rust-macro-builtins-format-args.cc 
(MacroBuiltin::format_args_handler): Likewise.
* expand/rust-macro-builtins-include.cc 
(MacroBuiltin::include_bytes_handler): Likewise.
(MacroBuiltin::include_str_handler): Likewise.
(MacroBuiltin::include_handler): Likewise.
* expand/rust-macro-builtins-location.cc 
(MacroBuiltin::file_handler): Likewise.
(MacroBuiltin::column_handler): Likewise.
(MacroBuiltin::line_handler): Likewise.
* expand/rust-macro-builtins-log-debug.cc 
(MacroBuiltin::assert_handler): Likewise.
* expand/rust-macro-builtins-utility.cc 
(MacroBuiltin::compile_error_handler): Likewise.
(MacroBuiltin::concat_handler): Likewise.
(MacroBuiltin::env_handler): Likewise.
(MacroBuiltin::cfg_handler): Likewise.
(MacroBuiltin::stringify_handler): Likewise.
* expand/rust-macro-builtins.cc (format_args_maker): Likewise.
(inline_asm_maker): Likewise.
(MacroBuiltin::sorry): Likewise.
(MacroBuiltin::proc_macro_builtin): Likewise.
* expand/rust-macro-builtins.h: Likewise.
* expand/rust-macro-expand.cc (MacroExpander::expand_decl_macro): 
Likewise.
(MacroExpander::expand_invoc): Likewise.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Remove 
rust_unreachable.
* ast/rust-ast.cc (InlineAsm::accept_vis): Likewise.
* hir/tree/rust-hir.cc (InlineAsm::accept_vis): Likewise.

Diff:
---
 gcc/rust/ast/rust-ast-fragment.h   |  3 +-
 gcc/rust/ast/rust-ast-visitor.cc   |  4 +-
 gcc/rust/ast/rust-ast.cc   |  1 -
 gcc/rust/ast/rust-macro.h  |  2 +-
 gcc/rust/expand/rust-macro-builtins-asm.cc | 23 +++---
 gcc/rust/expand/rust-macro-builtins-asm.h  |  2 +-
 gcc/rust/expand/rust-macro-builtins-format-args.cc |  2 +-
 gcc/rust/expand/rust-macro-builtins-include.cc |  6 +--
 gcc/rust/expand/rust-macro-builtins-location.cc|  7 +--
 gcc/rust/expand/rust-macro-builtins-log-debug.cc   |  2 +-
 gcc/rust/expand/rust-macro-builtins-utility.cc | 12 +++--
 gcc/rust/expand/rust-macro-builtins.cc | 16 ---
 gcc/rust/expand/rust-macro-builtins.h  | 53 ++
 gcc/rust/expand/rust-macro-expand.cc   | 20 +---
 gcc/rust/hir/tree/rust-hir.cc  |  5 +-
 15 files changed, 94 insertions(+), 64 deletions(-)

diff --git a/gcc/rust/ast/rust-ast-fragment.h b/gcc/rust/ast/rust-ast-fragment.h
index 33603ac5a4e5..0c4204f71fab 100644
--- a/gcc/rust/ast/rust-ast-fragment.h
+++ b/gcc/rust/ast/rust-ast-fragment.h
@@ -128,7 +128,8 @@ private:
  * rust-macro-builtins.{h,cc}.
  */
 using MacroTranscriberFunc
-  = std::function (location_t, MacroInvocData &)>;
+  = std::function (location_t, MacroInvocData &,
+ bool semicolon)>;
 
 } // namespace AST
 } // namespace Rust
diff --git a/gcc/rust/ast/rust-ast-visitor.cc b/gcc/rust/ast/rust-ast-visitor.cc
index c645ade4772b..fc31b0ae5d43 100644
--- a/gcc/rust/ast/rust-ast-visitor.cc
+++ b/gcc/rust/ast/rust-ast-visitor.cc
@@ -664,9 +664,7 @@ DefaultASTVisitor::visit (AST::AsyncBlockExpr &expr)
 
 void
 DefaultASTVisitor::visit (AST::InlineAsm &expr)
-{
-  rust_unreachable ();
-}
+{}
 
 void
 DefaultASTVisitor::visit (AST::TypeParam ¶m)
diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc
index d94b7118d5e2..2a173c4610df 100644
--- a/gcc/rust/ast/rust-ast.cc
+++ b/gcc/rust/ast/rust-ast.cc
@@ -4659,7 +4659,6 @@ AsyncBlockExpr::accept_vis (ASTVisitor &vis)
 void
 InlineAsm::accept_vis (ASTVisitor &vis)
 {
-  rust_unreachable ();
   vis.visit (*this);
 }
 
diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h
index 5300b59f5d3a..69b59c25d084 100644
--- a/gcc/rust/ast

[gcc/devel/rust/master] expand: Switch semicolon boolean to an enum instead.

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:7d22e900b069c5acdff8272da89b959c50dcb666

commit 7d22e900b069c5acdff8272da89b959c50dcb666
Author: Arthur Cohen 
Date:   Tue Jun 18 13:47:57 2024 +0200

expand: Switch semicolon boolean to an enum instead.

gcc/rust/ChangeLog:

* ast/rust-ast-fragment.h (enum class): Add InvocKind and AsmKind 
enums.
* ast/rust-macro.h: Switch semicolon boolean to InvocKind enum.
* expand/rust-expand-visitor.cc (ExpandVisitor::visit): Likewise.
* expand/rust-macro-builtins-asm.cc (MacroBuiltin::asm_handler): 
Likewise.
(parse_asm): Likewise.
* expand/rust-macro-builtins-asm.h (parse_asm): Likewise.
* expand/rust-macro-builtins-format-args.cc 
(MacroBuiltin::format_args_handler): Likewise.
* expand/rust-macro-builtins-include.cc 
(MacroBuiltin::include_bytes_handler): Likewise.
(MacroBuiltin::include_str_handler): Likewise.
(MacroBuiltin::include_handler): Likewise.
* expand/rust-macro-builtins-location.cc 
(MacroBuiltin::file_handler): Likewise.
(MacroBuiltin::column_handler): Likewise.
(MacroBuiltin::line_handler): Likewise.
* expand/rust-macro-builtins-log-debug.cc 
(MacroBuiltin::assert_handler): Likewise.
* expand/rust-macro-builtins-utility.cc 
(MacroBuiltin::compile_error_handler): Likewise.
(MacroBuiltin::concat_handler): Likewise.
(MacroBuiltin::env_handler): Likewise.
(MacroBuiltin::cfg_handler): Likewise.
(MacroBuiltin::stringify_handler): Likewise.
* expand/rust-macro-builtins.cc (format_args_maker): Likewise.
(enum class): Likewise.
(inline_asm_maker): Likewise.
(MacroBuiltin::sorry): Likewise.
(MacroBuiltin::proc_macro_builtin): Likewise.
* expand/rust-macro-builtins.h: Likewise.
* expand/rust-macro-expand.cc (MacroExpander::expand_decl_macro): 
Likewise.
(MacroExpander::expand_eager_invocations): Likewise.
(MacroExpander::expand_invoc): Likewise.
* expand/rust-macro-expand.h (struct MacroExpander): Likewise.

Diff:
---
 gcc/rust/ast/rust-ast-fragment.h   | 14 +++-
 gcc/rust/ast/rust-macro.h  |  2 +-
 gcc/rust/expand/rust-expand-visitor.cc |  5 ++-
 gcc/rust/expand/rust-macro-builtins-asm.cc | 20 +++-
 gcc/rust/expand/rust-macro-builtins-asm.h  |  3 +-
 gcc/rust/expand/rust-macro-builtins-format-args.cc |  4 ++-
 gcc/rust/expand/rust-macro-builtins-include.cc | 10 --
 gcc/rust/expand/rust-macro-builtins-location.cc|  9 --
 gcc/rust/expand/rust-macro-builtins-log-debug.cc   |  4 ++-
 gcc/rust/expand/rust-macro-builtins-utility.cc | 13 +---
 gcc/rust/expand/rust-macro-builtins.cc | 30 +++---
 gcc/rust/expand/rust-macro-builtins.h  | 37 +++---
 gcc/rust/expand/rust-macro-expand.cc   | 20 ++--
 gcc/rust/expand/rust-macro-expand.h|  7 ++--
 14 files changed, 105 insertions(+), 73 deletions(-)

diff --git a/gcc/rust/ast/rust-ast-fragment.h b/gcc/rust/ast/rust-ast-fragment.h
index 0c4204f71fab..8dde9ed5f6b9 100644
--- a/gcc/rust/ast/rust-ast-fragment.h
+++ b/gcc/rust/ast/rust-ast-fragment.h
@@ -123,13 +123,25 @@ private:
   void assert_single_fragment (SingleASTNode::NodeType expected) const;
 };
 
+enum class InvocKind
+{
+  Expr,
+  Semicoloned,
+};
+
+enum class AsmKind
+{
+  Global,
+  Inline
+};
+
 /**
  * This is the type for transcriber functions found in
  * rust-macro-builtins.{h,cc}.
  */
 using MacroTranscriberFunc
   = std::function (location_t, MacroInvocData &,
- bool semicolon)>;
+ InvocKind semicolon)>;
 
 } // namespace AST
 } // namespace Rust
diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h
index 69b59c25d084..71cdcf0471ea 100644
--- a/gcc/rust/ast/rust-macro.h
+++ b/gcc/rust/ast/rust-macro.h
@@ -482,7 +482,7 @@ private:
* should make use of the actual rules. If the macro is builtin, then another
* associated transcriber should be used
*/
-  static Fragment dummy_builtin (location_t, MacroInvocData &, bool)
+  static Fragment dummy_builtin (location_t, MacroInvocData &, AST::InvocKind)
   {
 rust_unreachable ();
 return Fragment::create_error ();
diff --git a/gcc/rust/expand/rust-expand-visitor.cc 
b/gcc/rust/expand/rust-expand-visitor.cc
index c840c25994ee..b29523b414bf 100644
--- a/gcc/rust/expand/rust-expand-visitor.cc
+++ b/gcc/rust/expand/rust-expand-visitor.cc
@@ -17,6 +17,7 @@
 // .
 
 #include "rust-expand-visitor.h"
+#include "rust-ast-fragment.h"
 #include "rust-proc-macro.h"
 #include "rust-attributes.h"
 #include "rust-ast.h"
@@ -467,7 +468,9 @@ void
 ExpandVisitor::visit (AS

[gcc/devel/rust/master] Expected first layer done

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:1d3031a9c83638c8393238dd6c1ed896e8c83294

commit 1d3031a9c83638c8393238dd6c1ed896e8c83294
Author: jjasmine 
Date:   Tue Jun 11 22:07:14 2024 -0700

Expected first layer done

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-asm.cc (parse_reg):
Expected first layer done
(parse_reg_operand): Likewise.
(parse_asm_arg): Likewise.
(parse_format_strings): Likewise.
(parse_asm): Likewise.
(validate): Likewise.
* expand/rust-macro-builtins-asm.h (parse_asm_arg): Likewise.
(validate): Likewise.
(parse_format_strings): Likewise.

Diff:
---
 gcc/rust/expand/rust-macro-builtins-asm.cc | 74 +-
 gcc/rust/expand/rust-macro-builtins-asm.h  | 23 --
 2 files changed, 61 insertions(+), 36 deletions(-)

diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index 19c842ff86d1..dba80c435a69 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -131,7 +131,6 @@ parse_reg (InlineAsmContext &inline_asm_ctx)
 {
   using RegType = AST::InlineAsmRegOrRegClass::Type;
   auto &parser = inline_asm_ctx.parser;
-  auto last_token_id = inline_asm_ctx.last_token_id;
 
   if (!parser.skip_token (LEFT_PAREN))
 {
@@ -204,7 +203,6 @@ parse_reg_operand (InlineAsmContext &inline_asm_ctx)
   //   None
   //   };
   auto &parser = inline_asm_ctx.parser;
-  auto last_token_id = inline_asm_ctx.last_token_id;
   AST::InlineAsmOperand reg_operand;
   rust_debug ("Enter parse_reg_operand");
   auto token = parser.peek_current_token ();
@@ -562,8 +560,8 @@ MacroBuiltin::asm_handler (location_t invoc_locus, 
AST::MacroInvocData &invoc,
   return parse_asm (invoc_locus, invoc, is_global_asm);
 }
 
-int
-parse_asm_arg (InlineAsmContext &inline_asm_ctx)
+tl::expected
+parse_asm_arg (InlineAsmContext inline_asm_ctx)
 {
   auto &parser = inline_asm_ctx.parser;
   auto last_token_id = inline_asm_ctx.last_token_id;
@@ -625,7 +623,7 @@ parse_asm_arg (InlineAsmContext &inline_asm_ctx)
   // std::cout << "reg_operand" << std::endl;
   auto operand = parse_reg_operand (inline_asm_ctx);
 }
-  return 0;
+  return tl::expected (inline_asm_ctx);
 }
 
 tl::optional
@@ -655,14 +653,48 @@ parse_asm (location_t invoc_locus, AST::MacroInvocData 
&invoc,
   AST::InlineAsm inline_asm (invoc_locus, is_global_asm);
   auto inline_asm_ctx = InlineAsmContext (inline_asm, parser, last_token_id);
 
+  // operands stream, also handles the optional ","
+  tl::expected resulting_context
+= tl::expected (inline_asm_ctx);
+  resulting_context.and_then (parse_format_strings)
+.and_then (parse_asm_arg)
+.and_then (validate);
+
+  // TODO: I'm putting the validation here because the rust reference put it
+  // 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)
+{
+  AST::SingleASTNode single = AST::SingleASTNode (
+   inline_asm_ctx.inline_asm.clone_expr_without_block ());
+  std::vector single_vec = {single};
+
+  AST::Fragment fragment_ast
+   = AST::Fragment (single_vec,
+std::vector> ());
+  return fragment_ast;
+}
+  else
+{
+  return tl::nullopt;
+}
+}
+
+tl::expected
+parse_format_strings (InlineAsmContext inline_asm_ctx)
+{
   // Parse the first ever formatted string, success or not, will skip 1 token
+  auto parser = inline_asm_ctx.parser;
+  auto last_token_id = inline_asm_ctx.last_token_id;
   auto fm_string = parse_format_string (inline_asm_ctx);
 
   if (fm_string == tl::nullopt)
 {
   rust_error_at (parser.peek_current_token ()->get_locus (),
 "%s template must be a string literal", "asm");
-  return tl::nullopt;
+  return tl::unexpected ("ERROR");
 }
 
   // formatted string stream
@@ -685,29 +717,7 @@ parse_asm (location_t invoc_locus, AST::MacroInvocData 
&invoc,
}
 }
 
-  // operands stream, also handles the optional ","
-  parse_asm_arg (inline_asm_ctx);
-
-  // TODO: I'm putting the validation here because the rust reference put it
-  // 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 = validate (inline_asm_ctx);
-
-  if (is_valid)
-{
-  AST::SingleASTNode single = AST::SingleASTNode (
-   inline_asm_ctx.inline_asm.clone_expr_without_block ());
-  std::vector single_vec = {single};
-
-  AST::Fragment fragment_ast
-   = AST::Fragment (single_vec,
-std::vector> ());
-  return fragment_ast;
-}
-  else
-{
-  return tl::nullopt;
-}
+  return tl::expected (inline_asm_ctx);
 }
 
 // bool
@@ -72

[gcc/devel/rust/master] Partial second layer of expected in parsing asm

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:7fa14d4f64a1339fcecf9c73c8831c6db434a741

commit 7fa14d4f64a1339fcecf9c73c8831c6db434a741
Author: jjasmine 
Date:   Tue Jun 11 23:25:50 2024 -0700

Partial second layer of expected in parsing asm

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-asm.cc (parseDirSpec):
Partial second layer of expected in parsing asm
(parse_clobber_abi): Likewise
(parse_operand): Likewise
(parse_reg_operand): Likewise
(parse_asm_arg): Likewise
* expand/rust-macro-builtins-asm.h (parse_clobber_abi): Likewise
(parse_reg_operand): Likewise
(parse_operand): Likewise

Diff:
---
 gcc/rust/expand/rust-macro-builtins-asm.cc | 81 +++---
 gcc/rust/expand/rust-macro-builtins-asm.h  | 25 +++--
 2 files changed, 37 insertions(+), 69 deletions(-)

diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index dba80c435a69..b7a53898306a 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -31,14 +31,8 @@ std::map 
InlineAsmOptionMap{
   {AST::InlineAsmOption::RAW, "raw"},
 };
 
-int
-parseDirSpec (Parser &parser, TokenId last_token_id)
-{
-  return 0;
-}
-
-int
-parse_clobber_abi (InlineAsmContext &inline_asm_ctx)
+tl::expected
+parse_clobber_abi (InlineAsmContext inline_asm_ctx)
 {
   // clobber_abi := "clobber_abi("  *("," ) [","] ")"
   // PARSE EVERYTHING COMMITTEDLY IN THIS FUNCTION, WE CONFIRMED VIA 
clobber_abi
@@ -59,14 +53,16 @@ parse_clobber_abi (InlineAsmContext &inline_asm_ctx)
{
  rust_error_at (token->get_locus (),
 "expected %<(%>, found end of macro arguments");
- return -1;
+ return tl::unexpected (
+   "Expected something else instead of end of macro arguments");
}
   else
{
  rust_error_at (token->get_locus (), "expected %<(%>, found %qs",
 token->get_token_description ());
}
-  return -1;
+  return tl::unexpected (
+   "Expected left parenthesis instead of something else");
 }
 
   if (parser.skip_token (RIGHT_PAREN))
@@ -76,7 +72,8 @@ parse_clobber_abi (InlineAsmContext &inline_asm_ctx)
   rust_error_at (
parser.peek_current_token ()->get_locus (),
"at least one abi must be provided as an argument to %");
-  return -1;
+  return tl::unexpected (
+   "at least one abi must be provided as an argument to %");
 }
 
   std::vector new_abis;
@@ -109,7 +106,7 @@ parse_clobber_abi (InlineAsmContext &inline_asm_ctx)
  // TODO: If the skip of comma is unsuccessful, which should be
  // illegal, pleaes emit the correct error.
  rust_unreachable ();
- return -1;
+ return tl::unexpected ("SKIP OF COMMA UNSUCCESSFUL");
}
 
   token = parser.peek_current_token ();
@@ -123,7 +120,7 @@ parse_clobber_abi (InlineAsmContext &inline_asm_ctx)
   inline_asm.clobber_abi.push_back (abi);
 }
 
-  return 0;
+  return inline_asm_ctx;
 }
 
 tl::optional
@@ -183,15 +180,9 @@ parse_reg (InlineAsmContext &inline_asm_ctx)
   return reg_class;
 }
 
-int
-parse_operand (InlineAsmContext &inline_asm_ctx)
-{
-  return 0;
-}
-
 // From rustc
-tl::optional
-parse_reg_operand (InlineAsmContext &inline_asm_ctx)
+tl::expected
+parse_reg_operand (InlineAsmContext inline_asm_ctx)
 {
   // let name = if p.token.is_ident() && p.look_ahead(1, |t| *t == token::Eq) {
   //   let (ident, _) = p.token.ident().unwrap();
@@ -204,15 +195,11 @@ parse_reg_operand (InlineAsmContext &inline_asm_ctx)
   //   };
   auto &parser = inline_asm_ctx.parser;
   AST::InlineAsmOperand reg_operand;
-  rust_debug ("Enter parse_reg_operand");
   auto token = parser.peek_current_token ();
   auto iden_token = parser.peek_current_token ();
   auto &inline_asm = inline_asm_ctx.inline_asm;
   if (check_identifier (parser, ""))
 {
-  rust_debug ("Didn't get passed identifier checking, %s",
- token->as_string ().c_str ());
-
   auto equal_token = parser.peek_current_token ();
   if (!parser.skip_token (EQUAL))
{
@@ -227,8 +214,6 @@ parse_reg_operand (InlineAsmContext &inline_asm_ctx)
   // Rust::IN search for #define RS_TOKEN_LIST in code base.
   if (!is_global_asm && parser.skip_token (IN))
 {
-  rust_debug ("Enter parse_reg_operand in");
-
   auto reg = parse_reg (inline_asm_ctx);
 
   if (parser.skip_token (UNDERSCORE))
@@ -244,13 +229,11 @@ parse_reg_operand (InlineAsmContext &inline_asm_ctx)
   // instead of nullptr
   struct AST::InlineAsmOperand::In in (reg, nullptr);
   reg_operand.set_in (in);
-
-  return reg_operand;
+  inline_asm_ctx.inline_asm.operands.push_back (reg_operand);
+  return inline_asm_ctx;
 }
   else if (!is_global_asm && check_identifier (parser, "out"))
 {
-  rust

[gcc/devel/rust/master] Finish incorporating expected of parse_reg_operand

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:79a2eaa693525d4d753ff5096b99fe43ef6b3bc1

commit 79a2eaa693525d4d753ff5096b99fe43ef6b3bc1
Author: jjasmine 
Date:   Thu Jun 13 23:06:01 2024 -0700

Finish incorporating expected of parse_reg_operand

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-asm.cc (parse_clobber_abi):
Finish incorporating expected of parse_reg_operand
(parse_reg): Likewise.
(parse_reg_operand): Likewise.
(parse_reg_operand_in): Likewise.
(parse_reg_operand_out): Likewise.
(parse_reg_operand_lateout): Likewise.
(parse_reg_operand_const): Likewise.
(parse_reg_operand_inout): Likewise.
(parse_reg_operand_sym): Likewise.
(MacroBuiltin::asm_handler): Likewise.
(parse_asm_arg): Likewise.
(parse_asm): Likewise.
(parse_format_strings): Likewise.
(validate): Likewise.
* expand/rust-macro-builtins-asm.h (class InlineAsmParseError): 
Likewise.
(enum InlineAsmParseError): Likewise.
(validate): Likewise.
(parse_format_strings): Likewise.
(parse_reg_operand_in): Likewise.
(parse_reg_operand_out): Likewise.
(parse_reg_operand_lateout): Likewise.
(parse_reg_operand_inout): Likewise.
(parse_reg_operand_inlateout): Likewise.
(parse_reg_operand_const): Likewise.
(parse_reg_operand_sym): Likewise.

Diff:
---
 gcc/rust/expand/rust-macro-builtins-asm.cc | 212 +
 gcc/rust/expand/rust-macro-builtins-asm.h  |  65 +++--
 2 files changed, 180 insertions(+), 97 deletions(-)

diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index 964ca679ebb0..8dd7238f8b9c 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -35,7 +35,7 @@ std::map 
InlineAsmOptionMap{
   {AST::InlineAsmOption::RAW, "raw"},
 };
 
-tl::expected
+tl::expected
 parse_clobber_abi (InlineAsmContext inline_asm_ctx)
 {
   // clobber_abi := "clobber_abi("  *("," ) [","] ")"
@@ -57,16 +57,14 @@ parse_clobber_abi (InlineAsmContext inline_asm_ctx)
{
  rust_error_at (token->get_locus (),
 "expected %<(%>, found end of macro arguments");
- return tl::unexpected (
-   "Expected something else instead of end of macro arguments");
+ return tl::unexpected (COMMITTED);
}
   else
{
  rust_error_at (token->get_locus (), "expected %<(%>, found %qs",
 token->get_token_description ());
}
-  return tl::unexpected (
-   "Expected left parenthesis instead of something else");
+  return tl::unexpected (COMMITTED);
 }
 
   if (parser.skip_token (RIGHT_PAREN))
@@ -76,8 +74,7 @@ parse_clobber_abi (InlineAsmContext inline_asm_ctx)
   rust_error_at (
parser.peek_current_token ()->get_locus (),
"at least one abi must be provided as an argument to %");
-  return tl::unexpected (
-   "at least one abi must be provided as an argument to %");
+  return tl::unexpected (COMMITTED);
 }
 
   std::vector new_abis;
@@ -110,7 +107,7 @@ parse_clobber_abi (InlineAsmContext inline_asm_ctx)
  // TODO: If the skip of comma is unsuccessful, which should be
  // illegal, pleaes emit the correct error.
  rust_unreachable ();
- return tl::unexpected ("SKIP OF COMMA UNSUCCESSFUL");
+ return tl::unexpected (COMMITTED);
}
 
   token = parser.peek_current_token ();
@@ -185,7 +182,7 @@ parse_reg (InlineAsmContext &inline_asm_ctx)
 }
 
 // From rustc
-tl::expected
+tl::expected
 parse_reg_operand (InlineAsmContext inline_asm_ctx)
 {
   // let name = if p.token.is_ident() && p.look_ahead(1, |t| *t == token::Eq) {
@@ -201,7 +198,6 @@ parse_reg_operand (InlineAsmContext inline_asm_ctx)
   AST::InlineAsmOperand reg_operand;
   auto token = parser.peek_current_token ();
   auto iden_token = parser.peek_current_token ();
-  auto &inline_asm = inline_asm_ctx.inline_asm;
   if (check_identifier (parser, ""))
 {
   auto equal_token = parser.peek_current_token ();
@@ -212,11 +208,55 @@ parse_reg_operand (InlineAsmContext inline_asm_ctx)
}
 }
 
-  bool is_global_asm = inline_asm.is_global_asm;
-
   // For the keyword IN, currently we count it as a seperate keyword called
   // Rust::IN search for #define RS_TOKEN_LIST in code base.
-  if (!is_global_asm && parser.skip_token (IN))
+  tl::expected parsing_operand
+= tl::expected (inline_asm_ctx);
+
+  // PARSING WITH IN
+  parsing_operand.map (parse_reg_operand_in);
+  if (parsing_operand || parsing_operand.error () == COMMITTED)
+return parsing_operand;
+
+  // KEEP ON PARSING WITH OUT
+  parsing_operand.emplace (inline_asm_ctx);
+  parsing_operand.map (parse_reg_operand_out);
+  

[gcc/devel/rust/master] Add RAW_STRING_LITERAL

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:9e5a4b410d026ac4a7d527edc4b6848524d281a3

commit 9e5a4b410d026ac4a7d527edc4b6848524d281a3
Author: ansh 
Date:   Mon Jun 24 04:01:53 2024 -0700

Add RAW_STRING_LITERAL

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit):
Handle case for RAW_STRING_LITERAL.
* ast/rust-ast.cc (AttributeParser::parse_meta_item_inner):
Likewise.
(AttributeParser::parse_literal): Likewise.
* ast/rust-ast.h: Likewise.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_literal):
Likewise.
* lex/rust-lex.cc (Lexer::parse_raw_string): Likewise.
* lex/rust-token.cc (Token::as_string): Likewise.
* lex/rust-token.h (enum PrimitiveCoreType): Likewise.
* parse/rust-parse-impl.h (Parser::parse_attr_input): Likewise.
(Parser::parse_literal_expr): Likewise.
(Parser::parse_pattern_no_alt): Likewise.

Signed-off-by: ansh 

Diff:
---
 gcc/rust/ast/rust-ast-collector.cc  |  6 ++
 gcc/rust/ast/rust-ast.cc|  5 +
 gcc/rust/ast/rust-ast.h |  2 ++
 gcc/rust/hir/rust-ast-lower-base.cc |  3 +++
 gcc/rust/lex/rust-lex.cc|  2 +-
 gcc/rust/lex/rust-token.cc  |  3 +++
 gcc/rust/lex/rust-token.h   |  8 
 gcc/rust/parse/rust-parse-impl.h| 17 +
 8 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/ast/rust-ast-collector.cc 
b/gcc/rust/ast/rust-ast-collector.cc
index 78a30afe0dd5..3a72bd17935c 100644
--- a/gcc/rust/ast/rust-ast-collector.cc
+++ b/gcc/rust/ast/rust-ast-collector.cc
@@ -398,6 +398,9 @@ TokenCollector::visit (Token &tok)
 case BYTE_STRING_LITERAL:
   push (Rust::Token::make_byte_string (tok.get_locus (), std::move 
(data)));
   break;
+case RAW_STRING_LITERAL:
+  push (Rust::Token::make_raw_string (tok.get_locus (), std::move (data)));
+  break;
 case INNER_DOC_COMMENT:
   push (Rust::Token::make_inner_doc_comment (tok.get_locus (),
 std::move (data)));
@@ -777,6 +780,9 @@ TokenCollector::visit (Literal &lit, location_t locus)
 case Literal::LitType::BYTE_STRING:
   push (Rust::Token::make_byte_string (locus, std::move (value)));
   break;
+case Literal::LitType::RAW_STRING:
+  push (Rust::Token::make_raw_string (locus, std::move (value)));
+  break;
 case Literal::LitType::INT:
   push (
Rust::Token::make_int (locus, std::move (value), lit.get_type_hint ()));
diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc
index 2a173c4610df..9c0b1bf82452 100644
--- a/gcc/rust/ast/rust-ast.cc
+++ b/gcc/rust/ast/rust-ast.cc
@@ -3506,6 +3506,7 @@ AttributeParser::parse_meta_item_inner ()
case STRING_LITERAL:
case BYTE_CHAR_LITERAL:
case BYTE_STRING_LITERAL:
+   case RAW_STRING_LITERAL:
case INT_LITERAL:
case FLOAT_LITERAL:
case TRUE_LITERAL:
@@ -3788,6 +3789,10 @@ AttributeParser::parse_literal ()
   skip_token ();
   return Literal (tok->as_string (), Literal::BYTE_STRING,
  tok->get_type_hint ());
+case RAW_STRING_LITERAL:
+  skip_token ();
+  return Literal (tok->as_string (), Literal::RAW_STRING,
+ tok->get_type_hint ());
 case INT_LITERAL:
   skip_token ();
   return Literal (tok->as_string (), Literal::INT, tok->get_type_hint ());
diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h
index 4fb803c258b9..d9edec063879 100644
--- a/gcc/rust/ast/rust-ast.h
+++ b/gcc/rust/ast/rust-ast.h
@@ -250,6 +250,7 @@ public:
   {
   case STRING_LITERAL:
   case BYTE_STRING_LITERAL:
+  case RAW_STRING_LITERAL:
return true;
   default:
return false;
@@ -311,6 +312,7 @@ public:
 STRING,
 BYTE,
 BYTE_STRING,
+RAW_STRING,
 INT,
 FLOAT,
 BOOL,
diff --git a/gcc/rust/hir/rust-ast-lower-base.cc 
b/gcc/rust/hir/rust-ast-lower-base.cc
index 5113880600ae..207ea6bca82f 100644
--- a/gcc/rust/hir/rust-ast-lower-base.cc
+++ b/gcc/rust/hir/rust-ast-lower-base.cc
@@ -928,6 +928,9 @@ ASTLoweringBase::lower_literal (const AST::Literal &literal)
 case AST::Literal::LitType::BYTE_STRING:
   type = HIR::Literal::LitType::BYTE_STRING;
   break;
+case AST::Literal::LitType::RAW_STRING: // TODO: Lower raw string literals.
+  rust_unreachable ();
+  break;
 case AST::Literal::LitType::INT:
   type = HIR::Literal::LitType::INT;
   break;
diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc
index e5c9148976c1..d1845a4f9e71 100644
--- a/gcc/rust/lex/rust-lex.cc
+++ b/gcc/rust/lex/rust-lex.cc
@@ -2218,7 +2218,7 @@ Lexer::parse_raw_string (location_t loc, int 
initial_hash_count)
 
   str.shrink_to_fit ();
 
-  return Token::make_string (loc, std::move (str));
+  return Token::make_raw_strin

[gcc r15-4410] rtl-optimization/116550 - Add test cases.

2024-10-17 Thread Georg-Johann Lay via Gcc-cvs
https://gcc.gnu.org/g:e74d25cd00629e001038cf6ff83e48d7ca6f4873

commit r15-4410-ge74d25cd00629e001038cf6ff83e48d7ca6f4873
Author: Georg-Johann Lay 
Date:   Thu Oct 17 13:19:51 2024 +0200

rtl-optimization/116550 - Add test cases.

PR rtl-optimization/116550
gcc/testsuite/
* gcc.target/avr/torture/lra-pr116550-1.c: New file.
* gcc.target/avr/torture/lra-pr116550-2.c: New file.

Diff:
---
 .../gcc.target/avr/torture/lra-pr116550-1.c| 216 +
 .../gcc.target/avr/torture/lra-pr116550-2.c|  23 +++
 2 files changed, 239 insertions(+)

diff --git a/gcc/testsuite/gcc.target/avr/torture/lra-pr116550-1.c 
b/gcc/testsuite/gcc.target/avr/torture/lra-pr116550-1.c
new file mode 100644
index ..854698c1ec20
--- /dev/null
+++ b/gcc/testsuite/gcc.target/avr/torture/lra-pr116550-1.c
@@ -0,0 +1,216 @@
+/* { dg-additional-options { -std=c99 } } */
+
+typedef int SItype __attribute__ ((mode (SI)));
+typedef unsigned int USItype __attribute__ ((mode (SI)));
+
+
+typedef int DItype __attribute__ ((mode (DI)));
+typedef unsigned int UDItype __attribute__ ((mode (DI)));
+
+struct DWstruct {SItype low, high;};
+
+typedef union
+{
+  struct DWstruct s;
+  DItype ll;
+} DWunion;
+
+
+static inline __attribute__ ((__always_inline__))
+
+UDItype
+__udivmoddi4 (UDItype n, UDItype d, UDItype *rp)
+{
+  const DWunion nn = {.ll = n};
+  const DWunion dd = {.ll = d};
+  DWunion rr;
+  USItype d0, d1, n0, n1, n2;
+  USItype q0, q1;
+  USItype b, bm;
+
+  d0 = dd.s.low;
+  d1 = dd.s.high;
+  n0 = nn.s.low;
+  n1 = nn.s.high;
+
+  if (d1 == 0)
+{
+  if (d0 > n1)
+ {
+
+
+   ((bm) = __builtin_clzl (d0));
+
+   if (bm != 0)
+ {
+
+
+
+   d0 = d0 << bm;
+   n1 = (n1 << bm) | (n0 >> ((4 * 8) - bm));
+   n0 = n0 << bm;
+ }
+
+   do { USItype __d1, __d0, __q1, __q0; USItype __r1, __r0, __m; __d1 = 
((USItype) (d0) >> ((4 * 8) / 2)); __d0 = ((USItype) (d0) & (((USItype) 1 << 
((4 * 8) / 2)) - 1)); __r1 = (n1) % __d1; __q1 = (n1) / __d1; __m = (USItype) 
__q1 * __d0; __r1 = __r1 * ((USItype) 1 << ((4 * 8) / 2)) | ((USItype) (n0) >> 
((4 * 8) / 2)); if (__r1 < __m) { __q1--, __r1 += (d0); if (__r1 >= (d0)) if 
(__r1 < __m) __q1--, __r1 += (d0); } __r1 -= __m; __r0 = __r1 % __d1; __q0 = 
__r1 / __d1; __m = (USItype) __q0 * __d0; __r0 = __r0 * ((USItype) 1 << ((4 * 
8) / 2)) | ((USItype) (n0) & (((USItype) 1 << ((4 * 8) / 2)) - 1)); if (__r0 < 
__m) { __q0--, __r0 += (d0); if (__r0 >= (d0)) if (__r0 < __m) __q0--, __r0 += 
(d0); } __r0 -= __m; (q0) = (USItype) __q1 * ((USItype) 1 << ((4 * 8) / 2)) | 
__q0; (n0) = __r0; } while (0);
+   q1 = 0;
+
+
+ }
+  else
+ {
+
+
+   if (d0 == 0)
+ d0 = 1 / d0;
+
+   ((bm) = __builtin_clzl (d0));
+
+   if (bm == 0)
+ {
+
+
+
+
+
+
+
+   n1 -= d0;
+   q1 = 1;
+ }
+   else
+ {
+
+
+   b = (4 * 8) - bm;
+
+   d0 = d0 << bm;
+   n2 = n1 >> b;
+   n1 = (n1 << bm) | (n0 >> b);
+   n0 = n0 << bm;
+
+   do { USItype __d1, __d0, __q1, __q0; USItype __r1, __r0, __m; __d1 = 
((USItype) (d0) >> ((4 * 8) / 2)); __d0 = ((USItype) (d0) & (((USItype) 1 << 
((4 * 8) / 2)) - 1)); __r1 = (n2) % __d1; __q1 = (n2) / __d1; __m = (USItype) 
__q1 * __d0; __r1 = __r1 * ((USItype) 1 << ((4 * 8) / 2)) | ((USItype) (n1) >> 
((4 * 8) / 2)); if (__r1 < __m) { __q1--, __r1 += (d0); if (__r1 >= (d0)) if 
(__r1 < __m) __q1--, __r1 += (d0); } __r1 -= __m; __r0 = __r1 % __d1; __q0 = 
__r1 / __d1; __m = (USItype) __q0 * __d0; __r0 = __r0 * ((USItype) 1 << ((4 * 
8) / 2)) | ((USItype) (n1) & (((USItype) 1 << ((4 * 8) / 2)) - 1)); if (__r0 < 
__m) { __q0--, __r0 += (d0); if (__r0 >= (d0)) if (__r0 < __m) __q0--, __r0 += 
(d0); } __r0 -= __m; (q1) = (USItype) __q1 * ((USItype) 1 << ((4 * 8) / 2)) | 
__q0; (n1) = __r0; } while (0);
+ }
+
+
+
+   do { USItype __d1, __d0, __q1, __q0; USItype __r1, __r0, __m; __d1 = 
((USItype) (d0) >> ((4 * 8) / 2)); __d0 = ((USItype) (d0) & (((USItype) 1 << 
((4 * 8) / 2)) - 1)); __r1 = (n1) % __d1; __q1 = (n1) / __d1; __m = (USItype) 
__q1 * __d0; __r1 = __r1 * ((USItype) 1 << ((4 * 8) / 2)) | ((USItype) (n0) >> 
((4 * 8) / 2)); if (__r1 < __m) { __q1--, __r1 += (d0); if (__r1 >= (d0)) if 
(__r1 < __m) __q1--, __r1 += (d0); } __r1 -= __m; __r0 = __r1 % __d1; __q0 = 
__r1 / __d1; __m = (USItype) __q0 * __d0; __r0 = __r0 * ((USItype) 1 << ((4 * 
8) / 2)) | ((USItype) (n0) & (((USItype) 1 << ((4 * 8) / 2)) - 1)); if (__r0 < 
__m) { __q0--, __r0 += (d0); if (__r0 >= (d0)) if (__r0 < __m) __q0--, __r0 += 
(d0); } __r0 -= __m; (q0) = (USItype) __q1 * ((USItype) 1 << ((4 * 8) / 2)) | 
__q0; (n0) = __r0; } while (0);
+
+
+ }
+
+  if (rp != 0)
+ {
+   rr.s.low = n0 >> bm;
+   rr.s.high = 0;
+   *rp = rr.ll;
+ }
+}
+
+
+  else
+{
+  if (d1 > n1)
+ {
+
+
+   q0 = 0;
+   q1 = 0;
+
+
+   if (rp != 0)
+ {
+   rr.s.low = n0;
+   rr.s.high = n1;
+   *rp = rr.ll;
+ }
+ }
+  else
+ {
+
+
+   ((bm) = __builtin_clzl (d1));
+   if

[gcc/devel/rust/master] libformat_parser: Lower minimum Rust version to 1.49

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:7680f97ee86462124b70c9fead87a5501b322636

commit 7680f97ee86462124b70c9fead87a5501b322636
Author: Arthur Cohen 
Date:   Tue Apr 23 14:13:21 2024 +0200

libformat_parser: Lower minimum Rust version to 1.49

libgrust/ChangeLog:

* libformat_parser/Cargo.toml: Change Rust edition from 2021 to 
2018.
* libformat_parser/generic_format_parser/Cargo.toml: Likewise.
* libformat_parser/generic_format_parser/src/lib.rs: Remove usage of
then-unstable std features and language constructs.
* libformat_parser/src/lib.rs: Likewise, plus provide extension 
trait
for String::leak.

Diff:
---
 libgrust/libformat_parser/Cargo.toml   |  2 +-
 .../generic_format_parser/Cargo.toml   |  2 +-
 .../generic_format_parser/src/lib.rs   | 41 --
 libgrust/libformat_parser/src/lib.rs   | 10 ++
 4 files changed, 42 insertions(+), 13 deletions(-)

diff --git a/libgrust/libformat_parser/Cargo.toml 
b/libgrust/libformat_parser/Cargo.toml
index 0fcfa3e89a4c..3c214915d31e 100644
--- a/libgrust/libformat_parser/Cargo.toml
+++ b/libgrust/libformat_parser/Cargo.toml
@@ -1,7 +1,7 @@
 [package]
 name = "libformat_parser"
 version = "0.1.0"
-edition = "2021"
+edition = "2018"
 
 [workspace]
 
diff --git a/libgrust/libformat_parser/generic_format_parser/Cargo.toml 
b/libgrust/libformat_parser/generic_format_parser/Cargo.toml
index 34577038cbed..224ad6826ec8 100644
--- a/libgrust/libformat_parser/generic_format_parser/Cargo.toml
+++ b/libgrust/libformat_parser/generic_format_parser/Cargo.toml
@@ -1,7 +1,7 @@
 [package]
 name = "generic_format_parser"
 version = "0.1.0"
-edition = "2021"
+edition = "2018"
 
 # See more keys and their definitions at 
https://doc.rust-lang.org/cargo/reference/manifest.html
 
diff --git a/libgrust/libformat_parser/generic_format_parser/src/lib.rs 
b/libgrust/libformat_parser/generic_format_parser/src/lib.rs
index 8062bf9e5cec..e255bf16908f 100644
--- a/libgrust/libformat_parser/generic_format_parser/src/lib.rs
+++ b/libgrust/libformat_parser/generic_format_parser/src/lib.rs
@@ -505,7 +505,7 @@ impl<'a> Parser<'a> {
 }
 
 pos = peek_pos;
-description = format!("expected `'}}'`, found `{maybe:?}`");
+description = format!("expected `'}}'`, found `{:?}`", maybe);
 } else {
 description = "expected `'}'` but string was 
terminated".to_owned();
 // point at closing `"`
@@ -690,12 +690,16 @@ impl<'a> Parser<'a> {
 
 // fill character
 if let Some(&(idx, c)) = self.cur.peek() {
-if let Some((_, '>' | '<' | '^')) = self.cur.clone().nth(1) {
-spec.fill = Some(c);
-spec.fill_span = Some(self.span(idx, idx + 1));
-self.cur.next();
+match self.cur.clone().nth(1) {
+Some((_, '>')) | Some((_, '<')) | Some((_, '^')) => {
+spec.fill = Some(c);
+spec.fill_span = Some(self.span(idx, idx + 1));
+self.cur.next();
+}
+_ => {}
 }
 }
+
 // Alignment
 if self.consume('<') {
 spec.align = AlignLeft;
@@ -908,7 +912,11 @@ impl<'a> Parser<'a> {
 );
 }
 
-found.then_some(cur)
+if found {
+Some(cur)
+} else {
+None
+}
 }
 
 fn suggest_format(&mut self) {
@@ -991,8 +999,9 @@ fn find_width_map_from_snippet(
 // If we only trimmed it off the input, `format!("\n")` would cause a 
mismatch as here we they actually match up.
 // Alternatively, we could just count the trailing newlines and only trim 
one from the input if they don't match up.
 let input_no_nl = input.trim_end_matches('\n');
-let Some(unescaped) = unescape_string(snippet) else {
-return InputStringKind::NotALiteral;
+let unescaped = match unescape_string(snippet) {
+Some(u) => u,
+None => return InputStringKind::NotALiteral,
 };
 
 let unescaped_no_nl = unescaped.trim_end_matches('\n');
@@ -1023,7 +1032,13 @@ fn find_width_map_from_snippet(
 
 width_mappings.push(InnerWidthMapping::new(pos, width, 0));
 }
-('\\', Some((_, 'n' | 't' | 'r' | '0' | '\\' | '\'' | '\"'))) => {
+('\\', Some((_, 'n')))
+| ('\\', Some((_, 't')))
+| ('\\', Some((_, 'r')))
+| ('\\', Some((_, '0')))
+| ('\\', Some((_, '\\')))
+| ('\\', Some((_, '\'')))
+| ('\\', Some((_, '\"'))) => {
 width_mappings.push(InnerWidthMapping::new(pos, 2, 1));
 let _ = s.next();
 }
@@ -1049,7 +1064,7 @@ fn find_width_map_from_snippet(
 .as_str()
 .get(..digits_len)
 

[gcc/devel/rust/master] Add testcases for handling struct as scrutinee for match expr

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:154ce770c6844d7211276a53b2ec3db0b5e3f485

commit 154ce770c6844d7211276a53b2ec3db0b5e3f485
Author: Nobel Singh 
Date:   Wed Apr 24 02:07:52 2024 +0545

Add testcases for handling struct as scrutinee for match expr

gcc/testsuite/ChangeLog:

* rust/compile/issue-2906.rs: New test.
* rust/execute/torture/issue-2906.rs: New test.

Signed-off-by: Nobel Singh 

Diff:
---
 gcc/testsuite/rust/compile/issue-2906.rs | 10 +++
 gcc/testsuite/rust/execute/torture/issue-2906.rs | 34 
 2 files changed, 44 insertions(+)

diff --git a/gcc/testsuite/rust/compile/issue-2906.rs 
b/gcc/testsuite/rust/compile/issue-2906.rs
new file mode 100644
index ..20abcb095b8f
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-2906.rs
@@ -0,0 +1,10 @@
+// { dg-warning "field is never read: .a." "" { target *-*-* } .-1 }
+struct Foo { a: i32 }
+
+fn main() {
+let a = Foo { a: 15 };
+
+match a {
+b => { }
+}
+}
\ No newline at end of file
diff --git a/gcc/testsuite/rust/execute/torture/issue-2906.rs 
b/gcc/testsuite/rust/execute/torture/issue-2906.rs
new file mode 100644
index ..d3ca8ae1c5d4
--- /dev/null
+++ b/gcc/testsuite/rust/execute/torture/issue-2906.rs
@@ -0,0 +1,34 @@
+// { dg-warning "field is never read: .x." "" { target *-*-* } .-1 }
+// { dg-warning "field is never read: .y." "" { target *-*-* } .-2 }
+struct Point {
+x: u32,
+y: u32,
+}
+
+fn is_origin(p: Point) -> bool {
+match p {
+Point { x, y } => {
+if x == 0 && y == 0 {
+return true;
+}
+false
+}
+_ => false,
+}
+}
+
+fn main() -> i32 {
+let p = Point { x: 0, y: 0 };
+let q = Point { x: 0, y: 1 };
+let mut retval = 2;
+
+if is_origin(p) {
+retval -= 1;
+}
+
+if !is_origin(q) {
+retval -= 1;
+}
+
+retval
+}


[gcc/devel/rust/master] Improve matching on non-enum ADTs

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:1c52754ee19991bc07c4023cad777a6a894bb64f

commit 1c52754ee19991bc07c4023cad777a6a894bb64f
Author: Owen Avery 
Date:   Thu May 2 20:58:49 2024 -0400

Improve matching on non-enum ADTs

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc
(check_match_scrutinee): Add assertion.
* backend/rust-compile-pattern.cc
(CompilePatternCheckExpr::visit):
Handle HIR::PathInExpression matching a non-enum.

gcc/testsuite/ChangeLog:

* rust/compile/match-struct-path.rs: New test.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/backend/rust-compile-expr.cc   |  2 ++
 gcc/rust/backend/rust-compile-pattern.cc| 11 ---
 gcc/testsuite/rust/compile/match-struct-path.rs |  7 +++
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-expr.cc 
b/gcc/rust/backend/rust-compile-expr.cc
index 6f37dd8a23ef..e53da939a773 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -956,6 +956,8 @@ check_match_scrutinee (HIR::MatchExpr &expr, Context *ctx)
   TyTy::ADTType *adt = static_cast (scrutinee_expr_tyty);
   if (adt->is_enum ())
rust_assert (adt->number_of_variants () > 0);
+  else
+   rust_assert (adt->number_of_variants () == 1);
 }
   else if (scrutinee_kind == TyTy::TypeKind::FLOAT)
 {
diff --git a/gcc/rust/backend/rust-compile-pattern.cc 
b/gcc/rust/backend/rust-compile-pattern.cc
index 74adc3f8c177..c462a6d7a025 100644
--- a/gcc/rust/backend/rust-compile-pattern.cc
+++ b/gcc/rust/backend/rust-compile-pattern.cc
@@ -35,11 +35,16 @@ CompilePatternCheckExpr::visit (HIR::PathInExpression 
&pattern)
  &lookup);
   rust_assert (ok);
 
-  // this must be an enum
-  // TODO: might not be
+  // must be an ADT (?)
   rust_assert (lookup->get_kind () == TyTy::TypeKind::ADT);
   TyTy::ADTType *adt = static_cast (lookup);
-  rust_assert (adt->is_enum ());
+
+  // if this isn't an enum, always succeed
+  if (!adt->is_enum ())
+{
+  check_expr = boolean_true_node;
+  return;
+}
 
   // lookup the variant
   HirId variant_id;
diff --git a/gcc/testsuite/rust/compile/match-struct-path.rs 
b/gcc/testsuite/rust/compile/match-struct-path.rs
new file mode 100644
index ..acadcdb87ad4
--- /dev/null
+++ b/gcc/testsuite/rust/compile/match-struct-path.rs
@@ -0,0 +1,7 @@
+pub struct S;
+
+pub fn foo(v: S) {
+match v {
+S => ()
+}
+}


[gcc/devel/rust/master] Handle structs as scrutinee for match expressions

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:9e45b86996ebff8bc9ac99170a2d0e1374c8fd7f

commit 9e45b86996ebff8bc9ac99170a2d0e1374c8fd7f
Author: Nobel Singh 
Date:   Mon Apr 22 00:26:12 2024 +0545

Handle structs as scrutinee for match expressions

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (check_match_scrutinee): Handle 
structs

Signed-off-by: Nobel Singh 

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

diff --git a/gcc/rust/backend/rust-compile-expr.cc 
b/gcc/rust/backend/rust-compile-expr.cc
index 4d79501ccc3b..6f37dd8a23ef 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -954,8 +954,8 @@ check_match_scrutinee (HIR::MatchExpr &expr, Context *ctx)
   // this will need to change but for now the first pass implementation,
   // lets assert this is the case
   TyTy::ADTType *adt = static_cast (scrutinee_expr_tyty);
-  rust_assert (adt->is_enum ());
-  rust_assert (adt->number_of_variants () > 0);
+  if (adt->is_enum ())
+   rust_assert (adt->number_of_variants () > 0);
 }
   else if (scrutinee_kind == TyTy::TypeKind::FLOAT)
 {


[gcc/devel/rust/master] Visit constant items without expressions properly

2024-10-17 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:c7687ef1f7a9d2683bb45dcbf547b42aae856075

commit c7687ef1f7a9d2683bb45dcbf547b42aae856075
Author: Owen Avery 
Date:   Wed Feb 28 20:19:04 2024 -0500

Visit constant items without expressions properly

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc
(DefaultResolver::visit):
Verify constant item has expression before attempting to visit
the later.

Signed-off-by: Owen Avery 

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

diff --git a/gcc/rust/resolve/rust-default-resolver.cc 
b/gcc/rust/resolve/rust-default-resolver.cc
index c54cabad2e5d..ca831840298e 100644
--- a/gcc/rust/resolve/rust-default-resolver.cc
+++ b/gcc/rust/resolve/rust-default-resolver.cc
@@ -449,13 +449,16 @@ DefaultResolver::visit (AST::EnumItemDiscriminant &item)
 void
 DefaultResolver::visit (AST::ConstantItem &item)
 {
-  auto expr_vis = [this, &item] () {
-item.get_expr ().accept_vis (*this);
-visit (item.get_type ());
-  };
+  if (item.has_expr ())
+{
+  auto expr_vis = [this, &item] () {
+   item.get_expr ().accept_vis (*this);
+   visit (item.get_type ());
+  };
 
-  // FIXME: Why do we need a Rib here?
-  ctx.scoped (Rib::Kind::Item, item.get_node_id (), expr_vis);
+  // FIXME: Why do we need a Rib here?
+  ctx.scoped (Rib::Kind::Item, item.get_node_id (), expr_vis);
+}
 }
 
 void


  1   2   3   4   >