[gcc r15-9232] Doc: Fix description of -Wno-aggressive-loop-optimizations [PR78874]

2025-04-05 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:13c9b353895fef8d5b1593b7527df41487c512d1

commit r15-9232-g13c9b353895fef8d5b1593b7527df41487c512d1
Author: Sandra Loosemore 
Date:   Sun Apr 6 04:39:59 2025 +

Doc: Fix description of -Wno-aggressive-loop-optimizations [PR78874]

gcc/ChangeLog
PR middle-end/78874
* doc/invoke.texi (Warning Options): Fix description of
-Wno-aggressive-loop-optimizations to reflect that this turns
off the warning, and the default is for it to be enabled.

Diff:
---
 gcc/doc/invoke.texi | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 91ed43dc21a0..d5103f461dfd 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -10109,8 +10109,9 @@ a warning.)
 @opindex Wno-aggressive-loop-optimizations
 @opindex Waggressive-loop-optimizations
 @item -Wno-aggressive-loop-optimizations
-Warn if in a loop with constant number of iterations the compiler detects
-undefined behavior in some statement during one or more of the iterations.
+Do not warn if the compiler detects undefined behavior in a loop with
+a constant number of iterations.  @option{-Waggressive-loop-optimizations}
+is enabled by default.
 
 @opindex Wno-attributes
 @opindex Wattributes


[gcc(refs/users/mikael/heads/refactor_descriptor_v04)] Suppression export gfc_conv_descriptor_span_set

2025-04-05 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:8410cda2b70228d358313cbacc0fe404c91b3ad2

commit 8410cda2b70228d358313cbacc0fe404c91b3ad2
Author: Mikael Morin 
Date:   Sat Mar 29 11:41:45 2025 +0100

Suppression export gfc_conv_descriptor_span_set

Diff:
---
 gcc/fortran/trans-descriptor.cc | 2 +-
 gcc/fortran/trans-descriptor.h  | 1 -
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index bc2055bf3b56..7e709609435c 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -721,7 +721,7 @@ gfc_conv_descriptor_span_get (tree desc)
   return gfc_descriptor::conv_span_get (desc);
 }
 
-void
+static void
 gfc_conv_descriptor_span_set (stmtblock_t *block, tree desc, tree value)
 {
   return gfc_descriptor::conv_span_set (block, desc, value);
diff --git a/gcc/fortran/trans-descriptor.h b/gcc/fortran/trans-descriptor.h
index 5e8af26d1d8e..b991d2a41895 100644
--- a/gcc/fortran/trans-descriptor.h
+++ b/gcc/fortran/trans-descriptor.h
@@ -64,7 +64,6 @@ void gfc_conv_descriptor_dtype_set (stmtblock_t *, tree, 
tree);
 void gfc_conv_descriptor_version_set (stmtblock_t *, tree, tree);
 void gfc_conv_descriptor_rank_set (stmtblock_t *, tree, tree);
 void gfc_conv_descriptor_rank_set (stmtblock_t *, tree, int);
-void gfc_conv_descriptor_span_set (stmtblock_t *, tree, tree);
 void gfc_conv_descriptor_ubound_set (stmtblock_t *, tree, tree, tree);
 
 /* CFI descriptor.  */


[gcc r15-8582] gccrs: lang-items: Collect trait functions that are lang items

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:2c883bb004c08cef9bf01f90cf39108e14dd98b5

commit r15-8582-g2c883bb004c08cef9bf01f90cf39108e14dd98b5
Author: Arthur Cohen 
Date:   Wed Dec 18 12:20:27 2024 +0100

gccrs: lang-items: Collect trait functions that are lang items

gcc/rust/ChangeLog:

* ast/rust-collect-lang-items.cc (CollectLangItems::visit): Add 
visitor for collecting
functions that might be lang items.
* ast/rust-collect-lang-items.h: Likewise.

Diff:
---
 gcc/rust/ast/rust-collect-lang-items.cc | 8 
 gcc/rust/ast/rust-collect-lang-items.h  | 1 +
 2 files changed, 9 insertions(+)

diff --git a/gcc/rust/ast/rust-collect-lang-items.cc 
b/gcc/rust/ast/rust-collect-lang-items.cc
index 308720ae69ab..50d134a429f5 100644
--- a/gcc/rust/ast/rust-collect-lang-items.cc
+++ b/gcc/rust/ast/rust-collect-lang-items.cc
@@ -82,5 +82,13 @@ CollectLangItems::visit (AST::TraitItemType &item)
   DefaultASTVisitor::visit (item);
 }
 
+void
+CollectLangItems::visit (AST::Function &item)
+{
+  maybe_add_lang_item (item);
+
+  DefaultASTVisitor::visit (item);
+}
+
 } // namespace AST
 } // namespace Rust
diff --git a/gcc/rust/ast/rust-collect-lang-items.h 
b/gcc/rust/ast/rust-collect-lang-items.h
index 552648f04eda..1d021b1d9c50 100644
--- a/gcc/rust/ast/rust-collect-lang-items.h
+++ b/gcc/rust/ast/rust-collect-lang-items.h
@@ -47,6 +47,7 @@ public:
 
   void visit (AST::Trait &item) override;
   void visit (AST::TraitItemType &item) override;
+  void visit (AST::Function &item) override;
 
 private:
   template  void maybe_add_lang_item (const T &item);


[gcc r15-8492] inliner: Silently drop musttail flag on calls during inlining unless the inlined routine was musttai

2025-04-05 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:37ae2e055687a22974d7bcb9e618f258fa49ab1a

commit r15-8492-g37ae2e055687a22974d7bcb9e618f258fa49ab1a
Author: Jakub Jelinek 
Date:   Fri Mar 21 12:17:01 2025 +0100

inliner: Silently drop musttail flag on calls during inlining unless the 
inlined routine was musttail called [PR119376]

As discussed in the PR, some packages fail to build because they use
musttail attribute on calls in functions which we inline, and if they
are inlined into a middle of the function, that results in an error
because we have a musttail call in the middle of a function and so it
can't be tail called there.

Now, guess the primary intent of the musttail attribute is ensuring
we don't get an extra stack frame in the backtrace.  Inlining itself
removes one extra stack frame from the backtrace as well (sure, not
counting virtual backtraces in gdb), so I think erroring out on that
is unnecessary.

Except when we are inlining a musttail call which has musttail calls
in it, in that case we are being asked to remove 2 stack frames from
the backtrace, inlining removes one, so we need to keep musttail
on the calls so that another stack frame is removed through a tail call.

The following patch implements that, keeping previous behavior when
id->call_stmt is NULL (i.e. when versioning/cloning etc.).

2025-03-21  Jakub Jelinek  

PR ipa/119376
* tree-inline.cc (remap_gimple_stmt): Silently clear
gimple_call_must_tail_p on inlined call stmts if id->call_stmt
is a call without that flag set.

* c-c++-common/musttail26.c: New test.

Diff:
---
 gcc/testsuite/c-c++-common/musttail26.c | 33 +
 gcc/tree-inline.cc  |  9 +
 2 files changed, 42 insertions(+)

diff --git a/gcc/testsuite/c-c++-common/musttail26.c 
b/gcc/testsuite/c-c++-common/musttail26.c
new file mode 100644
index ..3d0f8c97d9b3
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/musttail26.c
@@ -0,0 +1,33 @@
+/* PR ipa/119376 */
+/* { dg-do compile { target musttail } } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+/* { dg-final { scan-tree-dump-times "  \[^\n\r]* = foo \\\(3, \[^\n\r]*\\\); 
\\\[tail call\\\] \\\[must tail call\\\]" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "  \[^\n\r]* = foo \\\(4, \[^\n\r]*\\\); 
\\\[tail call\\\] \\\[must tail call\\\]" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-not "  foo \\\(\[12], \[^\n\r]*\\\); \\\[tail 
call\\\]" "optimized" } } */
+
+int foo (int, int);
+int v, w[10];
+
+static inline __attribute__((always_inline)) int
+bar (int x, int y)
+{
+  [[gnu::musttail]] return foo (x, y);
+}
+
+static int
+baz (int x, int y)
+{
+  [[gnu::musttail]] return foo (x, x + y + (v | y) * (v & y));
+}
+
+int
+qux (int x, int y)
+{
+  w[0] = bar (1, x + y);
+  w[1] = baz (2, x + y);
+  if (x == 42)
+[[gnu::musttail]] return bar (3, x + y);
+  if (x == -42)
+[[gnu::musttail]] return baz (4, x + y);
+  return 0;
+}
diff --git a/gcc/tree-inline.cc b/gcc/tree-inline.cc
index 5b3539009a38..05843b8ccf09 100644
--- a/gcc/tree-inline.cc
+++ b/gcc/tree-inline.cc
@@ -1892,6 +1892,15 @@ remap_gimple_stmt (gimple *stmt, copy_body_data *id)
gimple_call_set_tail (call_stmt, false);
  if (gimple_call_from_thunk_p (call_stmt))
gimple_call_set_from_thunk (call_stmt, false);
+ /* Silently clear musttail flag when inlining a function
+with must tail call from a non-musttail call.  The inlining
+removes one frame so acts like musttail's intent, and we
+can be inlining a function with musttail calls in the middle
+of caller where musttail will always error.  */
+ if (gimple_call_must_tail_p (call_stmt)
+ && id->call_stmt
+ && !gimple_call_must_tail_p (id->call_stmt))
+   gimple_call_set_must_tail (call_stmt, false);
  if (gimple_call_internal_p (call_stmt))
switch (gimple_call_internal_fn (call_stmt))
  {


[gcc r15-8204] gccrs: Expected first layer done

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:3c14514dbcbef818169cc06e5bace8daa1b4b476

commit r15-8204-g3c14514dbcbef818169cc06e5bace8daa1b4b476
Author: jjasmine 
Date:   Tue Jun 11 22:07:14 2024 -0700

gccrs: 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 21634725aa2c..49d1fd4014f3 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);
 }

[gcc r15-9146] cobol: Fix incorrect use of std::remove_if

2025-04-05 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:6621e5a1d1195137a1dd6d917961ab23609a244c

commit r15-9146-g6621e5a1d1195137a1dd6d917961ab23609a244c
Author: Jonathan Wakely 
Date:   Tue Mar 18 18:37:01 2025 +

cobol: Fix incorrect use of std::remove_if

The call to std::remove_if used here doesn't remove any elements, it
just overwrites the "removed" elements with later elements, leaving the
total number of elements unchanged. Use std::list::remove_if to actually
remove those unwanted elements from the list.

gcc/cobol/ChangeLog:

* symfind.cc (finalize_symbol_map2): Use std::list::remove_if
instead of std::remove_if.

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

diff --git a/gcc/cobol/symfind.cc b/gcc/cobol/symfind.cc
index 2687fdb83df2..899571551e8f 100644
--- a/gcc/cobol/symfind.cc
+++ b/gcc/cobol/symfind.cc
@@ -128,11 +128,10 @@ finalize_symbol_map2() {
 
   for( auto& elem : symbol_map2 ) {
 auto& fields( elem.second );
-std::remove_if( fields.begin(), fields.end(),
-  []( auto isym ) {
-auto f = cbl_field_of(symbol_at(isym));
-return f->type == FldInvalid;
-  } );
+fields.remove_if( []( auto isym ) {
+   auto f = cbl_field_of(symbol_at(isym));
+   return f->type == FldInvalid;
+ } );
 if( fields.empty() ) empties.insert(elem.first);
   }


[gcc r15-8120] gccrs: Change return type of lookup trait defid functions.

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:6dce8a479a288a64ffa87f3e3549f1dc6900b527

commit r15-8120-g6dce8a479a288a64ffa87f3e3549f1dc6900b527
Author: Pierre-Emmanuel Patry 
Date:   Thu May 2 12:33:20 2024 +0200

gccrs: 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 c7031edd30bd..add173c50a9b 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 a18a0e40ddf1..43404385cdd8 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 2e9a551e4c7e..565f2bc58aab 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 dcedea97e09f..41e4b048eb54 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_i

[gcc r15-8636] gccrs: derive(Clone): Add deriving of simple enum variants

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:4cbbaa71c1a2d438c9ac534ef6b2bf6c1887bf8e

commit r15-8636-g4cbbaa71c1a2d438c9ac534ef6b2bf6c1887bf8e
Author: Arthur Cohen 
Date:   Thu Jan 2 10:59:33 2025 +

gccrs: derive(Clone): Add deriving of simple enum variants

gcc/rust/ChangeLog:

* expand/rust-derive-clone.cc: Clone enum identifier variants 
properly
* expand/rust-derive-clone.h: Declare new functions used.

Diff:
---
 gcc/rust/expand/rust-derive-clone.cc | 52 ++--
 gcc/rust/expand/rust-derive-clone.h  |  3 +++
 2 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/expand/rust-derive-clone.cc 
b/gcc/rust/expand/rust-derive-clone.cc
index b8c92dcc6feb..e4702d8a8183 100644
--- a/gcc/rust/expand/rust-derive-clone.cc
+++ b/gcc/rust/expand/rust-derive-clone.cc
@@ -20,6 +20,7 @@
 #include "rust-ast.h"
 #include "rust-ast-dump.h"
 #include "rust-item.h"
+#include "rust-path.h"
 
 namespace Rust {
 namespace AST {
@@ -235,11 +236,58 @@ DeriveClone::visit_struct (StructStruct &item)
 item.get_generic_params ());
 }
 
+MatchCase
+DeriveClone::clone_enum_identifier (Enum &item,
+   const std::unique_ptr &variant)
+{
+  auto variant_path = PathInExpression (
+{builder.path_segment (item.get_identifier ().as_string ()),
+ builder.path_segment (variant->get_identifier ().as_string ())},
+{}, loc, false);
+
+  auto pattern = std::unique_ptr (new ReferencePattern (
+std::unique_ptr (new PathInExpression (variant_path)), false,
+false, loc));
+  auto expr = std::unique_ptr (new PathInExpression (variant_path));
+
+  return builder.match_case (std::move (pattern), std::move (expr));
+}
+
 void
 DeriveClone::visit_enum (Enum &item)
 {
-  rust_sorry_at (item.get_locus (), "cannot derive %qs for these items yet",
-"Clone");
+  // Create an arm for each variant of the enum
+  // For enum item variants, just create the same variant
+  // For struct and tuple variants, destructure the pattern and call clone for
+  // each field
+
+  auto cases = std::vector ();
+
+  for (const auto &variant : item.get_variants ())
+{
+  switch (variant->get_enum_item_kind ())
+   {
+   // Identifiers and discriminated variants are the same for a clone - we
+   // just return the same variant
+   case EnumItem::Kind::Identifier:
+   case EnumItem::Kind::Discriminant:
+ cases.emplace_back (clone_enum_identifier (item, variant));
+ break;
+   case EnumItem::Kind::Tuple:
+   case EnumItem::Kind::Struct:
+ rust_unreachable ();
+ break;
+   }
+}
+
+  // match self { ... }
+  auto match = builder.match (builder.identifier ("self"), std::move (cases));
+
+  expanded = clone_impl (clone_fn (std::move (match)),
+item.get_identifier ().as_string (),
+item.get_generic_params ());
+
+  AST::Dump::debug (*expanded);
 }
 
 void
diff --git a/gcc/rust/expand/rust-derive-clone.h 
b/gcc/rust/expand/rust-derive-clone.h
index 4a43b2ac1fc2..339cf6357ae9 100644
--- a/gcc/rust/expand/rust-derive-clone.h
+++ b/gcc/rust/expand/rust-derive-clone.h
@@ -63,6 +63,9 @@ private:
   clone_impl (std::unique_ptr &&clone_fn, std::string name,
  const std::vector> &type_generics);
 
+  MatchCase clone_enum_identifier (Enum &item,
+  const std::unique_ptr &variant);
+
   virtual void visit_struct (StructStruct &item);
   virtual void visit_tuple (TupleStruct &item);
   virtual void visit_enum (Enum &item);


[gcc r15-8148] gccrs: Add feature gate for box syntax

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:1e430a7957e7a3cf79f6f22f112f3d764706f50f

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

gccrs: 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 6ef2d1f710fb..69348cb90e85 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 de48f2255987..bef7cf1b449c 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 1e11bd541a58..f993bbb7245b 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 611dceaa2c94..736d97e1cde6 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 

[gcc r15-8468] gimple: sccopy: Don't increment i after vec::unordered_remove()

2025-04-05 Thread Filip Kastl via Gcc-cvs
https://gcc.gnu.org/g:a1363f8dd8037d40e9fbf04c2ba8d6d3e7e5c269

commit r15-8468-ga1363f8dd8037d40e9fbf04c2ba8d6d3e7e5c269
Author: Filip Kastl 
Date:   Thu Mar 20 11:54:59 2025 +0100

gimple: sccopy: Don't increment i after vec::unordered_remove()

I increment the index variable in a loop even when I do
vec::unordered_remove() which causes the vector traversal to miss some
elements.  Mikael notified me of this mistake I made in my last patch.

gcc/ChangeLog:

* gimple-ssa-sccopy.cc (scc_copy_prop::propagate): Don't
increment after vec::unordered_remove().

Reported-by: Mikael Morin 
Signed-off-by: Filip Kastl 

Diff:
---
 gcc/gimple-ssa-sccopy.cc | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gcc/gimple-ssa-sccopy.cc b/gcc/gimple-ssa-sccopy.cc
index 298feb055711..ee2a7fa8a727 100644
--- a/gcc/gimple-ssa-sccopy.cc
+++ b/gcc/gimple-ssa-sccopy.cc
@@ -582,9 +582,11 @@ scc_copy_prop::propagate ()
 get removed.  That means parts of CFG get removed.  Those may
 contain copy statements.  For that reason we prune SCCs here.  */
   unsigned i;
-  for (i = 0; i < scc.length (); i++)
+  for (i = 0; i < scc.length ();)
if (gimple_bb (scc[i]) == NULL)
  scc.unordered_remove (i);
+   else
+ i++;
   if (scc.is_empty ())
{
  scc.release ();


[gcc r15-8630] gccrs: derive(Clone): Mark PhantomData as a lang item

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:9bc5deb919ce4c33839fc331aa943c99c33adce6

commit r15-8630-g9bc5deb919ce4c33839fc331aa943c99c33adce6
Author: Arthur Cohen 
Date:   Thu Dec 26 10:57:07 2024 +

gccrs: derive(Clone): Mark PhantomData as a lang item

gcc/testsuite/ChangeLog:

* rust/compile/derive_macro4.rs: Make PhantomData a lang item.

Diff:
---
 gcc/testsuite/rust/compile/derive_macro4.rs | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/gcc/testsuite/rust/compile/derive_macro4.rs 
b/gcc/testsuite/rust/compile/derive_macro4.rs
index 7802e8fd8000..b20043ba927b 100644
--- a/gcc/testsuite/rust/compile/derive_macro4.rs
+++ b/gcc/testsuite/rust/compile/derive_macro4.rs
@@ -6,12 +6,9 @@ pub trait Clone {
 fn clone(&self) -> Self;
 }
 
+#[lang = "phantom_data"]
 struct PhantomData;
 
-pub struct AssertParamIsCopy {
-_field: PhantomData,
-}
-
 #[derive(Clone)] // { dg-error "bounds not satisfied for U .Copy. is not 
satisfied" }
 union U {
 i: i32,


[gcc/devel/rust/master] gccrs: add new -frust-overflow-checks flag to control overflow checks

2025-04-05 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:618f41a3cd69f3be63528ba8c451a43574500aeb

commit 618f41a3cd69f3be63528ba8c451a43574500aeb
Author: Philip Herron 
Date:   Thu Jan 23 14:44:20 2025 +

gccrs: add new -frust-overflow-checks flag to control overflow checks

This will be crucial for more complex gimple debugging to make it easier
to follow the code vs the original rust code.

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): disable 
overflow checks
* lang.opt: new flag

Signed-off-by: Philip Herron 

Diff:
---
 gcc/rust/backend/rust-compile-expr.cc | 33 +
 gcc/rust/lang.opt |  4 
 2 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-expr.cc 
b/gcc/rust/backend/rust-compile-expr.cc
index 1d68e85aa769..79383301f353 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -159,27 +159,28 @@ CompileExpr::visit (HIR::ArithmeticOrLogicalExpr &expr)
   return;
 }
 
-  if (ctx->in_fn () && !ctx->const_context_p ())
-{
-  auto receiver_tmp = NULL_TREE;
-  auto receiver
-   = Backend::temporary_variable (ctx->peek_fn ().fndecl, NULL_TREE,
-  TREE_TYPE (lhs), lhs, true,
-  expr.get_locus (), &receiver_tmp);
-  auto check
-   = Backend::arithmetic_or_logical_expression_checked (op, lhs, rhs,
-expr.get_locus (),
-receiver);
-
-  ctx->add_statement (check);
-  translated = receiver->get_tree (expr.get_locus ());
-}
-  else
+  bool can_generate_overflow_checks
+= (ctx->in_fn () && !ctx->const_context_p ()) && flag_overflow_checks;
+  if (!can_generate_overflow_checks)
 {
   translated
= Backend::arithmetic_or_logical_expression (op, lhs, rhs,
 expr.get_locus ());
+  return;
 }
+
+  auto receiver_tmp = NULL_TREE;
+  auto receiver
+= Backend::temporary_variable (ctx->peek_fn ().fndecl, NULL_TREE,
+  TREE_TYPE (lhs), lhs, true,
+  expr.get_locus (), &receiver_tmp);
+  auto check
+= Backend::arithmetic_or_logical_expression_checked (op, lhs, rhs,
+expr.get_locus (),
+receiver);
+
+  ctx->add_statement (check);
+  translated = receiver->get_tree (expr.get_locus ());
 }
 
 void
diff --git a/gcc/rust/lang.opt b/gcc/rust/lang.opt
index 10a91f33585c..e105c677995f 100644
--- a/gcc/rust/lang.opt
+++ b/gcc/rust/lang.opt
@@ -225,4 +225,8 @@ Enum(frust_panic) String(unwind) Value(0)
 EnumValue
 Enum(frust_panic) String(abort) Value(1)
 
+frust-overflow-checks
+Rust Var(flag_overflow_checks) Init(1)
+Enable the overflow checks in code generation
+
 ; This comment is to ensure we retain the blank line above.


[gcc r15-8634] gccrs: derive(Clone): Add note about Clone::clone()

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:72ad259a22c182756b883871285f7c30e7c778cb

commit r15-8634-g72ad259a22c182756b883871285f7c30e7c778cb
Author: Arthur Cohen 
Date:   Thu Jan 2 10:56:11 2025 +

gccrs: derive(Clone): Add note about Clone::clone()

gcc/rust/ChangeLog:

* expand/rust-derive-clone.cc (DeriveClone::clone_call): Mention 
using `clone_fn`
lang item in the future.

Diff:
---
 gcc/rust/expand/rust-derive-clone.cc | 14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/expand/rust-derive-clone.cc 
b/gcc/rust/expand/rust-derive-clone.cc
index 2f733fae9107..b8c92dcc6feb 100644
--- a/gcc/rust/expand/rust-derive-clone.cc
+++ b/gcc/rust/expand/rust-derive-clone.cc
@@ -30,6 +30,15 @@ DeriveClone::clone_call (std::unique_ptr &&to_clone)
   // $crate::core::clone::Clone::clone for the fully qualified path - we don't
   // link with `core` yet so that might be an issue. Use `Clone::clone` for 
now?
   // TODO: Factor this function inside the DeriveAccumulator
+
+  // Interestingly, later versions of Rust have a `clone_fn` lang item which
+  // corresponds to this. But because we are first targeting 1.49, we cannot 
use
+  // it yet. Once we target a new, more recent version of the language, we'll
+  // have figured out how to compile and distribute `core`, meaning we'll be
+  // able to directly call `::core::clone::Clone::clone()`
+
+  // Not sure how to call it properly in the meantime...
+
   auto path = std::unique_ptr (
 new PathInExpression (builder.path_in_expression ({"Clone", "clone"})));
 
@@ -79,10 +88,7 @@ DeriveClone::clone_impl (
   std::unique_ptr &&clone_fn, std::string name,
   const std::vector> &type_generics)
 {
-  // should that be `$crate::core::clone::Clone` instead?
-  auto segments = std::vector> ();
-  segments.emplace_back (builder.type_path_segment ("Clone"));
-  auto clone = TypePath (std::move (segments), loc);
+  auto clone = builder.type_path (LangItem::Kind::CLONE);
 
   auto trait_items = std::vector> ();
   trait_items.emplace_back (std::move (clone_fn));


[gcc r15-8639] gccrs: derive(Clone): Implement derive clone for enum struct variants

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:00c48701f1972882f0d60cdc5c266c771712e4c9

commit r15-8639-g00c48701f1972882f0d60cdc5c266c771712e4c9
Author: Arthur Cohen 
Date:   Fri Jan 3 15:14:45 2025 +

gccrs: derive(Clone): Implement derive clone for enum struct variants

gcc/rust/ChangeLog:

* expand/rust-derive-clone.cc (DeriveClone::clone_enum_struct): New 
function for deriving
enum struct variants.
(DeriveClone::visit_enum): Call into the new function.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude:
* rust/compile/derive_clone_enum1.rs: New test.
* rust/compile/derive_clone_enum2.rs: New test.
* rust/compile/derive_clone_enum3.rs: New test.
* rust/execute/torture/derive_clone_enum1.rs: New test.

Diff:
---
 gcc/rust/expand/rust-derive-clone.cc   | 85 --
 gcc/testsuite/rust/compile/derive_clone_enum1.rs   | 16 
 gcc/testsuite/rust/compile/derive_clone_enum2.rs   | 16 
 gcc/testsuite/rust/compile/derive_clone_enum3.rs   | 16 
 gcc/testsuite/rust/compile/nr2/exclude |  3 +
 .../rust/execute/torture/derive_clone_enum1.rs | 51 +
 6 files changed, 180 insertions(+), 7 deletions(-)

diff --git a/gcc/rust/expand/rust-derive-clone.cc 
b/gcc/rust/expand/rust-derive-clone.cc
index c2994b7b4f84..7620abe4e13a 100644
--- a/gcc/rust/expand/rust-derive-clone.cc
+++ b/gcc/rust/expand/rust-derive-clone.cc
@@ -19,6 +19,7 @@
 #include "rust-derive-clone.h"
 #include "rust-ast.h"
 #include "rust-ast-dump.h"
+#include "rust-expr.h"
 #include "rust-item.h"
 #include "rust-path.h"
 #include "rust-pattern.h"
@@ -300,13 +301,84 @@ DeriveClone::clone_enum_tuple (Enum &item, const 
EnumItemTuple &variant)
   return builder.match_case (std::move (pattern), std::move (expr));
 }
 
+MatchCase
+DeriveClone::clone_enum_struct (Enum &item, const EnumItemStruct &variant)
+{
+  auto variant_path = variant_match_path (item, variant.get_identifier ());
+
+  auto field_patterns = std::vector> ();
+  auto cloned_fields = std::vector> ();
+
+#if 0
+  // NOTE: We currently do not support compiling struct patterns where an
+  // identifier is assigned a new pattern, e.g. Bloop { f0: x }
+  // This is the code we should eventually produce as it mimics what rustc does
+  // - which is probably here for a good reason. In the meantime, we can just
+  // use the field's identifier as the pattern: Bloop { f0 }
+  // We can then clone the field directly instead of calling `clone()` on the
+  // new pattern.
+  // TODO: Figure out if that is actually needed and why rustc does it?
+
+  for (size_t i = 0; i < variant.get_struct_fields ().size (); i++)
+{
+  auto &field = variant.get_struct_fields ()[i];
+
+  // Just like for tuples, the pattern we're creating for each field is
+  // `self_` where `i` is the index of the field. It doesn't actually
+  // matter what we use, as long as it's ordered, unique, and that we can
+  // reuse it in the match case's return expression to clone the field.
+  auto pattern_str = "__self_" + std::to_string (i);
+
+  field_patterns.emplace_back (
+   std::unique_ptr (new StructPatternFieldIdentPat (
+ field.get_field_name (), builder.identifier_pattern (pattern_str), {},
+ loc)));
+
+  cloned_fields.emplace_back (
+   std::unique_ptr (new StructExprFieldIdentifierValue (
+ field.get_field_name (),
+ clone_call (builder.ref (builder.identifier (pattern_str))), {},
+ loc)));
+}
+#endif
+
+  for (const auto &field : variant.get_struct_fields ())
+{
+  // We match on the struct's fields, and then recreate an instance of that
+  // struct, cloning each field
+
+  field_patterns.emplace_back (
+   std::unique_ptr (new StructPatternFieldIdent (
+ field.get_field_name (), false /* is_ref? true? */, false, {}, loc)));
+
+  cloned_fields.emplace_back (
+   std::unique_ptr (new StructExprFieldIdentifierValue (
+ field.get_field_name (),
+ clone_call (builder.ref (
+   builder.identifier (field.get_field_name ().as_string (,
+ {}, loc)));
+}
+
+  auto pattern_elts = StructPatternElements (std::move (field_patterns));
+
+  auto pattern = std::unique_ptr (
+new ReferencePattern (std::unique_ptr (new StructPattern (
+   variant_path, loc, pattern_elts)),
+ false, false, loc));
+  auto expr = std::unique_ptr (
+new StructExprStructFields (variant_path, std::move (cloned_fields), loc));
+
+  return builder.match_case (std::move (pattern), std::move (expr));
+}
+
 void
 DeriveClone::visit_enum (Enum &item)
 {
-  // Create an arm for each variant of the enum
-  // For enum item variants, just create the same variant
-  // For struct and tuple variants, destructure the pattern and call clone for
-  // each field
+  // Create an arm for each var

[gcc r15-8633] gccrs: derive(Clone): Use lang item for PhantomData in Clone

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:d8c11ccefb48e600264f530df505ba96fa7d0835

commit r15-8633-gd8c11ccefb48e600264f530df505ba96fa7d0835
Author: Arthur Cohen 
Date:   Thu Dec 26 23:01:32 2024 +

gccrs: derive(Clone): Use lang item for PhantomData in Clone

gcc/rust/ChangeLog:

* expand/rust-derive-clone.cc (DeriveClone::visit_union): Create a 
lang item path
instead of a regular path.

Diff:
---
 gcc/rust/expand/rust-derive-clone.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/rust/expand/rust-derive-clone.cc 
b/gcc/rust/expand/rust-derive-clone.cc
index 8093bf67ff0a..2f733fae9107 100644
--- a/gcc/rust/expand/rust-derive-clone.cc
+++ b/gcc/rust/expand/rust-derive-clone.cc
@@ -263,7 +263,7 @@ DeriveClone::visit_union (Union &item)
 {StructField (
   Identifier ("_t"),
   builder.single_generic_type_path (
-   "PhantomData",
+   LangItem::Kind::PHANTOM_DATA,
GenericArgs (
  {}, {GenericArg::create_type (builder.single_type_path ("T"))}, {})),
   Visibility::create_private (), item.get_locus ())});


[gcc(refs/users/meissner/heads/work196-math)] Add ChangeLog.math and update REVISION.

2025-04-05 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:56203bba1a630d6f33e553f2d429c614abbae00b

commit 56203bba1a630d6f33e553f2d429c614abbae00b
Author: Michael Meissner 
Date:   Mon Mar 24 18:48:03 2025 -0400

Add ChangeLog.math and update REVISION.

2025-03-24  Michael Meissner  

gcc/

* ChangeLog.math: New file for branch.
* REVISION: Update.

Diff:
---
 gcc/ChangeLog.math | 5 +
 gcc/REVISION   | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog.math b/gcc/ChangeLog.math
new file mode 100644
index ..da7ffb4e0df1
--- /dev/null
+++ b/gcc/ChangeLog.math
@@ -0,0 +1,5 @@
+ Branch work196-math, baseline 
+
+2025-03-24   Michael Meissner  
+
+   Clone branch
diff --git a/gcc/REVISION b/gcc/REVISION
index 4879f9dc9d4e..1e732b52c53f 100644
--- a/gcc/REVISION
+++ b/gcc/REVISION
@@ -1 +1 @@
-work196 branch
+work196-math branch


[gcc r15-8588] gccrs: Remove Rust::make_unique

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:c8721ccdeb45396c5acf53da058a0fe1e3d03590

commit r15-8588-gc8721ccdeb45396c5acf53da058a0fe1e3d03590
Author: Owen Avery 
Date:   Wed Dec 4 15:23:07 2024 -0500

gccrs: Remove Rust::make_unique

Since our bootstrap requirement has been bumped to C++14, we don't need
a custom implementation of std::make_unique anymore.

gcc/rust/ChangeLog:

* ast/rust-ast-builder-type.cc: Remove inclusion of
rust-make-unique.h.
* ast/rust-ast-builder.cc: Likewise.
(Builder::array): Use std::make_unique instead of
Rust::make_unique.
* ast/rust-ast.cc (Attribute::get_traits_to_derive): Likewise.
* ast/rust-macro.h: Remove inclusion of rust-make-unique.h.
(MacroRulesDefinition::mbe): Use std::make_unique instead of
Rust::make_unique.
(MacroRulesDefinition::decl_macro): Likewise.
* ast/rust-path.h
(PathInExpression::PathInExpression): Likewise.
(QualifiedPathInExpression::QualifiedPathInExpression):
Likewise.
* backend/rust-compile-pattern.cc
(CompilePatternCheckExpr::visit): Likewise.
* expand/rust-derive-copy.cc
(DeriveCopy::copy_impl): Likewise.
* expand/rust-expand-format-args.cc
(expand_format_args): Likewise.
* expand/rust-macro-builtins-asm.cc: Remove inclusion of
rust-make-unique.h.
(parse_asm): Use std::make_unique instead of Rust::make_unique.
* hir/rust-ast-lower-expr.cc
(ASTLoweringExpr::visit): Likewise.
* hir/tree/rust-hir-expr.cc
(StructExprStructFields::StructExprStructFields): Likewise.
(StructExprStructFields::operator=): Likewise.
* hir/tree/rust-hir.cc
(TypePath::to_trait_bound): Likewise.
* lex/rust-token.h: Remove inclusion of rust-make-unique.h.
(Token::Token): Use std::make_unique instead of
Rust::make_unique.
* metadata/rust-import-archive.cc: Remove inclusion of
rust-make-unique.h.
(Import::find_archive_export_data): Use std::make_unique instead
of Rust::make_unique.
* metadata/rust-imports.cc: Remove inclusion of
rust-make-unique.h.
(Import::find_export_data): Use std::make_unique instead of
Rust::make_unique.
(Import::find_object_export_data): Likewise.
* parse/rust-parse-impl.h: Remove inclusion of
rust-make-unique.h.
(Parser::parse_function_param): Use std::make_unique instead of
Rust::make_unique.
(Parser::parse_self_param): Likewise.
(Parser::parse_array_expr): Likewise.
* typecheck/rust-hir-type-check-enumitem.cc
(TypeCheckEnumItem::visit): Likewise.
* typecheck/rust-hir-type-check-implitem.cc
(TypeCheckTopLevelExternItem::visit): Likewise.
(TypeCheckImplItem::visit): Likewise.
* typecheck/rust-hir-type-check-type.cc
(TypeResolveGenericParam::visit): Likewise.
* typecheck/rust-hir-type-check.cc: Remove inclusion of
rust-make-unique.h.
(TraitItemReference::get_type_from_fn): Use std::make_unique
instead of Rust::make_unique.
* typecheck/rust-tyty-bounds.cc
(TypeCheckBase::get_predicate_from_bound): Likewise.
* util/rust-make-unique.h: Removed.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/ast/rust-ast-builder-type.cc  |  1 -
 gcc/rust/ast/rust-ast-builder.cc   |  3 +-
 gcc/rust/ast/rust-ast.cc   |  4 +--
 gcc/rust/ast/rust-macro.h  |  5 ++--
 gcc/rust/ast/rust-path.h   |  8 ++---
 gcc/rust/backend/rust-compile-pattern.cc   |  2 +-
 gcc/rust/expand/rust-derive-copy.cc|  2 +-
 gcc/rust/expand/rust-expand-format-args.cc |  2 +-
 gcc/rust/expand/rust-macro-builtins-asm.cc |  7 ++---
 gcc/rust/hir/rust-ast-lower-expr.cc|  2 +-
 gcc/rust/hir/tree/rust-hir-expr.cc | 10 +++
 gcc/rust/hir/tree/rust-hir.cc  |  4 +--
 gcc/rust/lex/rust-token.h  |  7 ++---
 gcc/rust/metadata/rust-import-archive.cc   |  5 ++--
 gcc/rust/metadata/rust-imports.cc  |  5 ++--
 gcc/rust/parse/rust-parse-impl.h   | 23 +++---
 gcc/rust/typecheck/rust-hir-type-check-enumitem.cc |  6 ++--
 gcc/rust/typecheck/rust-hir-type-check-implitem.cc |  4 +--
 gcc/rust/typecheck/rust-hir-type-check-type.cc |  2 +-
 gcc/rust/typecheck/rust-hir-type-check.cc  |  3 +-
 gcc/rust/typecheck/rust-tyty-bounds.cc |  4 +--
 gcc/rust/util/rust-make-unique.h   | 35 ---

[gcc] Created branch 'meissner/heads/work196-bugs' in namespace 'refs/users'

2025-04-05 Thread Michael Meissner via Gcc-cvs
The branch 'meissner/heads/work196-bugs' was created in namespace 'refs/users' 
pointing to:

 bc61a0720b30... Add ChangeLog.meissner and REVISION.


[gcc r15-8830] gccrs: nr2.0: Handle lang item type path segments

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:d0e6dc1bb776b0d76b90d22407a4d951506b9688

commit r15-8830-gd0e6dc1bb776b0d76b90d22407a4d951506b9688
Author: Owen Avery 
Date:   Sun Feb 9 03:02:58 2025 -0500

gccrs: nr2.0: Handle lang item type path segments

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.hxx
(ForeverStack::find_starting_point): Stop when hitting a lang
item segment.
(ForeverStack::resolve_segments): Resolve lang item segments.
(ForeverStacl::resolve_path): Handle single segment lang item
paths and add comment.
* util/rust-unwrap-segment.cc
(unwrap_segment_get_lang_item): Add.
* util/rust-unwrap-segment.h
(unwrap_segment_get_lang_item): Add.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/resolve/rust-forever-stack.hxx | 27 +++
 gcc/rust/util/rust-unwrap-segment.cc| 20 
 gcc/rust/util/rust-unwrap-segment.h | 19 +++
 gcc/testsuite/rust/compile/nr2/exclude  |  5 -
 4 files changed, 66 insertions(+), 5 deletions(-)

diff --git a/gcc/rust/resolve/rust-forever-stack.hxx 
b/gcc/rust/resolve/rust-forever-stack.hxx
index 8abe8a61acbd..9ca8db2c09d3 100644
--- a/gcc/rust/resolve/rust-forever-stack.hxx
+++ b/gcc/rust/resolve/rust-forever-stack.hxx
@@ -384,6 +384,10 @@ ForeverStack::find_starting_point (
   for (; !is_last (iterator, segments); iterator++)
 {
   auto &outer_seg = *iterator;
+
+  if (unwrap_segment_get_lang_item (outer_seg).has_value ())
+   break;
+
   auto &seg = unwrap_type_segment (outer_seg);
   auto is_self_or_crate
= seg.is_crate_path_seg () || seg.is_lower_self_seg ();
@@ -452,6 +456,17 @@ ForeverStack::resolve_segments (
   for (; !is_last (iterator, segments); iterator++)
 {
   auto &outer_seg = *iterator;
+
+  if (auto lang_item = unwrap_segment_get_lang_item (outer_seg))
+   {
+ NodeId seg_id = Analysis::Mappings::get ().get_lang_item_node (
+   lang_item.value ());
+ current_node = &dfs_node (root, seg_id).value ();
+
+ insert_segment_resolution (outer_seg, seg_id);
+ continue;
+   }
+
   auto &seg = unwrap_type_segment (outer_seg);
   auto str = seg.as_string ();
   rust_debug ("[ARTHUR]: resolving segment part: %s", str.c_str ());
@@ -538,6 +553,17 @@ ForeverStack::resolve_path (
   // if there's only one segment, we just use `get`
   if (segments.size () == 1)
 {
+  auto &seg = segments.front ();
+  if (auto lang_item = unwrap_segment_get_lang_item (seg))
+   {
+ NodeId seg_id = Analysis::Mappings::get ().get_lang_item_node (
+   lang_item.value ());
+
+ insert_segment_resolution (seg, seg_id);
+ // TODO: does NonShadowable matter?
+ return Rib::Definition::NonShadowable (seg_id);
+   }
+
   auto res = get (unwrap_type_segment (segments.back ()).as_string ());
   if (res && !res->is_ambiguous ())
insert_segment_resolution (segments.back (), res->get_node_id ());
@@ -558,6 +584,7 @@ ForeverStack::resolve_path (
   // leave resolution within impl blocks to type checker
   if (final_node.rib.kind == Rib::Kind::TraitOrImpl)
return tl::nullopt;
+  // assuming this can't be a lang item segment
   auto res = final_node.rib.get (
unwrap_type_segment (segments.back ()).as_string ());
   if (res && !res->is_ambiguous ())
diff --git a/gcc/rust/util/rust-unwrap-segment.cc 
b/gcc/rust/util/rust-unwrap-segment.cc
index 38ff273fc064..083a0e54c91b 100644
--- a/gcc/rust/util/rust-unwrap-segment.cc
+++ b/gcc/rust/util/rust-unwrap-segment.cc
@@ -38,4 +38,24 @@ unwrap_segment_node_id (const AST::PathExprSegment &seg)
   return seg.get_node_id ();
 }
 
+tl::optional
+unwrap_segment_get_lang_item (const AST::TypePathSegment &seg)
+{
+  if (seg.is_lang_item ())
+return seg.get_lang_item ();
+  return tl::nullopt;
+}
+
+tl::optional
+unwrap_segment_get_lang_item (const AST::SimplePathSegment &seg)
+{
+  return tl::nullopt;
+}
+
+tl::optional
+unwrap_segment_get_lang_item (const AST::PathExprSegment &seg)
+{
+  return tl::nullopt;
+}
+
 } // namespace Rust
diff --git a/gcc/rust/util/rust-unwrap-segment.h 
b/gcc/rust/util/rust-unwrap-segment.h
index 4a3838a407a2..bebdc3aadd4d 100644
--- a/gcc/rust/util/rust-unwrap-segment.h
+++ b/gcc/rust/util/rust-unwrap-segment.h
@@ -99,4 +99,23 @@ unwrap_segment_node_id (const std::unique_ptr &ptr)
   return unwrap_segment_node_id (*ptr);
 }
 
+/**
+ * Used to check if a path segment is associated with a lang item
+ */
+tl::optional
+unwrap_segment_get_lang_item (const AST::TypePathSegment &seg);
+
+tl::optional
+unwrap_segment_get_lang_item (const AST::SimplePathSegment &seg);
+
+tl::optional
+unwrap_segment_get_lang_item (const AST::PathExprSegment &seg);
+
+t

[gcc r15-8456] Daily bump.

2025-04-05 Thread GCC Administrator via Libstdc++-cvs
https://gcc.gnu.org/g:c675c9dcb4eb006131f6a86d2e763a955c9b2fc8

commit r15-8456-gc675c9dcb4eb006131f6a86d2e763a955c9b2fc8
Author: GCC Administrator 
Date:   Thu Mar 20 00:20:10 2025 +

Daily bump.

Diff:
---
 gcc/ChangeLog   |   58 +++
 gcc/DATESTAMP   |2 +-
 gcc/ada/ChangeLog   |   18 +
 gcc/c/ChangeLog |   19 +
 gcc/cp/ChangeLog|   23 +
 gcc/fortran/ChangeLog   |   12 +
 gcc/po/ChangeLog|4 +
 gcc/rust/ChangeLog  | 1189 +++
 gcc/testsuite/ChangeLog |  639 +
 libstdc++-v3/ChangeLog  |   66 +++
 10 files changed, 2029 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 0f50aff777ce..86389dd74f80 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,61 @@
+2025-03-19  Vladimir N. Makarov  
+
+   PR target/119270
+   * ira-costs.cc (calculate_equiv_gains): Ignore equiv init insns
+   only for invariants.
+
+2025-03-19  David Malcolm  
+
+   PR c/119366
+   * diagnostic-format-sarif.cc (test_message_with_embedded_link):
+   Convert diagnostic_context from one urlifier to a stack of
+   urlifiers, where each node in the stack tracks whether the
+   urlifier is owned or borrowed.
+   * diagnostic.cc (diagnostic_context::initialize): Likewise.
+   (diagnostic_context::finish): Likewise.
+   (diagnostic_context::set_urlifier): Delete.
+   (diagnostic_context::push_owned_urlifier): New.
+   (diagnostic_context::push_borrowed_urlifier): New.
+   (diagnostic_context::pop_urlifier): New.
+   (diagnostic_context::get_urlifier): Reimplement in terms of stack.
+   (diagnostic_context::override_urlifier): Delete.
+   * diagnostic.h (diagnostic_context::set_urlifier): Delete decl.
+   (diagnostic_context::override_urlifier): Delete decl.
+   (diagnostic_context::push_owned_urlifier): New decl.
+   (diagnostic_context::push_borrowed_urlifier): New decl.
+   (diagnostic_context::pop_urlifier): New decl.
+   (diagnostic_context::get_urlifier): Make return value const; hide
+   implementation.
+   (diagnostic_context::m_urlifier): Replace with...
+   (diagnostic_context::urlifier_stack_node): ... this and...
+   (diagnostic_context::m_urlifier_stack): ...this.
+   * gcc-urlifier.cc
+   (auto_override_urlifier::auto_override_urlifier): Reimplement.
+   (auto_override_urlifier::~auto_override_urlifier): Reimplement.
+   * gcc-urlifier.h (class auto_override_urlifier): Reimplement.
+   (auto_urlify_attributes::auto_urlify_attributes): Update for
+   pass-by-reference.
+   * gcc.cc (driver::global_initializations): Update for
+   reimplementation of urlifiers in terms of a stack.
+   * toplev.cc (general_init): Likewise.
+
+2025-03-19  Jakub Jelinek  
+
+   PR target/119357
+   * config/i386/sse.md (pmovmskb 0x to ptest splitter,
+   *pmovsk_ptest__avx512): Force operands[0] into a REG.
+
+2025-03-19  Kyrylo Tkachov  
+
+   * config/aarch64/aarch64-arches.def (...): Add SVE2p1.
+   * doc/invoke.texi (AArch64 Options): Document +sve2p1 in
+   -march=armv9.4-a.
+
+2025-03-19  Xi Ruoyao  
+
+   * config/loongarch/loongarch.h (ADDITIONAL_REGISTER_NAMES): Add
+   fa0-fa7, ft0-ft16, and fs0-fs7.
+
 2025-03-18  Georg-Johann Lay  
 
PR target/119355
diff --git a/gcc/DATESTAMP b/gcc/DATESTAMP
index 22523f5c82fe..b76e7dd64105 100644
--- a/gcc/DATESTAMP
+++ b/gcc/DATESTAMP
@@ -1 +1 @@
-20250319
+20250320
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index 6be8962d195e..7f1295f27935 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,21 @@
+2025-03-19  Eric Botcazou  
+
+   * gnatvsn.adb (Gnat_Free_Software): Fix message formatting.
+
+2025-03-19  Eric Botcazou  
+
+   * gcc-interface/decl.cc (gnat_to_gnu_entity) : Set
+   the may_alias attribute if a specific GCC type is built.
+
+2025-03-19  Eric Botcazou  
+
+   * gen_il-gen-gen_nodes.adb (N_Formal_Package_Declaration): Use
+   N_Declaration instead of Node_Kind as ancestor.
+   * sem_ch12.adb (Get_Formal_Entity): Remove obsolete alternative.
+   (Instantiate_Formal_Package): Take into account the abbreviated
+   instances in the main loop running over the actuals of the local
+   package created for the formal package.
+
 2025-02-04  Eric Botcazou  
 
PR ada/118731
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index c2528f642078..8e5c4f740513 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,22 @@
+2025-03-19  Jakub Jelinek  
+
+   PR c/119350
+   * c-typeck.cc (pop_init_level): Don't ignore empty brackets for
+   flag_isoc23, still set constructor_type to NULL in that case but
+   emit a pedwarn_init in that case.
+
+2025-03-19  Martin Uecker  
+
+   PR c/118765
+   * c-decl.cc (finish_struct,finish_enum): Swap direction when
+   copying TYPE_ST

[gcc r14-11435] c: detect variably-modified types [PR117145, PR117245, PR100420]

2025-04-05 Thread Martin Uecker via Gcc-cvs
https://gcc.gnu.org/g:9d9dc4be6796966ee934f4929db94b250956201a

commit r14-11435-g9d9dc4be6796966ee934f4929db94b250956201a
Author: Martin Uecker 
Date:   Sat Mar 22 15:48:55 2025 +0100

c: detect variably-modified types [PR117145,PR117245,PR100420]

This fixes two cases where variably-modified types were not recognized as
such.  The first is when building composite types and the other when a type
is reconstructed for the 'vector' attribute.  Construction of types in
the C FE is reorganized to use c_build_* functions which are responsible for
setting C_TYPE_VARIABLE_SIZE, C_TYPE_VARIABLY_MODIFIED and 
TYPE_TYPELESS_STORAGE
based on the properties of the type itself and these replace all other logic
elsewhere (e.g. in grokdeclarator).  A new 'c_reconstruct_complex_type' 
based
on these functions is introduced which is called via a language hook when 
the
'vector' attribute is processed (as for C++).

One problem is are arrays of unspecified size 'T[*]' which were represented
identically to zero-sized arrays but with C_TYPE_VARIABLE_SIZE set.  To 
avoid
having to create distinct type copies for this, the representation was 
changed
to make it a natural VLA by giving it an upper bound of '(0, 0)'.  This also
then allows fixing of PR100420 where such arrays were printed as 'T[0]'.

Finally, a new function 'c_verify_type' checks consistency of properties
specific to C FE and is called when checking is on.

PR c/117145
PR c/117245
PR c/100420

gcc/c/ChangeLog:
* c-decl.cc (c_build_pointer_type): Move to c-typeck.cc
(grokdeclarator): Simplify logic.
(match_builtin_function_types): Adapt.
(push_decl): Adapt.
(implicitly_declare): Adapt.
(c_update_type_canonical): Adapt.
(c_make_fname_decl): Adapt.
(start_function): Adapt.
* c-objc-common.h: Add LANG_HOOKS_RECONSTRUCT_COMPLEX_TYPE.
* c-tree.h: Add prototypes.
* c-typeck.cc (c_verify_type): New function.
(c_set_type_bits). New function.
(c_build_pointer_type): Moved from c-decl.cc.
(c_build_pointer_type_for_mode): New function.
(c_build_function_type): New function.
(c_build_array_type): New function.
(c_build_type_attribute_variant): New function.
(c_reconstruct_complex_type): New function.
(c_build_functype_attribute_variant): Renamed.
(array_to_pointer_conversion): Simplify logic.
(composite_type_internal): Simplify logic..
(build_unary_op): Simplify logic..
(comptypes_verify): Add checking assertions.
(c_build_qualified_type): Add checking assertions.
(c_build_function_call_vec): Adapt.
(qualify_type): Adapt.
(build_functype_attribute_variant): Adapt.
(common_pointer_type): Adapt.
(c_common_type): Adapt.
(convert_for_assignment): Adapt.
(type_or_builtin_type): Adapt.
(build_access_with_size_for_counted_by): Adapt.
(build_conditional_expr): Adapt.
(build_modify_expr): Adapt.
(build_binary_op): Adapt.
(build_omp_array_section): Adapt.
(handle_omp_array_sections): Adapt.
(c_finish_omp_clauses): Adapt.
* c-parser.cc (c_parser_typeof_specifier): Adapt.
(c_parser_generic_selection): Adapt.

gcc/c-family/ChangeLog:
* c-pretty-print.cc (c_pretty_printer::direct_abstract_declarator):
Detect arrays of unspecified size.

gcc/testsuite/ChangeLog:
* gcc.dg/c23-tag-composite-11.c: New test.
* gcc.dg/Warray-parameter-4.c: Resolve xfails.
* gcc.dg/Wvla-parameter-2.c: Resolve xfails.
* gcc.dg/Wvla-parameter-3.c: Resolve xfails.
* gcc.dg/pr117145-1.c: New test.
* gcc.dg/pr117145-2.c: New test.
* gcc.dg/pr117245.c: New test.

(cherry picked from commit 9eae9268e41463927c9383004e58708048ec379f)

Diff:
---
 gcc/c-family/c-pretty-print.cc  |   6 +-
 gcc/c/c-decl.cc | 124 +++---
 gcc/c/c-objc-common.h   |   2 +
 gcc/c/c-parser.cc   |   2 +-
 gcc/c/c-tree.h  |   7 +
 gcc/c/c-typeck.cc   | 346 +++-
 gcc/testsuite/gcc.dg/Warray-parameter-4.c   |   6 +-
 gcc/testsuite/gcc.dg/Wvla-parameter-2.c |  15 +-
 gcc/testsuite/gcc.dg/Wvla-parameter-3.c |  11 +-
 gcc/testsuite/gcc.dg/c23-tag-composite-11.c |  27 +++
 gcc/testsuite/gcc.dg/pr117145-1.c   |  14 ++
 gcc/testsuite/gcc.dg/pr117145-2.c   |  10 +
 gcc/testsuite/gcc.dg/pr117245.c |  17 ++
 13 files changed, 417 insertion

[gcc r15-8631] gccrs: derive(Copy): Use copy lang item when deriving Copy.

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:a728f5f19a77d76e48ccfac5b3ccf0941f2150c3

commit r15-8631-ga728f5f19a77d76e48ccfac5b3ccf0941f2150c3
Author: Arthur Cohen 
Date:   Thu Dec 26 22:09:11 2024 +

gccrs: derive(Copy): Use copy lang item when deriving Copy.

gcc/rust/ChangeLog:

* expand/rust-derive-copy.cc: Use lang item path.

Diff:
---
 gcc/rust/expand/rust-derive-copy.cc | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/gcc/rust/expand/rust-derive-copy.cc 
b/gcc/rust/expand/rust-derive-copy.cc
index bcfe1db6b4a1..31b4819c0429 100644
--- a/gcc/rust/expand/rust-derive-copy.cc
+++ b/gcc/rust/expand/rust-derive-copy.cc
@@ -18,6 +18,7 @@
 
 #include "rust-derive-copy.h"
 #include "rust-ast-full.h"
+#include "rust-hir-map.h"
 #include "rust-mapping-common.h"
 #include "rust-path.h"
 
@@ -43,12 +44,7 @@ DeriveCopy::copy_impl (
   std::string name,
   const std::vector> &type_generics)
 {
-  // `$crate::core::marker::Copy` instead
-  auto segments = std::vector> ();
-  segments.emplace_back (builder.type_path_segment ("Copy"));
-
-  auto copy = TypePath (std::move (segments), loc);
-  // auto copy = TypePath (LangItem::Kind::COPY, loc);
+  auto copy = builder.type_path (LangItem::Kind::COPY);
 
   // we need to build up the generics for this impl block which will be just a
   // clone of the types specified ones


[gcc(refs/users/meissner/heads/work199)] Use architecture flags for defining _ARCH_PWR macros.

2025-04-05 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:76c081bc4e5b49c321b7459d5c7a3b474cbe3770

commit 76c081bc4e5b49c321b7459d5c7a3b474cbe3770
Author: Michael Meissner 
Date:   Thu Apr 3 16:14:55 2025 -0400

Use architecture flags for defining _ARCH_PWR macros.

For the newer architectures, this patch changes GCC to define the 
_ARCH_PWR
macros using the new architecture flags instead of relying on isa options 
like
-mpower10.

The -mpower8-internal, -mpower10, -mpower11, and -mfuture options were 
removed.
The -mpower11 and -mfuture options were removed completely, since they were 
just
added in GCC 15. The other two options were marked as WarnRemoved, and the
various ISA bits were removed.

TARGET_POWER8, TARGET_POWER10, TARGET_POWER11, and TARGET_FUTURE were 
re-defined
to use the architeture bits instead of the ISA bits.

There are other internal isa bits that aren't removed with this patch 
because
the built-in function support uses those bits.

I have built both big endian and little endian bootstrap compilers and there
were no regressions.

Can I install this patch on the GCC 15 trunk?

2025-04-03  Michael Meissner  

gcc/

* config/rs6000/rs6000-c.cc (rs6000_target_modify_macros) Add 
support to
use architecture flags instead of ISA flags for setting most of the
_ARCH_PWR* macros.
(rs6000_cpu_cpp_builtins): Update rs6000_target_modify_macros call.
* config/rs6000/rs6000-cpus.def (ISA_2_7_MASKS_SERVER): Remove
OPTION_MASK_POWER8.
(ISA_3_1_MASKS_SERVER): Remove OPTION_MASK_POWER10.
(POWER11_MASKS_SERVER): Remove OPTION_MASK_POWER11.
(FUTURE_MASKS_SERVER): Remove OPTION_MASK_FUTURE.
(POWERPC_MASKS): Remove OPTION_MASK_POWER8, OPTION_MASK_POWER10,
OPTION_MASK_POWER11, and OPTION_MASK_FUTURE.
* config/rs6000/rs6000-protos.h (rs6000_target_modify_macros): 
Update
declaration.
(rs6000_target_modify_macros_ptr): Likewise.
* config/rs6000/rs6000.cc (rs6000_target_modify_macros_ptr): 
Likewise.
(rs6000_option_override_internal): Use architecture flags instead 
of ISA
flags.
(rs6000_opt_masks): Remove -mpower10, -mpower11, and -mfuture which 
are
no longer in the ISA flags.
(rs6000_pragma_target_parse): Use architecture flags as well as ISA
flags.
* config/rs6000/rs6000.h (TARGET_POWER5): Redefine to use 
architecture
flags.
(TARGET_POWER5X): Likewise.
(TARGET_POWER6): Likewise.
(TARGET_POWER7): Likewise.
(TARGET_POWER8): Likewise.
(TARGET_POWER9): Likewise.
(TARGET_POWER10): New macro.
(TARGET_POWER11): Likewise.
(TARGET_FUTURE): Likewise.
* config/rs6000/rs6000.opt (-mpower8-internal): Remove ISA flag 
bits.
(-mpower10): Likewise.
(-mpower11): Likewise.
(-mfuture): Likewise.

Diff:
---
 gcc/config/rs6000/rs6000-c.cc | 29 -
 gcc/config/rs6000/rs6000-cpus.def | 10 +-
 gcc/config/rs6000/rs6000-protos.h |  5 +++--
 gcc/config/rs6000/rs6000.cc   | 20 +++-
 gcc/config/rs6000/rs6000.h| 19 +--
 gcc/config/rs6000/rs6000.opt  | 17 ++---
 6 files changed, 46 insertions(+), 54 deletions(-)

diff --git a/gcc/config/rs6000/rs6000-c.cc b/gcc/config/rs6000/rs6000-c.cc
index 6757a2477ad1..6d6838735b33 100644
--- a/gcc/config/rs6000/rs6000-c.cc
+++ b/gcc/config/rs6000/rs6000-c.cc
@@ -338,7 +338,8 @@ rs6000_define_or_undefine_macro (bool define_p, const char 
*name)
#pragma GCC target, we need to adjust the macros dynamically.  */
 
 void
-rs6000_target_modify_macros (bool define_p, HOST_WIDE_INT flags)
+rs6000_target_modify_macros (bool define_p, HOST_WIDE_INT flags,
+HOST_WIDE_INT arch_flags)
 {
   if (TARGET_DEBUG_BUILTIN || TARGET_DEBUG_TARGET)
 fprintf (stderr,
@@ -411,7 +412,7 @@ rs6000_target_modify_macros (bool define_p, HOST_WIDE_INT 
flags)
summary of the flags associated with particular cpu
definitions.  */
 
-  /* rs6000_isa_flags based options.  */
+  /* rs6000_isa_flags and rs6000_arch_flags based options.  */
   rs6000_define_or_undefine_macro (define_p, "_ARCH_PPC");
   if ((flags & OPTION_MASK_PPC_GPOPT) != 0)
 rs6000_define_or_undefine_macro (define_p, "_ARCH_PPCSQ");
@@ -419,25 +420,27 @@ rs6000_target_modify_macros (bool define_p, HOST_WIDE_INT 
flags)
 rs6000_define_or_undefine_macro (define_p, "_ARCH_PPCGR");
   if ((flags & OPTION_MASK_POWERPC64) != 0)
 rs6000_define_or_undefine_macro (define_p, "_ARCH_PPC64");
-  if ((flags & OPTION_MASK_MFCRF) != 0)
+  if ((flags & OPTION_MASK_POWERPC64) != 0)
+rs6000_define_or_undefine_macro (define_p, "_ARCH_PPC64");

[gcc r15-8537] gccrs: Use nr2.0 in PrivacyReporter

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:0884ed91a150e10bbdd462724505a7904654cd32

commit r15-8537-g0884ed91a150e10bbdd462724505a7904654cd32
Author: Owen Avery 
Date:   Tue Nov 19 13:57:34 2024 -0500

gccrs: Use nr2.0 in PrivacyReporter

gcc/rust/ChangeLog:

* checks/errors/privacy/rust-privacy-reporter.cc
(PrivacyReporter::check_for_privacy_violation): Use name
resolver 2.0.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc | 10 +-
 gcc/testsuite/rust/compile/nr2/exclude  |  2 --
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc 
b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
index 3413e5ab3dd7..dcc7681a 100644
--- a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
+++ b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
@@ -127,8 +127,16 @@ PrivacyReporter::check_for_privacy_violation (const NodeId 
&use_id,
 {
   NodeId ref_node_id = UNKNOWN_NODEID;
 
+  if (flag_name_resolution_2_0)
+{
+  auto &nr_ctx
+   = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+  if (auto id = nr_ctx.lookup (use_id))
+   ref_node_id = *id;
+}
   // FIXME: Don't assert here - we might be dealing with a type
-  if (!resolver.lookup_resolved_name (use_id, &ref_node_id))
+  else if (!resolver.lookup_resolved_name (use_id, &ref_node_id))
 resolver.lookup_resolved_type (use_id, &ref_node_id);
 
   // FIXME: Assert here. For now, we return since this causes issues when
diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index a73b1f027b1d..2e956960dad6 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -145,8 +145,6 @@ parse_complex_generic_application.rs
 parse_complex_generic_application2.rs
 path_as_generic_arg.rs
 pattern-struct.rs
-privacy1.rs
-privacy3.rs
 privacy4.rs
 privacy5.rs
 privacy8.rs


[gcc r15-9059] target/119010 - add mode attribute to *vmovv16si_constm1_pternlog_false_dep

2025-04-05 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:c99bdfc459c669346514347a863f1a1e9266cea1

commit r15-9059-gc99bdfc459c669346514347a863f1a1e9266cea1
Author: Richard Biener 
Date:   Thu Mar 27 14:06:00 2025 +0100

target/119010 - add mode attribute to *vmovv16si_constm1_pternlog_false_dep

Like the other instances.  This avoids

;;   1--> b  0: i6540 {xmm2=const_vector;unspec[xmm2] 38;}:nothing

PR target/119010
* config/i386/sse.md (*vmov_constm1_pternlog_false_dep):
Add mode attribute.

Diff:
---
 gcc/config/i386/sse.md | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
index ed5ac1abe80d..92dc93cb6532 100644
--- a/gcc/config/i386/sse.md
+++ b/gcc/config/i386/sse.md
@@ -1571,7 +1571,11 @@
"TARGET_AVX512VL ||  == 64"
"vpternlogd\t{$0xFF, %0, %0, %0|%0, %0, %0, 0xFF}"
   [(set_attr "type" "sselog1")
-   (set_attr "prefix" "evex")])
+   (set_attr "prefix" "evex")
+   (set (attr "mode")
+(if_then_else (match_test "TARGET_AVX512VL")
+ (const_string "")
+ (const_string "XI")))])
 
 ;; If mem_addr points to a memory region with less than whole vector size bytes
 ;; of accessible memory and k is a mask that would prevent reading the 
inaccessible


[gcc r15-8638] gccrs: derive(Clone): Implement clone for enum tuple variants

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:2c5d4994edbd42cb347ce487f32560005dbd9552

commit r15-8638-g2c5d4994edbd42cb347ce487f32560005dbd9552
Author: Arthur Cohen 
Date:   Fri Jan 3 14:27:52 2025 +

gccrs: derive(Clone): Implement clone for enum tuple variants

gcc/rust/ChangeLog:

* expand/rust-derive-clone.cc (DeriveClone::variant_match_path): 
New function.
(DeriveClone::clone_enum_identifier): Rename.
(DeriveClone::clone_enum_tuple): New function.
(DeriveClone::visit_enum): Visit tuple variants properly.
* expand/rust-derive-clone.h: Declare new functions.

Diff:
---
 gcc/rust/expand/rust-derive-clone.cc | 58 +---
 gcc/rust/expand/rust-derive-clone.h  | 12 
 2 files changed, 66 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/expand/rust-derive-clone.cc 
b/gcc/rust/expand/rust-derive-clone.cc
index e4702d8a8183..c2994b7b4f84 100644
--- a/gcc/rust/expand/rust-derive-clone.cc
+++ b/gcc/rust/expand/rust-derive-clone.cc
@@ -21,6 +21,8 @@
 #include "rust-ast-dump.h"
 #include "rust-item.h"
 #include "rust-path.h"
+#include "rust-pattern.h"
+#include "rust-system.h"
 
 namespace Rust {
 namespace AST {
@@ -236,14 +238,20 @@ DeriveClone::visit_struct (StructStruct &item)
 item.get_generic_params ());
 }
 
+PathInExpression
+DeriveClone::variant_match_path (Enum &item, const Identifier &variant)
+{
+  return PathInExpression ({builder.path_segment (
+ item.get_identifier ().as_string ()),
+   builder.path_segment (variant.as_string ())},
+  {}, loc, false);
+}
+
 MatchCase
 DeriveClone::clone_enum_identifier (Enum &item,
const std::unique_ptr &variant)
 {
-  auto variant_path = PathInExpression (
-{builder.path_segment (item.get_identifier ().as_string ()),
- builder.path_segment (variant->get_identifier ().as_string ())},
-{}, loc, false);
+  auto variant_path = variant_match_path (item, variant->get_identifier ());
 
   auto pattern = std::unique_ptr (new ReferencePattern (
 std::unique_ptr (new PathInExpression (variant_path)), false,
@@ -253,6 +261,45 @@ DeriveClone::clone_enum_identifier (Enum &item,
   return builder.match_case (std::move (pattern), std::move (expr));
 }
 
+MatchCase
+DeriveClone::clone_enum_tuple (Enum &item, const EnumItemTuple &variant)
+{
+  auto variant_path = variant_match_path (item, variant.get_identifier ());
+
+  auto patterns = std::vector> ();
+  auto cloned_patterns = std::vector> ();
+
+  for (size_t i = 0; i < variant.get_tuple_fields ().size (); i++)
+{
+  // The pattern we're creating for each field is `self_` where `i` is
+  // the index of the field. It doesn't actually matter what we use, as 
long
+  // as it's ordered, unique, and that we can reuse it in the match case's
+  // return expression to clone the field.
+  auto pattern_str = "__self_" + std::to_string (i);
+
+  patterns.emplace_back (builder.identifier_pattern (pattern_str));
+
+  // Now, for each tuple's element, we create a new expression calling
+  // `clone` on it for the match case's return expression
+  cloned_patterns.emplace_back (
+   clone_call (builder.ref (builder.identifier (pattern_str;
+}
+
+  auto pattern_items = std::unique_ptr (
+new TupleStructItemsNoRange (std::move (patterns)));
+
+  auto pattern = std::unique_ptr (
+new ReferencePattern (std::unique_ptr (new TupleStructPattern (
+   variant_path, std::move (pattern_items))),
+ false, false, loc));
+
+  auto expr
+= builder.call (std::unique_ptr (new PathInExpression 
(variant_path)),
+   std::move (cloned_patterns));
+
+  return builder.match_case (std::move (pattern), std::move (expr));
+}
+
 void
 DeriveClone::visit_enum (Enum &item)
 {
@@ -274,6 +321,9 @@ DeriveClone::visit_enum (Enum &item)
  cases.emplace_back (clone_enum_identifier (item, variant));
  break;
case EnumItem::Kind::Tuple:
+ cases.emplace_back (
+   clone_enum_tuple (item, static_cast (*variant)));
+ break;
case EnumItem::Kind::Struct:
  rust_unreachable ();
  break;
diff --git a/gcc/rust/expand/rust-derive-clone.h 
b/gcc/rust/expand/rust-derive-clone.h
index 339cf6357ae9..d48ec5d28893 100644
--- a/gcc/rust/expand/rust-derive-clone.h
+++ b/gcc/rust/expand/rust-derive-clone.h
@@ -63,8 +63,20 @@ private:
   clone_impl (std::unique_ptr &&clone_fn, std::string name,
  const std::vector> &type_generics);
 
+  /**
+   * Get the path to use for matching and creating a variant when matching on 
an
+   * enum. E.g. for the `Option` enum, with the `None` variant, this will 
create
+   * a path `Option::None`
+   */
+  PathInExpression variant_match_path (Enum &item, const Identifier &variant);
+
+  /**
+   * Implemen

[gcc r15-8558] gccrs: fix crash in hir dump

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:3fa779425cc550afb6e18671c45dba0e21d1d273

commit r15-8558-g3fa779425cc550afb6e18671c45dba0e21d1d273
Author: Philip Herron 
Date:   Mon Dec 2 17:38:55 2024 +

gccrs: fix crash in hir dump

gcc/rust/ChangeLog:

* hir/rust-hir-dump.cc (Dump::visit): add missing check for no 
return value

Signed-off-by: Philip Herron 

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

diff --git a/gcc/rust/hir/rust-hir-dump.cc b/gcc/rust/hir/rust-hir-dump.cc
index be785b9ebec2..2590eed19ae8 100644
--- a/gcc/rust/hir/rust-hir-dump.cc
+++ b/gcc/rust/hir/rust-hir-dump.cc
@@ -1365,7 +1365,8 @@ Dump::visit (ReturnExpr &e)
   begin ("ReturnExpr");
   do_mappings (e.get_mappings ());
 
-  visit_field ("return_expr", e.get_expr ());
+  if (e.has_return_expr ())
+visit_field ("return_expr", e.get_expr ());
 
   end ("ReturnExpr");
 }


[gcc/devel/rust/master] ast-builder: Add extra parameter for TypeParam builder

2025-04-05 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:c53c8d70e8dce2a400c1f3a01343f5d550ea3a03

commit c53c8d70e8dce2a400c1f3a01343f5d550ea3a03
Author: Arthur Cohen 
Date:   Wed Jan 15 12:59:51 2025 +

ast-builder: Add extra parameter for TypeParam builder

gcc/rust/ChangeLog:

* ast/rust-ast-builder.cc (Builder::new_type_param): Add optional 
extra trait bounds.
* ast/rust-ast-builder.h: Likewise.

Diff:
---
 gcc/rust/ast/rust-ast-builder.cc | 6 +-
 gcc/rust/ast/rust-ast-builder.h  | 4 +++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/ast/rust-ast-builder.cc b/gcc/rust/ast/rust-ast-builder.cc
index eccc474187f5..b3ee387ef9c1 100644
--- a/gcc/rust/ast/rust-ast-builder.cc
+++ b/gcc/rust/ast/rust-ast-builder.cc
@@ -361,7 +361,8 @@ Builder::new_lifetime_param (LifetimeParam ¶m)
 }
 
 std::unique_ptr
-Builder::new_type_param (TypeParam ¶m)
+Builder::new_type_param (
+  TypeParam ¶m, std::vector> extra_bounds)
 {
   location_t locus = param.get_locus ();
   AST::AttrVec outer_attrs = param.get_outer_attrs ();
@@ -372,6 +373,9 @@ Builder::new_type_param (TypeParam ¶m)
   if (param.has_type ())
 type = new_type (param.get_type ());
 
+  for (auto &&extra_bound : extra_bounds)
+type_param_bounds.emplace_back (std::move (extra_bound));
+
   for (const auto &b : param.get_type_param_bounds ())
 {
   switch (b->get_bound_type ())
diff --git a/gcc/rust/ast/rust-ast-builder.h b/gcc/rust/ast/rust-ast-builder.h
index 7e224d3db5ff..372e355fa9b6 100644
--- a/gcc/rust/ast/rust-ast-builder.h
+++ b/gcc/rust/ast/rust-ast-builder.h
@@ -200,7 +200,9 @@ public:
   static std::unique_ptr
   new_lifetime_param (LifetimeParam ¶m);
 
-  static std::unique_ptr new_type_param (TypeParam ¶m);
+  static std::unique_ptr new_type_param (
+TypeParam ¶m,
+std::vector> extra_trait_bounds = {});
 
   static Lifetime new_lifetime (const Lifetime &lifetime);


[gcc r15-8395] gccrs: imports: Make FinalizeImports a resolver visitor as well

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:9047b32383a05b5ef5909de5eed35a0cd3c9a76a

commit r15-8395-g9047b32383a05b5ef5909de5eed35a0cd3c9a76a
Author: Arthur Cohen 
Date:   Sat Apr 6 23:02:51 2024 +0200

gccrs: imports: Make FinalizeImports a resolver visitor as well

gcc/rust/ChangeLog:

* resolve/rust-finalize-imports-2.0.cc (FinalizeImports::go): Turn
static method into method.
(FinalizeImports::visit): New.
* resolve/rust-finalize-imports-2.0.h (class FinalizeImports): Make
FinalizeImports a visitor.
* resolve/rust-early-name-resolver-2.0.cc (Early::go): Use new 
FinalizeImports API.
(Early::resolve_glob_import): Use new API.
(Early::resolve_simple_import): Likewise.
(Early::resolve_rebind_import): Likewise.
(Early::build_import_mapping): Likewise.
* resolve/rust-early-name-resolver-2.0.h: Likewise.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): 
Likewise.
* resolve/rust-toplevel-name-resolver-2.0.h: Likewise.

Diff:
---
 gcc/rust/resolve/rust-early-name-resolver-2.0.cc   | 84 ++
 gcc/rust/resolve/rust-early-name-resolver-2.0.h| 14 ++--
 gcc/rust/resolve/rust-finalize-imports-2.0.cc  | 23 +-
 gcc/rust/resolve/rust-finalize-imports-2.0.h   | 23 --
 .../resolve/rust-toplevel-name-resolver-2.0.cc | 10 ++-
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h |  5 +-
 6 files changed, 114 insertions(+), 45 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 ba73a54d412a..ac8eb940c8d5 100644
--- a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
@@ -59,7 +59,7 @@ Early::go (AST::Crate &crate)
 build_import_mapping (std::move (import));
 
   // Once this is done, we finalize their resolution
-  FinalizeImports::go (import_mappings, toplevel, ctx);
+  FinalizeImports (std::move (import_mappings), toplevel, ctx).go (crate);
 
   // We now proceed with resolving macros, which can be nested in almost any
   // items
@@ -70,7 +70,7 @@ Early::go (AST::Crate &crate)
 }
 
 bool
-Early::resolve_glob_import (TopLevel::ImportKind &&glob)
+Early::resolve_glob_import (NodeId use_dec_id, TopLevel::ImportKind &&glob)
 {
   auto resolved = ctx.types.resolve_path (glob.to_resolve.get_segments ());
   if (!resolved.has_value ())
@@ -84,58 +84,86 @@ Early::resolve_glob_import (TopLevel::ImportKind &&glob)
   // here, we insert the module's NodeId into the import_mappings and will look
   // up the module proper in `FinalizeImports`
   // The namespace does not matter here since we are dealing with a glob
-  import_mappings.insert ({std::move (glob), ImportData::Glob (*resolved)});
+  // TODO: Ugly
+  import_mappings.insert (
+{use_dec_id, {{std::move (glob), ImportData::Glob (*resolved)}}});
 
   return true;
 }
 
 bool
-Early::resolve_simple_import (TopLevel::ImportKind &&import)
+Early::resolve_simple_import (NodeId use_dec_id, TopLevel::ImportKind &&import)
 {
   return ctx.resolve_path (import.to_resolve)
 .map ([&] (std::pair def_ns) {
-  import_mappings.insert (
-   {std::move (import), ImportData::Simple (def_ns)});
+  // We insert an empty vector, unless an element was already present for
+  // `use_dec_id` - which is returned in the tuple's first member
+  auto tuple = import_mappings.insert ({use_dec_id, {}});
+  // We then get that tuple's first member, which will be an iterator to 
the
+  // existing vec> OR an iterator to our newly
+  // created empty vector (plus its key since this is a hashmap iterator).
+  // we then access the second member of the pair to get access to the
+  // vector directly.
+  auto &imports = tuple.first->second;
+
+  imports.emplace_back (
+   std::make_pair (std::move (import), ImportData::Simple (def_ns)));
 })
 .has_value ();
 }
 
 bool
-Early::resolve_rebind_import (TopLevel::ImportKind &&rebind_import)
+Early::resolve_rebind_import (NodeId use_dec_id,
+ TopLevel::ImportKind &&rebind_import)
 {
   return ctx.resolve_path (rebind_import.to_resolve)
 .map ([&] (std::pair def_ns) {
-  import_mappings.insert (
-   {std::move (rebind_import), ImportData::Rebind (def_ns)});
+  // We insert an empty vector, unless an element was already present for
+  // `use_dec_id` - which is returned in the tuple's first member
+  auto tuple = import_mappings.insert ({use_dec_id, {}});
+  // We then get that tuple's first member, which will be an iterator to 
the
+  // existing vec> OR an iterator to our newly
+  // created empty vector (plus its key since this is a hashmap iterator).
+  // we then access the second member of the pair to get access to the
+  // vector directly.
+  auto &imports = tuple.first->second;
+

[gcc r15-8568] gccrs: hir: Lower lang-item paths

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:c7c6b5f89a39a39322aefb6e8f181c5fc230b162

commit r15-8568-gc7c6b5f89a39a39322aefb6e8f181c5fc230b162
Author: Arthur Cohen 
Date:   Fri Nov 29 11:06:25 2024 +0100

gccrs: hir: Lower lang-item paths

gcc/rust/ChangeLog:

* hir/rust-ast-lower-type.cc (ASTLowerTypePath::translate): Adapt to
handle lang item paths.
(ASTLowerTypePath::visit): Likewise.
(ASTLowerTypePath::translate_type_path): New.
(ASTLowerTypePath::translate_lang_item_type_path): New.
* hir/rust-ast-lower-type.h: Adapt to handle lang item paths.
* resolve/rust-ast-resolve-type.h: Likewise.

Diff:
---
 gcc/rust/hir/rust-ast-lower-type.cc  | 45 +---
 gcc/rust/hir/rust-ast-lower-type.h   |  6 -
 gcc/rust/resolve/rust-ast-resolve-type.h |  6 ++---
 3 files changed, 43 insertions(+), 14 deletions(-)

diff --git a/gcc/rust/hir/rust-ast-lower-type.cc 
b/gcc/rust/hir/rust-ast-lower-type.cc
index c09d60fafc6f..df06e48b801d 100644
--- a/gcc/rust/hir/rust-ast-lower-type.cc
+++ b/gcc/rust/hir/rust-ast-lower-type.cc
@@ -17,9 +17,10 @@
 // .
 
 #include "rust-ast-lower-type.h"
-#include "optional.h"
-#include "rust-attribute-values.h"
+#include "rust-hir-map.h"
+#include "rust-hir-path.h"
 #include "rust-path.h"
+#include "rust-pattern.h"
 
 namespace Rust {
 namespace HIR {
@@ -27,16 +28,20 @@ namespace HIR {
 HIR::TypePath *
 ASTLowerTypePath::translate (AST::Path &type)
 {
-  rust_assert (type.get_path_kind () == AST::Path::Kind::Type);
+  ASTLowerTypePath resolver;
 
-  return ASTLowerTypePath::translate (static_cast (type));
-}
+  switch (type.get_path_kind ())
+{
+case AST::Path::Kind::LangItem:
+  resolver.visit (static_cast (type));
+  break;
+case AST::Path::Kind::Type:
+  resolver.visit (static_cast (type));
+  break;
+default:
+  rust_unreachable ();
+}
 
-HIR::TypePath *
-ASTLowerTypePath::translate (AST::TypePath &type)
-{
-  ASTLowerTypePath resolver;
-  type.accept_vis (resolver);
   rust_assert (resolver.translated != nullptr);
   return resolver.translated;
 }
@@ -135,6 +140,26 @@ ASTLowerTypePath::visit (AST::TypePath &path)
 path.has_opening_scope_resolution_op ());
 }
 
+void
+ASTLowerTypePath::visit (AST::LangItemPath &path)
+{
+  auto crate_num = mappings.get_current_crate ();
+  auto hirid = mappings.get_next_hir_id (crate_num);
+
+  Analysis::NodeMapping mapping (crate_num, path.get_node_id (), hirid,
+mappings.get_next_localdef_id (crate_num));
+
+  std::vector> translated_segments;
+  translated_segments.emplace_back (std::unique_ptr (
+new HIR::TypePathSegment (mapping,
+ LangItem::ToString (path.get_lang_item_kind ()),
+ false, path.get_locus (;
+
+  translated
+= new HIR::TypePath (std::move (mapping), std::move (translated_segments),
+path.get_locus ());
+}
+
 HIR::QualifiedPathInType *
 ASTLowerQualifiedPathInType::translate (AST::QualifiedPathInType &type)
 {
diff --git a/gcc/rust/hir/rust-ast-lower-type.h 
b/gcc/rust/hir/rust-ast-lower-type.h
index 72c6b29d7dd0..0429e3fcf986 100644
--- a/gcc/rust/hir/rust-ast-lower-type.h
+++ b/gcc/rust/hir/rust-ast-lower-type.h
@@ -21,6 +21,7 @@
 
 #include "rust-ast-lower-base.h"
 #include "rust-ast-lower-expr.h"
+#include "rust-hir-path.h"
 
 namespace Rust {
 namespace HIR {
@@ -32,18 +33,21 @@ protected:
 
 public:
   static HIR::TypePath *translate (AST::Path &type);
-  static HIR::TypePath *translate (AST::TypePath &type);
 
   void visit (AST::TypePathSegmentFunction &segment) override;
   void visit (AST::TypePathSegment &segment) override;
   void visit (AST::TypePathSegmentGeneric &segment) override;
   void visit (AST::TypePath &path) override;
+  void visit (AST::LangItemPath &path) override;
 
 protected:
   HIR::TypePathSegment *translated_segment;
 
 private:
   HIR::TypePath *translated;
+
+  static HIR::TypePath *translate_type_path (AST::TypePath &type);
+  static HIR::TypePath *translate_lang_item_type_path (AST::LangItemPath 
&type);
 };
 
 class ASTLowerQualifiedPathInType : public ASTLowerTypePath
diff --git a/gcc/rust/resolve/rust-ast-resolve-type.h 
b/gcc/rust/resolve/rust-ast-resolve-type.h
index 7c3831a28294..518c0d80b14d 100644
--- a/gcc/rust/resolve/rust-ast-resolve-type.h
+++ b/gcc/rust/resolve/rust-ast-resolve-type.h
@@ -71,13 +71,13 @@ public:
   {
auto &type = static_cast (type_path);
 
-   rust_debug ("[ARTHUR]: lang item kind: %s",
-   LangItem::ToString (type.get_lang_item_kind ()).c_str ());
-
auto lang_item = Analysis::Mappings::get ()
   .lookup_lang_item_node (type.get_lang_item_kind ())
   .value ();
 
+   auto resolver = Resolver::get ();
+   resolver->insert_resolved_type (type.get_no

[gcc r14-11446] libstdc++: Fix ref_view branch of views::as_const [PR119135]

2025-04-05 Thread Patrick Palka via Libstdc++-cvs
https://gcc.gnu.org/g:925a744efec5a630eb9bf49e755c554a884fda99

commit r14-11446-g925a744efec5a630eb9bf49e755c554a884fda99
Author: Patrick Palka 
Date:   Thu Mar 13 09:15:21 2025 -0400

libstdc++: Fix ref_view branch of views::as_const [PR119135]

Unlike for span and empty_view, the range_reference_t of
ref_view doesn't correspond to X.  This patch fixes the ref_view
branch of views::as_const to correctly query its underlying range
type X.

PR libstdc++/119135

libstdc++-v3/ChangeLog:

* include/std/ranges: Include .
(views::__detail::__is_ref_view): Replace with ...
(views::__detail::__is_constable_ref_view): ... this.
(views::_AsConst::operator()): Replace bogus use of element_type
in the ref_view branch.
* testsuite/std/ranges/adaptors/as_const/1.cc (test03): Extend
test.

Reviewed-by: Tomasz Kamiński 
Reviewed-by: Jonathan Wakely 
(cherry picked from commit 50359c0a44381edb6dbd9359ef2ebdadbcc3ed42)

Diff:
---
 libstdc++-v3/include/std/ranges  | 12 ++--
 libstdc++-v3/testsuite/std/ranges/adaptors/as_const/1.cc |  4 
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index a966699479bb..c2dcb0265660 100644
--- a/libstdc++-v3/include/std/ranges
+++ b/libstdc++-v3/include/std/ranges
@@ -46,6 +46,7 @@
 #include 
 #include 
 #if __cplusplus > 202002L
+#include 
 #include 
 #endif
 #include 
@@ -9297,10 +9298,11 @@ namespace views::__adaptor
 namespace __detail
 {
   template
-   inline constexpr bool __is_ref_view = false;
+   inline constexpr bool __is_constable_ref_view = false;
 
   template
-   inline constexpr bool __is_ref_view> = true;
+   inline constexpr bool __is_constable_ref_view>
+ = constant_range;
 
   template
concept __can_as_const_view = requires { 
as_const_view(std::declval<_Range>()); };
@@ -9322,10 +9324,8 @@ namespace views::__adaptor
  return views::empty;
else if constexpr (std::__detail::__is_span<_Tp>)
  return span(std::forward<_Range>(__r));
-   else if constexpr (__detail::__is_ref_view<_Tp>
-  && constant_range)
- return ref_view(static_cast
- (std::forward<_Range>(__r).base()));
+   else if constexpr (__detail::__is_constable_ref_view<_Tp>)
+ return ref_view(std::as_const(std::forward<_Range>(__r).base()));
else if constexpr (is_lvalue_reference_v<_Range>
   && constant_range
   && !view<_Tp>)
diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/as_const/1.cc 
b/libstdc++-v3/testsuite/std/ranges/adaptors/as_const/1.cc
index c36786a8c5fa..3f1f8eb17726 100644
--- a/libstdc++-v3/testsuite/std/ranges/adaptors/as_const/1.cc
+++ b/libstdc++-v3/testsuite/std/ranges/adaptors/as_const/1.cc
@@ -63,6 +63,10 @@ test03()
   std::vector v;
   std::same_as>>
 auto r = views::as_const(v);
+
+  // PR libstdc++/119135
+  std::same_as>>
+auto r2 = views::as_const(views::all(v));
 }
 
 int


[gcc r13-9490] Daily bump.

2025-04-05 Thread GCC Administrator via Gcc-cvs
https://gcc.gnu.org/g:b1b75a253870a0466a5557cc2c6ae2b37e8930c6

commit r13-9490-gb1b75a253870a0466a5557cc2c6ae2b37e8930c6
Author: GCC Administrator 
Date:   Thu Apr 3 00:21:17 2025 +

Daily bump.

Diff:
---
 gcc/DATESTAMP  |  2 +-
 libstdc++-v3/ChangeLog | 54 ++
 2 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/gcc/DATESTAMP b/gcc/DATESTAMP
index 2508b1fc5e73..75f45468e7e7 100644
--- a/gcc/DATESTAMP
+++ b/gcc/DATESTAMP
@@ -1 +1 @@
-20250402
+20250403
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 60e0810e8780..e3d9a27b430d 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,57 @@
+2025-04-02  Jonathan Wakely  
+
+   * include/std/bit (bit_cast): Use library trait instead of
+   __is_trivially_copyable built-in.
+
+2025-04-02  Jonathan Wakely  
+
+   Backported from master:
+   2025-03-31  Jonathan Wakely  
+
+   PR libstdc++/110498
+   * include/bits/vector.tcc (vector::_M_reallocate):
+   Hoist loads of begin() and end() before allocation and use them
+   to state an unreachable condition.
+   * testsuite/23_containers/vector/bool/capacity/110498.cc: New
+   test.
+
+2025-04-02  Jonathan Wakely  
+
+   Backported from master:
+   2025-03-31  Jonathan Wakely  
+
+   PR libstdc++/114758
+   * include/bits/vector.tcc (vector::_M_fill_insert):
+   Hoist loads of begin() and end() before allocation.
+   * testsuite/23_containers/vector/bool/capacity/114758.cc: New
+   test.
+
+2025-04-02  Jonathan Wakely  
+
+   Backported from master:
+   2025-03-28  Jonathan Wakely  
+
+   PR libstdc++/117983
+   * include/bits/vector.tcc (vector::_M_range_insert): Add
+   unreachable condition to tell the compiler begin() <= end().
+   * testsuite/23_containers/vector/modifiers/insert/117983.cc: New
+   test.
+
+2025-04-02  Jonathan Wakely  
+
+   PR libstdc++/116212
+   * 
testsuite/20_util/specialized_algorithms/uninitialized_move/constrained.cc:
+   Use unsigned for vector size.
+
+2025-04-02  Jonathan Wakely  
+
+   Backported from master:
+   2024-06-13  Jonathan Wakely  
+
+   * include/bits/ranges_base.h (range_common_reference_t): New
+   alias template, as per LWG 3860.
+   * testsuite/std/ranges/range.cc: Check it.
+
 2025-03-31  Jonathan Wakely  
 
Backported from master:


[gcc(refs/users/meissner/heads/work198-bugs)] Fix PR 118541, do not generate unordered fp cmoves for IEEE compares.

2025-04-05 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:63da4eb89401a574adb6c484f2c49bae41a5174c

commit 63da4eb89401a574adb6c484f2c49bae41a5174c
Author: Michael Meissner 
Date:   Tue Apr 1 18:47:38 2025 -0400

Fix PR 118541, do not generate unordered fp cmoves for IEEE compares.

This is version 6 of the patch.

In version 6 of the patch, I fixed some typos.

In version 5 of the patch, I added the 'class' keyword in declaring the
enumeration.

In versions 4 of the patch, I changed the use of enums to match current C++.

In version 3, I made the following changes:

1:  The new argument to rs6000_reverse_condition that says whether we 
should
allow ordered floating point compares to be reversed is now an
enumeration instead of a boolean.

2:  I tried to make the code in rs6000_reverse_condition clearer.

3:  I added checks in invert_fpmask_comparison_operator to prevent 
ordered
floating point compares from being reversed unless -ffast-math.

4:  I split the test cases into 4 separate tests (ordered vs. unordered
compare and -O2 vs. -Ofast).

In bug PR target/118541 on power9, power10, and power11 systems, for the
function:

extern double __ieee754_acos (double);

double
__acospi (double x)
{
  double ret = __ieee754_acos (x) / 3.14;
  return __builtin_isgreater (ret, 1.0) ? 1.0 : ret;
}

GCC currently generates the following code:

Power9  Power10 and Power11
==  ===
bl __ieee754_acos   bl __ieee754_acos@notoc
nop plfd 0,.LC0@pcrel
addis 9,2,.LC2@toc@ha   xxspltidp 12,1065353216
addi 1,1,32 addi 1,1,32
lfd 0,.LC2@toc@l(9) ld 0,16(1)
addis 9,2,.LC0@toc@ha   fdiv 0,1,0
ld 0,16(1)  mtlr 0
lfd 12,.LC0@toc@l(9)xscmpgtdp 1,0,12
fdiv 0,1,0  xxsel 1,0,12,1
mtlr 0  blr
xscmpgtdp 1,0,12
xxsel 1,0,12,1
blr

This is because ifcvt.c optimizes the conditional floating point move to 
use the
XSCMPGTDP instruction.

However, the XSCMPGTDP instruction will generate an interrupt if one of the
arguments is a signalling NaN and signalling NaNs can generate an interrupt.
The IEEE comparison functions (isgreater, etc.) require that the comparison 
not
raise an interrupt.

The following patch changes the PowerPC back end so that ifcvt.c will not 
change
the if/then test and move into a conditional move if the comparison is one 
of
the comparisons that do not raise an error with signalling NaNs and -Ofast 
is
not used.  If a normal comparison is used or -Ofast is used, GCC will 
continue
to generate XSCMPGTDP and XXSEL.

For the following code:

double
ordered_compare (double a, double b, double c, double d)
{
  return __builtin_isgreater (a, b) ? c : d;
}

/* Verify normal > does generate xscmpgtdp.  */

double
normal_compare (double a, double b, double c, double d)
{
  return a > b ? c : d;
}

with the following patch, GCC generates the following for power9, power10, 
and
power11:

ordered_compare:
fcmpu 0,1,2
fmr 1,4
bnglr 0
fmr 1,3
blr

normal_compare:
xscmpgtdp 1,1,2
xxsel 1,4,3,1
blr

I have built bootstrap compilers on big endian power9 systems and little 
endian
power9/power10 systems and there were no regressions.  Can I check this 
patch
into the GCC trunk, and after a waiting period, can I check this into the 
active
older branches?

2025-04-01  Michael Meissner  

gcc/

PR target/118541
* config/rs6000/predicates.md (invert_fpmask_comparison_operator): 
Do
not allow UNLT and UNLE unless -ffast-math.
* config/rs6000/rs6000-protos.h (enum rev_cond_ordered): New 
enumeration.
(rs6000_reverse_condition): Add argument.
* config/rs6000/rs6000.cc (rs6000_reverse_condition): Do not allow
ordered comparisons to be reversed for floating point conditional 
moves,
but allow ordered comparisons to be reversed on jumps.
(rs6000_emit_sCOND): Adjust rs6000_reverse_condition call.
* config/rs6000/rs6000.h (REVERSE_CONDITION): Likewise.

[gcc(refs/users/meissner/heads/work199-bugs)] Add ChangeLog.bugs and update REVISION.

2025-04-05 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:364e0f5e28f33be5941601fc873bc828ebe1eca9

commit 364e0f5e28f33be5941601fc873bc828ebe1eca9
Author: Michael Meissner 
Date:   Thu Apr 3 15:24:39 2025 -0400

Add ChangeLog.bugs and update REVISION.

2025-04-03  Michael Meissner  

gcc/

* ChangeLog.bugs: New file for branch.
* REVISION: Update.

Diff:
---
 gcc/ChangeLog.bugs | 5 +
 gcc/REVISION   | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog.bugs b/gcc/ChangeLog.bugs
new file mode 100644
index ..8f82235b2084
--- /dev/null
+++ b/gcc/ChangeLog.bugs
@@ -0,0 +1,5 @@
+ Branch work199-bugs, baseline 
+
+2025-04-03   Michael Meissner  
+
+   Clone branch
diff --git a/gcc/REVISION b/gcc/REVISION
index 113e419bda0d..1c17811d60f2 100644
--- a/gcc/REVISION
+++ b/gcc/REVISION
@@ -1 +1 @@
-work199 branch
+work199-bugs branch


[gcc r15-8833] gccrs: lower: Error out when lowering ErrorPropagationExpr

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:1160e4b7e1c4e254f01107d8d5ef513ddccc7388

commit r15-8833-g1160e4b7e1c4e254f01107d8d5ef513ddccc7388
Author: Arthur Cohen 
Date:   Thu Jan 23 11:44:33 2025 +

gccrs: lower: Error out when lowering ErrorPropagationExpr

Adapt functions for lowering nodes that should never reach the lowering 
phase to cause an
unreachable, and mark them as final so as it not possible to override them 
in other visitors.

gcc/rust/ChangeLog:

* hir/rust-ast-lower-base.cc: Adapt functions for 
ErrorPropagationExpr and MacroInvocation.
* hir/rust-ast-lower-base.h: Mark them as final.
* hir/rust-ast-lower-expr.cc: Remove previous definition for those 
overrides.
* hir/rust-ast-lower-expr.h: Likewise.

Diff:
---
 gcc/rust/hir/rust-ast-lower-base.cc |  13 +-
 gcc/rust/hir/rust-ast-lower-base.h  | 356 ++--
 gcc/rust/hir/rust-ast-lower-expr.cc |  15 --
 gcc/rust/hir/rust-ast-lower-expr.h  |   1 -
 4 files changed, 188 insertions(+), 197 deletions(-)

diff --git a/gcc/rust/hir/rust-ast-lower-base.cc 
b/gcc/rust/hir/rust-ast-lower-base.cc
index f38697cf316c..c1fef3d7a207 100644
--- a/gcc/rust/hir/rust-ast-lower-base.cc
+++ b/gcc/rust/hir/rust-ast-lower-base.cc
@@ -23,6 +23,7 @@
 #include "rust-ast.h"
 #include "rust-attribute-values.h"
 #include "rust-diagnostics.h"
+#include "rust-expr.h"
 #include "rust-item.h"
 #include "rust-system.h"
 #include "rust-attributes.h"
@@ -30,7 +31,6 @@
 namespace Rust {
 namespace HIR {
 
-// We special case lowering macro invocations as that should NEVER happen
 void
 ASTLoweringBase::visit (AST::MacroInvocation &invoc)
 {
@@ -38,6 +38,14 @@ ASTLoweringBase::visit (AST::MacroInvocation &invoc)
   rust_unreachable ();
 }
 
+void
+ASTLoweringBase::visit (AST::ErrorPropagationExpr &expr)
+{
+  rust_fatal_error (expr.get_locus (),
+   "missing desugar for question mark operator");
+  rust_unreachable ();
+}
+
 void
 ASTLoweringBase::visit (AST::Token &)
 {}
@@ -116,9 +124,6 @@ void
 ASTLoweringBase::visit (AST::DereferenceExpr &)
 {}
 void
-ASTLoweringBase::visit (AST::ErrorPropagationExpr &)
-{}
-void
 ASTLoweringBase::visit (AST::NegationExpr &)
 {}
 void
diff --git a/gcc/rust/hir/rust-ast-lower-base.h 
b/gcc/rust/hir/rust-ast-lower-base.h
index 1bd1343bd166..b3bb174babfe 100644
--- a/gcc/rust/hir/rust-ast-lower-base.h
+++ b/gcc/rust/hir/rust-ast-lower-base.h
@@ -60,202 +60,204 @@ class ASTLoweringBase : public AST::ASTVisitor
 public:
   virtual ~ASTLoweringBase () {}
 
+  // Special casing nodes that should never reach the HIR lowering stage
+  virtual void visit (AST::MacroInvocation &) override final;
+  virtual void visit (AST::ErrorPropagationExpr &) override final;
+
   // visitor impl
   // rust-ast.h
   //  virtual void visit(AttrInput& attr_input);
   //  virtual void visit(TokenTree& token_tree);
   //  virtual void visit(MacroMatch& macro_match);
-  virtual void visit (AST::Token &tok);
-  virtual void visit (AST::DelimTokenTree &delim_tok_tree);
-  virtual void visit (AST::AttrInputMetaItemContainer &input);
-  //  virtual void visit(MetaItem& meta_item);
-  //  void vsit(Stmt& stmt);
-  //  virtual void visit(Expr& expr);
-  virtual void visit (AST::IdentifierExpr &ident_expr);
-  //  virtual void visit(Pattern& pattern);
-  //  virtual void visit(Type& type);
-  //  virtual void visit(TypeParamBound& type_param_bound);
-  virtual void visit (AST::Lifetime &lifetime);
-  //  virtual void visit(GenericParam& generic_param);
-  virtual void visit (AST::LifetimeParam &lifetime_param);
-  virtual void visit (AST::ConstGenericParam &const_param);
-  //  virtual void visit(TraitItem& trait_item);
-  //  virtual void visit(InherentImplItem& inherent_impl_item);
-  //  virtual void visit(TraitImplItem& trait_impl_item);
+  virtual void visit (AST::Token &tok) override;
+  virtual void visit (AST::DelimTokenTree &delim_tok_tree) override;
+  virtual void visit (AST::AttrInputMetaItemContainer &input) override;
+  //  virtual void visit(MetaItem& meta_item) override;
+  //  void vsit(Stmt& stmt) override;
+  //  virtual void visit(Expr& expr) override;
+  virtual void visit (AST::IdentifierExpr &ident_expr) override;
+  //  virtual void visit(Pattern& pattern) override;
+  //  virtual void visit(Type& type) override;
+  //  virtual void visit(TypeParamBound& type_param_bound) override;
+  virtual void visit (AST::Lifetime &lifetime) override;
+  //  virtual void visit(GenericParam& generic_param) override;
+  virtual void visit (AST::LifetimeParam &lifetime_param) override;
+  virtual void visit (AST::ConstGenericParam &const_param) override;
+  //  virtual void visit(TraitItem& trait_item) override;
+  //  virtual void visit(InherentImplItem& inherent_impl_item) override;
+  //  virtual void visit(TraitImplItem& trait_impl_item) override;
 
   // rust-path.h
-  virtual void visit (AST::PathInExpression &path);
-  virtual void visit (AST::TypePathSegme

[gcc r15-8560] gccrs: lang-items: Add lang-items AST collector

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:ed773fca7b930403d8863995077e1929bd715d91

commit r15-8560-ged773fca7b930403d8863995077e1929bd715d91
Author: Arthur Cohen 
Date:   Mon Nov 25 14:30:39 2024 +0100

gccrs: lang-items: Add lang-items AST collector

gcc/rust/ChangeLog:

* Make-lang.in: Add new object file.
* rust-session-manager.cc (Session::compile_crate): Call 
CollectLangItems.
* ast/rust-collect-lang-items.cc: New file.
* ast/rust-collect-lang-items.h: New file.

Diff:
---
 gcc/rust/Make-lang.in   |  3 +-
 gcc/rust/ast/rust-collect-lang-items.cc | 97 +
 gcc/rust/ast/rust-collect-lang-items.h  | 58 
 gcc/rust/rust-session-manager.cc|  3 +
 4 files changed, 160 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index 9c5ec49ec4e4..8771cdf91e1e 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -227,8 +227,9 @@ GRS_OBJS = \
 rust/rust-dir-owner.o \
 rust/rust-unicode.o \
 rust/rust-punycode.o \
-   rust/rust-lang-item.o \
rust/rust-expand-format-args.o \
+   rust/rust-lang-item.o \
+   rust/rust-collect-lang-items.o \
 $(END)
 # removed object files from here
 
diff --git a/gcc/rust/ast/rust-collect-lang-items.cc 
b/gcc/rust/ast/rust-collect-lang-items.cc
new file mode 100644
index ..11a30aa37a74
--- /dev/null
+++ b/gcc/rust/ast/rust-collect-lang-items.cc
@@ -0,0 +1,97 @@
+// Copyright (C) 2024 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3.  If not see
+// .
+
+#include "rust-collect-lang-items.h"
+#include "optional.h"
+#include "rust-ast-collector.h"
+#include "rust-ast.h"
+#include "rust-attribute-values.h"
+#include "rust-attributes.h"
+#include "rust-hir-map.h"
+
+namespace Rust {
+namespace AST {
+
+// FIXME: Before merging: De-duplicate with function in rust-ast-lower-base.cc
+bool
+is_known_attribute (const std::string &attribute_path)
+{
+  const auto &lookup
+= Analysis::BuiltinAttributeMappings::get ()->lookup_builtin (
+  attribute_path);
+
+  return !lookup.is_error ();
+}
+
+template 
+tl::optional
+get_lang_item_attr (const T &maybe_lang_item)
+{
+  for (const auto &attr : maybe_lang_item.get_outer_attrs ())
+{
+  const auto &str_path = attr.get_path ().as_string ();
+  if (!is_known_attribute (str_path))
+   {
+ rust_error_at (attr.get_locus (), "unknown attribute");
+ continue;
+   }
+
+  bool is_lang_item = str_path == Values::Attributes::LANG
+ && attr.has_attr_input ()
+ && attr.get_attr_input ().get_attr_input_type ()
+  == AST::AttrInput::AttrInputType::LITERAL;
+
+  if (is_lang_item)
+   {
+ auto &literal
+   = static_cast (attr.get_attr_input ());
+ const auto &lang_item_type_str = literal.get_literal ().as_string ();
+
+ return LangItem::Parse (lang_item_type_str);
+   }
+}
+
+  return tl::nullopt;
+}
+
+template 
+void
+CollectLangItems::maybe_add_lang_item (const T &item)
+{
+  if (auto lang_item = get_lang_item_attr (item))
+mappings.insert_lang_item_node (lang_item.value (), item.get_node_id ());
+}
+
+void
+CollectLangItems::visit (AST::Trait &item)
+{
+  maybe_add_lang_item (item);
+
+  DefaultASTVisitor::visit (item);
+}
+
+void
+CollectLangItems::visit (AST::TraitItemType &item)
+{
+  maybe_add_lang_item (item);
+
+  DefaultASTVisitor::visit (item);
+}
+
+} // namespace AST
+} // namespace Rust
diff --git a/gcc/rust/ast/rust-collect-lang-items.h 
b/gcc/rust/ast/rust-collect-lang-items.h
new file mode 100644
index ..552648f04eda
--- /dev/null
+++ b/gcc/rust/ast/rust-collect-lang-items.h
@@ -0,0 +1,58 @@
+// Copyright (C) 2024 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+// for mo

[gcc r15-9032] gcc/mingw: Align `.refptr.` to 8-byte boundaries for 64-bit targets

2025-04-05 Thread Jonathan Yong via Gcc-cvs
https://gcc.gnu.org/g:8d42378acdf1a011420ba78685f7a6c79808c881

commit r15-9032-g8d42378acdf1a011420ba78685f7a6c79808c881
Author: LIU Hao 
Date:   Sat Mar 29 22:47:54 2025 +0800

gcc/mingw: Align `.refptr.` to 8-byte boundaries for 64-bit targets

Windows only requires sections to be aligned on a 4-byte boundary. This used
to work because in binutils the `.rdata` section is over-aligned to a 
16-byte
boundary, which will be fixed in the future.

This matches the output of Clang.

Signed-off-by: LIU Hao 
Signed-off-by: Jonathan Yong <10wa...@gmail.com>

gcc/ChangeLog:
* config/mingw/winnt.cc (mingw_pe_file_end): Add `.p2align`.

Diff:
---
 gcc/config/mingw/winnt.cc | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/config/mingw/winnt.cc b/gcc/config/mingw/winnt.cc
index adaa6dfa3cff..08a761d3a6d4 100644
--- a/gcc/config/mingw/winnt.cc
+++ b/gcc/config/mingw/winnt.cc
@@ -819,6 +819,7 @@ mingw_pe_file_end (void)
}
 
  fprintf (asm_out_file, "\t.section\t.rdata$%s, \"dr\"\n"
+  "\t.p2align\t3, 0\n"
   "\t.globl\t%s\n"
   "\t.linkonce\tdiscard\n", oname, oname);
  fprintf (asm_out_file, "%s:\n\t.quad\t%s\n", oname, name);


[gcc r15-8619] gccrs: ast: Refactor how lang item paths are handled.

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:63023c032845b5d01e25c1f2e443e43d938337b0

commit r15-8619-g63023c032845b5d01e25c1f2e443e43d938337b0
Author: Arthur Cohen 
Date:   Thu Dec 26 21:46:03 2024 +

gccrs: ast: Refactor how lang item paths are handled.

Lang item typepaths were not handled properly, and required a complete 
overhaul.
All old classes that concerned lang item paths are now modified to use a 
simpler
version of `AST::LangItemPath`, which has been removed. TypePath segments 
can now
be lang items, as this is requied for having generic lang item paths such as
PhantomData.

gcc/rust/ChangeLog:

* ast/rust-path.h: Rework how lang item paths are represented.
* ast/rust-path.cc: Likewise.
* ast/rust-item.h: Likewise.
* ast/rust-ast.cc: Likewise.
* ast/rust-ast-collector.cc: Adapt to new lang item path system.
* ast/rust-ast-collector.h: Likewise.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise.
* ast/rust-ast-visitor.h: Likewise.
* expand/rust-derive-copy.cc: Likewise.
* expand/rust-derive.h: Likewise.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise.
* hir/rust-ast-lower-base.h: Likewise.
* hir/rust-ast-lower-type.cc (ASTLowerTypePath::translate): 
Likewise.
(ASTLowerTypePath::visit): Likewise.
* hir/rust-ast-lower-type.h: Likewise.
* resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise.
* resolve/rust-ast-resolve-base.h: Likewise.
* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Likewise.
* resolve/rust-ast-resolve-type.h: Likewise.
* resolve/rust-ast-resolve-type.cc (ResolveRelativeTypePath::go): 
Likewise.
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Likewise.
* resolve/rust-late-name-resolver-2.0.h: Likewise.
* hir/tree/rust-hir-path.cc (TypePathSegment::TypePathSegment): 
Likewise.
(TypePathSegmentGeneric::TypePathSegmentGeneric): Likewise.
* hir/tree/rust-hir-path.h: Likewise.
* typecheck/rust-hir-type-check-type.cc 
(TypeCheckType::resolve_root_path): Likewise.
* ast/rust-ast-builder.cc: Likewise.
* ast/rust-ast-builder.h: Likewise.

Diff:
---
 gcc/rust/ast/rust-ast-builder.cc|  20 +-
 gcc/rust/ast/rust-ast-builder.h |   4 -
 gcc/rust/ast/rust-ast-collector.cc  |  13 -
 gcc/rust/ast/rust-ast-collector.h   |   2 -
 gcc/rust/ast/rust-ast-visitor.cc|  11 -
 gcc/rust/ast/rust-ast-visitor.h |   4 -
 gcc/rust/ast/rust-ast.cc|   4 +-
 gcc/rust/ast/rust-item.h|  40 +--
 gcc/rust/ast/rust-path.cc   |  31 +-
 gcc/rust/ast/rust-path.h| 405 +---
 gcc/rust/expand/rust-derive-copy.cc |   4 +-
 gcc/rust/expand/rust-derive.h   |   2 -
 gcc/rust/hir/rust-ast-lower-base.cc |   6 -
 gcc/rust/hir/rust-ast-lower-base.h  |   2 -
 gcc/rust/hir/rust-ast-lower-type.cc |  75 +++--
 gcc/rust/hir/rust-ast-lower-type.h  |   6 +-
 gcc/rust/hir/tree/rust-hir-path.cc  |  21 +-
 gcc/rust/hir/tree/rust-hir-path.h   |  38 ++-
 gcc/rust/resolve/rust-ast-resolve-base.cc   |   8 -
 gcc/rust/resolve/rust-ast-resolve-base.h|   2 -
 gcc/rust/resolve/rust-ast-resolve-item.cc   |  27 +-
 gcc/rust/resolve/rust-ast-resolve-type.cc   |  79 +++--
 gcc/rust/resolve/rust-ast-resolve-type.h|  31 --
 gcc/rust/resolve/rust-late-name-resolver-2.0.cc |  19 --
 gcc/rust/resolve/rust-late-name-resolver-2.0.h  |   1 -
 gcc/rust/typecheck/rust-hir-type-check-type.cc  |   2 +-
 26 files changed, 311 insertions(+), 546 deletions(-)

diff --git a/gcc/rust/ast/rust-ast-builder.cc b/gcc/rust/ast/rust-ast-builder.cc
index 22fb0d83f979..f6d0f0dc4aed 100644
--- a/gcc/rust/ast/rust-ast-builder.cc
+++ b/gcc/rust/ast/rust-ast-builder.cc
@@ -42,15 +42,6 @@ Builder::call (std::unique_ptr &&path,
 new CallExpr (std::move (path), std::move (args), {}, loc));
 }
 
-std::unique_ptr
-Builder::call (std::unique_ptr &&path,
-  std::vector> &&args) const
-{
-  return call (std::unique_ptr (
-new PathInExpression (std::move (path), {}, loc)),
-  std::move (args));
-}
-
 std::unique_ptr
 Builder::call (std::unique_ptr &&path, std::unique_ptr &&arg) const
 {
@@ -60,15 +51,6 @@ Builder::call (std::unique_ptr &&path, 
std::unique_ptr &&arg) const
   return call (std::move (path), std::move (args));
 }
 
-std::unique_ptr
-Builder::call (std::unique_ptr &&path, std::unique_ptr &&arg) const
-{
-  auto args = std::vector> ();
-  args.emplace_back (std::move (arg));
-
-  return call (std::move (path

[gcc r15-8551] gccrs: hir: Remove duplicate function in TraitItemFunc

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:e7bf1b6291ea18a3848f9fc7d44421554eeafe4f

commit r15-8551-ge7bf1b6291ea18a3848f9fc7d44421554eeafe4f
Author: Arthur Cohen 
Date:   Fri Nov 29 11:05:29 2024 +0100

gccrs: hir: Remove duplicate function in TraitItemFunc

Both TraitItemFunc::has_definition() and TraitItemFunc::has_block_defined()
were exactly the same implementation, so remove one.

gcc/rust/ChangeLog:

* hir/tree/rust-hir-item.h: Remove 
TraitItemFunc::has_block_defined()
* backend/rust-compile-implitem.cc (CompileTraitItem::visit):
Call TraitItemFunc::has_definition() instead.
* checks/errors/rust-const-checker.cc (ConstChecker::visit): 
Likewise.
* checks/errors/rust-hir-pattern-analysis.cc 
(PatternChecker::visit): Likewise.
* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): 
Likewise.
* typecheck/rust-hir-trait-resolve.cc 
(ResolveTraitItemToRef::visit): Likewise.

Diff:
---
 gcc/rust/backend/rust-compile-implitem.cc   | 2 +-
 gcc/rust/checks/errors/rust-const-checker.cc| 2 +-
 gcc/rust/checks/errors/rust-hir-pattern-analysis.cc | 2 +-
 gcc/rust/checks/errors/rust-unsafe-checker.cc   | 2 +-
 gcc/rust/hir/tree/rust-hir-item.h   | 2 --
 gcc/rust/typecheck/rust-hir-trait-resolve.cc| 2 +-
 6 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-implitem.cc 
b/gcc/rust/backend/rust-compile-implitem.cc
index 352685e242f8..129e97879fa4 100644
--- a/gcc/rust/backend/rust-compile-implitem.cc
+++ b/gcc/rust/backend/rust-compile-implitem.cc
@@ -57,7 +57,7 @@ CompileTraitItem::visit (HIR::TraitItemConst &constant)
 void
 CompileTraitItem::visit (HIR::TraitItemFunc &func)
 {
-  rust_assert (func.has_block_defined ());
+  rust_assert (func.has_definition ());
 
   rust_assert (concrete->get_kind () == TyTy::TypeKind::FNDEF);
   TyTy::FnType *fntype = static_cast (concrete);
diff --git a/gcc/rust/checks/errors/rust-const-checker.cc 
b/gcc/rust/checks/errors/rust-const-checker.cc
index 420db8fb8b20..97b35288baed 100644
--- a/gcc/rust/checks/errors/rust-const-checker.cc
+++ b/gcc/rust/checks/errors/rust-const-checker.cc
@@ -678,7 +678,7 @@ ConstChecker::visit (StaticItem &static_item)
 void
 ConstChecker::visit (TraitItemFunc &item)
 {
-  if (item.has_block_defined ())
+  if (item.has_definition ())
 item.get_block_expr ().accept_vis (*this);
 }
 
diff --git a/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc 
b/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc
index db1e72725565..79416b5d50a5 100644
--- a/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc
+++ b/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc
@@ -522,7 +522,7 @@ PatternChecker::visit (StaticItem &static_item)
 void
 PatternChecker::visit (TraitItemFunc &item)
 {
-  if (item.has_block_defined ())
+  if (item.has_definition ())
 item.get_block_expr ().accept_vis (*this);
 }
 
diff --git a/gcc/rust/checks/errors/rust-unsafe-checker.cc 
b/gcc/rust/checks/errors/rust-unsafe-checker.cc
index 6c9141c2dd2c..fadfd9dea83a 100644
--- a/gcc/rust/checks/errors/rust-unsafe-checker.cc
+++ b/gcc/rust/checks/errors/rust-unsafe-checker.cc
@@ -776,7 +776,7 @@ UnsafeChecker::visit (StaticItem &static_item)
 void
 UnsafeChecker::visit (TraitItemFunc &item)
 {
-  if (item.has_block_defined ())
+  if (item.has_definition ())
 item.get_block_expr ().accept_vis (*this);
 }
 
diff --git a/gcc/rust/hir/tree/rust-hir-item.h 
b/gcc/rust/hir/tree/rust-hir-item.h
index 0fda1672b747..474471742155 100644
--- a/gcc/rust/hir/tree/rust-hir-item.h
+++ b/gcc/rust/hir/tree/rust-hir-item.h
@@ -1991,8 +1991,6 @@ public:
 
   const TraitFunctionDecl &get_decl () const { return decl; }
 
-  bool has_block_defined () const { return block_expr != nullptr; }
-
   BlockExpr &get_block_expr () { return *block_expr; }
 
   const std::string trait_identifier () const override final
diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc 
b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
index 2fbf123aa774..14e26f4512b8 100644
--- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc
+++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
@@ -69,7 +69,7 @@ ResolveTraitItemToRef::visit (HIR::TraitItemFunc &fn)
 {
   // create trait-item-ref
   location_t locus = fn.get_locus ();
-  bool is_optional = fn.has_block_defined ();
+  bool is_optional = fn.has_definition ();
   std::string identifier = fn.get_decl ().get_function_name ().as_string ();
 
   resolved = TraitItemReference (identifier, is_optional,


[gcc/devel/rust/master] lang-items: Add Result and Try lang items

2025-04-05 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:b87fd67fa807665d741968b7aca4b9399f2071db

commit b87fd67fa807665d741968b7aca4b9399f2071db
Author: Arthur Cohen 
Date:   Tue Jan 21 16:13:11 2025 +0100

lang-items: Add Result and Try lang items

gcc/rust/ChangeLog:

* util/rust-lang-item.h: Add handling for Result::Ok, Result::Err, 
Try, Try::into_result,
Try::from_ok, Try::from_err.
* util/rust-lang-item.cc: Likewise.

gcc/testsuite/ChangeLog:

* rust/compile/try-trait.rs: New test.

Diff:
---
 gcc/rust/util/rust-lang-item.cc |  8 ++
 gcc/rust/util/rust-lang-item.h  | 12 +
 gcc/testsuite/rust/compile/try-trait.rs | 44 +
 3 files changed, 64 insertions(+)

diff --git a/gcc/rust/util/rust-lang-item.cc b/gcc/rust/util/rust-lang-item.cc
index e6bcc8572982..affadf9bb1b6 100644
--- a/gcc/rust/util/rust-lang-item.cc
+++ b/gcc/rust/util/rust-lang-item.cc
@@ -97,11 +97,19 @@ const BiMap 
Rust::LangItem::lang_items = {{
   {"Some", Kind::OPTION_SOME},
   {"None", Kind::OPTION_NONE},
 
+  {"Ok", Kind::RESULT_OK},
+  {"Err", Kind::RESULT_ERR},
+
   {"into_iter", Kind::INTOITER_INTOITER},
   {"next", Kind::ITERATOR_NEXT},
 
   {"eq", Kind::EQ},
   {"partial_ord", Kind::PARTIAL_ORD},
+
+  {"try", Kind::TRY},
+  {"into_result", Kind::TRY_INTO_RESULT},
+  {"from_error", Kind::TRY_FROM_ERROR},
+  {"from_ok", Kind::TRY_FROM_OK},
 }};
 
 tl::optional
diff --git a/gcc/rust/util/rust-lang-item.h b/gcc/rust/util/rust-lang-item.h
index 3b3d86eddf2e..4836536e03ff 100644
--- a/gcc/rust/util/rust-lang-item.h
+++ b/gcc/rust/util/rust-lang-item.h
@@ -127,8 +127,20 @@ public:
 OPTION_SOME,
 OPTION_NONE,
 
+RESULT_OK,
+RESULT_ERR,
+
 INTOITER_INTOITER,
 ITERATOR_NEXT,
+
+// NOTE: These lang items are *not* necessarily present in later versions 
of
+// Rust (I am unsure at which point they have been removed as the `Try`
+// trait is unstable). They will need to be changed when updating the
+// targeted Rust version of gccrs
+TRY,
+TRY_INTO_RESULT,
+TRY_FROM_ERROR,
+TRY_FROM_OK,
   };
 
   static const BiMap lang_items;
diff --git a/gcc/testsuite/rust/compile/try-trait.rs 
b/gcc/testsuite/rust/compile/try-trait.rs
new file mode 100644
index ..9ec135dcd56c
--- /dev/null
+++ b/gcc/testsuite/rust/compile/try-trait.rs
@@ -0,0 +1,44 @@
+#[lang = "sized"]
+trait Sized {}
+
+enum Result {
+#[lang = "Ok"]
+Ok(T),
+#[lang = "Err"]
+Err(E)
+}
+
+#[lang = "try"]
+pub trait Try {
+/// The type of this value when viewed as successful.
+#[unstable(feature = "try_trait", issue = "42327")]
+type Ok;
+/// The type of this value when viewed as failed.
+#[unstable(feature = "try_trait", issue = "42327")]
+type Error;
+
+/// Applies the "?" operator. A return of `Ok(t)` means that the
+/// execution should continue normally, and the result of `?` is the
+/// value `t`. A return of `Err(e)` means that execution should branch
+/// to the innermost enclosing `catch`, or return from the function.
+///
+/// If an `Err(e)` result is returned, the value `e` will be "wrapped"
+/// in the return type of the enclosing scope (which must itself implement
+/// `Try`). Specifically, the value `X::from_error(From::from(e))`
+/// is returned, where `X` is the return type of the enclosing function.
+#[lang = "into_result"]
+#[unstable(feature = "try_trait", issue = "42327")]
+fn into_result(self) -> Result;
+
+/// Wrap an error value to construct the composite result. For example,
+/// `Result::Err(x)` and `Result::from_error(x)` are equivalent.
+#[lang = "from_error"]
+#[unstable(feature = "try_trait", issue = "42327")]
+fn from_error(v: Self::Error) -> Self;
+
+/// Wrap an OK value to construct the composite result. For example,
+/// `Result::Ok(x)` and `Result::from_ok(x)` are equivalent.
+#[lang = "from_ok"]
+#[unstable(feature = "try_trait", issue = "42327")]
+fn from_ok(v: Self::Ok) -> Self;
+}


[gcc r15-8548] gccrs: ensure packed and aligned is applied properly

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:65b68bed326c6acaa1fd50527d9c1dc61071579f

commit r15-8548-g65b68bed326c6acaa1fd50527d9c1dc61071579f
Author: Philip Herron 
Date:   Tue Nov 26 18:05:25 2024 +

gccrs: ensure packed and aligned is applied properly

We cannot apply aligned or packed after layout_type is called you need
to set this up first then call it.

Fixes Rust-GCC#3260

gcc/rust/ChangeLog:

* backend/rust-compile-type.cc (TyTyResolveCompile::visit): call 
lauout type directly
* rust-backend.h (struct_type): add optional layout parameter
(union_type): likewise
(fill_in_fields): likewise
* rust-gcc.cc (struct_type): likewise
(union_type): likewise
(fill_in_fields): only layout if we required

Signed-off-by: Philip Herron 

Diff:
---
 gcc/rust/backend/rust-compile-type.cc |  8 +---
 gcc/rust/rust-backend.h   |  6 +++---
 gcc/rust/rust-gcc.cc  | 15 +--
 3 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-type.cc 
b/gcc/rust/backend/rust-compile-type.cc
index 56d64e1405bd..50b52fbd37fa 100644
--- a/gcc/rust/backend/rust-compile-type.cc
+++ b/gcc/rust/backend/rust-compile-type.cc
@@ -22,6 +22,7 @@
 #include "rust-gcc.h"
 
 #include "tree.h"
+#include "stor-layout.h"
 
 namespace Rust {
 namespace Compile {
@@ -268,8 +269,8 @@ TyTyResolveCompile::visit (const TyTy::ADTType &type)
  fields.push_back (std::move (f));
}
 
-  type_record = type.is_union () ? Backend::union_type (fields)
-: Backend::struct_type (fields);
+  type_record = type.is_union () ? Backend::union_type (fields, false)
+: Backend::struct_type (fields, false);
 }
   else
 {
@@ -359,7 +360,7 @@ TyTyResolveCompile::visit (const TyTy::ADTType &type)
}
 
   // finally make the union or the enum
-  type_record = Backend::union_type (enum_fields);
+  type_record = Backend::union_type (enum_fields, false);
 }
 
   // Handle repr options
@@ -381,6 +382,7 @@ TyTyResolveCompile::visit (const TyTy::ADTType &type)
   SET_TYPE_ALIGN (type_record, repr.align * 8);
   TYPE_USER_ALIGN (type_record) = 1;
 }
+  layout_type (type_record);
 
   std::string named_struct_str
 = type.get_ident ().path.get () + type.subst_as_string ();
diff --git a/gcc/rust/rust-backend.h b/gcc/rust/rust-backend.h
index 9d28cf6d3931..414799edefee 100644
--- a/gcc/rust/rust-backend.h
+++ b/gcc/rust/rust-backend.h
@@ -133,11 +133,11 @@ function_ptr_type (tree result, const std::vector 
&praameters,
 
 // Get a struct type.
 tree
-struct_type (const std::vector &fields);
+struct_type (const std::vector &fields, bool layout = true);
 
 // Get a union type.
 tree
-union_type (const std::vector &fields);
+union_type (const std::vector &fields, bool layout = true);
 
 // Get an array type.
 tree
@@ -496,7 +496,7 @@ write_global_definitions (const std::vector 
&type_decls,
 // TODO: make static
 
 tree
-fill_in_fields (tree, const std::vector &);
+fill_in_fields (tree, const std::vector &, bool);
 
 tree fill_in_array (tree, tree, tree);
 
diff --git a/gcc/rust/rust-gcc.cc b/gcc/rust/rust-gcc.cc
index 273ab7889b08..59983ede97d7 100644
--- a/gcc/rust/rust-gcc.cc
+++ b/gcc/rust/rust-gcc.cc
@@ -592,23 +592,24 @@ function_ptr_type (tree result_type, const 
std::vector ¶meters,
 // Make a struct type.
 
 tree
-struct_type (const std::vector &fields)
+struct_type (const std::vector &fields, bool layout)
 {
-  return fill_in_fields (make_node (RECORD_TYPE), fields);
+  return fill_in_fields (make_node (RECORD_TYPE), fields, layout);
 }
 
 // Make a union type.
 
 tree
-union_type (const std::vector &fields)
+union_type (const std::vector &fields, bool layout)
 {
-  return fill_in_fields (make_node (UNION_TYPE), fields);
+  return fill_in_fields (make_node (UNION_TYPE), fields, layout);
 }
 
 // Fill in the fields of a struct or union type.
 
 tree
-fill_in_fields (tree fill, const std::vector &fields)
+fill_in_fields (tree fill, const std::vector &fields,
+   bool layout)
 {
   tree field_trees = NULL_TREE;
   tree *pp = &field_trees;
@@ -625,7 +626,9 @@ fill_in_fields (tree fill, const 
std::vector &fields)
   pp = &DECL_CHAIN (field);
 }
   TYPE_FIELDS (fill) = field_trees;
-  layout_type (fill);
+
+  if (layout)
+layout_type (fill);
 
   // Because Rust permits converting between named struct types and
   // equivalent struct types, for which we use VIEW_CONVERT_EXPR, and


[gcc(refs/users/meissner/heads/work199-vpair)] Merge commit 'refs/users/meissner/heads/work199-vpair' of git+ssh://gcc.gnu.org/git/gcc into me/work

2025-04-05 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:5b9a36c7eabc2d5fd41604197c52c6bbf7d6674b

commit 5b9a36c7eabc2d5fd41604197c52c6bbf7d6674b
Merge: 99242af0b0f2 67139bc62ba5
Author: Michael Meissner 
Date:   Thu Apr 3 16:35:30 2025 -0400

Merge commit 'refs/users/meissner/heads/work199-vpair' of 
git+ssh://gcc.gnu.org/git/gcc into me/work199-vpair

Diff:


[gcc/meissner/heads/work199-test] (14 commits) Merge commit 'refs/users/meissner/heads/work199-test' of gi

2025-04-05 Thread Michael Meissner via Gcc-cvs
The branch 'meissner/heads/work199-test' was updated to point to:

 eadedcdfa58e... Merge commit 'refs/users/meissner/heads/work199-test' of gi

It previously pointed to:

 c09fa69f394a... Add ChangeLog.test and update REVISION.

Diff:

Summary of changes (added commits):
---

  eadedcd... Merge commit 'refs/users/meissner/heads/work199-test' of gi
  f9073bb... Add ChangeLog.test and update REVISION.
  c62780a... Update ChangeLog.* (*)
  76c081b... Use architecture flags for defining _ARCH_PWR macros. (*)
  aa1860c... Add rs6000 architecture masks. (*)
  9dacc68... Use vector pair load/store for memcpy with -mcpu=future (*)
  c590949... Add -mcpu=future tests. (*)
  230fbe1... Add -mcpu=future tuning support. (*)
  c099046... Add support for -mcpu=future (*)
  04725bf... Change TARGET_MODULO to TARGET_POWER9. (*)
  08e5c71... Change TARGET_POPCNTD to TARGET_POWER7. (*)
  b9b3a52... Change TARGET_CMPB to TARGET_POWER6. (*)
  d0dbdbf... Change TARGET_FPRND to TARGET_POWER5X. (*)
  31d7966... Change TARGET_POPCNTB to TARGET_POWER5. (*)

(*) This commit already exists in another branch.
Because the reference `refs/users/meissner/heads/work199-test' matches
your hooks.email-new-commits-only configuration,
no separate email is sent for this commit.


[gcc r15-8418] rust: Add support for Clone and Copy derive on generic types

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:9b4f8f2d5177b006c6996e790f3874c8b1eeacfa

commit r15-8418-g9b4f8f2d5177b006c6996e790f3874c8b1eeacfa
Author: Philip Herron 
Date:   Thu Sep 19 16:45:54 2024 +0100

rust: Add support for Clone and Copy derive on generic types

When we generate derivations for Copy and Clone we need to make sure
the associated impl block sets up the generic parameters and arguments
correctly. This patch introduces the framework to copy chunks of the AST
because we need to make sure these new AST nodes have their own associated
id, calling clone on the nodes will just confuse name-resolution and
subsequent mappings.

Fixes #3139

gcc/rust/ChangeLog:

* Make-lang.in: new objects
* ast/rust-ast-builder.cc (Builder::generic_type_path_segment): new 
helper
(Builder::single_generic_type_path): likewise
(Builder::new_type): likewise
(Builder::new_lifetime_param): likewise
(Builder::new_type_param): likewise
(Builder::new_lifetime): likewise
(Builder::new_generic_args): likewise
* ast/rust-ast-builder.h: new helper decls
* ast/rust-ast.h: new const getters
* ast/rust-path.h: likewise
* ast/rust-type.h: likewise
* expand/rust-derive-clone.cc (DeriveClone::clone_impl): take the 
types generics
(DeriveClone::visit_tuple): likewise
(DeriveClone::visit_struct): likewise
(DeriveClone::visit_union): likewise
* expand/rust-derive-clone.h: update header
* expand/rust-derive-copy.cc (DeriveCopy::copy_impl): similarly 
take type generics
(DeriveCopy::visit_struct): likewise
(DeriveCopy::visit_tuple): likewise
(DeriveCopy::visit_enum): likewise
(DeriveCopy::visit_union): likewise
* expand/rust-derive-copy.h: likewse
* ast/rust-ast-builder-type.cc: New file.
* ast/rust-ast-builder-type.h: New file.

gcc/testsuite/ChangeLog:

* rust/compile/issue-3139-1.rs: New test.
* rust/compile/issue-3139-2.rs: New test.
* rust/compile/issue-3139-3.rs: New test.
* rust/compile/nr2/exclude: these all break nr2

Diff:
---
 gcc/rust/Make-lang.in  |   1 +
 gcc/rust/ast/rust-ast-builder-type.cc  | 164 +++
 gcc/rust/ast/rust-ast-builder-type.h   |  57 
 gcc/rust/ast/rust-ast-builder.cc   | 201 -
 gcc/rust/ast/rust-ast-builder.h|  17 +++
 gcc/rust/ast/rust-ast.h|  20 ++-
 gcc/rust/ast/rust-path.h   |  14 +-
 gcc/rust/ast/rust-type.h   |  10 ++
 gcc/rust/expand/rust-derive-clone.cc   |  88 -
 gcc/rust/expand/rust-derive-clone.h|   5 +-
 gcc/rust/expand/rust-derive-copy.cc|  87 -
 gcc/rust/expand/rust-derive-copy.h |   4 +-
 gcc/testsuite/rust/compile/issue-3139-1.rs |  45 +++
 gcc/testsuite/rust/compile/issue-3139-2.rs |  57 
 gcc/testsuite/rust/compile/issue-3139-3.rs |  32 +
 gcc/testsuite/rust/compile/nr2/exclude |   3 +
 16 files changed, 783 insertions(+), 22 deletions(-)

diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index 51645be6ff63..b1777e399639 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -92,6 +92,7 @@ GRS_OBJS = \
 rust/rust-cfg-strip.o \
 rust/rust-expand-visitor.o \
 rust/rust-ast-builder.o \
+rust/rust-ast-builder-type.o \
 rust/rust-derive.o \
 rust/rust-derive-clone.o \
 rust/rust-derive-copy.o \
diff --git a/gcc/rust/ast/rust-ast-builder-type.cc 
b/gcc/rust/ast/rust-ast-builder-type.cc
new file mode 100644
index ..e76d0de0e9ae
--- /dev/null
+++ b/gcc/rust/ast/rust-ast-builder-type.cc
@@ -0,0 +1,164 @@
+// Copyright (C) 2020-2024 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3.  If not see
+// .
+
+#include "rust-ast-builder-type.h"
+#include "rust-ast-builder.h"
+#include "rust-ast-full.h"
+#include "rust-common.h"
+#include "rust-make-unique.h"
+
+namespace Rust {
+namespace AST {
+
+ASTTypeBuilder::ASTTypeBuilder () : translated (nullptr) {}
+
+Type *
+ASTTypeBuilder::build (Type &type)
+{
+  ASTTypeBu

[gcc r15-8648] arm: testsuite: memcpy-aligned requires unaligned accesses

2025-04-05 Thread Richard Earnshaw via Gcc-cvs
https://gcc.gnu.org/g:b1ac0c5f1986d0774cfc980da8323f17747a1ce9

commit r15-8648-gb1ac0c5f1986d0774cfc980da8323f17747a1ce9
Author: Richard Earnshaw 
Date:   Fri Mar 21 15:15:21 2025 +

arm: testsuite: memcpy-aligned requires unaligned accesses

This test is designed to check that if one of the operands is
aligned (but the other isn't) we expand to a sensible sequence and
bypass most of the overhead of doing a memcpy.  But on targets without
unaligned accessess, we still end up calling memcpy.  It's then a
lottery as to whether the prologue and epilogue code, plus the
set-up for the memcpy itself, generate instructions that match the
scan patterns.

Since in those cases we're not actually testing what the test is looking
for anyway, just skip the test on strict-alignment targets.

gcc/testsuite:
* gcc.target/arm/memcpy-aligned-1.c: Require unaligned accesses.

Diff:
---
 gcc/testsuite/gcc.target/arm/memcpy-aligned-1.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/testsuite/gcc.target/arm/memcpy-aligned-1.c 
b/gcc/testsuite/gcc.target/arm/memcpy-aligned-1.c
index 852b391388bd..42e2a6bbdf74 100644
--- a/gcc/testsuite/gcc.target/arm/memcpy-aligned-1.c
+++ b/gcc/testsuite/gcc.target/arm/memcpy-aligned-1.c
@@ -1,4 +1,5 @@
 /* { dg-do compile } */
+/* { dg-require-effective-target arm_unaligned } */
 /* { dg-options "-O2 -save-temps" } */
 
 void *memcpy (void *dest, const void *src, unsigned int n);


[gcc/devel/rust/master] nr2.0: Adjust indentifier expression handling

2025-04-05 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:0a2bc0a252f1c45848e92fb8f1b537a7c7b69eab

commit 0a2bc0a252f1c45848e92fb8f1b537a7c7b69eab
Author: Owen Avery 
Date:   Tue Mar 18 20:28:25 2025 -0400

nr2.0: Adjust indentifier expression handling

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Make sure to return early after a resolution
error, improve the resolution error message, fix a typo, handle
ambiguous resolutions, and remove an old comment.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/resolve/rust-late-name-resolver-2.0.cc | 26 -
 gcc/testsuite/rust/compile/nr2/exclude  |  3 ---
 2 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
index 71c63f1be147..1d8e66195be2 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -232,21 +232,29 @@ Late::visit (AST::IdentifierExpr &expr)
 }
   else
 {
-  if (auto typ = ctx.types.get_prelude (expr.get_ident ()))
-   resolved = typ;
+  if (auto type = ctx.types.get_prelude (expr.get_ident ()))
+   {
+ resolved = type;
+   }
   else
-   rust_error_at (expr.get_locus (),
-  "could not resolve identifier expression: %qs",
-  expr.get_ident ().as_string ().c_str ());
+   {
+ rust_error_at (expr.get_locus (), ErrorCode::E0425,
+"cannot find value %qs in this scope",
+expr.get_ident ().as_string ().c_str ());
+ return;
+   }
+}
+
+  if (resolved->is_ambiguous ())
+{
+  rust_error_at (expr.get_locus (), ErrorCode::E0659, "%qs is ambiguous",
+expr.as_string ().c_str ());
+  return;
 }
 
   ctx.map_usage (Usage (expr.get_node_id ()),
 Definition (resolved->get_node_id ()));
 
-  // in the old resolver, resolutions are kept in the resolver, not the 
mappings
-  // :/ how do we deal with that?
-  // ctx.mappings.insert_resolved_name(expr, resolved);
-
   // For empty types, do we perform a lookup in ctx.types or should the
   // toplevel instead insert a name in ctx.values? (like it currently does)
 }
diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index de5824813b47..59964fc90e28 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -1,8 +1,6 @@
-break-rust2.rs
 canonical_paths1.rs
 cfg1.rs
 const_generics_3.rs
-const_generics_4.rs
 feature_rust_attri0.rs
 generics9.rs
 issue-1901.rs
@@ -19,7 +17,6 @@ macros/mbe/macro43.rs
 macros/mbe/macro6.rs
 multiple_bindings1.rs
 multiple_bindings2.rs
-not_find_value_in_scope.rs
 privacy5.rs
 privacy8.rs
 pub_restricted_1.rs


[gcc/devel/rust/master] backend: Allow anything as a match scrutinee

2025-04-05 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:3638b0551e48f7a9b292409f750174727ea7a5e2

commit 3638b0551e48f7a9b292409f750174727ea7a5e2
Author: Arthur Cohen 
Date:   Tue Dec 24 11:45:09 2024 +

backend: Allow anything as a match scrutinee

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (check_match_scrutinee): Allow 
anything to be used as a
match scrutinee, not just ADTs.

Diff:
---
 gcc/rust/backend/rust-compile-expr.cc | 6 +-
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-expr.cc 
b/gcc/rust/backend/rust-compile-expr.cc
index c24a22a3118f..1d68e85aa769 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -31,6 +31,7 @@
 #include "convert.h"
 #include "print-tree.h"
 #include "rust-system.h"
+#include "rust-tyty.h"
 
 namespace Rust {
 namespace Compile {
@@ -1035,11 +1036,6 @@ check_match_scrutinee (HIR::MatchExpr &expr, Context 
*ctx)
 }
 
   TyTy::TypeKind scrutinee_kind = scrutinee_expr_tyty->get_kind ();
-  rust_assert ((TyTy::is_primitive_type_kind (scrutinee_kind)
-   && scrutinee_kind != TyTy::TypeKind::NEVER)
-  || scrutinee_kind == TyTy::TypeKind::ADT
-  || scrutinee_kind == TyTy::TypeKind::TUPLE
-  || scrutinee_kind == TyTy::TypeKind::REF);
 
   if (scrutinee_kind == TyTy::TypeKind::FLOAT)
 {


[gcc r15-8593] gccrs: use StackedContexts for block context

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:1c13bc20ca23774567e192a47d894cad362086df

commit r15-8593-g1c13bc20ca23774567e192a47d894cad362086df
Author: Prajwal S N 
Date:   Mon Dec 16 13:29:46 2024 +0530

gccrs: use StackedContexts for block context

Replaces the DIY vector stack with a StackedContexts object for block
scopes in the type checker context.

Fixes #3284.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check.h (class TypeCheckContext): add
header file and use StackedContexts for blocks
* typecheck/rust-typecheck-context.cc: update methods
* typecheck/rust-hir-trait-resolve.cc: refactor function calls
* typecheck/rust-hir-type-check-implitem.cc: refactor function calls
* typecheck/rust-hir-type-check-type.cc: refactor function calls

Signed-off-by: Prajwal S N 

Diff:
---
 gcc/rust/typecheck/rust-hir-trait-resolve.cc   |  4 ++--
 gcc/rust/typecheck/rust-hir-type-check-implitem.cc |  5 +++--
 gcc/rust/typecheck/rust-hir-type-check-type.cc |  7 +++---
 gcc/rust/typecheck/rust-hir-type-check.h   |  8 +++
 gcc/rust/typecheck/rust-typecheck-context.cc   | 26 +++---
 5 files changed, 15 insertions(+), 35 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc 
b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
index 14e26f4512b8..82019328e16a 100644
--- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc
+++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
@@ -278,7 +278,7 @@ TraitResolver::resolve_trait (HIR::Trait *trait_reference)
 }
   self->inherit_bounds (specified_bounds);
 
-  context->push_block_context (TypeCheckBlockContextItem (trait_reference));
+  context->block_context ().enter (TypeCheckBlockContextItem 
(trait_reference));
   std::vector item_refs;
   for (auto &item : trait_reference->get_trait_items ())
 {
@@ -308,7 +308,7 @@ TraitResolver::resolve_trait (HIR::Trait *trait_reference)
   // resolve the blocks of functions etc because it can end up in a recursive
   // loop of trying to resolve traits as required by the types
   tref->on_resolved ();
-  context->pop_block_context ();
+  context->block_context ().exit ();
 
   return tref;
 }
diff --git a/gcc/rust/typecheck/rust-hir-type-check-implitem.cc 
b/gcc/rust/typecheck/rust-hir-type-check-implitem.cc
index 4521822410c9..937a8a8d0efc 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-implitem.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-implitem.cc
@@ -335,9 +335,10 @@ TypeCheckImplItem::Resolve (
 
   // resolve
   TypeCheckImplItem resolver (parent, self, substitutions);
-  resolver.context->push_block_context (TypeCheckBlockContextItem (&parent));
+  resolver.context->block_context ().enter (
+TypeCheckBlockContextItem (&parent));
   item.accept_vis (resolver);
-  resolver.context->pop_block_context ();
+  resolver.context->block_context ().exit ();
 
   return resolver.result;
 }
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc 
b/gcc/rust/typecheck/rust-hir-type-check-type.cc
index 859cdfedcd0b..bb23f8441edd 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc
@@ -591,10 +591,11 @@ TypeCheckType::resolve_segments (
   bool first_segment = i == offset;
   bool selfResolveOk = false;
 
-  if (first_segment && tySegIsBigSelf && context->have_block_context ()
- && context->peek_block_context ().is_impl_block ())
+  if (first_segment && tySegIsBigSelf
+ && context->block_context ().is_in_context ()
+ && context->block_context ().peek ().is_impl_block ())
{
- TypeCheckBlockContextItem ctx = context->peek_block_context ();
+ TypeCheckBlockContextItem ctx = context->block_context ().peek ();
  TyTy::BaseType *lookup = nullptr;
  selfResolveOk
= resolve_associated_type (seg->as_string (), ctx, &lookup);
diff --git a/gcc/rust/typecheck/rust-hir-type-check.h 
b/gcc/rust/typecheck/rust-hir-type-check.h
index 08c3d354f795..ef1f2dd02148 100644
--- a/gcc/rust/typecheck/rust-hir-type-check.h
+++ b/gcc/rust/typecheck/rust-hir-type-check.h
@@ -22,6 +22,7 @@
 #include "rust-hir-map.h"
 #include "rust-tyty.h"
 #include "rust-hir-trait-reference.h"
+#include "rust-stacked-contexts.h"
 #include "rust-autoderef.h"
 #include "rust-tyty-region.h"
 #include "rust-tyty-variance-analysis.h"
@@ -186,10 +187,7 @@ public:
 TyTy::BaseType *return_type);
   void pop_return_type ();
 
-  bool have_block_context () const;
-  TypeCheckBlockContextItem peek_block_context ();
-  void push_block_context (TypeCheckBlockContextItem item);
-  void pop_block_context ();
+  StackedContexts &block_context ();
 
   void iterate (std::function cb);
 
@@ -282,7 +280,7 @@ private:
   std::vector>
 return_type_stack;
   std::vector loop_type_stack;
-  std::vector block_stack;
+  StackedContexts block_stack;
   std::map trait_context

[gcc r15-8550] gccrs: mappings: Move lang_item definitions to .cc

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:6524f82fb901ddf5d2b8d60e220b9ec792d8aeeb

commit r15-8550-g6524f82fb901ddf5d2b8d60e220b9ec792d8aeeb
Author: Arthur Cohen 
Date:   Mon Nov 25 12:37:12 2024 +0100

gccrs: mappings: Move lang_item definitions to .cc

gcc/rust/ChangeLog:

* util/rust-hir-map.h: Move definitions from header...
* util/rust-hir-map.cc: ...to source file.

Diff:
---
 gcc/rust/util/rust-hir-map.cc | 19 +++
 gcc/rust/util/rust-hir-map.h  | 18 ++
 2 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index d1504e108c16..5f77f570073f 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -1258,5 +1258,24 @@ Mappings::lookup_trait_item_lang_item (LangItem::Kind 
item, location_t locus)
   return lookup_trait_item_defid (trait_item_id);
 }
 
+void
+Mappings::insert_lang_item (LangItem::Kind item_type, DefId id)
+{
+  auto it = lang_item_mappings.find (item_type);
+  rust_assert (it == lang_item_mappings.end ());
+
+  lang_item_mappings[item_type] = id;
+}
+
+tl::optional
+Mappings::lookup_lang_item (LangItem::Kind item_type)
+{
+  auto it = lang_item_mappings.find (item_type);
+  if (it == lang_item_mappings.end ())
+return tl::nullopt;
+
+  return it->second;
+}
+
 } // namespace Analysis
 } // namespace Rust
diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h
index bb7318e32ecc..14a0514338b4 100644
--- a/gcc/rust/util/rust-hir-map.h
+++ b/gcc/rust/util/rust-hir-map.h
@@ -256,22 +256,8 @@ public:
 return it->second;
   }
 
-  void insert_lang_item (LangItem::Kind item_type, DefId id)
-  {
-auto it = lang_item_mappings.find (item_type);
-rust_assert (it == lang_item_mappings.end ());
-
-lang_item_mappings[item_type] = id;
-  }
-
-  tl::optional lookup_lang_item (LangItem::Kind item_type)
-  {
-auto it = lang_item_mappings.find (item_type);
-if (it == lang_item_mappings.end ())
-  return tl::nullopt;
-
-return it->second;
-  }
+  void insert_lang_item (LangItem::Kind item_type, DefId id);
+  tl::optional lookup_lang_item (LangItem::Kind item_type);
 
   // This will fatal_error when this lang item does not exist
   DefId get_lang_item (LangItem::Kind item_type, location_t locus);


[gcc(refs/users/meissner/heads/work196)] Add rs6000 architecture masks.

2025-04-05 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:36b4a47d6872ddc0340b002ac8272c283a656327

commit 36b4a47d6872ddc0340b002ac8272c283a656327
Author: Michael Meissner 
Date:   Mon Mar 24 19:17:59 2025 -0400

Add rs6000 architecture masks.

This patch begins the journey to move architecture bits that are not user 
ISA
options from rs6000_isa_flags to a new targt variable rs6000_arch_flags.  
The
intention is to remove switches that are currently isa options, but the user
should not be using this particular option. For example, we want users to 
use
-mcpu=power10 and not just -mpower10.

This patch also changes the target_clones support to use an architecture 
mask
instead of isa bits.

This patch also switches the handling of .machine to use architecture masks 
if
they exist (power4 through power11).  All of the other PowerPCs will 
continue to
use the existing code for setting the .machine option.

I have built both big endian and little endian bootstrap compilers and there
were no regressions.

In addition, I constructed a test case that used every archiecture define 
(like
_ARCH_PWR4, etc.) and I also looked at the .machine directive generated.  I 
ran
this test for all supported combinations of -mcpu, big/little endian, and 
32/64
bit support.  Every single instance generated exactly the same code with the
patches installed compared to the compiler before installing the patches.

The only difference in this patch compared to the first version posted on
November 6th is that I the correct attribution and copyright year (i.e. 
that I
created rs6000-arch.def in 2024).

Can I install this patch on the GCC 15 trunk?

2025-03-24  Michael Meissner  

gcc/

* config/rs6000/default64.h (TARGET_CPU_DEFAULT): Set default cpu 
name.
* config/rs6000/rs6000-arch.def: New file.
* config/rs6000/rs6000.cc (struct clone_map): Switch to using
architecture masks instead of ISA masks.
(rs6000_clone_map): Likewise.
(rs6000_print_isa_options): Add an architecture flags argument, 
change
all callers.
(get_arch_flag): New function.
(rs6000_debug_reg_global): Update rs6000_print_isa_options calls.
(rs6000_option_override_internal): Likewise.
(rs6000_machine_from_flags): Switch to using architecture masks 
instead
of ISA masks.
(struct rs6000_arch_mask): New structure.
(rs6000_arch_masks): New table of architecutre masks and names.
(rs6000_function_specific_save): Save architecture flags.
(rs6000_function_specific_restore): Restore architecture flags.
(rs6000_function_specific_print): Update rs6000_print_isa_options 
calls.
(rs6000_print_options_internal): Add architecture flags options.
(rs6000_clone_priority): Switch to using architecture masks instead 
of
ISA masks.
(rs6000_can_inline_p): Don't allow inling if the callee requires a 
newer
architecture than the caller.
* config/rs6000/rs6000.h: Use rs6000-arch.def to create the 
architecture
masks.
* config/rs6000/rs6000.opt (rs6000_arch_flags): New target variable.
(x_rs6000_arch_flags): New save/restore field for rs6000_arch_flags.

Diff:
---
 gcc/config/rs6000/default64.h |  11 ++
 gcc/config/rs6000/rs6000-arch.def |  49 +
 gcc/config/rs6000/rs6000.cc   | 222 +++---
 gcc/config/rs6000/rs6000.h|  24 +
 gcc/config/rs6000/rs6000.opt  |   8 ++
 5 files changed, 277 insertions(+), 37 deletions(-)

diff --git a/gcc/config/rs6000/default64.h b/gcc/config/rs6000/default64.h
index 7f6001ded852..188f5c1d1378 100644
--- a/gcc/config/rs6000/default64.h
+++ b/gcc/config/rs6000/default64.h
@@ -21,6 +21,7 @@ along with GCC; see the file COPYING3.  If not see
 #define RS6000_CPU(NAME, CPU, FLAGS)
 #include "rs6000-cpus.def"
 #undef RS6000_CPU
+#undef TARGET_CPU_DEFAULT
 
 #if (TARGET_DEFAULT & MASK_LITTLE_ENDIAN)
 #undef TARGET_DEFAULT
@@ -28,10 +29,20 @@ along with GCC; see the file COPYING3.  If not see
| MASK_LITTLE_ENDIAN)
 #undef ASM_DEFAULT_SPEC
 #define ASM_DEFAULT_SPEC "-mpower8"
+#define TARGET_CPU_DEFAULT "power8"
+
 #else
 #undef TARGET_DEFAULT
 #define TARGET_DEFAULT (OPTION_MASK_PPC_GFXOPT | OPTION_MASK_PPC_GPOPT \
| OPTION_MASK_MFCRF | MASK_POWERPC64 | MASK_64BIT)
 #undef ASM_DEFAULT_SPEC
 #define ASM_DEFAULT_SPEC "-mpower4"
+
+#if (TARGET_DEFAULT & MASK_POWERPC64)
+#define TARGET_CPU_DEFAULT "powerpc64"
+
+#else
+#define TARGET_CPU_DEFAULT "powerpc"
+#endif
+
 #endif
diff --git a/gcc/config/rs6000/rs6000-arch.def 
b/gcc/config/rs6000/rs6000-arch.def
new file mode 100644
index ..c0dbc5834333
--- /dev/null
+++ b/gcc/config/rs6000/rs6000-arch.def
@

[gcc(refs/users/meissner/heads/work199-libs)] Add ChangeLog.libs and update REVISION.

2025-04-05 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:0696a01b15dfcfb016994ec98e4c4cdc789c6432

commit 0696a01b15dfcfb016994ec98e4c4cdc789c6432
Author: Michael Meissner 
Date:   Thu Apr 3 15:25:35 2025 -0400

Add ChangeLog.libs and update REVISION.

2025-04-03  Michael Meissner  

gcc/

* ChangeLog.libs: New file for branch.
* REVISION: Update.

Diff:
---
 gcc/ChangeLog.libs | 5 +
 gcc/REVISION   | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog.libs b/gcc/ChangeLog.libs
new file mode 100644
index ..9f21f063f041
--- /dev/null
+++ b/gcc/ChangeLog.libs
@@ -0,0 +1,5 @@
+ Branch work199-libs, baseline 
+
+2025-04-03   Michael Meissner  
+
+   Clone branch
diff --git a/gcc/REVISION b/gcc/REVISION
index 113e419bda0d..b0294b6f088f 100644
--- a/gcc/REVISION
+++ b/gcc/REVISION
@@ -1 +1 @@
-work199 branch
+work199-libs branch


[gcc r14-11416] c++: ICE when substituting packs into type aliases [PR118104]

2025-04-05 Thread Marek Polacek via Gcc-cvs
https://gcc.gnu.org/g:22bdc4d9dd7fd20b4745e810534299bca27c6943

commit r14-11416-g22bdc4d9dd7fd20b4745e810534299bca27c6943
Author: Marek Polacek 
Date:   Mon Mar 17 12:56:40 2025 -0400

c++: ICE when substituting packs into type aliases [PR118104]

r12-1094 mentions that adding the assert didn't lead to any regressions
in the testsuite, but this test case demonstrates that we can reach it
with valid code.

Here we arrive in use_pack_expansion_extra_args_p with t which is an
expansion whose pattern is void(Ts, Us) and tparm packs are {Us, Ts},
and parm_packs is { Ts -> , Us ->  }.  We want to
expand the pack into void(int, A) and void(int, P...).  We compare
int to A, which is fine, but then int to P... which crashes.  But
the code is valid so this patch removes the assert.

PR c++/118104

gcc/cp/ChangeLog:

* pt.cc (use_pack_expansion_extra_args_p): Remove an assert.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/alias-decl-variadic3.C: New test.

Reviewed-by: Jason Merrill 
(cherry picked from commit 6751bd4ac48a8529e2476a6848a77e81de540814)

Diff:
---
 gcc/cp/pt.cc  | 11 ++-
 gcc/testsuite/g++.dg/cpp0x/alias-decl-variadic3.C | 22 ++
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 3369e6218aa5..a1dd428cd10e 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -12973,7 +12973,16 @@ use_pack_expansion_extra_args_p (tree t,
 
   if (has_expansion_arg && has_non_expansion_arg)
{
- gcc_checking_assert (false);
+ /* We can get here with:
+
+ template  struct X {
+   template  using Y = Z;
+ };
+ template 
+ using foo = X::Y;
+
+where we compare int and A and then the second int and P...,
+whose expansion-ness doesn't match, but that's OK.  */
  return true;
}
 }
diff --git a/gcc/testsuite/g++.dg/cpp0x/alias-decl-variadic3.C 
b/gcc/testsuite/g++.dg/cpp0x/alias-decl-variadic3.C
new file mode 100644
index ..077f033d545e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/alias-decl-variadic3.C
@@ -0,0 +1,22 @@
+// PR c++/118104
+// { dg-do compile { target c++11 } }
+
+template struct Z { };
+
+template  struct X {
+  template  using W = Z;
+  template  using Y = X;
+};
+
+template 
+using foo = X::W;
+
+template 
+using bar = X::Y;
+
+void
+g ()
+{
+  foo f;
+  bar b;
+}


[gcc r15-8433] gccrs: Disambiguate generic args during name resolution 2.0

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:c7e00b1e8757f44e2afdb0263c6f0400e44a1f95

commit r15-8433-gc7e00b1e8757f44e2afdb0263c6f0400e44a1f95
Author: Owen Avery 
Date:   Tue Oct 15 23:16:23 2024 -0400

gccrs: Disambiguate generic args during name resolution 2.0

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Visit GenericArgs and GenericArg, the former
because the latter involves a non-virtual member function call.
* resolve/rust-late-name-resolver-2.0.h
(Late::visit): Likewise.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/resolve/rust-late-name-resolver-2.0.cc | 32 +
 gcc/rust/resolve/rust-late-name-resolver-2.0.h  |  2 ++
 2 files changed, 34 insertions(+)

diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
index daf0c871a62c..43f33dfab021 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -275,5 +275,37 @@ Late::visit (AST::StructExprStructFields &s)
   DefaultResolver::visit (s);
 }
 
+// needed because Late::visit (AST::GenericArg &) is non-virtual
+void
+Late::visit (AST::GenericArgs &args)
+{
+  for (auto &lifetime : args.get_lifetime_args ())
+visit (lifetime);
+
+  for (auto &generic : args.get_generic_args ())
+visit (generic);
+
+  for (auto &binding : args.get_binding_args ())
+visit (binding);
+}
+
+void
+Late::visit (AST::GenericArg &arg)
+{
+  if (arg.get_kind () == AST::GenericArg::Kind::Either)
+{
+  // prefer type parameter to const parameter on ambiguity
+  auto type = ctx.types.get (arg.get_path ());
+  auto value = ctx.values.get (arg.get_path ());
+
+  if (!type.has_value () && value.has_value ())
+   arg = arg.disambiguate_to_const ();
+  else
+   arg = arg.disambiguate_to_type ();
+}
+
+  DefaultResolver::visit (arg);
+}
+
 } // namespace Resolver2_0
 } // namespace Rust
diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.h 
b/gcc/rust/resolve/rust-late-name-resolver-2.0.h
index c4d0d82162ef..7e33c9658058 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.h
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.h
@@ -49,6 +49,8 @@ public:
   void visit (AST::StructExprStructBase &) override;
   void visit (AST::StructExprStructFields &) override;
   void visit (AST::StructStruct &) override;
+  void visit (AST::GenericArgs &) override;
+  void visit (AST::GenericArg &);
 
 private:
   /* Setup Rust's builtin types (u8, i32, !...) in the resolver */


[gcc r15-8567] gccrs: nr1.0: Resolve lang item paths properly.

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:70c87e94e11d97dc63d6ffa4862bd4f97c5f25ba

commit r15-8567-g70c87e94e11d97dc63d6ffa4862bd4f97c5f25ba
Author: Arthur Cohen 
Date:   Wed Dec 4 15:14:45 2024 +0100

gccrs: nr1.0: Resolve lang item paths properly.

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Adapt 
resolver
to lang item paths.
* resolve/rust-ast-resolve-type.h: Likewise.

Diff:
---
 gcc/rust/resolve/rust-ast-resolve-item.cc | 30 +++---
 gcc/rust/resolve/rust-ast-resolve-type.h  | 11 +--
 2 files changed, 32 insertions(+), 9 deletions(-)

diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc 
b/gcc/rust/resolve/rust-ast-resolve-item.cc
index a330541b6828..33b4fc9b9792 100644
--- a/gcc/rust/resolve/rust-ast-resolve-item.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-item.cc
@@ -678,16 +678,32 @@ ResolveItem::visit (AST::TraitImpl &impl_block)
   return;
 }
 
+  bool ok = true;
+
   // setup paths
   CanonicalPath canonical_trait_type = CanonicalPath::create_empty ();
-  bool ok = ResolveTypeToCanonicalPath::go (impl_block.get_trait_path_type (),
-   canonical_trait_type);
-  if (!ok)
+  if (impl_block.get_trait_path ().get_path_kind ()
+  == AST::Path::Kind::LangItem)
 {
-  resolver->get_name_scope ().pop ();
-  resolver->get_type_scope ().pop ();
-  resolver->get_label_scope ().pop ();
-  return;
+  auto &lang_item
+   = static_cast (impl_block.get_trait_path ());
+
+  canonical_trait_type
+   = CanonicalPath::new_seg (lang_item.get_node_id (),
+ LangItem::ToString (
+   lang_item.get_lang_item_kind ()));
+}
+  else
+{
+  ok = ResolveTypeToCanonicalPath::go (impl_block.get_trait_path_type (),
+  canonical_trait_type);
+  if (!ok)
+   {
+ resolver->get_name_scope ().pop ();
+ resolver->get_type_scope ().pop ();
+ resolver->get_label_scope ().pop ();
+ return;
+   }
 }
 
   rust_debug ("AST::TraitImpl resolve trait type: {%s}",
diff --git a/gcc/rust/resolve/rust-ast-resolve-type.h 
b/gcc/rust/resolve/rust-ast-resolve-type.h
index ed055a1f04ea..7c3831a28294 100644
--- a/gcc/rust/resolve/rust-ast-resolve-type.h
+++ b/gcc/rust/resolve/rust-ast-resolve-type.h
@@ -21,8 +21,10 @@
 
 #include "rust-ast-resolve-base.h"
 #include "rust-ast-resolve-expr.h"
+#include "rust-diagnostics.h"
 #include "rust-hir-map.h"
 #include "rust-path.h"
+#include "util/rust-hir-map.h"
 
 namespace Rust {
 namespace Resolver {
@@ -69,9 +71,14 @@ public:
   {
auto &type = static_cast (type_path);
 
-   Analysis::Mappings::get_lang_item (type);
+   rust_debug ("[ARTHUR]: lang item kind: %s",
+   LangItem::ToString (type.get_lang_item_kind ()).c_str ());
 
-   type.get_node_id ();
+   auto lang_item = Analysis::Mappings::get ()
+  .lookup_lang_item_node (type.get_lang_item_kind ())
+  .value ();
+
+   return lang_item;
   }
 
 rust_assert (type_path.get_path_kind () == AST::Path::Kind::Type);


[gcc r15-9081] gccrs: lower: Handle let-else properly

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:b31e1976cb0fe767db81febc6a30a6cc0b8f243a

commit r15-9081-gb31e1976cb0fe767db81febc6a30a6cc0b8f243a
Author: Arthur Cohen 
Date:   Wed Mar 5 15:36:19 2025 +

gccrs: lower: Handle let-else properly

gcc/rust/ChangeLog:

* hir/tree/rust-hir-stmt.h (class LetStmt): Add optional diverging 
else expression.
* hir/tree/rust-hir-stmt.cc: Likewise.
* hir/rust-ast-lower-stmt.cc (ASTLoweringStmt::visit): Add handling 
for lowering
diverging else.

Diff:
---
 gcc/rust/hir/rust-ast-lower-stmt.cc | 14 ++
 gcc/rust/hir/tree/rust-hir-stmt.cc  | 12 +++-
 gcc/rust/hir/tree/rust-hir-stmt.h   | 16 
 3 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/gcc/rust/hir/rust-ast-lower-stmt.cc 
b/gcc/rust/hir/rust-ast-lower-stmt.cc
index fd2cdfb0f115..dbb1723dfc5f 100644
--- a/gcc/rust/hir/rust-ast-lower-stmt.cc
+++ b/gcc/rust/hir/rust-ast-lower-stmt.cc
@@ -76,20 +76,26 @@ ASTLoweringStmt::visit (AST::LetStmt &stmt)
 type
   = std::unique_ptr (ASTLoweringType::translate (stmt.get_type ()));
 
-  tl::optional> init_expression = tl::nullopt;
+  tl::optional> init_expr = tl::nullopt;
+  tl::optional> else_expr = tl::nullopt;
 
   if (stmt.has_init_expr ())
-init_expression = std::unique_ptr (
+init_expr = std::unique_ptr (
   ASTLoweringExpr::translate (stmt.get_init_expr ()));
 
+  if (stmt.has_else_expr ())
+else_expr = std::unique_ptr (
+  ASTLoweringExpr::translate (stmt.get_else_expr ()));
+
   auto crate_num = mappings.get_current_crate ();
   Analysis::NodeMapping mapping (crate_num, stmt.get_node_id (),
 mappings.get_next_hir_id (crate_num),
 UNKNOWN_LOCAL_DEFID);
   translated
 = new HIR::LetStmt (mapping, std::unique_ptr (variables),
-   std::move (init_expression), std::move (type),
-   stmt.get_outer_attrs (), stmt.get_locus ());
+   std::move (init_expr), std::move (else_expr),
+   std::move (type), stmt.get_outer_attrs (),
+   stmt.get_locus ());
 }
 
 void
diff --git a/gcc/rust/hir/tree/rust-hir-stmt.cc 
b/gcc/rust/hir/tree/rust-hir-stmt.cc
index 025f67e2c9b1..fd58e29c7f8d 100644
--- a/gcc/rust/hir/tree/rust-hir-stmt.cc
+++ b/gcc/rust/hir/tree/rust-hir-stmt.cc
@@ -26,11 +26,13 @@ namespace HIR {
 LetStmt::LetStmt (Analysis::NodeMapping mappings,
  std::unique_ptr variables_pattern,
  tl::optional> init_expr,
+ tl::optional> else_expr,
  tl::optional> type,
  AST::AttrVec outer_attrs, location_t locus)
   : Stmt (std::move (mappings)), outer_attrs (std::move (outer_attrs)),
 variables_pattern (std::move (variables_pattern)), type (std::move (type)),
-init_expr (std::move (init_expr)), locus (locus)
+init_expr (std::move (init_expr)), else_expr (std::move (else_expr)),
+locus (locus)
 {}
 
 LetStmt::LetStmt (LetStmt const &other)
@@ -43,6 +45,8 @@ LetStmt::LetStmt (LetStmt const &other)
   // guard to prevent null dereference (always required)
   if (other.has_init_expr ())
 init_expr = other.get_init_expr ().clone_expr ();
+  if (other.has_else_expr ())
+else_expr = other.get_else_expr ().clone_expr ();
 
   if (other.has_type ())
 type = other.get_type ().clone_type ();
@@ -67,6 +71,12 @@ LetStmt::operator= (LetStmt const &other)
 init_expr = other.get_init_expr ().clone_expr ();
   else
 init_expr = nullptr;
+
+  if (other.has_else_expr ())
+else_expr = other.get_else_expr ().clone_expr ();
+  else
+else_expr = tl::nullopt;
+
   if (other.has_type ())
 type = other.get_type ().clone_type ();
   else
diff --git a/gcc/rust/hir/tree/rust-hir-stmt.h 
b/gcc/rust/hir/tree/rust-hir-stmt.h
index 3db1728202ee..9c1a9eccc385 100644
--- a/gcc/rust/hir/tree/rust-hir-stmt.h
+++ b/gcc/rust/hir/tree/rust-hir-stmt.h
@@ -101,6 +101,7 @@ class LetStmt : public Stmt
   tl::optional> type;
 
   tl::optional> init_expr;
+  tl::optional> else_expr;
 
   location_t locus;
 
@@ -113,12 +114,15 @@ public:
 
   // Returns whether let statement has an initialisation expression.
   bool has_init_expr () const { return init_expr.has_value (); }
+  // Returns whether let statement has a diverging else expression.
+  bool has_else_expr () const { return else_expr.has_value (); }
 
   std::string as_string () const override;
 
   LetStmt (Analysis::NodeMapping mappings,
   std::unique_ptr variables_pattern,
   tl::optional> init_expr,
+  tl::optional> else_expr,
   tl::optional> type, AST::AttrVec outer_attrs,
   location_t locus);
 
@@ -167,6 +171,18 @@ public:
 return *init_expr.value ();
   }
 
+  HIR::Expr &get_else_expr ()
+  {
+rust_assert (*else_expr);
+return *else_expr.value ();
+  }
+
+  const HIR::Expr &get_else_expr () const
+  {
+ru

[gcc/devel/rust/master] Lower raw string literals

2025-04-05 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:75ef9fd3ffc6ef0759cf9fa359c94bfa4fde1235

commit 75ef9fd3ffc6ef0759cf9fa359c94bfa4fde1235
Author: Owen Avery 
Date:   Tue Mar 25 18:50:56 2025 -0400

Lower raw string literals

gcc/rust/ChangeLog:

* hir/rust-ast-lower-base.cc
(ASTLoweringBase::lower_literal): Lower raw string literals into
normal string literals.

gcc/testsuite/ChangeLog:

* rust/compile/issue-3549.rs: New test.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/hir/rust-ast-lower-base.cc  | 4 ++--
 gcc/testsuite/rust/compile/issue-3549.rs | 3 +++
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/hir/rust-ast-lower-base.cc 
b/gcc/rust/hir/rust-ast-lower-base.cc
index 52781da1eaf5..749fe09f3baa 100644
--- a/gcc/rust/hir/rust-ast-lower-base.cc
+++ b/gcc/rust/hir/rust-ast-lower-base.cc
@@ -933,8 +933,8 @@ 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 ();
+case AST::Literal::LitType::RAW_STRING:
+  type = HIR::Literal::LitType::STRING;
   break;
 case AST::Literal::LitType::INT:
   type = HIR::Literal::LitType::INT;
diff --git a/gcc/testsuite/rust/compile/issue-3549.rs 
b/gcc/testsuite/rust/compile/issue-3549.rs
new file mode 100644
index ..cedbb5a02b55
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3549.rs
@@ -0,0 +1,3 @@
+fn main() {
+r#""#;
+}


[gcc(refs/users/meissner/heads/work199-paddis)] Merge commit 'refs/users/meissner/heads/work199-paddis' of git+ssh://gcc.gnu.org/git/gcc into me/wor

2025-04-05 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:b130aa485b39e66a5d0b6b286d6cc8b9ba8143ed

commit b130aa485b39e66a5d0b6b286d6cc8b9ba8143ed
Merge: c53b3461e27e 3d09f8d126ca
Author: Michael Meissner 
Date:   Thu Apr 3 16:29:20 2025 -0400

Merge commit 'refs/users/meissner/heads/work199-paddis' of 
git+ssh://gcc.gnu.org/git/gcc into me/work199-paddis

Diff:


[gcc r15-8547] gccrs: allow casts from numeric types to floats

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:80bc600efeb6d2e4342da3e558cd2b5562e78477

commit r15-8547-g80bc600efeb6d2e4342da3e558cd2b5562e78477
Author: Philip Herron 
Date:   Tue Nov 26 15:33:35 2024 +

gccrs: allow casts from numeric types to floats

Fixes Rust-GCC#3261

gcc/rust/ChangeLog:

* typecheck/rust-casts.cc (TypeCastRules::cast_rules): allow casts 
to float

gcc/testsuite/ChangeLog:

* rust/compile/issue-3261.rs: New test.

Signed-off-by: Philip Herron 

Diff:
---
 gcc/rust/typecheck/rust-casts.cc | 10 ++
 gcc/testsuite/rust/compile/issue-3261.rs | 18 ++
 2 files changed, 28 insertions(+)

diff --git a/gcc/rust/typecheck/rust-casts.cc b/gcc/rust/typecheck/rust-casts.cc
index 5235069fa231..cf4de4b33205 100644
--- a/gcc/rust/typecheck/rust-casts.cc
+++ b/gcc/rust/typecheck/rust-casts.cc
@@ -200,6 +200,16 @@ TypeCastRules::cast_rules ()
  }
  break;
 
+ case TyTy::TypeKind::FLOAT: {
+   // can only do this for number types not char
+   bool from_char
+ = from.get_ty ()->get_kind () == TyTy::TypeKind::CHAR;
+   if (!from_char)
+ return TypeCoercionRules::CoercionResult{{},
+  to.get_ty ()->clone ()};
+ }
+ break;
+
case TyTy::TypeKind::INFER:
case TyTy::TypeKind::USIZE:
case TyTy::TypeKind::ISIZE:
diff --git a/gcc/testsuite/rust/compile/issue-3261.rs 
b/gcc/testsuite/rust/compile/issue-3261.rs
new file mode 100644
index ..37e974d61696
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3261.rs
@@ -0,0 +1,18 @@
+// { dg-options "-w" }
+fn main() {
+let a: i8 = 50;
+let b = a as f32;
+let c = a as f64;
+
+let a: i16 = 1337;
+let b = a as f32;
+let c = a as f64;
+
+let a: i32 = 1337;
+let b = a as f32;
+let c = a as f64;
+
+let a: i64 = 1337;
+let b = a as f32;
+let c = a as f64;
+}


[gcc r15-9103] gccrs: Fix ICE in array ref constexpr

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:a0b0d2a58ec8b830d0a88039709e2002b32dc2a8

commit r15-9103-ga0b0d2a58ec8b830d0a88039709e2002b32dc2a8
Author: Philip Herron 
Date:   Fri Mar 28 16:59:33 2025 +

gccrs: Fix ICE in array ref constexpr

Since 898d55ad7e2 was fixed to remove the VIEW_CONVERT_EXPR from
array expressions we can now turn on the array element access
const expr.

Fixes Rust-GCC#3563

gcc/rust/ChangeLog:

* backend/rust-constexpr.cc (eval_store_expression): turn this back 
on

gcc/testsuite/ChangeLog:

* rust/compile/issue-3563.rs: New test.

Signed-off-by: Philip Herron 

Diff:
---
 gcc/rust/backend/rust-constexpr.cc   |  6 ++
 gcc/testsuite/rust/compile/issue-3563.rs | 17 +
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/backend/rust-constexpr.cc 
b/gcc/rust/backend/rust-constexpr.cc
index 2f2bbbd921d1..dc2d6b1066be 100644
--- a/gcc/rust/backend/rust-constexpr.cc
+++ b/gcc/rust/backend/rust-constexpr.cc
@@ -2697,10 +2697,8 @@ eval_store_expression (const constexpr_ctx *ctx, tree t, 
bool lval,
  }
if (TREE_CODE (probe) == ARRAY_REF)
  {
-   // TODO
-   rust_unreachable ();
-   // elt = eval_and_check_array_index (ctx, probe, false,
-   //non_constant_p, overflow_p);
+   elt = eval_and_check_array_index (ctx, probe, false,
+ non_constant_p, overflow_p);
if (*non_constant_p)
  return t;
  }
diff --git a/gcc/testsuite/rust/compile/issue-3563.rs 
b/gcc/testsuite/rust/compile/issue-3563.rs
new file mode 100644
index ..46e762464b82
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3563.rs
@@ -0,0 +1,17 @@
+pub struct AA {
+pub data: [u8; 10],
+}
+
+impl AA {
+pub const fn new() -> Self {
+let mut res: AA = AA { data: [0; 10] };
+res.data[0] = 5;
+res
+}
+}
+
+static mut BB: AA = AA::new();
+
+fn main() {
+let _ptr = unsafe { &mut BB };
+}


[gcc/devel/rust/master] Remove now passing test from exclusion list

2025-04-05 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:b79c452e07cae14be97ba9ebc175f1497a45bbbd

commit b79c452e07cae14be97ba9ebc175f1497a45bbbd
Author: Pierre-Emmanuel Patry 
Date:   Thu Mar 20 17:13:36 2025 +0100

Remove now passing test from exclusion list

Those tests were malformed and failed with the new name resolution
because of it.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove test from exclusion list.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/testsuite/rust/compile/nr2/exclude | 5 -
 1 file changed, 5 deletions(-)

diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index 1582d5a2d969..45e90a4df933 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -2,8 +2,6 @@ canonical_paths1.rs
 cfg1.rs
 const_generics_3.rs
 generics9.rs
-issue-1901.rs
-issue-1981.rs
 issue-2043.rs
 issue-2330.rs
 issue-2812.rs
@@ -21,7 +19,6 @@ privacy8.rs
 pub_restricted_1.rs
 pub_restricted_2.rs
 pub_restricted_3.rs
-sizeof-stray-infer-var-bug.rs
 undeclared_label.rs
 use_1.rs
 while_break_expr.rs
@@ -37,9 +34,7 @@ issue-3403.rs
 derive-eq-invalid.rs
 derive-hash1.rs
 torture/alt_patterns1.rs
-torture/builtin_abort.rs
 torture/loop4.rs
 torture/loop8.rs
 torture/name_resolve1.rs
-torture/uninit-intrinsic-1.rs
 # please don't delete the trailing newline


[gcc/devel/rust/master] ast: Add optional diverging else to AST::LetStmt

2025-04-05 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:b257ae69e13b870cdbf477cfcbb6aa53794f232a

commit b257ae69e13b870cdbf477cfcbb6aa53794f232a
Author: Arthur Cohen 
Date:   Wed Mar 5 15:31:56 2025 +

ast: Add optional diverging else to AST::LetStmt

gcc/rust/ChangeLog:

* ast/rust-stmt.h (class LetStmt): Add optional expression for 
diverging else.
* ast/rust-ast-builder.cc (Builder::let): Use new API.

Diff:
---
 gcc/rust/ast/rust-ast-builder.cc |  3 ++-
 gcc/rust/ast/rust-stmt.h | 29 -
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/ast/rust-ast-builder.cc b/gcc/rust/ast/rust-ast-builder.cc
index 58c37a5aa5f7..2e3685f2b198 100644
--- a/gcc/rust/ast/rust-ast-builder.cc
+++ b/gcc/rust/ast/rust-ast-builder.cc
@@ -17,6 +17,7 @@
 // .
 
 #include "rust-ast-builder.h"
+#include "optional.h"
 #include "rust-ast-builder-type.h"
 #include "rust-ast.h"
 #include "rust-common.h"
@@ -352,7 +353,7 @@ Builder::let (std::unique_ptr &&pattern, 
std::unique_ptr &&type,
 {
   return std::unique_ptr (new LetStmt (std::move (pattern),
 std::move (init), std::move (type),
-{}, loc));
+tl::nullopt, {}, loc));
 }
 
 std::unique_ptr
diff --git a/gcc/rust/ast/rust-stmt.h b/gcc/rust/ast/rust-stmt.h
index afe48f271c19..e64fbe4acd0a 100644
--- a/gcc/rust/ast/rust-stmt.h
+++ b/gcc/rust/ast/rust-stmt.h
@@ -19,6 +19,7 @@
 #ifndef RUST_AST_STATEMENT_H
 #define RUST_AST_STATEMENT_H
 
+#include "optional.h"
 #include "rust-ast.h"
 #include "rust-path.h"
 #include "rust-expr.h"
@@ -72,6 +73,8 @@ class LetStmt : public Stmt
   // bool has_init_expr;
   std::unique_ptr init_expr;
 
+  tl::optional> else_expr;
+
   location_t locus;
 
 public:
@@ -85,15 +88,18 @@ public:
 
   // Returns whether let statement has an initialisation expression.
   bool has_init_expr () const { return init_expr != nullptr; }
+  bool has_else_expr () const { return else_expr.has_value (); }
 
   std::string as_string () const override;
 
   LetStmt (std::unique_ptr variables_pattern,
   std::unique_ptr init_expr, std::unique_ptr type,
+  tl::optional> else_expr,
   std::vector outer_attrs, location_t locus)
 : outer_attrs (std::move (outer_attrs)),
   variables_pattern (std::move (variables_pattern)),
-  type (std::move (type)), init_expr (std::move (init_expr)), locus (locus)
+  type (std::move (type)), init_expr (std::move (init_expr)),
+  else_expr (std::move (else_expr)), locus (locus)
   {}
 
   // Copy constructor with clone
@@ -107,6 +113,9 @@ public:
 // guard to prevent null dereference (always required)
 if (other.init_expr != nullptr)
   init_expr = other.init_expr->clone_expr ();
+if (other.else_expr.has_value ())
+  else_expr = other.else_expr.value ()->clone_expr ();
+
 if (other.type != nullptr)
   type = other.type->clone_type ();
   }
@@ -128,6 +137,12 @@ public:
   init_expr = other.init_expr->clone_expr ();
 else
   init_expr = nullptr;
+
+if (other.else_expr != nullptr)
+  else_expr = other.else_expr.value ()->clone_expr ();
+else
+  else_expr = tl::nullopt;
+
 if (other.type != nullptr)
   type = other.type->clone_type ();
 else
@@ -162,12 +177,24 @@ public:
 return *init_expr;
   }
 
+  Expr &get_else_expr ()
+  {
+rust_assert (has_else_expr ());
+return *else_expr.value ();
+  }
+
   std::unique_ptr &get_init_expr_ptr ()
   {
 rust_assert (has_init_expr ());
 return init_expr;
   }
 
+  std::unique_ptr &get_else_expr_ptr ()
+  {
+rust_assert (has_else_expr ());
+return else_expr.value ();
+  }
+
   Pattern &get_pattern ()
   {
 rust_assert (variables_pattern != nullptr);


[gcc r15-8241] [RISC-V] Fix unreported code quality regression with single bit manipulations

2025-04-05 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:d9a8ec7fe0cbc04e28e650f079952bf529ae612e

commit r15-8241-gd9a8ec7fe0cbc04e28e650f079952bf529ae612e
Author: Jeff Law 
Date:   Mon Mar 17 17:29:42 2025 -0600

[RISC-V] Fix unreported code quality regression with single bit 
manipulations

I was reviewing some code recently and spotted an oddity.  In a few places 
we
were emitting andi dst,src,-1 and in others [x]ori dst,src,0. Those are
obviously nops and we should get rid of them.

Most of these are coming from a split part of a couple define_insn_and_split
patterns added back in late 2022, so this is an unreported 13, 14 & 15 code
quality regression (verified on godbolt, https://godbolt.org/z/EPszox5Kd).
Essentially the split part is matching over-aggressively and splitting what
should be a trivial bitmanip insn such as bset, bclr or binv into a nop 
logical
with a bit twiddle.

Since the split portions trigger post-reload nothing comes along to remove 
the
nop logical operations.

The fix is trivial.  Just refine the condition.  I considered refining the
operand predicates too.  Both are valid approaches.  I noticed the 
formatting
was goofy, so fixed that while I was in there.

I'm aware of one other similar case, but I haven't concluded if it's a
regression or not.

Tested in my tester.  Waiting for pre-commit CI to do its thing.

Jeff

gcc/
* config/riscv/bitmanip.md (*i_extrabit): Reject 
cases
where we only need to twiddle one bit.  Fix formatting.
(*andiextrabit): Likewise.

gcc/testsuite/

* gcc.target/riscv/redundant-andi.c: New test.
* gcc.target/riscv/redundant-ori.c: Likewise

Diff:
---
 gcc/config/riscv/bitmanip.md| 20 ++--
 gcc/testsuite/gcc.target/riscv/redundant-andi.c | 41 +
 gcc/testsuite/gcc.target/riscv/redundant-ori.c  | 18 +++
 3 files changed, 69 insertions(+), 10 deletions(-)

diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md
index 684e5d2ae8b6..b29c127bcb84 100644
--- a/gcc/config/riscv/bitmanip.md
+++ b/gcc/config/riscv/bitmanip.md
@@ -1017,17 +1017,17 @@
   [(set (match_operand:X 0 "register_operand" "=r")
(any_or:X (match_operand:X 1 "register_operand" "r")
  (match_operand:X 2 "uimm_extra_bit_or_twobits" "i")))]
-  "TARGET_ZBS"
+  "TARGET_ZBS && !single_bit_mask_operand (operands[2], VOIDmode)"
   "#"
   "&& reload_completed"
   [(set (match_dup 0) (:X (match_dup 1) (match_dup 3)))
(set (match_dup 0) (:X (match_dup 0) (match_dup 4)))]
 {
-   unsigned HOST_WIDE_INT bits = UINTVAL (operands[2]);
-   unsigned HOST_WIDE_INT topbit = HOST_WIDE_INT_1U << floor_log2 (bits);
+  unsigned HOST_WIDE_INT bits = UINTVAL (operands[2]);
+  unsigned HOST_WIDE_INT topbit = HOST_WIDE_INT_1U << floor_log2 (bits);
 
-   operands[3] = GEN_INT (bits &~ topbit);
-   operands[4] = GEN_INT (topbit);
+  operands[3] = GEN_INT (bits &~ topbit);
+  operands[4] = GEN_INT (topbit);
 }
 [(set_attr "type" "bitmanip")])
 
@@ -1036,17 +1036,17 @@
   [(set (match_operand:X 0 "register_operand" "=r")
(and:X (match_operand:X 1 "register_operand" "r")
   (match_operand:X 2 "not_uimm_extra_bit_or_nottwobits" "i")))]
-  "TARGET_ZBS"
+  "TARGET_ZBS && !not_single_bit_mask_operand (operands[2], VOIDmode)"
   "#"
   "&& reload_completed"
   [(set (match_dup 0) (and:X (match_dup 1) (match_dup 3)))
(set (match_dup 0) (and:X (match_dup 0) (match_dup 4)))]
 {
-   unsigned HOST_WIDE_INT bits = UINTVAL (operands[2]);
-   unsigned HOST_WIDE_INT topbit = HOST_WIDE_INT_1U << floor_log2 (~bits);
+  unsigned HOST_WIDE_INT bits = UINTVAL (operands[2]);
+  unsigned HOST_WIDE_INT topbit = HOST_WIDE_INT_1U << floor_log2 (~bits);
 
-   operands[3] = GEN_INT (bits | topbit);
-   operands[4] = GEN_INT (~topbit);
+  operands[3] = GEN_INT (bits | topbit);
+  operands[4] = GEN_INT (~topbit);
 }
 [(set_attr "type" "bitmanip")])
 
diff --git a/gcc/testsuite/gcc.target/riscv/redundant-andi.c 
b/gcc/testsuite/gcc.target/riscv/redundant-andi.c
new file mode 100644
index ..8945fafb
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/redundant-andi.c
@@ -0,0 +1,41 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gcb -mabi=lp64" } */
+/* { dg-skip-if "" { *-*-* } { "-O0" } } */
+
+
+typedef struct sv SV;
+
+typedef struct magic MAGIC;
+typedef short I16;
+typedef unsigned short U16;
+typedef int I32;
+typedef unsigned int U32;
+struct sv
+{
+  U32 sv_refcnt;
+  U32 sv_flags;
+};
+struct magic
+{
+  U16 mg_private;
+};
+extern SV **PL_psig_ptr;
+int
+Perl_magic_setsig (SV *sv, MAGIC *mg, const char *s)
+{
+  I32 i;
+  i = (I16) mg->mg_private;
+  if (sv)
+{
+  PL_psig_ptr[i] = (++((sv)->sv_refcnt), ((SV *) ((void *) (sv;
+  ((sv)->sv_flags &= ~0x0008);
+}
+  else
+{
+  PL_psig_pt

[gcc r15-8637] gccrs: ast-builder: Add new methods for building structs

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:8dedd0d11ddb3c999530edf6c810b1aa7ca7378b

commit r15-8637-g8dedd0d11ddb3c999530edf6c810b1aa7ca7378b
Author: Arthur Cohen 
Date:   Fri Jan 3 14:27:38 2025 +

gccrs: ast-builder: Add new methods for building structs

gcc/rust/ChangeLog:

* ast/rust-ast-builder.cc: Add new methods for constructing struct 
exprs.
* ast/rust-ast-builder.h: Mention how to build tuple expressions.

Diff:
---
 gcc/rust/ast/rust-ast-builder.cc | 12 ++--
 gcc/rust/ast/rust-ast-builder.h  |  5 +
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/ast/rust-ast-builder.cc b/gcc/rust/ast/rust-ast-builder.cc
index fe80924fece7..47044df91714 100644
--- a/gcc/rust/ast/rust-ast-builder.cc
+++ b/gcc/rust/ast/rust-ast-builder.cc
@@ -24,6 +24,7 @@
 #include "rust-path.h"
 #include "rust-item.h"
 #include "rust-path.h"
+#include "rust-system.h"
 #include "rust-token.h"
 
 namespace Rust {
@@ -261,10 +262,17 @@ std::unique_ptr
 Builder::struct_expr (
   std::string struct_name,
   std::vector> &&fields) const
+{
+  return struct_expr (path_in_expression ({struct_name}), std::move (fields));
+}
+
+std::unique_ptr
+Builder::struct_expr (
+  PathInExpression struct_name,
+  std::vector> &&fields) const
 {
   return std::unique_ptr (
-new StructExprStructFields (path_in_expression ({struct_name}),
-   std::move (fields), loc));
+new StructExprStructFields (struct_name, std::move (fields), loc));
 }
 
 std::unique_ptr
diff --git a/gcc/rust/ast/rust-ast-builder.h b/gcc/rust/ast/rust-ast-builder.h
index 624cd715181d..e5bae6ed6e95 100644
--- a/gcc/rust/ast/rust-ast-builder.h
+++ b/gcc/rust/ast/rust-ast-builder.h
@@ -160,10 +160,15 @@ public:
 
   /**
* Create an expression for struct instantiation with fields (`S { a, b: c 
}`)
+   * Tuple expressions are call expressions and can thus be constructed with
+   * `call`
*/
   std::unique_ptr
   struct_expr (std::string struct_name,
   std::vector> &&fields) const;
+  std::unique_ptr
+  struct_expr (PathInExpression struct_name,
+  std::vector> &&fields) const;
 
   /* Create a field expression for struct instantiation (`field_name: value`) 
*/
   std::unique_ptr


[gcc r15-8578] gccrs: resolve: Name resolve trait bounds properly

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:c0640954e1a340764368a10f3b7774696e32a8ae

commit r15-8578-gc0640954e1a340764368a10f3b7774696e32a8ae
Author: Arthur Cohen 
Date:   Wed Dec 25 11:03:44 2024 +

gccrs: resolve: Name resolve trait bounds properly

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-type.cc 
(ResolveTypeToCanonicalPath::visit): Resolve additional
trait bounds.
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Error out 
properly on unresolved
type-path instead of crashing.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Exclude additional-trait-bounds2 for 
different error message.
* rust/compile/additional-trait-bounds1.rs: New test.
* rust/compile/additional-trait-bounds2.rs: New test.
* rust/compile/additional-trait-bounds2nr2.rs: New test.

Diff:
---
 gcc/rust/resolve/rust-ast-resolve-type.cc  | 57 --
 gcc/rust/resolve/rust-late-name-resolver-2.0.cc|  3 +-
 .../rust/compile/additional-trait-bounds1.rs   | 10 
 .../rust/compile/additional-trait-bounds2.rs   |  9 
 .../rust/compile/additional-trait-bounds2nr2.rs| 11 +
 gcc/testsuite/rust/compile/nr2/exclude |  1 +
 6 files changed, 87 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/resolve/rust-ast-resolve-type.cc 
b/gcc/rust/resolve/rust-ast-resolve-type.cc
index ec5e8a762a70..cb5a18d5d477 100644
--- a/gcc/rust/resolve/rust-ast-resolve-type.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-type.cc
@@ -18,6 +18,8 @@
 
 #include "rust-ast-resolve-type.h"
 #include "rust-ast-resolve-expr.h"
+#include "rust-canonical-path.h"
+#include "rust-type.h"
 
 namespace Rust {
 namespace Resolver {
@@ -495,10 +497,59 @@ ResolveTypeToCanonicalPath::visit 
(AST::TraitObjectTypeOneBound &type)
 }
 
 void
-ResolveTypeToCanonicalPath::visit (AST::TraitObjectType &)
+ResolveTypeToCanonicalPath::visit (AST::TraitObjectType &type)
 {
-  // FIXME is this actually allowed? dyn A+B
-  rust_unreachable ();
+  rust_assert (!type.get_type_param_bounds ().empty ());
+
+  auto &first_bound = type.get_type_param_bounds ().front ();
+
+  // Is it allowed or even possible to have a lifetime bound as a first bound?
+  if (first_bound->get_bound_type () == AST::TraitBound::LIFETIME)
+rust_unreachable ();
+
+  auto &trait = static_cast (*first_bound);
+
+  CanonicalPath path = CanonicalPath::create_empty ();
+  bool ok = ResolveTypeToCanonicalPath::go (trait.get_type_path (), path);
+
+  // right?
+  rust_assert (ok);
+
+  auto slice_path = "get_bound_type ())
+   {
+ case AST::TypeParamBound::TRAIT: {
+   auto bound_path = CanonicalPath::create_empty ();
+
+   auto &bound_type_path
+ = static_cast (*additional_bound)
+ .get_type_path ();
+   bool ok
+ = ResolveTypeToCanonicalPath::go (bound_type_path, bound_path);
+
+   if (!ok)
+ continue;
+
+   str = bound_path.get ();
+   break;
+ }
+   case AST::TypeParamBound::LIFETIME:
+ rust_unreachable ();
+ break;
+   }
+  slice_path += " + " + str;
+}
+
+  slice_path += ">";
+
+  result = CanonicalPath::new_seg (type.get_node_id (), slice_path);
 }
 
 void
diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
index ac5f1c575461..40f067319b57 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -282,7 +282,8 @@ Late::visit (AST::TypePath &type)
 ctx.map_usage (Usage (type.get_node_id ()),
   Definition (resolved->get_node_id ()));
   else
-rust_unreachable ();
+rust_error_at (type.get_locus (), "could not resolve type path %qs",
+  str.c_str ());
 
   DefaultResolver::visit (type);
 }
diff --git a/gcc/testsuite/rust/compile/additional-trait-bounds1.rs 
b/gcc/testsuite/rust/compile/additional-trait-bounds1.rs
new file mode 100644
index ..449a72fe4612
--- /dev/null
+++ b/gcc/testsuite/rust/compile/additional-trait-bounds1.rs
@@ -0,0 +1,10 @@
+#![feature(optin_builtin_traits)]
+
+pub unsafe auto trait Send {}
+#[lang = "sync"]
+pub unsafe auto trait Sync {}
+
+trait A {}
+
+impl dyn A + Send {}
+impl dyn A + Send + Sync {}
diff --git a/gcc/testsuite/rust/compile/additional-trait-bounds2.rs 
b/gcc/testsuite/rust/compile/additional-trait-bounds2.rs
new file mode 100644
index ..843228ae9a64
--- /dev/null
+++ b/gcc/testsuite/rust/compile/additional-trait-bounds2.rs
@@ -0,0 +1,9 @@
+#![feature(optin_builtin_traits)]
+
+pub unsafe auto trait Send {}
+#[lang = "sync"]
+pub unsafe auto trait Sync {}
+
+trait A {}
+
+impl dyn A + Send + Sync + NonExist {} // { dg-error "failed to resolve 
TypePath: NonExist in this scope" }
diff --git a/gcc/testsuite/rust/compile/additional-trait-bounds2nr2.rs 
b/gcc/testsuite/rust/c

[gcc(refs/users/meissner/heads/work196-sha)] Add ChangeLog.sha and update REVISION.

2025-04-05 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:e76a94bcd793942fe451534c3af72b9b32bb4767

commit e76a94bcd793942fe451534c3af72b9b32bb4767
Author: Michael Meissner 
Date:   Mon Mar 24 18:46:18 2025 -0400

Add ChangeLog.sha and update REVISION.

2025-03-24  Michael Meissner  

gcc/

* ChangeLog.sha: New file for branch.
* REVISION: Update.

Diff:
---
 gcc/ChangeLog.sha | 5 +
 gcc/REVISION  | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog.sha b/gcc/ChangeLog.sha
new file mode 100644
index ..a0b372938ef1
--- /dev/null
+++ b/gcc/ChangeLog.sha
@@ -0,0 +1,5 @@
+ Branch work196-sha, baseline 
+
+2025-03-24   Michael Meissner  
+
+   Clone branch
diff --git a/gcc/REVISION b/gcc/REVISION
index 4879f9dc9d4e..0f1987bb7cb2 100644
--- a/gcc/REVISION
+++ b/gcc/REVISION
@@ -1 +1 @@
-work196 branch
+work196-sha branch


[gcc(refs/users/meissner/heads/work196)] Add support for -mcpu=future

2025-04-05 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:81c30dcda087186b1286486189ea2a7d8e5ec08e

commit 81c30dcda087186b1286486189ea2a7d8e5ec08e
Author: Michael Meissner 
Date:   Mon Mar 24 19:11:21 2025 -0400

Add support for -mcpu=future

This patch adds the support that can be used in developing GCC support for
future PowerPC processors.

2025-03-24  Michael Meissner  

* config.gcc (powerpc*-*-*): Add support for --with-cpu=future.
* config/rs6000/aix71.h (ASM_CPU_SPEC): Add support for 
-mcpu=future.
* config/rs6000/aix72.h (ASM_CPU_SPEC): Likewise.
* config/rs6000/aix73.h (ASM_CPU_SPEC): Likewise.
* config/rs6000/driver-rs6000.cc (asm_names): Likewise.
* config/rs6000/rs6000-c.cc (rs6000_target_modify_macros): If
-mcpu=future, define _ARCH_FUTURE.
* config/rs6000/rs6000-cpus.def (FUTURE_MASKS_SERVER): New macro.
(POWERPC_MASKS): Add OPTION_MASK_FUTURE.
(future cpu): Define.
* config/rs6000/rs6000-opts.h (enum processor_type): Add
PROCESSOR_FUTURE.
* config/rs6000/rs6000-tables.opt: Regenerate.
* config/rs6000/rs6000.cc (power10_cost): Update comment.
(get_arch_flags): Add support for future processor.
(rs6000_option_override_internal): Likewise.
(rs6000_machine_from_flags): Likewise.
(rs6000_reassociation_width): Likewise.
(rs6000_adjust_cost): Likewise.
(rs6000_issue_rate): Likewise.
(rs6000_sched_reorder): Likewise.
(rs6000_sched_reorder2): Likewise.
(rs6000_register_move_cost): Likewise.
(rs6000_opt_masks): Add -mfuture.
* config/rs6000/rs6000.h (ASM_CPU_SPEC): Likewise.
* config/rs6000/rs6000.md (cpu attribute): Likewise.
* config/rs6000/rs6000.opt (-mfuture): New internal option.

Diff:
---
 gcc/config.gcc  |  4 ++--
 gcc/config/rs6000/aix71.h   |  1 +
 gcc/config/rs6000/aix72.h   |  1 +
 gcc/config/rs6000/aix73.h   |  1 +
 gcc/config/rs6000/driver-rs6000.cc  |  2 ++
 gcc/config/rs6000/rs6000-c.cc   |  2 ++
 gcc/config/rs6000/rs6000-cpus.def   |  5 +
 gcc/config/rs6000/rs6000-opts.h |  1 +
 gcc/config/rs6000/rs6000-tables.opt | 11 +++
 gcc/config/rs6000/rs6000.cc | 30 ++
 gcc/config/rs6000/rs6000.h  |  1 +
 gcc/config/rs6000/rs6000.md |  2 +-
 gcc/config/rs6000/rs6000.opt|  6 ++
 13 files changed, 52 insertions(+), 15 deletions(-)

diff --git a/gcc/config.gcc b/gcc/config.gcc
index f7f2002a45f3..7bb8a2925cd3 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -535,7 +535,7 @@ powerpc*-*-*)
extra_headers="${extra_headers} ppu_intrinsics.h spu2vmx.h vec_types.h 
si2vmx.h"
extra_headers="${extra_headers} amo.h"
case x$with_cpu in
-   
xpowerpc64|xdefault64|x6[23]0|x970|xG5|xpower[3456789]|xpower1[01]|xpower6x|xrs64a|xcell|xa2|xe500mc64|xe5500|xe6500)
+   
xpowerpc64|xdefault64|x6[23]0|x970|xG5|xpower[3456789]|xpower1[01]|xpower6x|xrs64a|xcell|xa2|xe500mc64|xe5500|xe6500|xfuture)
cpu_is_64bit=yes
;;
esac
@@ -5682,7 +5682,7 @@ case "${target}" in
tm_defines="${tm_defines} CONFIG_PPC405CR"
eval "with_$which=405"
;;
-   "" | common | native \
+   "" | common | native | future \
| power[3456789] | power1[01] | power5+ | power6x \
| powerpc | powerpc64 | powerpc64le \
| rs64 \
diff --git a/gcc/config/rs6000/aix71.h b/gcc/config/rs6000/aix71.h
index 2b21dd7cd1e0..77651f5ea309 100644
--- a/gcc/config/rs6000/aix71.h
+++ b/gcc/config/rs6000/aix71.h
@@ -79,6 +79,7 @@ do {  
\
 #undef ASM_CPU_SPEC
 #define ASM_CPU_SPEC \
 "%{mcpu=native: %(asm_cpu_native); \
+  mcpu=future: -mfuture; \
   mcpu=power11: -mpwr11; \
   mcpu=power10: -mpwr10; \
   mcpu=power9: -mpwr9; \
diff --git a/gcc/config/rs6000/aix72.h b/gcc/config/rs6000/aix72.h
index 53c0bde5ad4a..652f60c7f494 100644
--- a/gcc/config/rs6000/aix72.h
+++ b/gcc/config/rs6000/aix72.h
@@ -79,6 +79,7 @@ do {  
\
 #undef ASM_CPU_SPEC
 #define ASM_CPU_SPEC \
 "%{mcpu=native: %(asm_cpu_native); \
+  mcpu=future: -mfuture; \
   mcpu=power11: -mpwr11; \
   mcpu=power10: -mpwr10; \
   mcpu=power9: -mpwr9; \
diff --git a/gcc/config/rs6000/aix73.h b/gcc/config/rs6000/aix73.h
index c7639368a264..3c66ac1d9171 100644
--- a/gcc/config/rs6000/aix73.h
+++ b/gcc/config/rs6000/aix73.h
@@ -79,6 +79,7 @@ do {  
\
 #undef ASM_CPU_SPEC
 #define ASM_CPU_SPEC \
 "%{mcpu=nati

[gcc/devel/rust/master] gccrs: Fix ICE during const expr eval on array expressions

2025-04-05 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:898d55ad7e2ae64a0184d736f29a1184a29867c3

commit 898d55ad7e2ae64a0184d736f29a1184a29867c3
Author: Philip Herron 
Date:   Thu Mar 27 17:27:56 2025 +

gccrs: Fix ICE during const expr eval on array expressions

Array expressions are still getting turned into VIEW_CONVERT_EXPR's becuase
TYPE_MAIN_VARIANT is not set so then we might as well reuse the type-hasher
to sort this out.

Fixes Rust-GCC#3588

gcc/rust/ChangeLog:

* backend/rust-compile-context.h: only push named types
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): run the 
type hasher

gcc/testsuite/ChangeLog:

* rust/compile/issue-3588.rs: New test.

Signed-off-by: Philip Herron 

Diff:
---
 gcc/rust/backend/rust-compile-context.h  | 5 -
 gcc/rust/backend/rust-compile-type.cc| 2 ++
 gcc/testsuite/rust/compile/issue-3588.rs | 5 +
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/backend/rust-compile-context.h 
b/gcc/rust/backend/rust-compile-context.h
index 18d27f484296..22e6e19e7679 100644
--- a/gcc/rust/backend/rust-compile-context.h
+++ b/gcc/rust/backend/rust-compile-context.h
@@ -72,7 +72,10 @@ public:
   return it->second;
 
 compiled_type_map.insert ({h, type});
-push_type (type);
+
+if (TYPE_NAME (type) != NULL)
+  push_type (type);
+
 return type;
   }
 
diff --git a/gcc/rust/backend/rust-compile-type.cc 
b/gcc/rust/backend/rust-compile-type.cc
index 0ab9e420b5dd..5be2b9e317e4 100644
--- a/gcc/rust/backend/rust-compile-type.cc
+++ b/gcc/rust/backend/rust-compile-type.cc
@@ -481,6 +481,8 @@ TyTyResolveCompile::visit (const TyTy::ArrayType &type)
   tree folded_capacity_expr = fold_expr (capacity_expr);
 
   translated = Backend::array_type (element_type, folded_capacity_expr);
+  if (translated != error_mark_node)
+translated = ctx->insert_compiled_type (translated);
 }
 
 void
diff --git a/gcc/testsuite/rust/compile/issue-3588.rs 
b/gcc/testsuite/rust/compile/issue-3588.rs
new file mode 100644
index ..744d9671c42a
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3588.rs
@@ -0,0 +1,5 @@
+const FOO: i32 = if true { [1, 2, 3] } else { [2, 3, 4] }[0];
+
+pub fn test() -> i32 {
+FOO
+}


[gcc r12-11005] Daily bump.

2025-04-05 Thread GCC Administrator via Gcc-cvs
https://gcc.gnu.org/g:4b83e7c83427eb540951589ca1936c7d7399e080

commit r12-11005-g4b83e7c83427eb540951589ca1936c7d7399e080
Author: GCC Administrator 
Date:   Fri Mar 28 00:21:02 2025 +

Daily bump.

Diff:
---
 gcc/DATESTAMP | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/DATESTAMP b/gcc/DATESTAMP
index 0e0aca037f52..2bb0fd3370e1 100644
--- a/gcc/DATESTAMP
+++ b/gcc/DATESTAMP
@@ -1 +1 @@
-20250327
+20250328


[gcc r15-8507] gccrs: add test case to show method resolution is working

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:9725d15a88376b69e61bb5a3a5385145e1a5b5f7

commit r15-8507-g9725d15a88376b69e61bb5a3a5385145e1a5b5f7
Author: Philip Herron 
Date:   Fri Nov 1 14:07:54 2024 +

gccrs: add test case to show method resolution is working

The issue here was that the impl block for Cell defines that T must have
the bound of Copy implemented. But simultaneously if you do an deref
you get direct access to the unsafe cell which also defines a get method
so these are two valid ways of accessing the method in question but
when Copy is implementet the simplest case is prefered so it does resolve
to Cell::get.

Fixes #3033

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr can't handle this
* rust/compile/issue-3033.rs: New test.

Signed-off-by: Philip Herron 

Diff:
---
 gcc/testsuite/rust/compile/issue-3033.rs | 144 +++
 gcc/testsuite/rust/compile/nr2/exclude   |   1 +
 2 files changed, 145 insertions(+)

diff --git a/gcc/testsuite/rust/compile/issue-3033.rs 
b/gcc/testsuite/rust/compile/issue-3033.rs
new file mode 100644
index ..9085b7616c0d
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3033.rs
@@ -0,0 +1,144 @@
+#![feature(negative_impls)]
+
+#[lang = "copy"]
+trait Copy {}
+
+mod copy_impls {
+use super::Copy;
+
+macro_rules! impl_copy {
+($($t:ty)*) => {
+$(
+impl Copy for $t {}
+)*
+}
+}
+
+impl_copy! {
+usize u8 u16 u32 u64 // u128
+isize i8 i16 i32 i64 // i128
+f32 f64
+bool char
+}
+}
+
+#[stable(feature = "rust1", since = "1.0.0")]
+#[repr(transparent)]
+#[repr(no_niche)] // rust-lang/rust#68303.
+pub struct UnsafeCell {
+value: T,
+// { dg-warning "field is never read" "" { target *-*-* } .-1 }
+}
+
+impl UnsafeCell {
+/// Gets a mutable pointer to the wrapped value.
+///
+/// This can be cast to a pointer of any kind.
+/// Ensure that the access is unique (no active references, mutable or not)
+/// when casting to `&mut T`, and ensure that there are no mutations
+/// or mutable aliases going on when casting to `&T`
+///
+/// # Examples
+///
+///
+/// use std::cell::UnsafeCell;
+///
+/// let uc = UnsafeCell::new(5);
+///
+/// let five = uc.get();
+///
+#[inline]
+#[stable(feature = "rust1", since = "1.0.0")]
+// #[rustc_const_stable(feature = "const_unsafecell_get", since = 
"1.32.0")]
+pub const fn get(&self) -> *mut T {
+// We can just cast the pointer from `UnsafeCell` to `T` because of
+// #[repr(transparent)]. This exploits libstd's special status, there 
is
+// no guarantee for user code that this will work in future versions 
of the compiler!
+self as *const UnsafeCell as *const T as *mut T
+}
+}
+
+#[stable(feature = "rust1", since = "1.0.0")]
+#[repr(transparent)]
+pub struct Cell {
+value: UnsafeCell,
+// { dg-warning "field is never read" "" { target *-*-* } .-1 }
+}
+
+impl Cell {
+/// Returns a copy of the contained value.
+///
+/// # Examples
+///
+///
+/// use std::cell::Cell;
+///
+/// let c = Cell::new(5);
+///
+/// let five = c.get();
+///
+#[inline]
+#[stable(feature = "rust1", since = "1.0.0")]
+pub fn get(&self) -> T {
+// SAFETY: This can cause data races if called from a separate thread,
+// but `Cell` is `!Sync` so this won't happen.
+unsafe { *self.value.get() }
+}
+}
+
+#[lang = "sized"]
+trait Sized {}
+
+#[lang = "deref"]
+pub trait Deref {
+/// The resulting type after dereferencing.
+#[stable(feature = "rust1", since = "1.0.0")]
+// #[rustc_diagnostic_item = "deref_target"]
+type Target: ?Sized;
+
+/// Dereferences the value.
+#[must_use]
+#[stable(feature = "rust1", since = "1.0.0")]
+// #[rustc_diagnostic_item = "deref_method"]
+fn deref(&self) -> &Self::Target;
+}
+
+impl Deref for &T {
+type Target = T;
+
+fn deref(&self) -> &T {
+*self
+}
+}
+
+// this is added because of #3030
+extern "C" {
+fn never() -> !;
+}
+
+impl !DerefMut for &T {
+fn deref_mut(&mut self) -> &mut T {
+unsafe { never() }
+}
+}
+
+impl Deref for &mut T {
+type Target = T;
+
+fn deref(&self) -> &T {
+*self
+}
+}
+
+#[lang = "deref_mut"]
+pub trait DerefMut: Deref {
+/// Mutably dereferences the value.
+#[stable(feature = "rust1", since = "1.0.0")]
+fn deref_mut(&mut self) -> &mut Self::Target;
+}
+
+#[inline]
+pub fn new<'b>(borrow: &'b Cell) {
+let b = borrow.get();
+// { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index b4799edd4f5b..ceada8bc51a6 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust

[gcc/devel/rust/master] ast-builder: Add methods for QualifiedPathInExpressions

2025-04-05 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:4ab7564dd217cbb8913d852189302ef9e097d184

commit 4ab7564dd217cbb8913d852189302ef9e097d184
Author: Arthur Cohen 
Date:   Thu Jan 30 13:07:48 2025 +0100

ast-builder: Add methods for QualifiedPathInExpressions

gcc/rust/ChangeLog:

* ast/rust-ast-builder.cc (Builder::qualified_path_in_expression): 
New.
(Builder::function): Change the return type.
* ast/rust-ast-builder.h: Declare qualified_path_in_expression 
functions.
* expand/rust-derive-debug.cc (DeriveDebug::stub_debug_fn): Adapt 
to new APIs.

Diff:
---
 gcc/rust/ast/rust-ast-builder.cc | 32 +++-
 gcc/rust/ast/rust-ast-builder.h  | 16 +---
 gcc/rust/expand/rust-derive-debug.cc |  4 ++--
 3 files changed, 42 insertions(+), 10 deletions(-)

diff --git a/gcc/rust/ast/rust-ast-builder.cc b/gcc/rust/ast/rust-ast-builder.cc
index 0538998f0170..9685ae5aca9d 100644
--- a/gcc/rust/ast/rust-ast-builder.cc
+++ b/gcc/rust/ast/rust-ast-builder.cc
@@ -64,6 +64,27 @@ Builder::array (std::vector> 
&&members) const
   return std::unique_ptr (new ArrayExpr (std::move (elts), {}, {}, loc));
 }
 
+std::unique_ptr
+Builder::qualified_path_in_expression (std::unique_ptr &&type,
+  TypePath trait,
+  PathExprSegment segment) const
+{
+  auto segments = {segment};
+
+  return qualified_path_in_expression (std::move (type), trait, segments);
+}
+
+std::unique_ptr
+Builder::qualified_path_in_expression (
+  std::unique_ptr &&type, TypePath trait,
+  std::vector &&segments) const
+{
+  auto qual_type = QualifiedPathType (std::move (type), loc, trait);
+
+  return std::unique_ptr (
+new QualifiedPathInExpression (qual_type, std::move (segments), {}, loc));
+}
+
 std::unique_ptr
 Builder::identifier (std::string name) const
 {
@@ -111,17 +132,18 @@ Builder::fn_qualifiers () const
   return FunctionQualifiers (loc, Async::No, Const::No, Unsafety::Normal);
 }
 
-Function
-Builder::function (Identifier function_name,
+std::unique_ptr
+Builder::function (std::string function_name,
   std::vector> params,
   std::unique_ptr return_type,
   std::unique_ptr block,
   FunctionQualifiers qualifiers, WhereClause where_clause,
   Visibility visibility) const
 {
-  return Function (function_name, qualifiers, {}, std::move (params),
-  std::move (return_type), where_clause, std::move (block),
-  visibility, {}, loc);
+  return std::unique_ptr (
+new Function (function_name, qualifiers, {}, std::move (params),
+ std::move (return_type), where_clause, std::move (block),
+ visibility, {}, loc));
 }
 
 PathExprSegment
diff --git a/gcc/rust/ast/rust-ast-builder.h b/gcc/rust/ast/rust-ast-builder.h
index f67546fe8809..262bdcf18ff7 100644
--- a/gcc/rust/ast/rust-ast-builder.h
+++ b/gcc/rust/ast/rust-ast-builder.h
@@ -104,7 +104,8 @@ public:
* arguments (`path(arg0, arg1, arg2)`)
*/
   std::unique_ptr call (std::unique_ptr &&path,
- std::vector> &&args) const;
+ std::vector> &&args
+ = {}) const;
   std::unique_ptr call (std::unique_ptr &&path,
  std::unique_ptr &&arg) const;
 
@@ -114,6 +115,15 @@ public:
   std::unique_ptr
   array (std::vector> &&members) const;
 
+  /* Create a qualified path in expression (`::seg::expr`) */
+  std::unique_ptr
+  qualified_path_in_expression (std::unique_ptr &&type, TypePath trait,
+   PathExprSegment segment) const;
+  std::unique_ptr
+  qualified_path_in_expression (std::unique_ptr &&type, TypePath trait,
+   std::vector &&segments
+   = {}) const;
+
   /* Self parameter for a function definition (`&self`) */
   std::unique_ptr self_ref_param (bool mutability = false) const;
   /* A regular named function parameter for a definition (`a: type`) */
@@ -123,8 +133,8 @@ public:
   /* Empty function qualifiers, with no specific qualifiers */
   FunctionQualifiers fn_qualifiers () const;
 
-  Function
-  function (Identifier function_name,
+  std::unique_ptr
+  function (std::string function_name,
std::vector> params,
std::unique_ptr return_type, std::unique_ptr block,
FunctionQualifiers qualifiers
diff --git a/gcc/rust/expand/rust-derive-debug.cc 
b/gcc/rust/expand/rust-derive-debug.cc
index 910f27c67b2f..f37547459a0e 100644
--- a/gcc/rust/expand/rust-derive-debug.cc
+++ b/gcc/rust/expand/rust-derive-debug.cc
@@ -77,10 +77,10 @@ DeriveDebug::stub_debug_fn ()
 
   auto params = vec (std::move (self), std::move (fmt));
 
-  auto function = builder.function ({"fmt"}, std::move (params),
+  auto function = builder.function ("fmt", std::move (params),
  

[gcc r15-8484] move global data to symbol_table_init

2025-04-05 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:ff7ac551ba2e1bf996586ae053d4d5f2cbf05c91

commit r15-8484-gff7ac551ba2e1bf996586ae053d4d5f2cbf05c91
Author: Richard Biener 
Date:   Thu Mar 20 10:48:38 2025 +0100

move global data to symbol_table_init

The following avoids early runtime initialization of cbl_field_t
objects which, when using tree to represent the current _Float128
data, segfaults as tree data like float128_type_node is not yet
initialized.  The solution is to move the global data to
symbol_table_init which is the only user and it already has one
such instance locally, the 'constants' array.

* symbols.cc (empty_float, empty_comp5, empty_literal,
empty_conditional, debug_registers, special_registers): Move
global cbl_field_t typed data to ...
(symbol_table_init): ... local scope here.

Diff:
---
 gcc/cobol/symbols.cc | 173 +--
 1 file changed, 84 insertions(+), 89 deletions(-)

diff --git a/gcc/cobol/symbols.cc b/gcc/cobol/symbols.cc
index 17583e002a12..b8d785f25319 100644
--- a/gcc/cobol/symbols.cc
+++ b/gcc/cobol/symbols.cc
@@ -295,81 +295,12 @@ symbol_valid_udf_args( size_t function, 
std::list args ) {
 
 static const struct cbl_occurs_t nonarray = cbl_occurs_t();
 
-static const struct cbl_field_t empty_float = {
-0, FldFloat, FldInvalid,
-intermediate_e,
-0, 0, 0, nonarray, 0, "",
-0, cbl_field_t::linkage_t(),
-{16, 16, 32, 0, NULL}, NULL };
-
-static const struct cbl_field_t empty_comp5 = {
-0, FldNumericBin5, FldInvalid,
-signable_e | intermediate_e,
-0, 0, 0, nonarray, 0, "",
-0, cbl_field_t::linkage_t(),
-{16, 16, MAX_FIXED_POINT_DIGITS, 0, NULL}, 
NULL };
-
 #if 0
 # define CONSTANT_E constant_e
 #else
 # define CONSTANT_E intermediate_e
 #endif
 
-static struct cbl_field_t empty_literal = {
-0, FldInvalid, FldInvalid, CONSTANT_E,
-0, 0, 0, nonarray, 0, "",
-0, cbl_field_t::linkage_t(),
-{}, NULL };
-
-static const struct cbl_field_t empty_conditional = {
-0, FldConditional, FldInvalid, intermediate_e,
-0, 0, 0, nonarray, 0, "",
-0, cbl_field_t::linkage_t(),
-{}, NULL };
-
-
-/**
- * Debug register record
- 01 DEBUG-ITEM.
-02 DEBUG-LINE PIC X(6).
-02 FILLER PIC X VALUE SPACE.
-02 DEBUG-NAME PIC X(30).
-02 FILLER PIC X VALUE SPACE.
-02 DEBUG-SUB-1 PIC S SIGN IS LEADING SEPARATE CHARACTER.
-02 FILLER PIC X VALUE SPACE.
-02 DEBUG-SUB-2 PIC S SIGN IS LEADING SEPARATE CHARACTER.
-02 FILLER PIC X VALUE SPACE.
-02 DEBUG-SUB-3 PIC S SIGN IS LEADING SEPARATE CHARACTER.
-02 FILLER PIC X VALUE SPACE.
-02 DEBUG-CONTENTS PIC X(76).
- **/
-
-static cbl_field_t debug_registers[] = {
-{ 0, FldGroup, FldInvalid, global_e, 0,0,1, nonarray, 0,
-  "DEBUG-ITEM", 0, {}, {132,132,0,0, NULL}, NULL },
-{ 0, FldAlphanumeric, FldInvalid, global_e, 0,0,2, nonarray, 0,
-  "DEBUG-LINE", 0, {}, {6,6,0,0, "  "}, NULL },
-{ 0, FldAlphanumeric, FldInvalid, 0, 0,0,2, nonarray, 0,
-  "FILLER", 0, {}, {1,1,0,0, " "}, NULL },
-{ 0, FldAlphanumeric, FldInvalid, global_e, 0,0,2, nonarray, 0,
-  "DEBUG-NAME", 0, {}, {30,30,0,0, NULL}, NULL },
-{ 0, FldAlphanumeric, FldInvalid, 0, 0,0,2, nonarray, 0,
-  "FILLER", 0, {}, {1,1,0,0, " "}, NULL },
-{ 0, FldNumericDisplay, FldInvalid, signable_e | global_e | leading_e | 
separate_e, 0,0,2, nonarray, 0,
-  "DEBUG-SUB-1", 0, {}, {5,5,3,0, NULL}, NULL },
-{ 0, FldAlphanumeric, FldInvalid, 0, 0,0,2, nonarray, 0,
-  "FILLER", 0, {}, {1,1,0,0, " "}, NULL },
-{ 0, FldNumericDisplay, FldInvalid, signable_e | global_e | leading_e | 
separate_e, 0,0,2, nonarray, 0,
-  "DEBUG-SUB-2", 0, {}, {5,5,3,0, NULL}, NULL },
-{ 0, FldAlphanumeric, FldInvalid, 0, 0,0,2, nonarray, 0,
-  "FILLER", 0, {}, {1,1,0,0, " "}, NULL },
-{ 0, FldNumericDisplay, FldInvalid, signable_e | global_e | leading_e | 
separate_e, 0,0,2, nonarray, 0,
-  "DEBUG-SUB-3", 0, {}, {5,5,3,0, NULL}, NULL },
-{ 0, FldAlphanumeric, FldInvalid, 0, 0,0,2, nonarray, 0,
-  "FILLER", 0, {}, {1,1,0,0, " "}, NULL },
-{ 0, FldAlphanumeric, FldInvalid, signable_e | global_e, 0,0,2, nonarray, 
0,
-  "DEBUG-CONTENTS", 0, {}, {76,76,0,0, NULL}, NULL },
-};
 
 class group_size_t {
   size_t size;
@@ -384,26 +315,6 @@ class group_size_t {
 
 enum  { constq = constant_e | quo

[gcc/devel/rust/master] lower: Properly lower non-generic lang item type path segments.

2025-04-05 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:15b928c77f4656394d1d519f3d31bb936ee84fec

commit 15b928c77f4656394d1d519f3d31bb936ee84fec
Author: Arthur Cohen 
Date:   Thu Jan 2 10:41:44 2025 +

lower: Properly lower non-generic lang item type path segments.

gcc/rust/ChangeLog:

* hir/rust-ast-lower-type.cc (ASTLowerTypePath::visit): Adapt code 
to lang item
type path segments.

Diff:
---
 gcc/rust/hir/rust-ast-lower-type.cc | 40 +
 1 file changed, 14 insertions(+), 26 deletions(-)

diff --git a/gcc/rust/hir/rust-ast-lower-type.cc 
b/gcc/rust/hir/rust-ast-lower-type.cc
index 83532f842b84..1b229ce258aa 100644
--- a/gcc/rust/hir/rust-ast-lower-type.cc
+++ b/gcc/rust/hir/rust-ast-lower-type.cc
@@ -74,11 +74,20 @@ ASTLowerTypePath::visit (AST::TypePathSegment &segment)
   Analysis::NodeMapping mapping (crate_num, segment.get_node_id (), hirid,
 UNKNOWN_LOCAL_DEFID);
 
-  HIR::PathIdentSegment ident (segment.get_ident_segment ().as_string ());
-  translated_segment
-= new HIR::TypePathSegment (std::move (mapping), ident,
-   segment.get_separating_scope_resolution (),
-   segment.get_locus ());
+  if (segment.is_lang_item ())
+{
+  translated_segment = new HIR::TypePathSegment (std::move (mapping),
+segment.get_lang_item (),
+segment.get_locus ());
+}
+  else
+{
+  HIR::PathIdentSegment ident (segment.get_ident_segment ().as_string ());
+  translated_segment
+   = new HIR::TypePathSegment (std::move (mapping), ident,
+   segment.get_separating_scope_resolution (),
+   segment.get_locus ());
+}
 }
 
 void
@@ -139,27 +148,6 @@ ASTLowerTypePath::visit (AST::TypePath &path)
 path.has_opening_scope_resolution_op ());
 }
 
-// void
-// ASTLowerTypePath::visit (AST::LangItemPath &path)
-// {
-//   auto crate_num = mappings.get_current_crate ();
-//   auto hirid = mappings.get_next_hir_id (crate_num);
-
-//   Analysis::NodeMapping mapping (crate_num, path.get_node_id (), hirid,
-//  mappings.get_next_localdef_id (crate_num));
-
-//   std::vector> translated_segments;
-//   translated_segments.emplace_back (std::unique_ptr (
-// new HIR::TypePathSegment (mapping,
-//   LangItem::ToString (path.get_lang_item_kind ()),
-//   false, path.get_locus (;
-
-//   translated
-// = new HIR::TypePath (std::move (mapping), std::move
-// (translated_segments),
-//  path.get_locus ());
-// }
-
 HIR::QualifiedPathInType *
 ASTLowerQualifiedPathInType::translate (AST::QualifiedPathInType &type)
 {


[gcc r15-8410] gccrs: Update exclude list with working tests

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:a7992fee681bc5a554ed407f069f2cfb4d9a50a6

commit r15-8410-ga7992fee681bc5a554ed407f069f2cfb4d9a50a6
Author: Pierre-Emmanuel Patry 
Date:   Tue Sep 17 15:25:41 2024 +0200

gccrs: Update exclude list with working tests

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove working tests from nr2 exclude 
list.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/testsuite/rust/compile/nr2/exclude | 27 +--
 1 file changed, 1 insertion(+), 26 deletions(-)

diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index 3412617f7eb2..695da317cf06 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -3,7 +3,6 @@
 debug-diagnostics-on.rs
 
 # main list
-all-cast.rs
 attr-mismatch-crate-name.rs
 attr_deprecated.rs
 attr_deprecated_2.rs
@@ -11,13 +10,9 @@ auto_trait_super_trait.rs
 auto_trait_valid.rs
 auto_trait_invalid.rs
 bad=file-name.rs
-bad_type2.rs
 bounds1.rs
-break-rust1.rs
 break-rust2.rs
 break-rust3.rs
-break2.rs
-break_with_value_inside_loop.rs
 macros/builtin/eager1.rs
 macros/builtin/eager2.rs
 macros/builtin/recurse2.rs
@@ -35,14 +30,9 @@ complex_qualified_path_in_expr.rs
 const-issue1440.rs
 const1.rs
 const3.rs
-const4.rs
-const8.rs
-const9.rs
-const_generics_1.rs
 const_generics_3.rs
 const_generics_4.rs
 const_generics_5.rs
-const_generics_6.rs
 const_generics_7.rs
 const_generics_8.rs
 derive_empty.rs
@@ -51,7 +41,6 @@ derive_macro3.rs
 derive_macro4.rs
 derive_macro6.rs
 diagnostic_underline.rs
-expand_macro_qual_path_in_type.rs
 expected_type_args2.rs
 expected_type_args3.rs
 feature_rust_attri0.rs
@@ -59,7 +48,6 @@ feature_rust_attri1.rs
 for_lifetimes.rs
 format_args_basic_expansion.rs
 found_struct.rs
-func1.rs
 generic-default1.rs
 generics1.rs
 generics10.rs
@@ -73,20 +61,17 @@ generics7.rs
 generics8.rs
 generics9.rs
 if_let_expr.rs
-implicit_returns_err4.rs
 infer-crate-name.rs
 issue-1005.rs
 issue-1006.rs
 issue-1019.rs
 issue-1031.rs
 issue-1034.rs
-issue-1073.rs
 issue-1089.rs
 issue-1128.rs
 issue-1129-2.rs
 issue-1130.rs
 issue-1131.rs
-issue-1152.rs
 issue-1165.rs
 issue-1173.rs
 issue-1235.rs
@@ -96,7 +81,6 @@ issue-1289.rs
 issue-1383.rs
 issue-1447.rs
 issue-1483.rs
-issue-1524.rs
 issue-1589.rs
 issue-1725-1.rs
 issue-1725-2.rs
@@ -142,7 +126,6 @@ issue-2772-2.rs
 issue-2775.rs
 issue-2747.rs
 issue-2782.rs
-issue-2788.rs
 issue-2812.rs
 issue-850.rs
 issue-852.rs
@@ -157,14 +140,12 @@ macros/mbe/macro15.rs
 macros/mbe/macro20.rs
 macros/mbe/macro23.rs
 macros/mbe/macro40.rs
-macros/mbe/macro42.rs
 macros/mbe/macro43.rs
 macros/mbe/macro44.rs
 macros/mbe/macro50.rs
 macros/mbe/macro54.rs
 macros/mbe/macro55.rs
 macros/mbe/macro6.rs
-macros/mbe/macro9.rs
 macros/mbe/macro_rules_macro_rules.rs
 macros/mbe/macro_use1.rs
 match-never-ltype.rs
@@ -204,10 +185,7 @@ privacy5.rs
 privacy6.rs
 privacy8.rs
 macros/proc/attribute_non_function.rs
-macros/proc/attribute_non_root_method.rs
 macros/proc/derive_non_function.rs
-macros/proc/non_root_method.rs
-macros/proc/non_root_trait_method.rs
 macros/proc/non_function.rs
 pub_restricted_1.rs
 pub_restricted_2.rs
@@ -256,7 +234,6 @@ use_2.rs
 v0-mangle1.rs
 v0-mangle2.rs
 while_break_expr.rs
-rust-const-blog-issue.rs
 negative_impls.rs
 auto_trait.rs
 exhaustiveness1.rs
@@ -272,9 +249,7 @@ issue-3045-1.rs
 issue-3045-2.rs
 issue-3046.rs
 unknown-associated-item.rs
-box_syntax_feature_gate.rs
-dropck_eyepatch_feature_gate.rs
 inline_asm_parse_output_operand.rs
 issue-3030.rs
 issue-3035.rs
-issue-3082.rs
\ No newline at end of file
+issue-3082.rs


[gcc r15-8415] gccrs: Resolve TypeParam with name resolution 2.0

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:712e92cb20173df1f040c57140d159b99e952b64

commit r15-8415-g712e92cb20173df1f040c57140d159b99e952b64
Author: Pierre-Emmanuel Patry 
Date:   Thu Sep 26 23:16:21 2024 +0200

gccrs: Resolve TypeParam with name resolution 2.0

Resolve TypeParam unless it is Self.

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): 
Resolve
TypeParam.
* resolve/rust-toplevel-name-resolver-2.0.h: Add visit function
prototype.

Signed-off-by: Pierre-Emmanuel Patry 

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

diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
index 6a54978a67cb..35732e244b4f 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -253,6 +253,15 @@ TopLevel::visit (AST::StaticItem &static_item)
 void
 TopLevel::visit (AST::StructStruct &struct_item)
 {
+  auto generic_vis = [this, &struct_item] () {
+for (auto &g : struct_item.get_generic_params ())
+  {
+   g->accept_vis (*this);
+  }
+  };
+
+  ctx.scoped (Rib::Kind::Item, struct_item.get_node_id (), generic_vis);
+
   insert_or_error_out (struct_item.get_struct_name (), struct_item,
   Namespace::Types);
 
@@ -264,6 +273,16 @@ TopLevel::visit (AST::StructStruct &struct_item)
 Namespace::Values);
 }
 
+void
+TopLevel::visit (AST::TypeParam &type_param)
+{
+  // Hacky and weird, find a better solution
+  // We should probably not even insert self in the first place ?
+  if (type_param.get_type_representation ().as_string () != "Self")
+insert_or_error_out (type_param.get_type_representation (), type_param,
+Namespace::Types);
+}
+
 void
 TopLevel::visit (AST::TupleStruct &tuple_struct)
 {
diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
index 99ed65398c6a..09b22612f78c 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
@@ -162,6 +162,7 @@ private:
   void visit (AST::Union &union_item) override;
   void visit (AST::ConstantItem &const_item) override;
   void visit (AST::ExternCrate &crate) override;
+  void visit (AST::TypeParam &type_param) override;
 
   void visit (AST::UseDeclaration &use) override;
 };


[gcc r15-8521] gccrs: typecheck: Remove unused parameter in TyTyCheckCallExpr

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:bbbf9a239b54d697f5978a4dcd63ebbda9f3f1c4

commit r15-8521-gbbbf9a239b54d697f5978a4dcd63ebbda9f3f1c4
Author: Arthur Cohen 
Date:   Wed Nov 6 15:19:10 2024 +0100

gccrs: typecheck: Remove unused parameter in TyTyCheckCallExpr

gcc/rust/ChangeLog:

* typecheck/rust-tyty-call.h: Remove unused context member.

Diff:
---
 gcc/rust/typecheck/rust-tyty-call.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/gcc/rust/typecheck/rust-tyty-call.h 
b/gcc/rust/typecheck/rust-tyty-call.h
index 67cfe30057af..00ac655e5e4f 100644
--- a/gcc/rust/typecheck/rust-tyty-call.h
+++ b/gcc/rust/typecheck/rust-tyty-call.h
@@ -73,14 +73,12 @@ private:
   TypeCheckCallExpr (HIR::CallExpr &c, TyTy::VariantDef &variant,
 Resolver::TypeCheckContext *context)
 : resolved (new TyTy::ErrorType (c.get_mappings ().get_hirid ())), call 
(c),
-  variant (variant), context (context),
-  mappings (Analysis::Mappings::get ())
+  variant (variant), mappings (Analysis::Mappings::get ())
   {}
 
   BaseType *resolved;
   HIR::CallExpr &call;
   TyTy::VariantDef &variant;
-  Resolver::TypeCheckContext *context;
   Analysis::Mappings &mappings;
 };


[gcc r15-8596] gccrs: fix ICE in borrows to invalid expressions

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:a362f8a7d78da919d3e8ad5d924109a3c1521131

commit r15-8596-ga362f8a7d78da919d3e8ad5d924109a3c1521131
Author: Philip Herron 
Date:   Tue Jan 7 12:32:43 2025 +

gccrs: fix ICE in borrows to invalid expressions

We need to check if the borrowed value is valid before creating the
reference type. Otherwise this will lead to an ICE.

Fixes Rust-GCC#3140

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): 
check for error
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): likewise 
and remove debug error

gcc/testsuite/ChangeLog:

* rust/compile/issue-3046.rs: remove old error message
* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/issue-3140.rs: New test.

Signed-off-by: Philip Herron 

Diff:
---
 gcc/rust/typecheck/rust-hir-type-check-expr.cc |  2 ++
 gcc/rust/typecheck/rust-tyty-call.cc   |  9 ++---
 gcc/testsuite/rust/compile/issue-3046.rs   |  4 +---
 gcc/testsuite/rust/compile/issue-3140.rs   | 27 ++
 gcc/testsuite/rust/compile/nr2/exclude |  1 +
 5 files changed, 33 insertions(+), 10 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc 
b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index 5a96c359d7c5..2ea8b4127e69 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -1366,6 +1366,8 @@ void
 TypeCheckExpr::visit (HIR::BorrowExpr &expr)
 {
   TyTy::BaseType *resolved_base = TypeCheckExpr::Resolve (expr.get_expr ());
+  if (resolved_base->is ())
+return;
 
   // In Rust this is valid because of DST's
   //
diff --git a/gcc/rust/typecheck/rust-tyty-call.cc 
b/gcc/rust/typecheck/rust-tyty-call.cc
index 5fea34de40a2..2e0830e4adad 100644
--- a/gcc/rust/typecheck/rust-tyty-call.cc
+++ b/gcc/rust/typecheck/rust-tyty-call.cc
@@ -140,13 +140,8 @@ TypeCheckCallExpr::visit (FnType &type)
 {
   location_t arg_locus = argument->get_locus ();
   auto argument_expr_tyty = Resolver::TypeCheckExpr::Resolve (*argument);
-  if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR)
-   {
- rust_error_at (
-   argument->get_locus (),
-   "failed to resolve type for argument expr in CallExpr");
- return;
-   }
+  if (argument_expr_tyty->is ())
+   return;
 
   // it might be a variadic function
   if (i < type.num_params ())
diff --git a/gcc/testsuite/rust/compile/issue-3046.rs 
b/gcc/testsuite/rust/compile/issue-3046.rs
index c982cc98f582..f0c72a3cef4b 100644
--- a/gcc/testsuite/rust/compile/issue-3046.rs
+++ b/gcc/testsuite/rust/compile/issue-3046.rs
@@ -12,12 +12,10 @@ fn test(v: LOption) -> Res {
 return Res::BAD;
 }
 
-
 fn main() {
 // Should be:
 // test(LOption::Some(2));
-// 
+//
 test(LOption(2));
 // { dg-error "expected function, tuple struct or tuple variant, found 
enum" "" { target *-*-* } .-1 }
-// { dg-error "failed to resolve type for argument expr in CallExpr" "" { 
target *-*-* } .-2 }
 }
diff --git a/gcc/testsuite/rust/compile/issue-3140.rs 
b/gcc/testsuite/rust/compile/issue-3140.rs
new file mode 100644
index ..dcf86db56161
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3140.rs
@@ -0,0 +1,27 @@
+enum State {
+Succeeded,
+Failed,
+}
+
+fn print_on_failure(state: &State) {
+let mut num = 0;
+match *state {
+// error: expected unit struct, unit variant or constant, found tuple
+//variant `State::Failed`
+State::Failed => {
+num = 1;
+}
+State::Succeeded => {
+num = 2;
+}
+_ => (),
+}
+}
+
+fn main() {
+let b = State::Failed(1);
+// { dg-error "expected function, tuple struct or tuple variant, found 
struct .State." "" { target *-*-* } .-1 }
+
+print_on_failure(&b);
+// { dg-error "cannot find value .b. in this scope" "" { target *-*-* } 
.-1 }
+}
diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index 945a697f677c..e7344ed0d597 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -195,4 +195,5 @@ issue-266.rs
 additional-trait-bounds2.rs
 auto_traits2.rs
 auto_traits3.rs
+issue-3140.rs
 # please don't delete the trailing newline


[gcc(refs/users/meissner/heads/work199)] Change TARGET_POPCNTD to TARGET_POWER7.

2025-04-05 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:08e5c71131f456b196b2f199b740ece2411a5c61

commit 08e5c71131f456b196b2f199b740ece2411a5c61
Author: Michael Meissner 
Date:   Thu Apr 3 16:03:01 2025 -0400

Change TARGET_POPCNTD to TARGET_POWER7.

This patch changes TARGET_POPCNTD to TARGET_POWER7.  The -mpopcntd switch 
is not
being changed, just the name of the macros used to determine if the PowerPC
processor supports ISA 2.6 (Power7).

2025-04-03  Michael Meissner  

gcc/

* gcc/config/rs6000/dfp.md (cmp_internal1): Change 
TARGET_POPCNTD
to TARGET_POWER7.
* gcc/config/rs6000/rs6000-builtin.cc (rs6000_builtin_is_supported):
Likewise.
* gcc/config/rs6000/rs6000-string.cc (expand_block_compare): 
Likewise.
* gcc/config/rs6000/rs6000.cc (rs6000_hard_regno_mode_ok_uncached):
Likewise.
(rs6000_option_override_internal): Likewise.
(rs6000_rtx_costs): Likewise.
* gcc/config/rs6000/rs6000.h (TARGET_LDBRX): Likewise.
(TARGET_FCFID): Likewise.
(TARGET_LFIWZX): Likewise.
(TARGET_FCFIDS): Likewise.
(TARGET_FCFIDU): Likewise.
(TARGET_FCFIDUS): Likewise.
(TARGET_FCTIDUZ): Likewise.
(TARGET_FCTIWUZ): Likewise.
(TARGET_FCTIDUZ): Likewise.
(TARGET_POWER7): New macro.
(TARGET_EXTRA_BUILTINS): Change TARGET_POPCNTD to TARGET_POWER7.
(CTZ_DEFINED_VALUE_AT_ZERO): Likewise.
* gcc/config/rs6000/rs6000.md (enabled attribute): Likewise.
(lrintsi2): Likewise.
(lrintsi): Likewise.
(lrintsi_di): Likewise.
(cmpmemsi): Likewise.
(bpermd_): Likewise.
(addg6s): Likewise.
(cdtbcd): Likewise.
(cbcdtd): Likewise.
(div_): Likewise.

Diff:
---
 gcc/config/rs6000/dfp.md|  2 +-
 gcc/config/rs6000/rs6000-builtin.cc |  4 ++--
 gcc/config/rs6000/rs6000-string.cc  |  2 +-
 gcc/config/rs6000/rs6000.cc |  8 
 gcc/config/rs6000/rs6000.h  | 21 +++--
 gcc/config/rs6000/rs6000.md | 20 ++--
 6 files changed, 29 insertions(+), 28 deletions(-)

diff --git a/gcc/config/rs6000/dfp.md b/gcc/config/rs6000/dfp.md
index 59fa66ae15c8..5919149682b2 100644
--- a/gcc/config/rs6000/dfp.md
+++ b/gcc/config/rs6000/dfp.md
@@ -214,7 +214,7 @@
 (define_insn "floatdidd2"
   [(set (match_operand:DD 0 "gpc_reg_operand" "=d")
(float:DD (match_operand:DI 1 "gpc_reg_operand" "d")))]
-  "TARGET_DFP && TARGET_POPCNTD"
+  "TARGET_DFP && TARGET_POWER7"
   "dcffix %0,%1"
   [(set_attr "type" "dfp")])
 
diff --git a/gcc/config/rs6000/rs6000-builtin.cc 
b/gcc/config/rs6000/rs6000-builtin.cc
index dbb8520ab039..2366b2aee00a 100644
--- a/gcc/config/rs6000/rs6000-builtin.cc
+++ b/gcc/config/rs6000/rs6000-builtin.cc
@@ -161,9 +161,9 @@ rs6000_builtin_is_supported (enum rs6000_gen_builtins 
fncode)
 case ENB_P6_64:
   return TARGET_POWER6 && TARGET_POWERPC64;
 case ENB_P7:
-  return TARGET_POPCNTD;
+  return TARGET_POWER7;
 case ENB_P7_64:
-  return TARGET_POPCNTD && TARGET_POWERPC64;
+  return TARGET_POWER7 && TARGET_POWERPC64;
 case ENB_P8:
   return TARGET_POWER8;
 case ENB_P8V:
diff --git a/gcc/config/rs6000/rs6000-string.cc 
b/gcc/config/rs6000/rs6000-string.cc
index 3d2911ca08a0..703f77fa0bf1 100644
--- a/gcc/config/rs6000/rs6000-string.cc
+++ b/gcc/config/rs6000/rs6000-string.cc
@@ -1949,7 +1949,7 @@ bool
 expand_block_compare (rtx operands[])
 {
   /* TARGET_POPCNTD is already guarded at expand cmpmemsi.  */
-  gcc_assert (TARGET_POPCNTD);
+  gcc_assert (TARGET_POWER7);
 
   /* For P8, this case is complicated to handle because the subtract
  with carry instructions do not generate the 64-bit carry and so
diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index c01af37200ac..503b07339647 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -1924,7 +1924,7 @@ rs6000_hard_regno_mode_ok_uncached (int regno, 
machine_mode mode)
  if(GET_MODE_SIZE (mode) == UNITS_PER_FP_WORD)
return 1;
 
- if (TARGET_POPCNTD && mode == SImode)
+ if (TARGET_POWER7 && mode == SImode)
return 1;
 
  if (TARGET_P9_VECTOR && (mode == QImode || mode == HImode))
@@ -3918,7 +3918,7 @@ rs6000_option_override_internal (bool global_init_p)
 rs6000_isa_flags |= (ISA_2_7_MASKS_SERVER & ~ignore_masks);
   else if (TARGET_VSX)
 rs6000_isa_flags |= (ISA_2_6_MASKS_SERVER & ~ignore_masks);
-  else if (TARGET_POPCNTD)
+  else if (TARGET_POWER7)
 rs6000_isa_flags |= (ISA_2_6_MASKS_EMBEDDED & ~ignore_masks);
   else if (TARGET_DFP)
 rs6000_isa_flags |= (ISA_2_5_MASKS_SERVER & ~ignore_masks);
@@ -4131,7 +4131,7 @@ rs6000_option_override_internal (bool global_init_p)
   else if (TARGET_LONG_DOUBLE_128)
  

[gcc(refs/users/meissner/heads/work196-math)] Add ChangeLog.math and update REVISION.

2025-04-05 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:e07838f07364c9ea5fdf71f4af63e0e6ab014788

commit e07838f07364c9ea5fdf71f4af63e0e6ab014788
Author: Michael Meissner 
Date:   Mon Mar 24 18:48:03 2025 -0400

Add ChangeLog.math and update REVISION.

2025-03-24  Michael Meissner  

gcc/

* ChangeLog.math: New file for branch.
* REVISION: Update.

Diff:
---
 gcc/ChangeLog.math | 5 +
 gcc/REVISION   | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog.math b/gcc/ChangeLog.math
new file mode 100644
index ..da7ffb4e0df1
--- /dev/null
+++ b/gcc/ChangeLog.math
@@ -0,0 +1,5 @@
+ Branch work196-math, baseline 
+
+2025-03-24   Michael Meissner  
+
+   Clone branch
diff --git a/gcc/REVISION b/gcc/REVISION
index 4879f9dc9d4e..1e732b52c53f 100644
--- a/gcc/REVISION
+++ b/gcc/REVISION
@@ -1 +1 @@
-work196 branch
+work196-math branch


[gcc/devel/rust/master] Fix an issue with ForeverStack::dfs_rib

2025-04-05 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:af2fdca5a3c9c18159a02dc8e94a95e701b66f81

commit af2fdca5a3c9c18159a02dc8e94a95e701b66f81
Author: Owen Avery 
Date:   Fri Jan 31 23:03:03 2025 -0500

Fix an issue with ForeverStack::dfs_rib

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.hxx
(ForeverStack::dfs_rib): Fix const implementation.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/resolve/rust-forever-stack.hxx | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/gcc/rust/resolve/rust-forever-stack.hxx 
b/gcc/rust/resolve/rust-forever-stack.hxx
index 2b628e44aead..be05f528c47b 100644
--- a/gcc/rust/resolve/rust-forever-stack.hxx
+++ b/gcc/rust/resolve/rust-forever-stack.hxx
@@ -638,9 +638,8 @@ tl::optional
 ForeverStack::dfs_rib (const ForeverStack::Node &starting_point,
  NodeId to_find) const
 {
-  return dfs_node (starting_point, to_find).map ([] (Node &x) -> Rib & {
-return x.rib;
-  });
+  return dfs_node (starting_point, to_find)
+.map ([] (const Node &x) -> const Rib & { return x.rib; });
 }
 
 template 


[gcc r15-8525] gccrs: Improve handling of static items in toplevel 2.0

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:d3a3e52addbe07fed81209a29fe653d840dc67d2

commit r15-8525-gd3a3e52addbe07fed81209a29fe653d840dc67d2
Author: Owen Avery 
Date:   Mon Nov 11 16:19:44 2024 -0500

gccrs: Improve handling of static items in toplevel 2.0

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Use DefaultResolver::visit and avoid a call
to Identifier::as_string while handling instances of StaticItem.

Signed-off-by: Owen Avery 

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

diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
index ef7a727dae98..a2f695e54f68 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -241,13 +241,10 @@ TopLevel::visit (AST::BlockExpr &expr)
 void
 TopLevel::visit (AST::StaticItem &static_item)
 {
-  auto sub_vis
-= [this, &static_item] () { static_item.get_expr ().accept_vis (*this); };
-
-  ctx.scoped (Rib::Kind::Item, static_item.get_node_id (), sub_vis);
-
-  insert_or_error_out (static_item.get_identifier ().as_string (), static_item,
+  insert_or_error_out (static_item.get_identifier (), static_item,
   Namespace::Values);
+
+  DefaultResolver::visit (static_item);
 }
 
 void


[gcc r15-8937] cobol: Bring trunk in line with Dubner's test system.

2025-04-05 Thread Robert Dubner via Gcc-cvs
https://gcc.gnu.org/g:4c05d6d26dbc0e8799325cc1c1a8221b52e7e28e

commit r15-8937-g4c05d6d26dbc0e8799325cc1c1a8221b52e7e28e
Author: Bob Dubner 
Date:   Wed Mar 26 16:07:44 2025 -0400

cobol: Bring trunk in line with Dubner's test system.

gcc/cobol

* genapi.cc: (parser_display_internal): Adjust for E vs e exponent 
notation.
* parse.y: (literal_refmod_valid): Display correct value in error 
message.

Diff:
---
 gcc/cobol/genapi.cc | 24 ++--
 gcc/cobol/parse.y   |  4 ++--
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc
index dc0bb79e1532..032236b15dba 100644
--- a/gcc/cobol/genapi.cc
+++ b/gcc/cobol/genapi.cc
@@ -4818,14 +4818,34 @@ parser_display_internal(tree file_descriptor,
 if( !p )
   {
   // Probably INF -INF NAN or -NAN, so ach has our result
+  // Except that real_to_decimal prints -0.0 and 0.0 like that with
+  // no e.
+  if( ach[0] == '0' || ( ach[0] == '-' && ach[1] == '0' ))
+__gg__remove_trailing_zeroes(ach);
   }
 else
   {
-  p += 1;
-  int exp = atoi(p);
+  int exp = atoi(p+1);
   if( exp >= 6 || exp <= -5 )
 {
 // We are going to stick with the E notation, so ach has our result
+// Except that real_to_decimal prints with e notation rather than E
+// and doesn't guarantee at least two exponent digits.
+*p = 'E';
+if( exp < 0 && exp >= -9 )
+  {
+p[1] = '-';
+p[2] = '0';
+p[3] = '0' - exp;
+p[4] = '\0';
+  }
+else if( exp >= 0 && exp <= 9 )
+  {
+p[1] = '+';
+p[2] = '0';
+p[3] = '0' + exp;
+p[4] = '\0';
+  }
 }
   else if (exp == 0)
 {
diff --git a/gcc/cobol/parse.y b/gcc/cobol/parse.y
index bad99528e599..538e56fa64d1 100644
--- a/gcc/cobol/parse.y
+++ b/gcc/cobol/parse.y
@@ -12856,14 +12856,14 @@ literal_refmod_valid( YYLTYPE loc, const cbl_refer_t& 
r ) {
 if( ! is_literal(refmod.len->field) ) return true;
 auto edge = refmod.len->field->as_integer();
 if( 0 < edge ) {
-  if( --edge < r.field->data.capacity ) return true;
+  if( edge-1 < r.field->data.capacity ) return true;
 }
 // len < 0 or not: 0 < from + len <= capacity
 error_msg(loc, "%s(%s:%zu) out of bounds, "
   "size is %u",
  r.field->name,
  refmod.from->name(),
- size_t(refmod.len->field->data.value_of()),
+ size_t(edge),
  static_cast(r.field->data.capacity) );
 return false;
   }


[gcc r14-11506] debug/101533 - ICE with variant typedef DIE generation

2025-04-05 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:c839965c2ef689cfd62c4ddeb61d872c0d04366c

commit r14-11506-gc839965c2ef689cfd62c4ddeb61d872c0d04366c
Author: Richard Biener 
Date:   Wed Mar 5 14:24:50 2025 +0100

debug/101533 - ICE with variant typedef DIE generation

There's a sanity check in gen_type_die_with_usage that trips
unnecessarily for a case where the relevant DIE has already been
generated successfully in other ways.  The following keys the
existing TREE_ASM_WRITTEN check on the correct object, honoring
this and does nothing instead of ICEing for the testcase at hand.

PR debug/101533
* dwarf2out.cc (gen_type_die_with_usage): When we have
output the typedef already do nothing for a typedef variant.
Do not set TREE_ASM_WRITTEN on the type.

* g++.dg/debug/pr101533.C: New testcase.

(cherry picked from commit 99a3f013c3bb8bc022ca488b40aa18fd97b5224d)

Diff:
---
 gcc/dwarf2out.cc  |  6 ++
 gcc/testsuite/g++.dg/debug/pr101533.C | 11 +++
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc
index 1b0e8b5a5b29..e1398c61cd59 100644
--- a/gcc/dwarf2out.cc
+++ b/gcc/dwarf2out.cc
@@ -26300,10 +26300,10 @@ gen_type_die_with_usage (tree type, dw_die_ref 
context_die,
  for the parent typedef which TYPE is a type of.  */
   if (typedef_variant_p (type))
 {
-  if (TREE_ASM_WRITTEN (type))
+  tree name = TYPE_NAME (type);
+  if (TREE_ASM_WRITTEN (name))
return;
 
-  tree name = TYPE_NAME (type);
   tree origin = decl_ultimate_origin (name);
   if (origin != NULL && origin != name)
{
@@ -26317,8 +26317,6 @@ gen_type_die_with_usage (tree type, dw_die_ref 
context_die,
   /* Give typedefs the right scope.  */
   context_die = scope_die_for (type, context_die);
 
-  TREE_ASM_WRITTEN (type) = 1;
-
   gen_decl_die (name, NULL, NULL, context_die);
   return;
 }
diff --git a/gcc/testsuite/g++.dg/debug/pr101533.C 
b/gcc/testsuite/g++.dg/debug/pr101533.C
new file mode 100644
index ..fc1e2e742a1d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/debug/pr101533.C
@@ -0,0 +1,11 @@
+// { dg-do compile }
+// { dg-options "-g" }
+
+template  class T
+{
+  typedef struct {} a __attribute__((aligned));
+};
+void f ()
+{
+  T();
+}


[gcc r15-8458] i386: Add AVX10.2 SAT CVT Intrinsics without Rounding Control

2025-04-05 Thread Hu via Gcc-cvs
https://gcc.gnu.org/g:e35327242317282a4ff5e2d933719828a0285e81

commit r15-8458-ge35327242317282a4ff5e2d933719828a0285e81
Author: Hu, Lin1 
Date:   Thu Mar 13 16:36:15 2025 +0800

i386: Add AVX10.2 SAT CVT Intrinsics without Rounding Control

gcc/ChangeLog:

* config/i386/avx10_2-512satcvtintrin.h: Add new intrinsics.
* config/i386/avx10_2satcvtintrin.h: Ditto.
* config/i386/i386-builtin-types.def:
Add DEF_FUNCTION_TYPE (V32HI, V32HF, V32HI, USI),
(V16SI, V16SF, V16SI, UHI), (V8DI, V8SF, V8DI, UQI),
(V8DI, V8DF, V8DI, UQI), (V8SI, V8DF, V8SI, UQI).
* config/i386/i386-builtin.def: Add new builtins.
* config/i386/i386-expand.cc: Handle V16SI_FTYPE_V16SF_V16SI_UHI,
V32HI_FTYPE_V32HF_V32HI_USI, V8DI_FTYPE_V8SF_V8DI_UQI,
V8DI_FTYPE_V8DF_V8DI_UQI, V8SI_FTYPE_V8DF_V8SI_UQI.

Diff:
---
 gcc/config/i386/avx10_2-512satcvtintrin.h | 496 ++
 gcc/config/i386/avx10_2satcvtintrin.h | 560 ++
 gcc/config/i386/i386-builtin-types.def|   5 +
 gcc/config/i386/i386-builtin.def  |  32 ++
 gcc/config/i386/i386-expand.cc|   5 +
 5 files changed, 1098 insertions(+)

diff --git a/gcc/config/i386/avx10_2-512satcvtintrin.h 
b/gcc/config/i386/avx10_2-512satcvtintrin.h
index a08f98c92a0f..1cef1dae0b12 100644
--- a/gcc/config/i386/avx10_2-512satcvtintrin.h
+++ b/gcc/config/i386/avx10_2-512satcvtintrin.h
@@ -157,6 +157,502 @@ _mm512_maskz_ipcvttbf16_epu8 (__mmask32 __U, __m512bh __A)
  (__mmask32) __U);
 }
 
+extern __inline __m512i
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
+_mm512_ipcvtph_epi8 (__m512h __A)
+{
+  return
+(__m512i) __builtin_ia32_cvtph2ibs512_mask ((__v32hf) __A,
+   (__v32hi)
+   _mm512_undefined_si512 (),
+   (__mmask32) -1);
+}
+
+extern __inline __m512i
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
+_mm512_mask_ipcvtph_epi8 (__m512i __W, __mmask32 __U, __m512h __A)
+{
+  return (__m512i) __builtin_ia32_cvtph2ibs512_mask ((__v32hf) __A,
+(__v32hi) __W,
+(__mmask32) __U);
+}
+
+extern __inline __m512i
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
+_mm512_maskz_ipcvtph_epi8 (__mmask32 __U, __m512h __A)
+{
+  return
+(__m512i) __builtin_ia32_cvtph2ibs512_mask ((__v32hf) __A,
+   (__v32hi)
+   _mm512_setzero_si512 (),
+   (__mmask32) __U);
+}
+
+extern __inline __m512i
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
+_mm512_ipcvtph_epu8 (__m512h __A)
+{
+  return
+(__m512i) __builtin_ia32_cvtph2iubs512_mask ((__v32hf) __A,
+(__v32hi)
+_mm512_undefined_si512 (),
+(__mmask32) -1);
+}
+
+extern __inline __m512i
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
+_mm512_mask_ipcvtph_epu8 (__m512i __W, __mmask32 __U, __m512h __A)
+{
+  return (__m512i) __builtin_ia32_cvtph2iubs512_mask ((__v32hf) __A,
+ (__v32hi) __W,
+ (__mmask32) __U);
+}
+
+extern __inline __m512i
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
+_mm512_maskz_ipcvtph_epu8 (__mmask32 __U, __m512h __A)
+{
+  return
+(__m512i) __builtin_ia32_cvtph2iubs512_mask ((__v32hf) __A,
+(__v32hi)
+_mm512_setzero_si512 (),
+(__mmask32) __U);
+}
+
+extern __inline __m512i
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
+_mm512_ipcvtps_epi8 (__m512 __A)
+{
+  return
+(__m512i) __builtin_ia32_cvtps2ibs512_mask ((__v16sf) __A,
+   (__v16si)
+   _mm512_undefined_si512 (),
+   (__mmask16) -1);
+}
+
+extern __inline __m512i
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
+_mm512_mask_ipcvtps_epi8 (__m512i __W, __mmask16 __U, __m512 __A)
+{
+  return (__m512i) __builtin_ia32_cvtps2ibs512_mask ((__v16sf) __A,
+(__v16si) __W,
+(__mmask16) __U);
+}
+
+extern __inline __m512i
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
+_mm512_maskz_ipcvtps_

[gcc r15-8808] gccrs: nr2.0: Run DefaultResolver::visit on PathInExpression

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:228ee853d9258099aa3bff0d5b89afe72761193f

commit r15-8808-g228ee853d9258099aa3bff0d5b89afe72761193f
Author: Owen Avery 
Date:   Tue Feb 4 05:53:10 2025 -0500

gccrs: nr2.0: Run DefaultResolver::visit on PathInExpression

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): When visiting a PathInExpression instance, call
into DefaultResolver::visit, ensuring generic arguments are
visited.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery 

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

diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
index 7253deb42d9c..8dd1088d65d3 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -284,6 +284,8 @@ Late::visit (AST::PathInExpression &expr)
 
   ctx.map_usage (Usage (expr.get_node_id ()),
 Definition (resolved->get_node_id ()));
+
+  DefaultResolver::visit (expr);
 }
 
 void
diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index 2186a1106d95..6eff293f0aa9 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -2,20 +2,14 @@ break-rust2.rs
 canonical_paths1.rs
 cfg1.rs
 complex-path1.rs
-const-issue1440.rs
 const_generics_3.rs
 const_generics_4.rs
 const_generics_7.rs
 derive_macro1.rs
-expected_type_args2.rs
 feature_rust_attri0.rs
 generic-default1.rs
-generics3.rs
-generics4.rs
 generics5.rs
 generics9.rs
-issue-1130.rs
-issue-1173.rs
 issue-1483.rs
 issue-1786.rs
 issue-1901.rs
@@ -24,14 +18,12 @@ issue-2043.rs
 issue-2330.rs
 issue-2723-1.rs
 issue-2723-2.rs
-issue-2775.rs
 issue-2782.rs
 issue-2812.rs
 issue-850.rs
 issue-855.rs
 iterators1.rs
 lookup_err1.rs
-macros/mbe/macro40.rs
 macros/mbe/macro43.rs
 macros/mbe/macro44.rs
 macros/mbe/macro6.rs
@@ -43,7 +35,6 @@ nested_macro_use1.rs
 nested_macro_use2.rs
 nested_macro_use3.rs
 not_find_value_in_scope.rs
-privacy4.rs
 privacy5.rs
 privacy8.rs
 pub_restricted_1.rs
@@ -56,8 +47,6 @@ self-path2.rs
 sizeof-stray-infer-var-bug.rs
 struct-expr-parse.rs
 traits3.rs
-traits6.rs
-traits7.rs
 undeclared_label.rs
 use_1.rs
 v0-mangle1.rs


[gcc/devel/rust/master] gccrs: self paths are patterns but we dont have mappings for it

2025-04-05 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:1eb46203ced28c5a3e44f6b63a23d4e91bd4f344

commit 1eb46203ced28c5a3e44f6b63a23d4e91bd4f344
Author: Philip Herron 
Date:   Thu Feb 13 17:45:09 2025 +

gccrs: self paths are patterns but we dont have mappings for it

With simple patterns we dont introduce any more inference varaibles as
they are already declared in a specific way. This would only lead to
more unconstrained inference varaibles than is required.

Fixes Rust-GCC#3022

gcc/rust/ChangeLog:

* hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_self): add 
location mappings
* typecheck/rust-hir-type-check-path.cc 
(TypeCheckExpr::resolve_root_path): check for self

gcc/testsuite/ChangeLog:

* rust/compile/issue-3022.rs: New test.

Signed-off-by: Philip Herron 

Diff:
---
 gcc/rust/hir/rust-ast-lower-base.cc|  1 +
 gcc/rust/typecheck/rust-hir-type-check-path.cc |  5 -
 gcc/testsuite/rust/compile/issue-3022.rs   | 18 ++
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/hir/rust-ast-lower-base.cc 
b/gcc/rust/hir/rust-ast-lower-base.cc
index 229f6e09c889..02fac9af7e91 100644
--- a/gcc/rust/hir/rust-ast-lower-base.cc
+++ b/gcc/rust/hir/rust-ast-lower-base.cc
@@ -666,6 +666,7 @@ ASTLoweringBase::lower_self (AST::Param ¶m)
   Analysis::NodeMapping mapping (crate_num, self.get_node_id (),
 mappings.get_next_hir_id (crate_num),
 mappings.get_next_localdef_id (crate_num));
+  mappings.insert_location (mapping.get_hirid (), param.get_locus ());
 
   if (self.has_type ())
 {
diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc 
b/gcc/rust/typecheck/rust-hir-type-check-path.cc
index 73d973847897..1904eba0c194 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-path.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc
@@ -312,6 +312,8 @@ TypeCheckExpr::resolve_root_path (HIR::PathInExpression 
&expr, size_t *offset,
   auto seg_is_module = mappings.lookup_module (ref).has_value ();
   auto seg_is_crate = mappings.is_local_hirid_crate (ref);
   auto seg_is_pattern = mappings.lookup_hir_pattern (ref).has_value ();
+  auto seg_is_self = is_root && !have_more_segments
+&& seg.get_segment ().as_string () == "self";
   if (seg_is_module || seg_is_crate)
{
  // A::B::C::this_is_a_module::D::E::F
@@ -388,7 +390,8 @@ TypeCheckExpr::resolve_root_path (HIR::PathInExpression 
&expr, size_t *offset,
  if (lookup->get_kind () == TyTy::TypeKind::ERROR)
return new TyTy::ErrorType (expr.get_mappings ().get_hirid ());
}
-  else if (lookup->needs_generic_substitutions () && !seg_is_pattern)
+  else if (lookup->needs_generic_substitutions () && !seg_is_pattern
+  && !seg_is_self)
{
  lookup = SubstMapper::InferSubst (lookup, expr.get_locus ());
}
diff --git a/gcc/testsuite/rust/compile/issue-3022.rs 
b/gcc/testsuite/rust/compile/issue-3022.rs
new file mode 100644
index ..b8b8e6fd5c79
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3022.rs
@@ -0,0 +1,18 @@
+#[lang = "sized"]
+trait Sized {}
+
+trait Foo {
+fn foo(self) -> T;
+}
+
+struct Bar {
+// { dg-warning "struct is never constructed" "" { target *-*-* } .-1 }
+value: U,
+valte: T,
+}
+
+impl, U> Foo for Bar {
+fn foo(self) -> U {
+self.value
+}
+}


[gcc r15-8604] gccrs: rust/intrinsic: add new "catch_unwind" variant of API

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:33462c81bb01469837c0cfe5039963b53495481a

commit r15-8604-g33462c81bb01469837c0cfe5039963b53495481a
Author: liushuyu 
Date:   Mon Dec 2 14:24:04 2024 -0700

gccrs: rust/intrinsic: add new "catch_unwind" variant of API

gcc/rust/ChangeLog:
* backend/rust-compile-intrinsic.cc: add the new `catch_unwind` 
variant
of the `try` intrinsic: this variant can be seen on Rust 1.78+
and returns `()` instead of `i32`.

Diff:
---
 gcc/rust/backend/rust-compile-intrinsic.cc | 57 --
 1 file changed, 47 insertions(+), 10 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-intrinsic.cc 
b/gcc/rust/backend/rust-compile-intrinsic.cc
index 77b67c36c3e0..0f0545882207 100644
--- a/gcc/rust/backend/rust-compile-intrinsic.cc
+++ b/gcc/rust/backend/rust-compile-intrinsic.cc
@@ -196,7 +196,15 @@ expect_handler (bool likely)
 }
 
 static tree
-try_handler (Context *ctx, TyTy::FnType *fntype);
+try_handler_inner (Context *ctx, TyTy::FnType *fntype, bool is_new_api);
+
+const static std::function
+try_handler (bool is_new_api)
+{
+  return [is_new_api] (Context *ctx, TyTy::FnType *fntype) {
+return try_handler_inner (ctx, fntype, is_new_api);
+  };
+}
 
 inline tree
 sorry_handler (Context *ctx, TyTy::FnType *fntype)
@@ -245,7 +253,8 @@ static const std::mapget_params ().size () == 3);
 
@@ -1283,6 +1292,13 @@ try_handler (Context *ctx, TyTy::FnType *fntype)
 
   enter_intrinsic_block (ctx, fndecl);
 
+  // The following tricks are needed to make sure the try-catch blocks are not
+  // optimized away
+  TREE_READONLY (fndecl) = 0;
+  DECL_DISREGARD_INLINE_LIMITS (fndecl) = 1;
+  DECL_ATTRIBUTES (fndecl) = tree_cons (get_identifier ("always_inline"),
+   NULL_TREE, DECL_ATTRIBUTES (fndecl));
+
   // BUILTIN try_handler FN BODY BEGIN
   // setup the params
   std::vector param_vars;
@@ -1296,15 +1312,31 @@ try_handler (Context *ctx, TyTy::FnType *fntype)
   tree try_fn = Backend::var_expression (param_vars[0], UNDEF_LOCATION);
   tree user_data = Backend::var_expression (param_vars[1], UNDEF_LOCATION);
   tree catch_fn = Backend::var_expression (param_vars[2], UNDEF_LOCATION);
-  tree normal_return_stmt
-= Backend::return_statement (fndecl, integer_zero_node, BUILTINS_LOCATION);
-  tree error_return_stmt
-= Backend::return_statement (fndecl, integer_one_node, BUILTINS_LOCATION);
+  tree normal_return_stmt = NULL_TREE;
+  tree error_return_stmt = NULL_TREE;
   tree try_call = Backend::call_expression (try_fn, {user_data}, nullptr,
BUILTINS_LOCATION);
   tree catch_call = NULL_TREE;
   tree try_block = Backend::block (fndecl, enclosing_scope, {}, UNDEF_LOCATION,
   UNDEF_LOCATION);
+
+  if (is_new_api)
+{
+  auto ret_type = TyTyResolveCompile::get_unit_type ();
+  auto ret_expr = Backend::constructor_expression (ret_type, false, {}, -1,
+  UNDEF_LOCATION);
+  normal_return_stmt
+   = Backend::return_statement (fndecl, ret_expr, BUILTINS_LOCATION);
+  error_return_stmt
+   = Backend::return_statement (fndecl, ret_expr, BUILTINS_LOCATION);
+}
+  else
+{
+  normal_return_stmt = Backend::return_statement (fndecl, 
integer_zero_node,
+ BUILTINS_LOCATION);
+  error_return_stmt = Backend::return_statement (fndecl, integer_one_node,
+BUILTINS_LOCATION);
+}
   Backend::block_add_statements (try_block,
 std::vector{try_call,
   normal_return_stmt});
@@ -1320,17 +1352,22 @@ try_handler (Context *ctx, TyTy::FnType *fntype)
 = build_call_expr (builtin_decl_explicit (BUILT_IN_EH_POINTER), 1,
   integer_zero_node);
   catch_call = Backend::call_expression (catch_fn, {user_data, eh_pointer},
-nullptr, BUILTINS_LOCATION);
+NULL_TREE, BUILTINS_LOCATION);
 
   tree catch_block = Backend::block (fndecl, enclosing_scope, {},
 UNDEF_LOCATION, UNDEF_LOCATION);
   Backend::block_add_statements (catch_block,
 std::vector{catch_call,
   error_return_stmt});
+  // emulate what cc1plus is doing for C++ try-catch
+  tree inner_eh_construct
+= Backend::exception_handler_statement (catch_call, NULL_TREE,
+   error_return_stmt,
+   BUILTINS_LOCATION);
   // TODO(liushuyu): eh_personality needs to be implemented as a runtime thing
   auto eh_construct
-= Backend::exception_handler_statement (try_block, catch_block, NULL_TREE,
- 

[gcc r15-8258] Build and install gcobol driver for the cross build

2025-04-05 Thread Matthias Klose via Gcc-cvs
https://gcc.gnu.org/g:d1fd9da39abc4e0430fed46d14ebd2360324f8b8

commit r15-8258-gd1fd9da39abc4e0430fed46d14ebd2360324f8b8
Author: Matthias Klose 
Date:   Tue Mar 18 16:12:37 2025 +0100

Build and install gcobol driver for the cross build

gcc/cobol/

2025-03-18  Matthias Klose  

* Make-lang.in (GCOBC_TARGET_INSTALL_NAME, gcobol-cross): New.
(cobol.all.cross): Depend on gcobol-cross.
(cobol.install-common): Adjust install for the cross build.
(cobol.uninstall): Use *_INSTALL_NAME for uninstall.

Diff:
---
 gcc/cobol/Make-lang.in | 26 ++
 1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/gcc/cobol/Make-lang.in b/gcc/cobol/Make-lang.in
index eccc1c43f23b..5b61ae912192 100644
--- a/gcc/cobol/Make-lang.in
+++ b/gcc/cobol/Make-lang.in
@@ -38,6 +38,7 @@ GCOBOL_INSTALL_NAME := $(shell echo gcobol|sed 
'$(program_transform_name)')
 GCOBOL_TARGET_INSTALL_NAME := $(target_noncanonical)-$(shell echo gcobol|sed 
'$(program_transform_name)')
 
 GCOBC_INSTALL_NAME := $(shell echo gcobc|sed '$(program_transform_name)')
+GCOBC_TARGET_INSTALL_NAME := $(target_noncanonical)-$(shell echo gcobc|sed 
'$(program_transform_name)')
 
 cobol: cobol1$(exeext)
 cobol.serial = cobol1$(exeext)
@@ -149,6 +150,11 @@ gcobol$(exeext): \
 $(GCOBOL_D_OBJS) $(EXTRA_GCC_OBJS) libcommon-target.a  \
 $(EXTRA_GCC_LIBS) $(LIBS)
 
+# Create a version of the gcobol driver which calls the cross-compiler.
+gcobol-cross$(exeext): gcobol$(exeext)
+   -rm -f gcobol-cross$(exeext)
+   cp gcobol$(exeext) gcobol-cross$(exeext)
+
 #
 # These control the build of the cobol1 source-to-GENERIC converter
 #
@@ -277,17 +283,29 @@ cobol1$(exeext): $(cobol1_OBJS) $(BACKEND) $(LIBDEPS) 
attribs.o $(cobol.prev)
  $(cobol1_OBJS) $(BACKEND) $(LIBS) $(BACKENDLIBS)
@$(call LINK_PROGRESS,$(INDEX.cobol),end)
 
-# FIXME
-cobol.all.cross:
+cobol.all.cross: gcobol-cross$(exeext)
 
 cobol.start.encap: gcobol$(exeext)
 
 cobol.rest.encap:
 
 cobol.install-common: installdirs
+   -rm -f $(DESTDIR)$(bindir)/$(GCOBOL_INSTALL_NAME)$(exeext)
+   -rm -f $(DESTDIR)$(bindir)/$(GCOBC_INSTALL_NAME)$(exeext)
$(INSTALL_PROGRAM) gcobol$(exeext)  
$(DESTDIR)$(bindir)/$(GCOBOL_INSTALL_NAME)$(exeext)
$(INSTALL_PROGRAM) cobol1$(exeext)  $(DESTDIR)$(libexecsubdir)/
$(INSTALL) -m 755 $(srcdir)/cobol/gcobc 
$(DESTDIR)$(bindir)/$(GCOBC_INSTALL_NAME)$(exeext)
+   -if test -f cobol1$(exeext); then \
+ if test -f gcobol-cross$(exeext); then \
+   :; \
+ else \
+   rm -f $(DESTDIR)$(bindir)/$(GCOBOL_TARGET_INSTALL_NAME)$(exeext); \
+   rm -f $(DESTDIR)$(bindir)/$(GCOBC_TARGET_INSTALL_NAME)$(exeext); \
+   ( cd $(DESTDIR)$(bindir) && \
+ $(LN) $(GCOBOL_INSTALL_NAME)$(exeext) 
$(GCOBOL_TARGET_INSTALL_NAME)$(exeext) ); \
+ $(LN) $(GCOBC_INSTALL_NAME)$(exeext) 
$(GCOBC_TARGET_INSTALL_NAME)$(exeext) ); \
+ fi; \
+   fi
mkdir -p $(DESTDIR)$(datadir)/gcobol/udf
$(INSTALL_DATA) $(srcdir)/cobol/udf/*   $(DESTDIR)$(datadir)/gcobol/udf/
 
@@ -338,9 +356,9 @@ gcobol-io.html: $(srcdir)/cobol/gcobol.3
 # the installed location of the cobol1 compiler.
 cobol.uninstall:
rm -rf  $(DESTDIR)$(bindir)/$(GCOBOL_INSTALL_NAME)$(exeext) \
-   $(DESTDIR)$(bindir)/gcobc   \
+   $(DESTDIR)$(bindir)/$(GCOBC_INSTALL_NAME)   \
$(DESTDIR)$(datadir)/gcobol/\
-   $(DESTDIR)$(man1dir)/gcobol.1   \
+   $(DESTDIR)$(man1dir)/$(GCOBOL_INSTALL_NAME).1   \
$(DESTDIR)$(man3dir)/gcobol.3
 
 cobol.man:


[gcc(refs/users/omachota/heads/rtl-ssa-dce)] rtl-ssa: dce mark sketch

2025-04-05 Thread Ondrej Machota via Gcc-cvs
https://gcc.gnu.org/g:3136c46e7d16842d921aa15b268e72e04f9c5af5

commit 3136c46e7d16842d921aa15b268e72e04f9c5af5
Author: Ondřej Machota 
Date:   Sun Sep 29 20:20:11 2024 +0200

rtl-ssa: dce mark sketch

Diff:
---
 gcc/dce.cc | 57 +
 1 file changed, 57 insertions(+)

diff --git a/gcc/dce.cc b/gcc/dce.cc
index 640040dbf3d3..ed3231d91404 100644
--- a/gcc/dce.cc
+++ b/gcc/dce.cc
@@ -40,6 +40,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "dbgcnt.h"
 #include "rtl-iter.h"
 
+using namespace rtl_ssa;
+
 
 /* -
Core mark/delete routines
@@ -1300,6 +1302,15 @@ public:
 
 } // namespace
 
+
+bool is_inherently_live(insn_info *insn) {
+
+}
+
+static void rti_ssa_dce_() {
+  
+}
+
 static void
 rtl_ssa_dce_init ()
 {
@@ -1326,6 +1337,52 @@ rtl_ssa_dce ()
 {
 rtl_ssa_dce_init ();
 
+insn_info *next;
+sbitmap marked;
+auto_vec worklist;
+for (insn_info *insn = crtl->ssa->first_insn (); insn; insn = next)
+{
+  next = insn->next_any_insn ();
+  auto *rtl = insn->rtl();
+  /*
+  I would like to mark visited instruction with something like plf (Pass 
local flags) as in gimple
+
+  This file contains some useful functions: e.g. marked_insn_p, mark_insn
+  mark_insn does much more than I want now...
+  It does quite a useful job. If rtl_insn is a call and it is obsolete, it 
will find call arguments.
+  */
+ // insn.defs() // UD chain - this is what I want - reach the ancestors\
+ // insn.uses() // DU chain
+  if (is_inherently_live(insn)) {
+if (dump_file)
+ fprintf (dump_file, "  Adding insn %d to worklist\n", 
INSN_UID (insn));
+worklist.safe_push (insn);
+bitmap_set_bit(marked, INSN_UID (insn)); 
+  }
+
+  //if (insn->can_be_optimized () || insn->is_debug_insn ())
+   // if (fwprop_insn (insn, fwprop_addr_p))
+   // worklist.safe_push (insn);
+}
+
+while (!worklist.is_empty())
+{
+  insn_info *insn = worklist.pop();
+  def_array defs = insn->defs(); // array - because of phi?
+  for (size_t i = 0; i < defs.size(); i++)
+  {
+
+insn_info* parent_insn = defs[i]->insn();
+
+if (!bitmap_bit_p(INSN_UID (parent_insn))) {
+  if (dump_file)
+ fprintf (dump_file, "  Adding insn %d to worklist\n", 
INSN_UID (parent_insn));
+  worklist.safe_push(parent_insn);
+  bitmap_set_bit(marked, INSN_UID (parent_insn)); 
+}
+  }
+}
+
 rtl_ssa_dce_done ();
 return 0;
 }


[gcc r15-8603] gccrs: rust/intrinsic: add try intrinsic and panic strategy options

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:165e7575a96af9ba901af199fa525f069efef574

commit r15-8603-g165e7575a96af9ba901af199fa525f069efef574
Author: liushuyu 
Date:   Sat Sep 9 14:19:06 2023 -0600

gccrs: rust/intrinsic: add try intrinsic and panic strategy options

gcc/rust/ChangeLog:
* backend/rust-compile-intrinsic.cc: add `try` intrinsic handler.
* lang.opt: add `-frust-panic` option.
* rust-lang.cc: enable exception handler code generation.
* rust-session-manager.cc: add getter and setter for panic
strategy option.
* rust-session-manager.h: Likewise.

Signed-off-by: Zixing Liu 

Diff:
---
 gcc/rust/backend/rust-compile-intrinsic.cc | 72 ++
 gcc/rust/lang.opt  | 13 ++
 gcc/rust/rust-lang.cc  |  2 +
 gcc/rust/rust-session-manager.cc   |  3 ++
 gcc/rust/rust-session-manager.h| 14 ++
 5 files changed, 104 insertions(+)

diff --git a/gcc/rust/backend/rust-compile-intrinsic.cc 
b/gcc/rust/backend/rust-compile-intrinsic.cc
index 16447b29a51e..77b67c36c3e0 100644
--- a/gcc/rust/backend/rust-compile-intrinsic.cc
+++ b/gcc/rust/backend/rust-compile-intrinsic.cc
@@ -23,6 +23,7 @@
 #include "rust-diagnostics.h"
 #include "rust-location.h"
 #include "rust-constexpr.h"
+#include "rust-session-manager.h"
 #include "rust-tree.h"
 #include "tree-core.h"
 #include "rust-gcc.h"
@@ -194,6 +195,9 @@ expect_handler (bool likely)
   };
 }
 
+static tree
+try_handler (Context *ctx, TyTy::FnType *fntype);
+
 inline tree
 sorry_handler (Context *ctx, TyTy::FnType *fntype)
 {
@@ -241,6 +245,7 @@ static const std::mapget_params ().size () == 3);
+
+  tree lookup = NULL_TREE;
+  if (check_for_cached_intrinsic (ctx, fntype, &lookup))
+return lookup;
+  auto fndecl = compile_intrinsic_function (ctx, fntype);
+
+  enter_intrinsic_block (ctx, fndecl);
+
+  // BUILTIN try_handler FN BODY BEGIN
+  // setup the params
+  std::vector param_vars;
+  compile_fn_params (ctx, fntype, fndecl, ¶m_vars);
+  if (!Backend::function_set_parameters (fndecl, param_vars))
+return error_mark_node;
+  tree enclosing_scope = NULL_TREE;
+
+  bool panic_is_abort = Session::get_instance ().options.get_panic_strategy ()
+   == CompileOptions::PanicStrategy::Abort;
+  tree try_fn = Backend::var_expression (param_vars[0], UNDEF_LOCATION);
+  tree user_data = Backend::var_expression (param_vars[1], UNDEF_LOCATION);
+  tree catch_fn = Backend::var_expression (param_vars[2], UNDEF_LOCATION);
+  tree normal_return_stmt
+= Backend::return_statement (fndecl, integer_zero_node, BUILTINS_LOCATION);
+  tree error_return_stmt
+= Backend::return_statement (fndecl, integer_one_node, BUILTINS_LOCATION);
+  tree try_call = Backend::call_expression (try_fn, {user_data}, nullptr,
+   BUILTINS_LOCATION);
+  tree catch_call = NULL_TREE;
+  tree try_block = Backend::block (fndecl, enclosing_scope, {}, UNDEF_LOCATION,
+  UNDEF_LOCATION);
+  Backend::block_add_statements (try_block,
+std::vector{try_call,
+  normal_return_stmt});
+  if (panic_is_abort)
+{
+  // skip building the try-catch construct
+  ctx->add_statement (try_block);
+  finalize_intrinsic_block (ctx, fndecl);
+  return fndecl;
+}
+
+  tree eh_pointer
+= build_call_expr (builtin_decl_explicit (BUILT_IN_EH_POINTER), 1,
+  integer_zero_node);
+  catch_call = Backend::call_expression (catch_fn, {user_data, eh_pointer},
+nullptr, BUILTINS_LOCATION);
+
+  tree catch_block = Backend::block (fndecl, enclosing_scope, {},
+UNDEF_LOCATION, UNDEF_LOCATION);
+  Backend::block_add_statements (catch_block,
+std::vector{catch_call,
+  error_return_stmt});
+  // TODO(liushuyu): eh_personality needs to be implemented as a runtime thing
+  auto eh_construct
+= Backend::exception_handler_statement (try_block, catch_block, NULL_TREE,
+   BUILTINS_LOCATION);
+  ctx->add_statement (eh_construct);
+  // BUILTIN try_handler FN BODY END
+  finalize_intrinsic_block (ctx, fndecl);
+
+  return fndecl;
+}
+
 } // namespace Compile
 } // namespace Rust
diff --git a/gcc/rust/lang.opt b/gcc/rust/lang.opt
index ae601eb13ad2..0e9aab48dfb7 100644
--- a/gcc/rust/lang.opt
+++ b/gcc/rust/lang.opt
@@ -212,4 +212,17 @@ frust-borrowcheck
 Rust Var(flag_borrowcheck)
 Use the WIP borrow checker.
 
+frust-panic=
+Rust Joined RejectNegative Enum(frust_panic) Var(flag_rust_panic)
+-frust-edition=[unwind|abort] Panic strategy to compile crate with
+
+Enum
+Name(frust_panic) Type(int) UnknownError(unknown panic strategy %qs)
+
+EnumValue
+Enum(frust_pan

[gcc(refs/users/omachota/heads/rtl-ssa-dce)] rtl-ssa-dce: add prefetch as prelive + clone on pass

2025-04-05 Thread Ondrej Machota via Gcc-cvs
https://gcc.gnu.org/g:cbfcd3865f6b87df53891ab62edde5cbdb3a0cbd

commit cbfcd3865f6b87df53891ab62edde5cbdb3a0cbd
Author: Ondřej Machota 
Date:   Mon Mar 17 23:30:08 2025 +0100

rtl-ssa-dce: add prefetch as prelive + clone on pass

Diff:
---
 gcc/dce.cc | 17 +
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/gcc/dce.cc b/gcc/dce.cc
index 091e5c620f5b..b11ced743d74 100644
--- a/gcc/dce.cc
+++ b/gcc/dce.cc
@@ -1454,8 +1454,7 @@ bool is_rtx_insn_prelive(rtx_insn *insn) {
 // return !find_call_stack_args (as_a  (insn), false, 
fast, arg_stores);
 
   // Only rtx_insn should be handled here
-  auto code = GET_CODE(insn);
-  gcc_assert(code == INSN);
+  gcc_assert(GET_CODE(insn) == INSN);
 
   /* Don't delete insns that may throw if we cannot do so.  */
   if (!(cfun->can_delete_dead_exceptions && can_alter_cfg) && !insn_nothrow_p 
(insn))
@@ -1476,6 +1475,11 @@ bool is_rtx_insn_prelive(rtx_insn *insn) {
   if (GET_CODE(body) == CLOBBER) // 
gcc/gcc/testsuite/gcc.c-torture/compile/2605-1.c
 return true;
 
+  if (GET_CODE(body) == PREFETCH)
+return true;
+
+  // See deletable_insn_p_1 for UNSPEC. TRAP_IF is caught by 
may_trap_or_fault_p
+
   // may_trap_or_fault_p helps a lot to pass some tests from 
RUNTESTSFLAGS=execute.exp
   // e. g. this one: testsuite/gcc.c-torture/execute/20020418-1.c
   // TODO : debug the testcase
@@ -1484,10 +1488,6 @@ bool is_rtx_insn_prelive(rtx_insn *insn) {
   if (side_effects_with_mem(body) || can_throw_internal(body) || 
may_trap_or_fault_p(body))
 return true;
 
-  // TODO : parallel, {pre,post}_{int,dec}, {pre,post}_modify, 
may_trap_or_fault_p
-  // Parallel is handled by volatile_refs_p
-
-
   return false;
 }
 
@@ -1767,8 +1767,9 @@ namespace
   public:
 pass_rtl_ssa_dce(gcc::context *ctxt)
 : rtl_opt_pass(pass_data_rtl_ssa_dce, ctxt)
-{
-}
+{}
+
+opt_pass * clone () final override { return new pass_rtl_ssa_dce (m_ctxt); 
}
 
 /* opt_pass methods: */
 bool gate(function *) final override { return optimize > 0 && flag_dce; }


[gcc/devel/rust/master] derive(PartialEq): Add partial implementation

2025-04-05 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:d45dfed78f9243addd015c8534876b5c32f09c25

commit d45dfed78f9243addd015c8534876b5c32f09c25
Author: Arthur Cohen 
Date:   Thu Jan 30 14:41:11 2025 +0100

derive(PartialEq): Add partial implementation

We are still missing some deriving for enums, as part of our codegen and 
nameres for rebinding struct
field patterns is missing.

gcc/rust/ChangeLog:

* expand/rust-derive-partial-eq.cc: New file.
* expand/rust-derive-partial-eq.h: New file.
* expand/rust-derive.cc (DeriveVisitor::derive): Call them.
* Make-lang.in: Compile them.

gcc/testsuite/ChangeLog:

* rust/compile/derive-eq-invalid.rs: Mark PartialEq def as a lang 
item.
* rust/compile/derive-partialeq1.rs: New test.
* rust/execute/torture/derive-partialeq1.rs: New test.
* rust/compile/nr2/exclude: Exclude all of them.

Diff:
---
 gcc/rust/Make-lang.in  |   1 +
 gcc/rust/expand/rust-derive-partial-eq.cc  | 308 +
 gcc/rust/expand/rust-derive-partial-eq.h   |  81 ++
 gcc/rust/expand/rust-derive.cc |   2 +
 gcc/testsuite/rust/compile/derive-eq-invalid.rs|   9 +-
 gcc/testsuite/rust/compile/derive-partialeq1.rs|  59 
 gcc/testsuite/rust/compile/nr2/exclude |   2 +
 .../rust/execute/torture/derive-partialeq1.rs  |  61 
 8 files changed, 519 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index 287c18d1a8e1..c2df71021e2f 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -98,6 +98,7 @@ GRS_OBJS = \
 rust/rust-derive-copy.o \
 rust/rust-derive-debug.o \
 rust/rust-derive-default.o \
+rust/rust-derive-partial-eq.o \
 rust/rust-derive-eq.o \
 rust/rust-proc-macro.o \
 rust/rust-macro-invoc-lexer.o \
diff --git a/gcc/rust/expand/rust-derive-partial-eq.cc 
b/gcc/rust/expand/rust-derive-partial-eq.cc
new file mode 100644
index ..6f7ef7d8780f
--- /dev/null
+++ b/gcc/rust/expand/rust-derive-partial-eq.cc
@@ -0,0 +1,308 @@
+// Copyright (C) 2020-2024 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3.  If not see
+// .
+
+#include "rust-derive-partial-eq.h"
+#include "rust-ast.h"
+#include "rust-expr.h"
+#include "rust-item.h"
+#include "rust-operators.h"
+#include "rust-path.h"
+#include "rust-pattern.h"
+#include "rust-system.h"
+
+namespace Rust {
+namespace AST {
+DerivePartialEq::DerivePartialEq (location_t loc)
+  : DeriveVisitor (loc), expanded (nullptr)
+{}
+
+std::unique_ptr
+DerivePartialEq::go (Item &item)
+{
+  item.accept_vis (*this);
+
+  rust_assert (expanded);
+
+  return std::move (expanded);
+}
+
+std::unique_ptr
+DerivePartialEq::partial_eq_impl (
+  std::unique_ptr &&eq_fn, std::string name,
+  const std::vector> &type_generics)
+{
+  auto eq = builder.type_path (LangItem::Kind::EQ);
+
+  auto trait_items = vec (std::move (eq_fn));
+
+  auto generics
+= setup_impl_generics (name, type_generics, builder.trait_bound (eq));
+
+  return builder.trait_impl (eq, std::move (generics.self_type),
+std::move (trait_items),
+std::move (generics.impl));
+}
+
+std::unique_ptr
+DerivePartialEq::eq_fn (std::unique_ptr &&cmp_expression,
+   std::string type_name)
+{
+  auto block = builder.block (tl::nullopt, std::move (cmp_expression));
+
+  auto self_type
+= std::unique_ptr (new TypePath (builder.type_path 
("Self")));
+
+  auto params
+= vec (builder.self_ref_param (),
+  builder.function_param (builder.identifier_pattern ("other"),
+  builder.reference_type (
+std::move (self_type;
+
+  return builder.function ("eq", std::move (params),
+  builder.single_type_path ("bool"),
+  std::move (block));
+}
+
+DerivePartialEq::SelfOther
+DerivePartialEq::tuple_indexes (int idx)
+{
+  return SelfOther{
+builder.tuple_idx ("self", idx),
+builder.tuple_idx ("other", idx),
+  };
+}
+
+DerivePartialEq::SelfOther
+DerivePartialEq::field_acccesses (const std::string &field_name)
+{
+  return SelfOther{
+builder.field_access (builder.identifier ("self"), field_nam

[gcc r15-9092] gccrs: Fix ICE when using super mid way though path

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:a99268b1cc0069ba3d4ad177e8ab0cefc335b9ea

commit r15-9092-ga99268b1cc0069ba3d4ad177e8ab0cefc335b9ea
Author: Philip Herron 
Date:   Wed Mar 26 17:26:12 2025 +

gccrs: Fix ICE when using super mid way though path

Fixes Rust-GCC#3568

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path): 
check for super mid path

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 puts out a different error multiple 
times
* rust/compile/issue-3568.rs: New test.

Signed-off-by: Philip Herron 

Diff:
---
 gcc/rust/resolve/rust-ast-resolve-path.cc | 6 ++
 gcc/testsuite/rust/compile/issue-3568.rs  | 7 +++
 gcc/testsuite/rust/compile/nr2/exclude| 1 +
 3 files changed, 14 insertions(+)

diff --git a/gcc/rust/resolve/rust-ast-resolve-path.cc 
b/gcc/rust/resolve/rust-ast-resolve-path.cc
index b2b10719e190..530926d5d97a 100644
--- a/gcc/rust/resolve/rust-ast-resolve-path.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-path.cc
@@ -370,6 +370,12 @@ ResolvePath::resolve_path (AST::SimplePath &expr)
}
   else if (segment.is_super_path_seg ())
{
+ if (!is_first_segment)
+   {
+ rust_error_at (segment.get_locus (),
+"% can only be used in start position");
+ return UNKNOWN_NODEID;
+   }
  if (module_scope_id == crate_scope_id)
{
  rust_error_at (segment.get_locus (),
diff --git a/gcc/testsuite/rust/compile/issue-3568.rs 
b/gcc/testsuite/rust/compile/issue-3568.rs
new file mode 100644
index ..222a174ef381
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3568.rs
@@ -0,0 +1,7 @@
+pub type T = ();
+mod foo {
+pub use super::T;
+}
+
+pub use foo::super::foo::S as T;
+// { dg-error ".super. can only be used in start position" "" { target *-*-* } 
.-1 }
diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index 71c2b682bf02..9273bd1489e1 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -36,4 +36,5 @@ torture/alt_patterns1.rs
 torture/loop4.rs
 torture/loop8.rs
 torture/name_resolve1.rs
+issue-3568.rs
 # please don't delete the trailing newline


[gcc r15-8559] gccrs: lang-items: Store NodeId mappings for lang items

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:e0315c138337ddfac4dc41d1e26d0c8dd7564e0b

commit r15-8559-ge0315c138337ddfac4dc41d1e26d0c8dd7564e0b
Author: Arthur Cohen 
Date:   Mon Nov 25 15:05:32 2024 +0100

gccrs: lang-items: Store NodeId mappings for lang items

gcc/rust/ChangeLog:

* util/rust-hir-map.h: Keep a NodeId mappings for lang items.
* util/rust-hir-map.cc (Mappings::insert_lang_item_node): New 
function.
(Mappings::lookup_lang_item_node): Likewise.

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

diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index 5f77f570073f..f11a77954aef 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -1241,6 +1241,9 @@ Mappings::lookup_builtin_marker ()
   return builtinMarker;
 }
 
+// FIXME: Before merging: Should we remove the `locus` parameter here? since
+// lang items are looked up mostly for code generation, it doesn't make sense 
to
+// error out on the locus of the node trying to access an inexistant lang item
 DefId
 Mappings::get_lang_item (LangItem::Kind item_type, location_t locus)
 {
@@ -1277,5 +1280,24 @@ Mappings::lookup_lang_item (LangItem::Kind item_type)
   return it->second;
 }
 
+void
+Mappings::insert_lang_item_node (LangItem::Kind item_type, NodeId node_id)
+{
+  auto it = lang_item_nodes.find (item_type);
+  rust_assert (it == lang_item_nodes.end ());
+
+  lang_item_nodes.insert ({item_type, node_id});
+}
+
+tl::optional
+Mappings::lookup_lang_item_node (LangItem::Kind item_type)
+{
+  auto it = lang_item_nodes.find (item_type);
+  if (it == lang_item_nodes.end ())
+return tl::nullopt;
+
+  return it->second;
+}
+
 } // namespace Analysis
 } // namespace Rust
diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h
index 14a0514338b4..aba51be4827f 100644
--- a/gcc/rust/util/rust-hir-map.h
+++ b/gcc/rust/util/rust-hir-map.h
@@ -259,6 +259,9 @@ public:
   void insert_lang_item (LangItem::Kind item_type, DefId id);
   tl::optional lookup_lang_item (LangItem::Kind item_type);
 
+  void insert_lang_item_node (LangItem::Kind item_type, NodeId node_id);
+  tl::optional lookup_lang_item_node (LangItem::Kind item_type);
+
   // This will fatal_error when this lang item does not exist
   DefId get_lang_item (LangItem::Kind item_type, location_t locus);
 
@@ -375,7 +378,12 @@ private:
   std::map hirGenericParamMappings;
   std::map hirTraitItemsToTraitMappings;
   std::map hirPatternMappings;
+
+  // We need to have two maps here, as lang-items need to be used for both AST
+  // passes and HIR passes. Thus those two maps are created at different times.
   std::map lang_item_mappings;
+  std::map lang_item_nodes;
+
   std::map paths;
   std::map locations;
   std::map nodeIdToHirMappings;


[gcc/devel/rust/master] gccrs: Fix ICE when resolving lifetimes without name

2025-04-05 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:20c8539a23e0a0462e3763c3983ffb3ca9b7e709

commit 20c8539a23e0a0462e3763c3983ffb3ca9b7e709
Author: Philip Herron 
Date:   Mon Mar 31 17:33:59 2025 +0100

gccrs: Fix ICE when resolving lifetimes without name

We dont need to assert here the lifetime code already supports this case.

Fixes Rust-GCC#3657

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-base.cc: remove assertion

gcc/testsuite/ChangeLog:

* rust/compile/issue-3657.rs: New test.

Signed-off-by: Philip Herron 

Diff:
---
 gcc/rust/typecheck/rust-hir-type-check-base.cc | 2 --
 gcc/testsuite/rust/compile/issue-3657.rs   | 8 
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.cc 
b/gcc/rust/typecheck/rust-hir-type-check-base.cc
index 378ef02eda12..55ab86f4105b 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-base.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-base.cc
@@ -397,8 +397,6 @@ TypeCheckBase::resolve_generic_params (
auto lifetime_param
  = static_cast (*generic_param);
auto lifetime = lifetime_param.get_lifetime ();
-   rust_assert (lifetime.get_lifetime_type ()
-== AST::Lifetime::LifetimeType::NAMED);
context->get_lifetime_resolver ().insert_mapping (
  context->intern_lifetime (lifetime));
  }
diff --git a/gcc/testsuite/rust/compile/issue-3657.rs 
b/gcc/testsuite/rust/compile/issue-3657.rs
new file mode 100644
index ..978f3ce336fb
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3657.rs
@@ -0,0 +1,8 @@
+struct Foo<'_>(&'_ u8);
+
+impl Foo<'a> {
+// { dg-error "unresolved lifetime" "" { target *-*-* } .-1 }
+fn x() {}
+}
+
+fn x() {}


[gcc r15-8597] gccrs: add support for lang_item eq and PartialEq trait

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:ef4028cd8472edd3b898dc5a2ac353b82c6303f4

commit r15-8597-gef4028cd8472edd3b898dc5a2ac353b82c6303f4
Author: Philip Herron 
Date:   Thu Dec 19 16:43:49 2024 +

gccrs: add support for lang_item eq and PartialEq trait

The Eq and Partial Ord are very similar to the operator overloads
we support for add/sub/etc... but they differ in that usually the
function call name matches the name of the lang item. This time
we need to have support to send in a new path for the method call
on the lang item we want instead of just the name of the lang item.

NOTE: this test case doesnt work correctly yet we need to support
the derive of partial eq on enums to generate the correct comparison
code for that.

Fixes Rust-GCC#3302

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): handle 
partial_eq possible call
* backend/rust-compile-expr.h: handle case where lang item calls 
differ from name
* hir/tree/rust-hir-expr.cc (OperatorExprMeta::OperatorExprMeta): 
new helper
* hir/tree/rust-hir-expr.h: likewise
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): 
handle partial_eq
(TypeCheckExpr::resolve_operator_overload): likewise
* typecheck/rust-hir-type-check-expr.h: likewise
* util/rust-lang-item.cc (LangItem::ComparisonToLangItem): map 
comparison to lang item
(LangItem::ComparisonToSegment): likewise
* util/rust-lang-item.h: new lang items PartialOrd and Eq
* util/rust-operators.h (enum class): likewise

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/cmp1.rs: New test.

Signed-off-by: Philip Herron 

Diff:
---
 gcc/rust/backend/rust-compile-expr.cc  | 28 -
 gcc/rust/backend/rust-compile-expr.h   |  4 +-
 gcc/rust/hir/tree/rust-hir-expr.cc |  6 ++
 gcc/rust/hir/tree/rust-hir-expr.h  |  2 +
 gcc/rust/typecheck/rust-hir-type-check-expr.cc | 27 +++--
 gcc/rust/typecheck/rust-hir-type-check-expr.h  |  4 +-
 gcc/rust/util/rust-lang-item.cc| 44 +++
 gcc/rust/util/rust-lang-item.h |  5 ++
 gcc/rust/util/rust-operators.h |  8 +--
 gcc/testsuite/rust/compile/cmp1.rs | 78 ++
 gcc/testsuite/rust/compile/nr2/exclude |  1 +
 11 files changed, 194 insertions(+), 13 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-expr.cc 
b/gcc/rust/backend/rust-compile-expr.cc
index e0fb1da3feb3..900e080ea0ef 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -279,6 +279,26 @@ CompileExpr::visit (HIR::ComparisonExpr &expr)
   auto rhs = CompileExpr::Compile (expr.get_rhs (), ctx);
   auto location = expr.get_locus ();
 
+  // this might be an operator overload situation lets check
+  TyTy::FnType *fntype;
+  bool is_op_overload = ctx->get_tyctx ()->lookup_operator_overload (
+expr.get_mappings ().get_hirid (), &fntype);
+  if (is_op_overload)
+{
+  auto seg_name = LangItem::ComparisonToSegment (expr.get_expr_type ());
+  auto segment = HIR::PathIdentSegment (seg_name);
+  auto lang_item_type
+   = LangItem::ComparisonToLangItem (expr.get_expr_type ());
+
+  rhs = address_expression (rhs, EXPR_LOCATION (rhs));
+
+  translated = resolve_operator_overload (
+   lang_item_type, expr, lhs, rhs, expr.get_lhs (),
+   tl::optional> (expr.get_rhs ()),
+   segment);
+  return;
+}
+
   translated = Backend::comparison_expression (op, lhs, rhs, location);
 }
 
@@ -1478,7 +1498,8 @@ CompileExpr::get_receiver_from_dyn (const 
TyTy::DynamicObjectType *dyn,
 tree
 CompileExpr::resolve_operator_overload (
   LangItem::Kind lang_item_type, HIR::OperatorExprMeta expr, tree lhs, tree 
rhs,
-  HIR::Expr &lhs_expr, tl::optional> 
rhs_expr)
+  HIR::Expr &lhs_expr, tl::optional> 
rhs_expr,
+  HIR::PathIdentSegment specified_segment)
 {
   TyTy::FnType *fntype;
   bool is_op_overload = ctx->get_tyctx ()->lookup_operator_overload (
@@ -1499,7 +1520,10 @@ CompileExpr::resolve_operator_overload (
 }
 
   // lookup compiled functions since it may have already been compiled
-  HIR::PathIdentSegment segment_name (LangItem::ToString (lang_item_type));
+  HIR::PathIdentSegment segment_name
+= specified_segment.is_error ()
+   ? HIR::PathIdentSegment (LangItem::ToString (lang_item_type))
+   : specified_segment;
   tree fn_expr = resolve_method_address (fntype, receiver, expr.get_locus ());
 
   // lookup the autoderef mappings
diff --git a/gcc/rust/backend/rust-compile-expr.h 
b/gcc/rust/backend/rust-compile-expr.h
index b8c4220ded7e..dc78dee3c8f6 100644
--- a/gcc/rust/backend/rust-compile-expr.h
+++ b/gcc/rust/backend/rust-compile-expr.h
@@ -99,7 +99,9 @@ protected:
   tree 

[gcc(refs/users/meissner/heads/work196-dmf)] RFC2686-Add paddis support.

2025-04-05 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:88cd7ab63df5e2510faed43870f7bdeefabcfff6

commit 88cd7ab63df5e2510faed43870f7bdeefabcfff6
Author: Michael Meissner 
Date:   Mon Mar 24 19:48:48 2025 -0400

RFC2686-Add paddis support.

2025-03-24  Michael Meissner  

gcc/

* config/rs6000/constraints.md (eU): New constraint.
(eV): Likewise.
* config/rs6000/predicates.md (paddis_operand): New predicate.
(paddis_paddi_operand): Likewise.
(add_operand): Add paddis support.
* config/rs6000/rs6000.cc (num_insns_constant_gpr): Add paddis 
support.
(num_insns_constant_multi): Likewise.
(print_operand): Add %B for paddis support.
* config/rs6000/rs6000.h (TARGET_PADDIS): New macro.
(SIGNED_INTEGER_32BIT_P): Likewise.
* config/rs6000/rs6000.md (isa attribute): Add paddis support.
(enabled attribute); Likewise.
(add3): Likewise.
(adddi3 splitter): New splitter for paddis.
(movdi_internal64): Add paddis support.
(movdi splitter): New splitter for paddis.

gcc/testsuite/

* gcc.target/powerpc/prefixed-addis.c: New test.

Diff:
---
 gcc/config/rs6000/constraints.md  | 10 +++
 gcc/config/rs6000/predicates.md   | 52 +++-
 gcc/config/rs6000/rs6000.cc   | 25 ++
 gcc/config/rs6000/rs6000.h|  4 +
 gcc/config/rs6000/rs6000.md   | 96 ---
 gcc/testsuite/gcc.target/powerpc/prefixed-addis.c | 24 ++
 6 files changed, 197 insertions(+), 14 deletions(-)

diff --git a/gcc/config/rs6000/constraints.md b/gcc/config/rs6000/constraints.md
index 3da9ed086810..5440becb6e6c 100644
--- a/gcc/config/rs6000/constraints.md
+++ b/gcc/config/rs6000/constraints.md
@@ -222,6 +222,16 @@
   "An IEEE 128-bit constant that can be loaded into VSX registers."
   (match_operand 0 "easy_vector_constant_ieee128"))
 
+(define_constraint "eU"
+  "@internal integer constant that can be loaded with paddis"
+  (and (match_code "const_int")
+   (match_operand 0 "paddis_operand")))
+
+(define_constraint "eV"
+  "@internal integer constant that can be loaded with paddis + paddi"
+  (and (match_code "const_int")
+   (match_operand 0 "paddis_paddi_operand")))
+
 ;; Floating-point constraints.  These two are defined so that insn
 ;; length attributes can be calculated exactly.
 
diff --git a/gcc/config/rs6000/predicates.md b/gcc/config/rs6000/predicates.md
index c95b4336f062..c206860e4927 100644
--- a/gcc/config/rs6000/predicates.md
+++ b/gcc/config/rs6000/predicates.md
@@ -369,6 +369,53 @@
   return SIGNED_INTEGER_34BIT_P (INTVAL (op));
 })
 
+;; Return 1 if op is a 64-bit constant that uses the paddis instruction
+(define_predicate "paddis_operand"
+  (match_code "const_int")
+{
+  if (!TARGET_PADDIS && TARGET_POWERPC64)
+return 0;
+
+  /* If addi, addis, or paddi can handle the number, don't return true.  */
+  HOST_WIDE_INT value = INTVAL (op);
+  if (SIGNED_INTEGER_34BIT_P (value))
+return false;
+
+  /* If the number is too large for padds, return false.  */
+  if (!SIGNED_INTEGER_32BIT_P (value >> 32))
+return false;
+
+  /* If the bottom 32-bits are non-zero, paddis can't handle it.  */
+  if ((value & HOST_WIDE_INT_C(0x)) != 0)
+return false;
+
+  return true;
+})
+
+;; Return 1 if op is a 64-bit constant that needs the paddis instruction and an
+;; addi/addis/paddi instruction combination.
+(define_predicate "paddis_paddi_operand"
+  (match_code "const_int")
+{
+  if (!TARGET_PADDIS && TARGET_POWERPC64)
+return 0;
+
+  /* If addi, addis, or paddi can handle the number, don't return true.  */
+  HOST_WIDE_INT value = INTVAL (op);
+  if (SIGNED_INTEGER_34BIT_P (value))
+return false;
+
+  /* If the number is too large for padds, return false.  */
+  if (!SIGNED_INTEGER_32BIT_P (value >> 32))
+return false;
+
+  /* If the bottom 32-bits are zero, we can use paddis alone to handle it.  */
+  if ((value & HOST_WIDE_INT_C(0x)) == 0)
+return false;
+
+  return true;
+})
+
 ;; Return 1 if op is a register that is not special.
 ;; Disallow (SUBREG:SF (REG:SI)) and (SUBREG:SI (REG:SF)) on VSX systems where
 ;; you need to be careful in moving a SFmode to SImode and vice versa due to
@@ -1113,7 +1160,10 @@
   (if_then_else (match_code "const_int")
 (match_test "satisfies_constraint_I (op)
 || satisfies_constraint_L (op)
-|| satisfies_constraint_eI (op)")
+|| satisfies_constraint_eI (op)
+|| satisfies_constraint_eU (op)
+|| satisfies_constraint_eV (op)")
+
 (match_operand 0 "gpc_reg_operand")))
 
 ;; Return 1 if the operand is either a non-special register, or 0, or -1.
diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index 4415430e2b7a..fda8ae333438 100644
--- a/gcc/con

[gcc r15-8399] gccrs: Fix missing error on duplicated nodes

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:57dc3ab97393f526afcc74fa6c82347f3f77402a

commit r15-8399-g57dc3ab97393f526afcc74fa6c82347f3f77402a
Author: Pierre-Emmanuel Patry 
Date:   Wed Aug 21 17:01:29 2024 +0200

gccrs: Fix missing error on duplicated nodes

When we tried to insert a shadowable node and another shadowable node has
been inserted before, we didn't emit any error if the node has already
been inserted previously and failed silently.

gcc/rust/ChangeLog:

* resolve/rust-rib.cc (Rib::insert): Emit an error when trying to
insert an already inserted node.

Signed-off-by: Pierre-Emmanuel Patry 

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

diff --git a/gcc/rust/resolve/rust-rib.cc b/gcc/rust/resolve/rust-rib.cc
index 0a8fce34a1a9..714507219e02 100644
--- a/gcc/rust/resolve/rust-rib.cc
+++ b/gcc/rust/resolve/rust-rib.cc
@@ -92,9 +92,9 @@ Rib::insert (std::string name, Definition def)
{
  if (std::find (current.ids.cbegin (), current.ids.cend (), id)
  == current.ids.cend ())
-   {
- current.ids.push_back (id);
-   }
+   current.ids.push_back (id);
+ else
+   return tl::make_unexpected (DuplicateNameError (name, id));
}
 }
   else if (it->second.shadowable)


[gcc r15-8718] nvptx: Default at least to '-mptx=6.3'

2025-04-05 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:5450afcfb761834b7f4156022f1ec38f2226c193

commit r15-8718-g5450afcfb761834b7f4156022f1ec38f2226c193
Author: Thomas Schwinge 
Date:   Thu Mar 20 14:21:26 2025 +0100

nvptx: Default at least to '-mptx=6.3'

gcc/
* config/nvptx/nvptx.cc (default_ptx_version_option): Default at
least to '-mptx=6.3'.
* doc/invoke.texi (Nvidia PTX Options): Update '-mptx=[...]'.
gcc/testsuite/
* gcc.target/nvptx/march-map=sm_30.c: Adjust.
* gcc.target/nvptx/march-map=sm_32.c: Likewise.
* gcc.target/nvptx/march-map=sm_35.c: Likewise.
* gcc.target/nvptx/march-map=sm_37.c: Likewise.
* gcc.target/nvptx/march-map=sm_50.c: Likewise.
* gcc.target/nvptx/march=sm_30.c: Likewise.
* gcc.target/nvptx/march=sm_35.c: Likewise.
* gcc.target/nvptx/march=sm_37.c: Likewise.

Diff:
---
 gcc/config/nvptx/nvptx.cc| 3 +++
 gcc/doc/invoke.texi  | 2 +-
 gcc/testsuite/gcc.target/nvptx/march-map=sm_30.c | 4 ++--
 gcc/testsuite/gcc.target/nvptx/march-map=sm_32.c | 4 ++--
 gcc/testsuite/gcc.target/nvptx/march-map=sm_35.c | 4 ++--
 gcc/testsuite/gcc.target/nvptx/march-map=sm_37.c | 4 ++--
 gcc/testsuite/gcc.target/nvptx/march-map=sm_50.c | 4 ++--
 gcc/testsuite/gcc.target/nvptx/march=sm_30.c | 4 ++--
 gcc/testsuite/gcc.target/nvptx/march=sm_35.c | 4 ++--
 gcc/testsuite/gcc.target/nvptx/march=sm_37.c | 4 ++--
 10 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc
index d1648d52f2fa..5cd4b2427714 100644
--- a/gcc/config/nvptx/nvptx.cc
+++ b/gcc/config/nvptx/nvptx.cc
@@ -245,6 +245,9 @@ default_ptx_version_option (void)
  warp convergence.  */
   res = MAX (res, PTX_VERSION_6_0);
 
+  /* Pick at least 6.3.  */
+  res = MAX (res, PTX_VERSION_6_3);
+
   /* For sm_52+, pick at least 7.3, to enable PTX 'alloca'.  */
   if (ptx_isa_option >= PTX_ISA_SM52)
 res = MAX (res, PTX_VERSION_7_3);
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 3f5b7e9f3668..b3f7f0479cc4 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -30410,7 +30410,7 @@ Valid version strings are
 @samp{7.0}, @samp{7.3}, and @samp{7.8}.
 The default PTX ISA version is the one that added support for the
 selected PTX ISA target architecture, see @option{-march=}, but at
-least @samp{6.0}, or @samp{7.3} for @option{-march=sm_52} and higher.
+least @samp{6.3}, or @samp{7.3} for @option{-march=sm_52} and higher.
 
 This option sets the values of the preprocessor macros
 @code{__PTX_ISA_VERSION_MAJOR__} and @code{__PTX_ISA_VERSION_MINOR__};
diff --git a/gcc/testsuite/gcc.target/nvptx/march-map=sm_30.c 
b/gcc/testsuite/gcc.target/nvptx/march-map=sm_30.c
index b69926e6debc..b5e2c19b07c9 100644
--- a/gcc/testsuite/gcc.target/nvptx/march-map=sm_30.c
+++ b/gcc/testsuite/gcc.target/nvptx/march-map=sm_30.c
@@ -1,14 +1,14 @@
 /* { dg-do assemble } */
 /* { dg-options {-march-map=sm_30 -mptx=_} } */
 /* { dg-additional-options -save-temps } */
-/* { dg-final { scan-assembler-times {(?n)^\.version   6\.0$} 1 } } */
+/* { dg-final { scan-assembler-times {(?n)^\.version   6\.3$} 1 } } */
 /* { dg-final { scan-assembler-times {(?n)^\.targetsm_30$} 1 } } */
 
 #if __PTX_ISA_VERSION_MAJOR__ != 6
 #error wrong value for __PTX_ISA_VERSION_MAJOR__
 #endif
 
-#if __PTX_ISA_VERSION_MINOR__ != 0
+#if __PTX_ISA_VERSION_MINOR__ != 3
 #error wrong value for __PTX_ISA_VERSION_MINOR__
 #endif
 
diff --git a/gcc/testsuite/gcc.target/nvptx/march-map=sm_32.c 
b/gcc/testsuite/gcc.target/nvptx/march-map=sm_32.c
index dcf9e05233fa..9a066bb52f4b 100644
--- a/gcc/testsuite/gcc.target/nvptx/march-map=sm_32.c
+++ b/gcc/testsuite/gcc.target/nvptx/march-map=sm_32.c
@@ -1,14 +1,14 @@
 /* { dg-do assemble } */
 /* { dg-options {-march-map=sm_32 -mptx=_} } */
 /* { dg-additional-options -save-temps } */
-/* { dg-final { scan-assembler-times {(?n)^\.version   6\.0$} 1 } } */
+/* { dg-final { scan-assembler-times {(?n)^\.version   6\.3$} 1 } } */
 /* { dg-final { scan-assembler-times {(?n)^\.targetsm_30$} 1 } } */
 
 #if __PTX_ISA_VERSION_MAJOR__ != 6
 #error wrong value for __PTX_ISA_VERSION_MAJOR__
 #endif
 
-#if __PTX_ISA_VERSION_MINOR__ != 0
+#if __PTX_ISA_VERSION_MINOR__ != 3
 #error wrong value for __PTX_ISA_VERSION_MINOR__
 #endif
 
diff --git a/gcc/testsuite/gcc.target/nvptx/march-map=sm_35.c 
b/gcc/testsuite/gcc.target/nvptx/march-map=sm_35.c
index ce4669053ab5..15f5faeb1c68 100644
--- a/gcc/testsuite/gcc.target/nvptx/march-map=sm_35.c
+++ b/gcc/testsuite/gcc.target/nvptx/march-map=sm_35.c
@@ -1,14 +1,14 @@
 /* { dg-do assemble } */
 /* { dg-options {-march-map=sm_35 -mptx=_} } */
 /* { dg-additional-options -save-temps } */
-/* { dg-final { scan-assembler-times {(?n)^\.version   6\.0$} 1 } } */
+/* { dg-final { scan-assembler-times {(?

[gcc r15-8422] gccrs: Fix ICE when typechecking non-trait item when we expect one

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:308fd792af6c220b505515e6d40e7ba0f9820cf5

commit r15-8422-g308fd792af6c220b505515e6d40e7ba0f9820cf5
Author: Philip Herron 
Date:   Wed Oct 2 15:47:33 2024 +0100

gccrs: Fix ICE when typechecking non-trait item when we expect one

We just had an assertion here for this case where we expect a trait.
This changes the assertion into error handling producing the correct
error code with fixit suggestion like rustc.

Fixes #2499

gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-resolve.cc 
(TraitResolver::resolve_path_to_trait):
use error handling instead of assertion
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): 
reuse trait reference
* typecheck/rust-hir-type-check-item.h: update prototype

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron 

Diff:
---
 gcc/rust/typecheck/rust-hir-trait-resolve.cc   | 27 --
 gcc/rust/typecheck/rust-hir-type-check-item.cc | 19 +-
 gcc/rust/typecheck/rust-hir-type-check-item.h  |  3 ++-
 gcc/testsuite/rust/compile/issue-2499.rs   | 11 +++
 gcc/testsuite/rust/compile/nr2/exclude |  3 ++-
 5 files changed, 46 insertions(+), 17 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc 
b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
index 51a64174ea4d..ec331cf6e95c 100644
--- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc
+++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
@@ -117,19 +117,26 @@ TraitResolver::resolve_path_to_trait (const HIR::TypePath 
&path,
   return false;
 }
 
-  if (auto hid = mappings.lookup_node_to_hir (ref))
+  auto hid = mappings.lookup_node_to_hir (ref);
+  if (!hid)
 {
-  tl::optional resolved_item
-   = mappings.lookup_hir_item (hid.value ());
-  rust_assert (resolved_item.has_value ());
-  rust_assert (resolved_item.value ()->get_item_kind ()
-  == HIR::Item::ItemKind::Trait);
-  *resolved = static_cast (*resolved_item);
+  rust_error_at (path.get_locus (), "Failed to resolve path to hir-id");
+  return false;
+}
 
-  return true;
+  auto resolved_item = mappings.lookup_hir_item (hid.value ());
+  rust_assert (resolved_item.has_value ());
+  if (resolved_item.value ()->get_item_kind () != HIR::Item::ItemKind::Trait)
+{
+  rich_location r (line_table, path.get_locus ());
+  r.add_fixit_replace ("not a trait");
+  rust_error_at (r, ErrorCode::E0404, "Expected a trait found %qs",
+path.as_simple_path ().as_string ().c_str ());
+  return false;
 }
-  rust_error_at (path.get_locus (), "Failed to resolve path to hir-id");
-  return false;
+
+  *resolved = static_cast (*resolved_item);
+  return true;
 }
 
 TraitReference *
diff --git a/gcc/rust/typecheck/rust-hir-type-check-item.cc 
b/gcc/rust/typecheck/rust-hir-type-check-item.cc
index d707e3458f1d..3858d5132f9a 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-item.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-item.cc
@@ -453,6 +453,15 @@ TypeCheckItem::visit (HIR::ImplBlock &impl_block)
 {
   auto binder_pin = context->push_clean_lifetime_resolver (true);
 
+  TraitReference *trait_reference = &TraitReference::error_node ();
+  if (impl_block.has_trait_ref ())
+{
+  std::unique_ptr &ref = impl_block.get_trait_ref ();
+  trait_reference = TraitResolver::Resolve (*ref);
+  if (trait_reference->is_error ())
+   return;
+}
+
   bool failed_flag = false;
   auto result = resolve_impl_block_substitutions (impl_block, failed_flag);
   if (failed_flag)
@@ -474,7 +483,7 @@ TypeCheckItem::visit (HIR::ImplBlock &impl_block)
 }
 
   // validate the impl items
-  validate_trait_impl_block (impl_block, self, substitutions);
+  validate_trait_impl_block (trait_reference, impl_block, self, substitutions);
 }
 
 TyTy::BaseType *
@@ -698,16 +707,16 @@ TypeCheckItem::resolve_impl_block_substitutions 
(HIR::ImplBlock &impl_block,
 
 void
 TypeCheckItem::validate_trait_impl_block (
-  HIR::ImplBlock &impl_block, TyTy::BaseType *self,
+  TraitReference *trait_reference, HIR::ImplBlock &impl_block,
+  TyTy::BaseType *self,
   std::vector &substitutions)
 {
   auto specified_bound = TyTy::TypeBoundPredicate::error ();
-  TraitReference *trait_reference = &TraitReference::error_node ();
   if (impl_block.has_trait_ref ())
 {
   std::unique_ptr &ref = impl_block.get_trait_ref ();
-  trait_reference = TraitResolver::Resolve (*ref);
-  rust_assert (!trait_reference->is_error ());
+  if (trait_reference->is_error ())
+   return;
 
   // we don't error out here see: gcc/testsuite/rust/compile/traits2.rs
   // for example
diff --git a/gcc/rust/typecheck/rust-hir-type-check-item.h 
b/gcc/rust/typecheck/rust-hir-type-check-item.h
index c5b

[gcc r15-8561] gccrs: attributes: Add class for sharing methods on attributes.

2025-04-05 Thread Arthur Cohen via Gcc-cvs
https://gcc.gnu.org/g:f8dd4cc166149c9a9a6393b440a4cf89b8fa6307

commit r15-8561-gf8dd4cc166149c9a9a6393b440a4cf89b8fa6307
Author: Arthur Cohen 
Date:   Wed Dec 4 13:53:11 2024 +

gccrs: attributes: Add class for sharing methods on attributes.

gcc/rust/ChangeLog:

* util/rust-attributes.h (class Attributes): New.
* util/rust-attributes.cc: Implement Attributes::is_known().
* ast/rust-collect-lang-items.cc (is_known_attribute): Remove.
(get_lang_item_attr): Call Attributes::is_known() instead.
* hir/rust-ast-lower-base.cc 
(ASTLoweringBase::handle_outer_attributes): Likewise.
(ASTLoweringBase::is_known_attribute): Remove.

Diff:
---
 gcc/rust/ast/rust-collect-lang-items.cc | 13 +
 gcc/rust/hir/rust-ast-lower-base.cc | 10 ++
 gcc/rust/util/rust-attributes.cc|  9 +
 gcc/rust/util/rust-attributes.h |  6 ++
 4 files changed, 18 insertions(+), 20 deletions(-)

diff --git a/gcc/rust/ast/rust-collect-lang-items.cc 
b/gcc/rust/ast/rust-collect-lang-items.cc
index 11a30aa37a74..308720ae69ab 100644
--- a/gcc/rust/ast/rust-collect-lang-items.cc
+++ b/gcc/rust/ast/rust-collect-lang-items.cc
@@ -27,17 +27,6 @@
 namespace Rust {
 namespace AST {
 
-// FIXME: Before merging: De-duplicate with function in rust-ast-lower-base.cc
-bool
-is_known_attribute (const std::string &attribute_path)
-{
-  const auto &lookup
-= Analysis::BuiltinAttributeMappings::get ()->lookup_builtin (
-  attribute_path);
-
-  return !lookup.is_error ();
-}
-
 template 
 tl::optional
 get_lang_item_attr (const T &maybe_lang_item)
@@ -45,7 +34,7 @@ get_lang_item_attr (const T &maybe_lang_item)
   for (const auto &attr : maybe_lang_item.get_outer_attrs ())
 {
   const auto &str_path = attr.get_path ().as_string ();
-  if (!is_known_attribute (str_path))
+  if (!Analysis::Attributes::is_known (str_path))
{
  rust_error_at (attr.get_locus (), "unknown attribute");
  continue;
diff --git a/gcc/rust/hir/rust-ast-lower-base.cc 
b/gcc/rust/hir/rust-ast-lower-base.cc
index 18e6fff6f446..f6d7f0caf5b8 100644
--- a/gcc/rust/hir/rust-ast-lower-base.cc
+++ b/gcc/rust/hir/rust-ast-lower-base.cc
@@ -25,6 +25,7 @@
 #include "rust-diagnostics.h"
 #include "rust-item.h"
 #include "rust-system.h"
+#include "rust-attributes.h"
 
 namespace Rust {
 namespace HIR {
@@ -751,7 +752,7 @@ ASTLoweringBase::handle_outer_attributes (const ItemWrapper 
&item)
   for (const auto &attr : item.get_outer_attrs ())
 {
   const auto &str_path = attr.get_path ().as_string ();
-  if (!is_known_attribute (str_path))
+  if (!Analysis::Attributes::is_known (str_path))
{
  rust_error_at (attr.get_locus (), "unknown attribute");
  continue;
@@ -814,13 +815,6 @@ ASTLoweringBase::handle_lang_item_attribute (const 
ItemWrapper &item,
 rust_error_at (attr.get_locus (), "unknown lang item");
 }
 
-bool
-ASTLoweringBase::is_known_attribute (const std::string &attribute_path) const
-{
-  const auto &lookup = attr_mappings->lookup_builtin (attribute_path);
-  return !lookup.is_error ();
-}
-
 bool
 ASTLoweringBase::attribute_handled_in_another_pass (
   const std::string &attribute_path) const
diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc
index 958f7c352849..9f63234112c5 100644
--- a/gcc/rust/util/rust-attributes.cc
+++ b/gcc/rust/util/rust-attributes.cc
@@ -29,6 +29,15 @@
 namespace Rust {
 namespace Analysis {
 
+bool
+Attributes::is_known (const std::string &attribute_path)
+{
+  const auto &lookup
+= BuiltinAttributeMappings::get ()->lookup_builtin (attribute_path);
+
+  return !lookup.is_error ();
+}
+
 using Attrs = Values::Attributes;
 
 // 
https://doc.rust-lang.org/stable/nightly-rustc/src/rustc_feature/builtin_attrs.rs.html#248
diff --git a/gcc/rust/util/rust-attributes.h b/gcc/rust/util/rust-attributes.h
index 1345168cdea8..c928c8eb9d26 100644
--- a/gcc/rust/util/rust-attributes.h
+++ b/gcc/rust/util/rust-attributes.h
@@ -25,6 +25,12 @@
 namespace Rust {
 namespace Analysis {
 
+class Attributes
+{
+public:
+  static bool is_known (const std::string &attribute_path);
+};
+
 enum CompilerPass
 {
   UNKNOWN,


  1   2   >