[gcc r15-8543] gccrs: Prevent execution of some nr1.0 functions with nr2.0

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

commit r15-8543-g8d04c93d6ddc910530093e64ac4cde9fb8d1ee83
Author: Owen Avery 
Date:   Thu Nov 21 15:28:46 2024 -0500

gccrs: Prevent execution of some nr1.0 functions with nr2.0

gcc/rust/ChangeLog:

* resolve/rust-name-resolver.cc: Include options.txt.
(Resolver::insert_resolved_name): Assert that name resolution
2.0 is disabled.
(Resolver::lookup_resolved_name): Likewise.
(Resolver::insert_resolved_type): Likewise.
(Resolver::lookup_resolved_type): Likewise.
(Resolver::insert_resolved_label): Likewise.
(Resolver::lookup_resolved_label): Likewise.
(Resolver::insert_resolved_macro): Likewise.
(Resolver::lookup_resolved_macro): Likewise.
(Resolver::insert_resolved_misc): Likewise.
(Resolver::lookup_resolved_misc): Likewise.

Signed-off-by: Owen Avery 

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

diff --git a/gcc/rust/resolve/rust-name-resolver.cc 
b/gcc/rust/resolve/rust-name-resolver.cc
index 3b4e3111d936..0f5b10847742 100644
--- a/gcc/rust/resolve/rust-name-resolver.cc
+++ b/gcc/rust/resolve/rust-name-resolver.cc
@@ -19,6 +19,9 @@
 #include "rust-name-resolver.h"
 #include "rust-ast-full.h"
 
+// for flag_name_resolution_2_0
+#include "options.h"
+
 namespace Rust {
 namespace Resolver {
 
@@ -468,6 +471,7 @@ Resolver::setup_builtin (const std::string &name, 
TyTy::BaseType *tyty)
 void
 Resolver::insert_resolved_name (NodeId refId, NodeId defId)
 {
+  rust_assert (!flag_name_resolution_2_0);
   resolved_names[refId] = defId;
   get_name_scope ().append_reference_for_def (refId, defId);
   insert_captured_item (defId);
@@ -476,6 +480,7 @@ Resolver::insert_resolved_name (NodeId refId, NodeId defId)
 bool
 Resolver::lookup_resolved_name (NodeId refId, NodeId *defId)
 {
+  rust_assert (!flag_name_resolution_2_0);
   auto it = resolved_names.find (refId);
   if (it == resolved_names.end ())
 return false;
@@ -489,6 +494,7 @@ Resolver::insert_resolved_type (NodeId refId, NodeId defId)
 {
   // auto it = resolved_types.find (refId);
   // rust_assert (it == resolved_types.end ());
+  rust_assert (!flag_name_resolution_2_0);
 
   resolved_types[refId] = defId;
   get_type_scope ().append_reference_for_def (refId, defId);
@@ -497,6 +503,7 @@ Resolver::insert_resolved_type (NodeId refId, NodeId defId)
 bool
 Resolver::lookup_resolved_type (NodeId refId, NodeId *defId)
 {
+  rust_assert (!flag_name_resolution_2_0);
   auto it = resolved_types.find (refId);
   if (it == resolved_types.end ())
 return false;
@@ -508,6 +515,7 @@ Resolver::lookup_resolved_type (NodeId refId, NodeId *defId)
 void
 Resolver::insert_resolved_label (NodeId refId, NodeId defId)
 {
+  rust_assert (!flag_name_resolution_2_0);
   auto it = resolved_labels.find (refId);
   rust_assert (it == resolved_labels.end ());
 
@@ -518,6 +526,7 @@ Resolver::insert_resolved_label (NodeId refId, NodeId defId)
 bool
 Resolver::lookup_resolved_label (NodeId refId, NodeId *defId)
 {
+  rust_assert (!flag_name_resolution_2_0);
   auto it = resolved_labels.find (refId);
   if (it == resolved_labels.end ())
 return false;
@@ -529,6 +538,7 @@ Resolver::lookup_resolved_label (NodeId refId, NodeId 
*defId)
 void
 Resolver::insert_resolved_macro (NodeId refId, NodeId defId)
 {
+  rust_assert (!flag_name_resolution_2_0);
   auto it = resolved_macros.find (refId);
   rust_assert (it == resolved_macros.end ());
 
@@ -539,6 +549,7 @@ Resolver::insert_resolved_macro (NodeId refId, NodeId defId)
 bool
 Resolver::lookup_resolved_macro (NodeId refId, NodeId *defId)
 {
+  rust_assert (!flag_name_resolution_2_0);
   auto it = resolved_macros.find (refId);
   if (it == resolved_macros.end ())
 return false;
@@ -550,6 +561,7 @@ Resolver::lookup_resolved_macro (NodeId refId, NodeId 
*defId)
 void
 Resolver::insert_resolved_misc (NodeId refId, NodeId defId)
 {
+  rust_assert (!flag_name_resolution_2_0);
   auto it = misc_resolved_items.find (refId);
   rust_assert (it == misc_resolved_items.end ());
 
@@ -559,6 +571,7 @@ Resolver::insert_resolved_misc (NodeId refId, NodeId defId)
 bool
 Resolver::lookup_resolved_misc (NodeId refId, NodeId *defId)
 {
+  rust_assert (!flag_name_resolution_2_0);
   auto it = misc_resolved_items.find (refId);
   if (it == misc_resolved_items.end ())
 return false;


[gcc r15-9188] rs6000: Add Cobol support to traceback table [PR119308]

2025-04-04 Thread Peter Bergner via Gcc-cvs
https://gcc.gnu.org/g:c669ab0a866697577fec0c8c2e662640c4be4c94

commit r15-9188-gc669ab0a866697577fec0c8c2e662640c4be4c94
Author: Peter Bergner 
Date:   Thu Apr 3 10:52:29 2025 -0500

rs6000: Add Cobol support to traceback table [PR119308]

The AIX traceback table documentation states the tbtab "lang" field for
Cobol should be set to 7.  Use it.

2025-04-03  Peter Bergner  

gcc/
PR target/119308
* config/rs6000/rs6000-logue.cc (rs6000_output_function_epilogue):
Handle GCC COBOL for the tbtab lang field.

Diff:
---
 gcc/config/rs6000/rs6000-logue.cc | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/gcc/config/rs6000/rs6000-logue.cc 
b/gcc/config/rs6000/rs6000-logue.cc
index 52f44b114b06..5377ad6cee62 100644
--- a/gcc/config/rs6000/rs6000-logue.cc
+++ b/gcc/config/rs6000/rs6000-logue.cc
@@ -5351,6 +5351,8 @@ rs6000_output_function_epilogue (FILE *file)
i = 1;
   else if (! strcmp (language_string, "GNU Ada"))
i = 3;
+  else if (! strcmp (language_string, "GCC COBOL"))
+   i = 7;
   else if (! strcmp (language_string, "GNU Modula-2"))
i = 8;
   else if (lang_GNU_CXX ()


[gcc r15-8508] gccrs: Make TyTy::TupleType::get_unit_type cache its return value

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

commit r15-8508-g2f0df594cf8a7b1a9a11bb947ff2a9ae4a82bc40
Author: Owen Avery 
Date:   Mon Oct 28 19:02:23 2024 -0400

gccrs: Make TyTy::TupleType::get_unit_type cache its return value

This removes a usage of Resolver::get_unit_type_node_id in
rust-hir-type-check-expr.cc (the HIR::TupleExpr overload of
TypeCheckExpr::visit).

gcc/rust/ChangeLog:

* typecheck/rust-tyty.cc
(TupleType::get_unit_type): Remove parameter, cache return
value.
* typecheck/rust-tyty.h
(TupleType::get_unit_type): Remove parameter.
* resolve/rust-late-name-resolver-2.0.cc
(Late::setup_builtin_types): Adjust calls to get_unit_type.
* resolve/rust-name-resolver.cc
(Resolver::generate_builtins): Likewise.
* typecheck/rust-hir-type-check-expr.cc
(TypeCheckExpr::visit): Likewise.
* typecheck/rust-hir-type-check-implitem.cc
(TypeCheckTopLevelExternItem::visit): Likewise.
(TypeCheckImplItem::visit): Likewise.
* typecheck/rust-hir-type-check-item.cc
(TypeCheckItem::visit): Likewise.
* typecheck/rust-hir-type-check-stmt.cc
(TypeCheckStmt::visit): Likewise.
* typecheck/rust-hir-type-check-type.cc
(TypeCheckType::visit): Likewise.
* typecheck/rust-hir-type-check.cc
(TraitItemReference::get_type_from_fn): Likewise.

Signed-off-by: Owen Avery 

Diff:
---
 gcc/rust/resolve/rust-late-name-resolver-2.0.cc|  2 +-
 gcc/rust/resolve/rust-name-resolver.cc |  3 +-
 gcc/rust/typecheck/rust-hir-type-check-expr.cc | 43 --
 gcc/rust/typecheck/rust-hir-type-check-implitem.cc |  6 +--
 gcc/rust/typecheck/rust-hir-type-check-item.cc |  3 +-
 gcc/rust/typecheck/rust-hir-type-check-stmt.cc |  4 +-
 gcc/rust/typecheck/rust-hir-type-check-type.cc |  2 +-
 gcc/rust/typecheck/rust-hir-type-check.cc  |  2 +-
 gcc/rust/typecheck/rust-tyty.cc|  8 +++-
 gcc/rust/typecheck/rust-tyty.h |  2 +-
 10 files changed, 31 insertions(+), 44 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 5fc97a0922b0..812154eaf799 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -100,7 +100,7 @@ Late::setup_builtin_types ()
 }
 
   // ...here!
-  auto *unit_type = TyTy::TupleType::get_unit_type (next_hir_id ());
+  auto *unit_type = TyTy::TupleType::get_unit_type ();
   ty_ctx.insert_builtin (unit_type->get_ref (), next_node_id (), unit_type);
 }
 
diff --git a/gcc/rust/resolve/rust-name-resolver.cc 
b/gcc/rust/resolve/rust-name-resolver.cc
index 21147bd86fa5..3b4e3111d936 100644
--- a/gcc/rust/resolve/rust-name-resolver.cc
+++ b/gcc/rust/resolve/rust-name-resolver.cc
@@ -435,8 +435,7 @@ Resolver::generate_builtins ()
   set_never_type_node_id (never_node_id);
 
   // unit type ()
-  TyTy::TupleType *unit_tyty
-= TyTy::TupleType::get_unit_type (mappings.get_next_hir_id ());
+  TyTy::TupleType *unit_tyty = TyTy::TupleType::get_unit_type ();
   std::vector > elems;
   AST::TupleType *unit_type
 = new AST::TupleType (std::move (elems), BUILTINS_LOCATION);
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc 
b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index 5b64daf33b75..225d83624e00 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -131,12 +131,7 @@ TypeCheckExpr::visit (HIR::TupleExpr &expr)
 {
   if (expr.is_unit ())
 {
-  auto unit_node_id = resolver->get_unit_type_node_id ();
-  if (!context->lookup_builtin (unit_node_id, &infered))
-   {
- rust_error_at (expr.get_locus (),
-"failed to lookup builtin unit type");
-   }
+  infered = TyTy::TupleType::get_unit_type ();
   return;
 }
 
@@ -165,10 +160,9 @@ TypeCheckExpr::visit (HIR::ReturnExpr &expr)
   location_t expr_locus = expr.has_return_expr ()
? expr.get_expr ()->get_locus ()
: expr.get_locus ();
-  TyTy::BaseType *expr_ty
-= expr.has_return_expr ()
-   ? TypeCheckExpr::Resolve (expr.get_expr ().get ())
-   : TyTy::TupleType::get_unit_type (expr.get_mappings ().get_hirid ());
+  TyTy::BaseType *expr_ty = expr.has_return_expr ()
+ ? TypeCheckExpr::Resolve (expr.get_expr ().get ())
+ : TyTy::TupleType::get_unit_type ();
 
   coercion_site (expr.get_mappings ().get_hirid (),
 TyTy::TyWithLocation (fn_return_tyty),
@@ -242,7 +236,7 @@ TypeCheckExpr::visit (HIR::CallExpr &expr)
 void
 TypeCheckExpr::visit (HIR::AssignmentExpr &expr)
 {
-  infered = T

[gcc r14-11523] libstdc++: Fix handling of field width for wide strings and characters [PR119593]

2025-04-04 Thread Tomasz Kaminski via Libstdc++-cvs
https://gcc.gnu.org/g:ad1b71fc2882c14271ebf2bbaf216cceaa88c76a

commit r14-11523-gad1b71fc2882c14271ebf2bbaf216cceaa88c76a
Author: Tomasz Kamiński 
Date:   Thu Apr 3 10:23:45 2025 +0200

libstdc++: Fix handling of field width for wide strings and characters 
[PR119593]

This patch corrects handling of UTF-32LE and UTF32-BE in
__unicode::__literal_encoding_is_unicode<_CharT>, so they are
recognized as unicode and functions produces correct result for wchar_t.

Use `__unicode::__field_width` to compute the estimated witdh
of the charcter for unicode wide encoding.

PR libstdc++/119593

libstdc++-v3/ChangeLog:

* include/bits/unicode.h
(__unicode::__literal_encoding_is_unicode<_CharT>):
Corrected handing for UTF-16 and UTF-32 with "LE" or "BE" suffix.
* include/std/format (__formatter_str::_S_character_width):
Define.
(__formatter_str::_S_character_width): Updated passed char
length.
* testsuite/std/format/functions/format.cc: Test for wchar_t.

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

Diff:
---
 libstdc++-v3/include/bits/unicode.h   |  2 ++
 libstdc++-v3/include/std/format   | 16 +++-
 libstdc++-v3/testsuite/std/format/functions/format.cc |  8 ++--
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/libstdc++-v3/include/bits/unicode.h 
b/libstdc++-v3/include/bits/unicode.h
index 4b408948d722..eee3b7e37609 100644
--- a/libstdc++-v3/include/bits/unicode.h
+++ b/libstdc++-v3/include/bits/unicode.h
@@ -1039,6 +1039,8 @@ inline namespace __v15_1_0
  string_view __s(__enc);
  if (__s.ends_with("//"))
__s.remove_suffix(2);
+ if (__s.ends_with("LE") || __s.ends_with("BE"))
+   __s.remove_suffix(2);
  return __s == "16" || __s == "32";
}
}
diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format
index f64947a0e293..15bded87c9cd 100644
--- a/libstdc++-v3/include/std/format
+++ b/libstdc++-v3/include/std/format
@@ -1184,12 +1184,26 @@ namespace __format
  _M_spec);
}
 
+  [[__gnu__::__always_inline__]]
+  static size_t
+  _S_character_width(_CharT __c)
+  {
+   // N.B. single byte cannot encode charcter of width greater than 1
+   if constexpr (sizeof(_CharT) > 1u && 
+   __unicode::__literal_encoding_is_unicode<_CharT>())
+ return __unicode::__field_width(__c);
+   else
+ return 1u;
+  }
+
   template
typename basic_format_context<_Out, _CharT>::iterator
_M_format_character(_CharT __c,
  basic_format_context<_Out, _CharT>& __fc) const
{
- return __format::__write_padded_as_spec({&__c, 1u}, 1, __fc, _M_spec);
+ return __format::__write_padded_as_spec({&__c, 1u},
+ _S_character_width(__c),
+ __fc, _M_spec);
}
 
   template
diff --git a/libstdc++-v3/testsuite/std/format/functions/format.cc 
b/libstdc++-v3/testsuite/std/format/functions/format.cc
index 78cc1ab482ad..97eb0957e5e1 100644
--- a/libstdc++-v3/testsuite/std/format/functions/format.cc
+++ b/libstdc++-v3/testsuite/std/format/functions/format.cc
@@ -497,9 +497,14 @@ test_unicode()
 {
   // Similar to sC example in test_std_examples, but not from the standard.
   // Verify that the character "🤡" has estimated field width 2,
-  // rather than estimated field width equal to strlen("🤡"), which would be 4.
+  // rather than estimated field width equal to strlen("🤡"), which would be 4,
+  // or just width 1 for single character.
   std::string sC = std::format("{:*<3}", "🤡");
   VERIFY( sC == "🤡*" );
+  std::wstring wsC = std::format(L"{:*<3}", L"🤡");
+  VERIFY( wsC == L"🤡*" );
+  wsC = std::format(L"{:*<3}", L'🤡');
+  VERIFY( wsC == L"🤡*" );
 
   // Verify that "£" has estimated field width 1, not strlen("£") == 2.
   std::string sL = std::format("{:*<3}", "£");
@@ -513,7 +518,6 @@ test_unicode()
   std::string sP = std::format("{:1.1} {:*<1.1}", "£", "🤡");
   VERIFY( sP == "£ *" );
   sP = std::format("{:*<2.1} {:*<2.1}", "£", "🤡");
-  VERIFY( sP == "£* **" );
 
   // Verify field width handling for extended grapheme clusters,
   // and that a cluster gets output as a single item, not truncated.


[gcc r15-8600] gccrs: cleanup our enum type layout to be closer to rustc

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

commit r15-8600-gf821a513843baabed8a39601bbc714558110b748
Author: Philip Herron 
Date:   Tue Jan 7 18:15:37 2025 +

gccrs: cleanup our enum type layout to be closer to rustc

This changes our enum type layout so for example:

  enum Foo {
  A,
  B,
  C(char),
  D { x: i32, y: i32 },
  }

Used to get layed out like this in gccrs:

  union {
struct A { int RUST$ENUM$DISR; };
struct B { int RUST$ENUM$DISR; };
struct C { int RUST$ENUM$DISR; char __0; };
struct D { int RUST$ENUM$DISR; i64 x; i64 y; };
  }

This has some issues notably with the constexpr because this is just a
giant union it means its not simple to constify what enum variant we are
looking at because the discriminant is a mess.

This now gets layed out as:

  struct {
 int RUST$ENUM$DISR;
 union {
 struct A { };
 struct B { };
 struct C { char __0; };
 struct D { i64 x; i64 y; };
 } payload;
  }

This layout is much cleaner and allows for our constexpr to work properly.

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): new layout
* backend/rust-compile-pattern.cc (CompilePatternCheckExpr::visit): 
likewise
(CompilePatternBindings::visit): likewise
* backend/rust-compile-resolve-path.cc: likewise
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): 
implement new layout
* rust-gcc.cc (constructor_expression): get rid of useless assert

Signed-off-by: Philip Herron 

Diff:
---
 gcc/rust/backend/rust-compile-expr.cc | 74 ---
 gcc/rust/backend/rust-compile-pattern.cc  | 64 +++
 gcc/rust/backend/rust-compile-resolve-path.cc |  5 +-
 gcc/rust/backend/rust-compile-type.cc | 62 +-
 gcc/rust/rust-gcc.cc  |  2 +-
 5 files changed, 128 insertions(+), 79 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-expr.cc 
b/gcc/rust/backend/rust-compile-expr.cc
index 900e080ea0ef..b40aa33866ea 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -558,24 +558,32 @@ CompileExpr::visit (HIR::StructExprStructFields 
&struct_expr)
}
 }
 
-  // the constructor depends on whether this is actually an enum or not if
-  // its an enum we need to setup the discriminator
-  std::vector ctor_arguments;
-  if (adt->is_enum ())
+  if (!adt->is_enum ())
 {
-  HIR::Expr &discrim_expr = variant->get_discriminant ();
-  tree discrim_expr_node = CompileExpr::Compile (discrim_expr, ctx);
-  tree folded_discrim_expr = fold_expr (discrim_expr_node);
-  tree qualifier = folded_discrim_expr;
-
-  ctor_arguments.push_back (qualifier);
+  translated
+   = Backend::constructor_expression (compiled_adt_type, adt->is_enum (),
+  arguments, union_disriminator,
+  struct_expr.get_locus ());
+  return;
 }
-  for (auto &arg : arguments)
-ctor_arguments.push_back (arg);
+
+  HIR::Expr &discrim_expr = variant->get_discriminant ();
+  tree discrim_expr_node = CompileExpr::Compile (discrim_expr, ctx);
+  tree folded_discrim_expr = fold_expr (discrim_expr_node);
+  tree qualifier = folded_discrim_expr;
+
+  tree enum_root_files = TYPE_FIELDS (compiled_adt_type);
+  tree payload_root = DECL_CHAIN (enum_root_files);
+
+  tree payload = Backend::constructor_expression (TREE_TYPE (payload_root),
+ adt->is_enum (), arguments,
+ union_disriminator,
+ struct_expr.get_locus ());
+
+  std::vector ctor_arguments = {qualifier, payload};
 
   translated
-= Backend::constructor_expression (compiled_adt_type, adt->is_enum (),
-  ctor_arguments, union_disriminator,
+= Backend::constructor_expression (compiled_adt_type, 0, ctor_arguments, 
-1,
   struct_expr.get_locus ());
 }
 
@@ -1247,26 +1255,34 @@ CompileExpr::visit (HIR::CallExpr &expr)
  arguments.push_back (rvalue);
}
 
-  // the constructor depends on whether this is actually an enum or not if
-  // its an enum we need to setup the discriminator
-  std::vector ctor_arguments;
-  if (adt->is_enum ())
+  if (!adt->is_enum ())
{
- HIR::Expr &discrim_expr = variant->get_discriminant ();
- tree discrim_expr_node = CompileExpr::Compile (discrim_expr, ctx);
- tree folded_discrim_expr = fold_expr (discrim_expr_node);
- tree qualifier = folded_discrim_expr;
-
- ctor_argum

[gcc r15-8381] gccrs: Fix ICE on error propagation with generic

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

commit r15-8381-g21e43d47d3f946a0b4f046125b07cdfc7172c41a
Author: benjamin.thos 
Date:   Thu Sep 12 17:10:49 2024 +

gccrs: Fix ICE on error propagation with generic

add a resolve expr visitor on error propagation to avoid internal
compiler error when used with generics

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Add
implementation of error propagation visitor
* resolve/rust-ast-resolve-expr.h: Add prototype of error
propagation

Signed-off-by: benjamin.thos 

Diff:
---
 gcc/rust/resolve/rust-ast-resolve-expr.cc | 7 +++
 gcc/rust/resolve/rust-ast-resolve-expr.h  | 2 ++
 2 files changed, 9 insertions(+)

diff --git a/gcc/rust/resolve/rust-ast-resolve-expr.cc 
b/gcc/rust/resolve/rust-ast-resolve-expr.cc
index 7c2ba9c9d2cf..7ddf4a98f222 100644
--- a/gcc/rust/resolve/rust-ast-resolve-expr.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-expr.cc
@@ -23,6 +23,7 @@
 #include "rust-ast-resolve-pattern.h"
 #include "rust-ast-resolve-path.h"
 #include "diagnostic.h"
+#include "rust-expr.h"
 
 namespace Rust {
 namespace Resolver {
@@ -94,6 +95,12 @@ ResolveExpr::visit (AST::MethodCallExpr &expr)
 ResolveExpr::go (*param, prefix, canonical_prefix);
 }
 
+void
+ResolveExpr::visit (AST::ErrorPropagationExpr &expr)
+{
+  ResolveExpr::go (expr.get_propagating_expr (), prefix, canonical_prefix);
+}
+
 void
 ResolveExpr::visit (AST::AssignmentExpr &expr)
 {
diff --git a/gcc/rust/resolve/rust-ast-resolve-expr.h 
b/gcc/rust/resolve/rust-ast-resolve-expr.h
index 51a69e9886cc..562a3bd02722 100644
--- a/gcc/rust/resolve/rust-ast-resolve-expr.h
+++ b/gcc/rust/resolve/rust-ast-resolve-expr.h
@@ -22,6 +22,7 @@
 #include "rust-ast-resolve-base.h"
 #include "rust-ast.h"
 #include "rust-ast-resolve-pattern.h"
+#include "rust-expr.h"
 
 namespace Rust {
 namespace Resolver {
@@ -80,6 +81,7 @@ public:
   void visit (AST::RangeFromToInclExpr &expr) override;
   void visit (AST::ClosureExprInner &expr) override;
   void visit (AST::ClosureExprInnerTyped &expr) override;
+  void visit (AST::ErrorPropagationExpr &expr) override;
 
 protected:
   void resolve_closure_param (AST::ClosureParam ¶m,


[gcc r15-9117] i386: Add attr_isa for vaes patterns to sync with attr gpr16. [pr119473]

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

commit r15-9117-ge5cfa7f797b79613e5483786484567b9ca72db06
Author: Hu, Lin1 
Date:   Wed Mar 26 16:15:52 2025 +0800

i386: Add attr_isa for vaes patterns to sync with attr gpr16. [pr119473]

For vaes patterns with jm constraint and gpr16 attr, it requires "isa"
attr to distinct avx/avx512 alternatives in ix86_memory_address_reg_class.
Also adds missing type and mode attributes for those vaes patterns.

gcc/ChangeLog:

PR target/119473
* config/i386/sse.md
(vaesdec_): Set attr "isa" as "avx,vaes_avx512vl", "type" as
"sselog1", "mode" as "TI".
(vaesdeclast_): Ditto.
(vaesenc_): Ditto.
(vaesenclast_): Ditto.

gcc/testsuite/ChangeLog:

PR target/119473
* gcc.target/i386/pr119473.c: New test.

Co-authored-by: Hongyu Wang 

Diff:
---
 gcc/config/i386/sse.md   | 20 
 gcc/testsuite/gcc.target/i386/pr119473.c | 26 ++
 2 files changed, 42 insertions(+), 4 deletions(-)

diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
index 92dc93cb6532..b280676eee6b 100644
--- a/gcc/config/i386/sse.md
+++ b/gcc/config/i386/sse.md
@@ -30849,7 +30849,10 @@
   else
 return "vaesdec\t{%2, %1, %0|%0, %1, %2}";
 }
-[(set_attr "addr" "gpr16,*")])
+[(set_attr "isa" "avx,vaes_avx512vl")
+ (set_attr "type" "sselog1")
+ (set_attr "addr" "gpr16,*")
+ (set_attr "mode" "TI")])
 
 (define_insn "vaesdeclast_"
   [(set (match_operand:VI1_AVX512VL_F 0 "register_operand" "=x,v")
@@ -30864,7 +30867,10 @@
   else
 return "vaesdeclast\t{%2, %1, %0|%0, %1, %2}";
 }
-[(set_attr "addr" "gpr16,*")])
+[(set_attr "isa" "avx,vaes_avx512vl")
+ (set_attr "type" "sselog1")
+ (set_attr "addr" "gpr16,*")
+ (set_attr "mode" "TI")])
 
 (define_insn "vaesenc_"
   [(set (match_operand:VI1_AVX512VL_F 0 "register_operand" "=x,v")
@@ -30879,7 +30885,10 @@
   else
 return "vaesenc\t{%2, %1, %0|%0, %1, %2}";
 }
-[(set_attr "addr" "gpr16,*")])
+[(set_attr "isa" "avx,vaes_avx512vl")
+ (set_attr "type" "sselog1")
+ (set_attr "addr" "gpr16,*")
+ (set_attr "mode" "TI")])
 
 (define_insn "vaesenclast_"
   [(set (match_operand:VI1_AVX512VL_F 0 "register_operand" "=x,v")
@@ -30894,7 +30903,10 @@
   else
 return "vaesenclast\t{%2, %1, %0|%0, %1, %2}";
 }
-[(set_attr "addr" "gpr16,*")])
+[(set_attr "isa" "avx,vaes_avx512vl")
+ (set_attr "type" "sselog1")
+ (set_attr "addr" "gpr16,*")
+ (set_attr "mode" "TI")])
 
 (define_insn "vpclmulqdq_"
   [(set (match_operand:VI8_FVL 0 "register_operand" "=v")
diff --git a/gcc/testsuite/gcc.target/i386/pr119473.c 
b/gcc/testsuite/gcc.target/i386/pr119473.c
new file mode 100644
index ..574c9217ac9e
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr119473.c
@@ -0,0 +1,26 @@
+/* PR target/119473  */
+/* { dg-do compile { target { ! ia32 } } } */
+/* { dg-options "-O2 -mapxf -m64 -mvaes" } */
+
+typedef char __v32qi __attribute__ ((__vector_size__(32)));
+typedef long long __m256i __attribute__((__vector_size__(32), 
__aligned__(32)));
+
+typedef union
+{
+  __v32qi qi[8];
+} tmp_u;
+
+
+void foo ()
+{
+  register tmp_u *tdst __asm__("%rdx");
+  register tmp_u *src1 __asm__("%rcx");
+  register tmp_u *src2 __asm__("%r26");
+
+  tdst->qi[0] = __builtin_ia32_vaesdec_v32qi(src1->qi[0], src2->qi[0]);
+  tdst->qi[0] = __builtin_ia32_vaesdeclast_v32qi(src1->qi[0], src2->qi[0]);
+  tdst->qi[0] = __builtin_ia32_vaesenc_v32qi(src1->qi[0], src2->qi[0]);
+  tdst->qi[0] = __builtin_ia32_vaesenclast_v32qi(src1->qi[0], src2->qi[0]);
+}
+
+/* { dg-final { scan-assembler-not "\\\(%r26\\\), " } } */


[gcc r15-9212] c++: lambda in requires outside template [PR99546]

2025-04-04 Thread Jason Merrill via Gcc-cvs
https://gcc.gnu.org/g:25992d8daff60726a247ec7850d540aed5335639

commit r15-9212-g25992d8daff60726a247ec7850d540aed5335639
Author: Jason Merrill 
Date:   Wed Jan 29 05:15:00 2025 -0500

c++: lambda in requires outside template [PR99546]

Since r10-7441 we set processing_template_decl in a requires-expression so
that we can use tsubst_expr to evaluate the requirements, but that confuses
lambdas terribly; begin_lambda_type silently returns error_mark_node and we
continue into other failures.  This patch clears processing_template_decl
again while we're defining the closure and op() function, so it only remains
set while parsing the introducer (i.e. any init-captures) and building the
resulting object.  This properly avoids trying to create another lambda in
tsubst_lambda_expr.

PR c++/99546
PR c++/113925
PR c++/106976
PR c++/109961
PR c++/117336

gcc/cp/ChangeLog:

* lambda.cc (build_lambda_object): Handle fake
requires-expr processing_template_decl.
* parser.cc (cp_parser_lambda_expression): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/lambda-requires2.C: New test.
* g++.dg/cpp2a/lambda-requires3.C: New test.
* g++.dg/cpp2a/lambda-requires4.C: New test.
* g++.dg/cpp2a/lambda-requires5.C: New test.

Diff:
---
 gcc/cp/lambda.cc  |  8 +-
 gcc/cp/parser.cc  | 41 ++-
 gcc/testsuite/g++.dg/cpp2a/lambda-requires2.C |  8 ++
 gcc/testsuite/g++.dg/cpp2a/lambda-requires3.C |  6 
 gcc/testsuite/g++.dg/cpp2a/lambda-requires4.C |  6 
 gcc/testsuite/g++.dg/cpp2a/lambda-requires5.C | 10 +++
 6 files changed, 64 insertions(+), 15 deletions(-)

diff --git a/gcc/cp/lambda.cc b/gcc/cp/lambda.cc
index ed70bb0ba8e0..f0a54b602750 100644
--- a/gcc/cp/lambda.cc
+++ b/gcc/cp/lambda.cc
@@ -59,7 +59,13 @@ build_lambda_object (tree lambda_expr)
   vec *elts = NULL;
   tree node, expr, type;
 
-  if (processing_template_decl || lambda_expr == error_mark_node)
+  if (processing_template_decl && !in_template_context
+  && current_binding_level->requires_expression)
+/* As in cp_parser_lambda_expression, don't get confused by
+   cp_parser_requires_expression setting processing_template_decl.  In that
+   case we want to return the result of finish_compound_literal, to avoid
+   tsubst_lambda_expr.  */;
+  else if (processing_template_decl || lambda_expr == error_mark_node)
 return lambda_expr;
 
   /* Make sure any error messages refer to the lambda-introducer.  */
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 53e6237f6c48..812a7c5ae7d9 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -11736,21 +11736,34 @@ cp_parser_lambda_expression (cp_parser* parser)
   if (cp_parser_error_occurred (parser))
 return error_mark_node;
 
-  type = begin_lambda_type (lambda_expr);
-  if (type == error_mark_node)
-return error_mark_node;
-
-  record_lambda_scope (lambda_expr);
-  record_lambda_scope_discriminator (lambda_expr);
-
-  /* Do this again now that LAMBDA_EXPR_EXTRA_SCOPE is set.  */
-  determine_visibility (TYPE_NAME (type));
-
-  /* Now that we've started the type, add the capture fields for any
- explicit captures.  */
-  register_capture_members (LAMBDA_EXPR_CAPTURE_LIST (lambda_expr));
-
   {
+/* OK, this is a bit tricksy.  cp_parser_requires_expression sets
+   processing_template_decl to make checking more normal, but that confuses
+   lambda parsing terribly.  In non-template context, we want to parse the
+   lambda once and not tsubst_lambda_expr.  So in that case, clear
+   processing_template_decl now, and restore it before the call to
+   build_lambda_object; that way we end up with what looks like a templatey
+   functional cast to the closure type, which is suitable for the
+   requires-expression tsubst_expr.  This is PR99546 and friends.  */
+processing_template_decl_sentinel ptds (/*reset*/false);
+if (processing_template_decl && !in_template_context
+   && current_binding_level->requires_expression)
+  processing_template_decl = 0;
+
+type = begin_lambda_type (lambda_expr);
+if (type == error_mark_node)
+  return error_mark_node;
+
+record_lambda_scope (lambda_expr);
+record_lambda_scope_discriminator (lambda_expr);
+
+/* Do this again now that LAMBDA_EXPR_EXTRA_SCOPE is set.  */
+determine_visibility (TYPE_NAME (type));
+
+/* Now that we've started the type, add the capture fields for any
+   explicit captures.  */
+register_capture_members (LAMBDA_EXPR_CAPTURE_LIST (lambda_expr));
+
 /* Inside the class, surrounding template-parameter-lists do not apply.  */
 unsigned int saved_num_template_parameter_lists
 = parser->num_template_parameter_lists;
diff --git a/gc

[gcc r15-9124] gimple-low: Diagnose assume attr expressions defining labels which are used as unary && operands out

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

commit r15-9124-ga6c2248cfd4bc922378f554578ee44e6b4690f5d
Author: Jakub Jelinek 
Date:   Tue Apr 1 11:40:58 2025 +0200

gimple-low: Diagnose assume attr expressions defining labels which are used 
as unary && operands outside of those [PR119537]

The following testcases ICE on invalid code which defines
labels inside of statement expressions and then uses &&label
from code outside of the statement expressions.
The C++ FE diagnoses that with a warning (not specifically for
assume attribute, genericallly about taking address of a label
outside of a statement expression so computed goto could violate
the requirement that statement expression is not entered from
outside of it through a jump into it), the C FE doesn't diagnose
anything.
Normal direct gotos to such labels are diagnosed by both C and C++.
In the assume attribute case it is actually worse than for
addresses of labels in normal statement expressions, in that case
the labels are still in the current function, so invalid program
can still jump to those (and in case of OpenMP/OpenACC where it
is also invalid and stuff is moved to a separate function, such
movement is done post cfg discovery of FORCED_LABELs and worst
case one can run into cases which fail to assemble, but I haven't
succeeded in creating ICE for that).
For assume at -O0 we'd just throw away the assume expression if
it is not a simple condition and so the label is then not defined
anywhere and we ICE during cfg pass.
The gimplify.cc hunks fix that, as we don't have FORCED_LABELs
discovery done yet, it preserves all assume expressions which contain
used user labels.
With that we ICE during IRA, which is upset about an indirect jump
to a label which doesn't exist.
So, the gimple-low.cc hunks add diagnostics of the problem, it gathers
uids of all the user used labels inside of the assume expressions (usually
none) and if it finds any, walks the IL to find uses of those from outside
of those expressions now outlined into separate magic functions.

2025-04-01  Jakub Jelinek  

PR middle-end/119537
* gimplify.cc (find_used_user_labels): New function.
(gimplify_call_expr): Don't remove complex assume expression at -O0
if it defines any user labels.
* gimple-low.cc: Include diagnostic-core.h.
(assume_labels): New variable.
(diagnose_assume_labels): New function.
(lower_function_body): Call it via walk_gimple_seq if assume_labels
is non-NULL, then BITMAP_FREE assume_labels.
(find_assumption_locals_r): Record in assume_labels uids of user
labels defined in assume attribute expressions.

* c-c++-common/pr119537-1.c: New test.
* c-c++-common/pr119537-2.c: New test.

Diff:
---
 gcc/gimple-low.cc   | 43 +
 gcc/gimplify.cc | 25 +--
 gcc/testsuite/c-c++-common/pr119537-1.c | 23 ++
 gcc/testsuite/c-c++-common/pr119537-2.c | 23 ++
 4 files changed, 112 insertions(+), 2 deletions(-)

diff --git a/gcc/gimple-low.cc b/gcc/gimple-low.cc
index b612970a55ac..79cdd7763dad 100644
--- a/gcc/gimple-low.cc
+++ b/gcc/gimple-low.cc
@@ -41,6 +41,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-inline.h"
 #include "gimple-walk.h"
 #include "attribs.h"
+#include "diagnostic-core.h"
 
 /* The differences between High GIMPLE and Low GIMPLE are the
following:
@@ -78,6 +79,10 @@ struct lower_data
   bool cannot_fallthru;
 };
 
+/* Bitmap of LABEL_DECL uids for user labels moved into assume outlined
+   functions.  */
+static bitmap assume_labels;
+
 static void lower_stmt (gimple_stmt_iterator *, struct lower_data *);
 static void lower_gimple_bind (gimple_stmt_iterator *, struct lower_data *);
 static void lower_try_catch (gimple_stmt_iterator *, struct lower_data *);
@@ -87,6 +92,29 @@ static void lower_builtin_posix_memalign 
(gimple_stmt_iterator *);
 static void lower_builtin_assume_aligned (gimple_stmt_iterator *);
 
 
+/* Helper function for lower_function_body, called via walk_gimple_seq.
+   Diagnose uses of user labels defined inside of assume attribute
+   expressions.  */
+
+static tree
+diagnose_assume_labels (tree *tp, int *, void *data)
+{
+  if (TREE_CODE (*tp) == LABEL_DECL
+  && !DECL_ARTIFICIAL (*tp)
+  && DECL_NAME (*tp)
+  && bitmap_bit_p (assume_labels, DECL_UID (*tp)))
+{
+  struct walk_stmt_info *wi = (struct walk_stmt_info *) data;
+  auto_diagnostic_group d;
+  error_at (gimple_location (gsi_stmt (wi->gsi)),
+   "reference to label %qD defined inside of % "
+   "attribute expression from outside of the attribute", *tp);
+  inform (DECL_SO

[gcc r15-9216] c++/modules: Propagate bits to DECL_MAYBE_DELETED dups [PR119462]

2025-04-04 Thread Nathaniel Shead via Gcc-cvs
https://gcc.gnu.org/g:f4a3ae1ef5ec951f007c4bd530f30e44945c5f0d

commit r15-9216-gf4a3ae1ef5ec951f007c4bd530f30e44945c5f0d
Author: Nathaniel Shead 
Date:   Fri Apr 4 19:08:40 2025 +1100

c++/modules: Propagate bits to DECL_MAYBE_DELETED dups [PR119462]

In the linked PR, we're importing over a DECL_MAYBE_DELETED decl with a
decl that has already been instantiated.  This patch ensures that the
needed bits are propagated across and that DECL_MAYBE_DELETED is cleared
from the existing decl, so that later synthesize_method doesn't crash
due to a definition unexpectedly already existing.

PR c++/119462

gcc/cp/ChangeLog:

* module.cc (trees_in::is_matching_decl): Propagate exception
spec and constexpr to DECL_MAYBE_DELETED; clear if appropriate.

gcc/testsuite/ChangeLog:

* g++.dg/modules/noexcept-3_a.C: New test.
* g++.dg/modules/noexcept-3_b.C: New test.
* g++.dg/modules/noexcept-3_c.C: New test.

Signed-off-by: Nathaniel Shead 
Reviewed-by: Jason Merrill 

Diff:
---
 gcc/cp/module.cc| 16 +++-
 gcc/testsuite/g++.dg/modules/noexcept-3_a.C | 14 ++
 gcc/testsuite/g++.dg/modules/noexcept-3_b.C | 12 
 gcc/testsuite/g++.dg/modules/noexcept-3_c.C | 11 +++
 4 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 89deabbfee37..ff8cd86c427d 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -12122,7 +12122,7 @@ trees_in::is_matching_decl (tree existing, tree decl, 
bool is_typedef)
 instantiate it in the middle of loading.   */
   tree e_spec = TYPE_RAISES_EXCEPTIONS (e_type);
   tree d_spec = TYPE_RAISES_EXCEPTIONS (d_type);
-  if (DEFERRED_NOEXCEPT_SPEC_P (e_spec))
+  if (DECL_MAYBE_DELETED (e_inner) || DEFERRED_NOEXCEPT_SPEC_P (e_spec))
{
  if (!DEFERRED_NOEXCEPT_SPEC_P (d_spec)
  || (UNEVALUATED_NOEXCEPT_SPEC_P (e_spec)
@@ -12161,6 +12161,20 @@ trees_in::is_matching_decl (tree existing, tree decl, 
bool is_typedef)
   else if (type_uses_auto (d_ret)
   && !same_type_p (TREE_TYPE (d_type), TREE_TYPE (e_type)))
goto mismatch;
+
+  /* Similarly if EXISTING has undeduced constexpr, but DECL's
+is already deduced.  */
+  if (DECL_MAYBE_DELETED (e_inner) && !DECL_MAYBE_DELETED (d_inner)
+ && DECL_DECLARED_CONSTEXPR_P (d_inner))
+   DECL_DECLARED_CONSTEXPR_P (e_inner) = true;
+  else if (DECL_DECLARED_CONSTEXPR_P (e_inner)
+  != DECL_DECLARED_CONSTEXPR_P (d_inner))
+   goto mismatch;
+
+  /* Don't synthesize a defaulted function if we're importing one
+we've already determined.  */
+  if (!DECL_MAYBE_DELETED (d_inner))
+   DECL_MAYBE_DELETED (e_inner) = false;
 }
   else if (is_typedef)
 {
diff --git a/gcc/testsuite/g++.dg/modules/noexcept-3_a.C 
b/gcc/testsuite/g++.dg/modules/noexcept-3_a.C
new file mode 100644
index ..00494d33d7cb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/noexcept-3_a.C
@@ -0,0 +1,14 @@
+// PR c++/119462
+// { dg-additional-options "-fmodules -std=c++20 -Wno-global-module" }
+// { dg-module-cmi M:part }
+
+module;
+struct exception_ptr {
+  // implicitly noexcept and constexpr
+  friend bool operator==(const exception_ptr&, const exception_ptr&) = default;
+};
+export module M:part;
+export template  void enqueue() {
+  exception_ptr e;
+  e == e;
+}
diff --git a/gcc/testsuite/g++.dg/modules/noexcept-3_b.C 
b/gcc/testsuite/g++.dg/modules/noexcept-3_b.C
new file mode 100644
index ..f26f8f0f5d3d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/noexcept-3_b.C
@@ -0,0 +1,12 @@
+// PR c++/119462
+// { dg-additional-options "-fmodules -std=c++20 -Wno-global-module" }
+// { dg-module-cmi M }
+
+module;
+struct exception_ptr {
+  // implicitly noexcept and constexpr, but this isn't known yet
+  friend bool operator==(const exception_ptr&, const exception_ptr&) = default;
+};
+export module M;
+export import :part;
+export using ::exception_ptr;
diff --git a/gcc/testsuite/g++.dg/modules/noexcept-3_c.C 
b/gcc/testsuite/g++.dg/modules/noexcept-3_c.C
new file mode 100644
index ..a1e98a5461aa
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/noexcept-3_c.C
@@ -0,0 +1,11 @@
+// PR c++/119462
+// { dg-additional-options "-fmodules -std=c++20" }
+
+import M;
+int main() {
+  enqueue();
+
+  constexpr exception_ptr e;
+  static_assert(e == e);
+  static_assert(noexcept(e == e));
+}


[gcc r15-9217] c++/modules: Fix divergence in streaming/non-streaming tree walks [PR119608]

2025-04-04 Thread Nathaniel Shead via Gcc-cvs
https://gcc.gnu.org/g:b8e8829cfb73d7aa009d387ab09bdbab221930d7

commit r15-9217-gb8e8829cfb73d7aa009d387ab09bdbab221930d7
Author: Nathaniel Shead 
Date:   Fri Apr 4 11:56:53 2025 +1100

c++/modules: Fix divergence in streaming/non-streaming tree walks [PR119608]

Modules streaming walks decls multiple times, first as a non-streaming
walk to find dependencies, and then later to actually emit the decls.
The first walk needs to be done to note locations that will be emitted.

In the PR we are getting a checking ICE because we are streaming a decl
that we didn't initially walk when collecting dependencies, so the
location isn't in the noted locations map.  This is because in decl_node
we have a branch where a PARM_DECL that hasn't previously been
referenced gets walked by value only if 'streaming_p ()' is true.

The true root cause here is that the decltype(v) in the testcase refers
to a different PARM_DECL from the one in the declaration that we're
streaming; it's the PARM_DECL from the initial forward-declaration, that
we're not streaming.  A proper fix would be to ensure that it gets
remapped to the decl in the definition we're actually emitting, but for
now this workaround fixes the bug (and any other bugs that might
manifest similarly).

PR c++/119608

gcc/cp/ChangeLog:

* module.cc (trees_out::decl_node): Maybe require by-value
walking not just when streaming.

gcc/testsuite/ChangeLog:

* g++.dg/modules/pr119608_a.C: New test.
* g++.dg/modules/pr119608_b.C: New test.

Signed-off-by: Nathaniel Shead 
Reviewed-by: Jason Merrill 

Diff:
---
 gcc/cp/module.cc  | 39 +--
 gcc/testsuite/g++.dg/modules/pr119608_a.C | 16 +
 gcc/testsuite/g++.dg/modules/pr119608_b.C |  8 +++
 3 files changed, 45 insertions(+), 18 deletions(-)

diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index ff8cd86c427d..37fab5b5a43e 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -9004,25 +9004,28 @@ trees_out::decl_node (tree decl, walk_kind ref)
if (streaming_p ())
  i (tt_parm);
tree_node (DECL_CONTEXT (decl));
-   if (streaming_p ())
- {
-   /* That must have put this in the map.  */
-   walk_kind ref = ref_node (decl);
-   if (ref != WK_none)
- // FIXME:OPTIMIZATION We can wander into bits of the
- // template this was instantiated from.  For instance
- // deferred noexcept and default parms.  Currently we'll
- // end up cloning those bits of tree.  It would be nice
- // to reference those specific nodes.  I think putting
- // those things in the map when we reference their
- // template by name.  See the note in add_indirects.
- return true;
 
-   dump (dumper::TREE)
- && dump ("Wrote %s reference %N",
-  TREE_CODE (decl) == PARM_DECL ? "parameter" : "result",
-  decl);
- }
+   /* That must have put this in the map.  */
+   walk_kind ref = ref_node (decl);
+   if (ref != WK_none)
+ // FIXME:OPTIMIZATION We can wander into bits of the
+ // template this was instantiated from, for instance
+ // deferred noexcept and default parms, or references
+ // to parms from earlier forward-decls (PR c++/119608).
+ //
+ // Currently we'll end up cloning those bits of tree. 
+ // It would be nice to reference those specific nodes.
+ // I think putting those things in the map when we
+ // reference their template by name.
+ //
+ // See the note in add_indirects.
+ return true;
+
+   if (streaming_p ())
+ dump (dumper::TREE)
+   && dump ("Wrote %s reference %N",
+TREE_CODE (decl) == PARM_DECL ? "parameter" : "result",
+decl);
   }
   return false;
 
diff --git a/gcc/testsuite/g++.dg/modules/pr119608_a.C 
b/gcc/testsuite/g++.dg/modules/pr119608_a.C
new file mode 100644
index ..4e7b359ac581
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/pr119608_a.C
@@ -0,0 +1,16 @@
+// PR c++/119608
+// { dg-additional-options "-fmodules" }
+// { dg-module-cmi repro }
+
+export module repro;
+
+export template
+auto
+visit(
+  Visitor v
+) -> decltype(
+  v);
+
+export template auto visit(Visitor v) -> decltype(v) {
+  return {};
+}
diff --git a/gcc/testsuite/g++.dg/modules/pr119608_b.C 
b/gcc/testsuite/g++.dg/modules/pr119608_b.C
new file mode 100644
index ..023d20adf4c5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/pr119608_b.C
@@ -0,0 +1,8 @@
+// PR c++/119608
+// { dg-additional-options "-fmodules" }
+
+import repro;
+
+int main() {
+  visit(123);
+}


[gcc r15-8583] gccrs: ast: Add new constructors for PathInExpression

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

commit r15-8583-gb76ee925818b5617ec3b86e07edbf1f880d5e6e7
Author: Arthur Cohen 
Date:   Sat Dec 21 22:53:50 2024 +

gccrs: ast: Add new constructors for PathInExpression

This commit adds two new constructors for AST::PathInExpression: One using 
a provided lang-item, and one with an already built std::unique_ptr

gcc/rust/ChangeLog:

* ast/rust-path.h: Add two new constructors.

Diff:
---
 gcc/rust/ast/rust-path.h | 21 -
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/ast/rust-path.h b/gcc/rust/ast/rust-path.h
index 563ad52a9d6d..39d42fd7e155 100644
--- a/gcc/rust/ast/rust-path.h
+++ b/gcc/rust/ast/rust-path.h
@@ -715,6 +715,24 @@ public:
   marked_for_strip (false)
   {}
 
+  PathInExpression (LangItem::Kind lang_item_kind,
+   std::vector outer_attrs, location_t locus)
+: outer_attrs (std::move (outer_attrs)),
+  has_opening_scope_resolution (false), locus (locus),
+  _node_id (Analysis::Mappings::get ().get_next_node_id ()),
+  path (Rust::make_unique (lang_item_kind, locus)),
+  marked_for_strip (false)
+  {}
+
+  PathInExpression (std::unique_ptr path,
+   std::vector outer_attrs, location_t locus,
+   bool has_opening_scope_resolution = false)
+: outer_attrs (std::move (outer_attrs)),
+  has_opening_scope_resolution (has_opening_scope_resolution),
+  locus (locus), _node_id (Analysis::Mappings::get ().get_next_node_id ()),
+  path (std::move (path)), marked_for_strip (false)
+  {}
+
   PathInExpression (const PathInExpression &other)
 : outer_attrs (other.outer_attrs),
   has_opening_scope_resolution (other.has_opening_scope_resolution),
@@ -738,7 +756,8 @@ public:
   // Creates an error state path in expression.
   static PathInExpression create_error ()
   {
-return PathInExpression ({}, {}, UNDEF_LOCATION);
+return PathInExpression (std::vector (), {},
+UNDEF_LOCATION);
   }
 
   // Returns whether path in expression is in an error state.


[gcc r15-8374] gccrs: Implement initial pattern analysis pass.

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

commit r15-8374-ge620a86e4d7591eb446df828506da76c070d1eb9
Author: Raiki Tamura 
Date:   Thu Aug 8 02:25:05 2024 +0900

gccrs: Implement initial pattern analysis pass.

gcc/rust/ChangeLog:

* Make-lang.in: Add rust-hir-pattern-analysis.o.
* rust-session-manager.cc (Session::compile_crate):
Add pattern analysis pass.
* typecheck/rust-hir-type-check-pattern.cc 
(TypeCheckPattern::visit):
Do typecheck for subpatterns.
* checks/errors/rust-hir-pattern-analysis.cc: New file.
* checks/errors/rust-hir-pattern-analysis.h: New file.

gcc/testsuite/ChangeLog:

* rust/compile/exhaustiveness1.rs: New test.
* rust/compile/exhaustiveness2.rs: New test.
* rust/compile/exhaustiveness3.rs: New test.

Signed-off-by: Raiki Tamura 

Diff:
---
 gcc/rust/Make-lang.in  |1 +
 .../checks/errors/rust-hir-pattern-analysis.cc | 1554 
 gcc/rust/checks/errors/rust-hir-pattern-analysis.h |  526 +++
 gcc/rust/rust-session-manager.cc   |6 +
 gcc/rust/typecheck/rust-hir-type-check-pattern.cc  |2 +
 gcc/testsuite/rust/compile/exhaustiveness1.rs  |   53 +
 gcc/testsuite/rust/compile/exhaustiveness2.rs  |   28 +
 gcc/testsuite/rust/compile/exhaustiveness3.rs  |   55 +
 8 files changed, 2225 insertions(+)

diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index d291dd647654..950cd3af0735 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -188,6 +188,7 @@ GRS_OBJS = \
 rust/rust-readonly-check.o \
 rust/rust-hir-type-check-path.o \
 rust/rust-unsafe-checker.o \
+rust/rust-hir-pattern-analysis.o \
 rust/rust-compile-intrinsic.o \
 rust/rust-compile-pattern.o \
 rust/rust-compile-fnparam.o \
diff --git a/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc 
b/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc
new file mode 100644
index ..fdbc6e8d2ec0
--- /dev/null
+++ b/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc
@@ -0,0 +1,1554 @@
+// 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-system.h"
+#include "rust-hir-pattern-analysis.h"
+#include "rust-diagnostics.h"
+#include "rust-hir-full-decls.h"
+#include "rust-hir-path.h"
+#include "rust-hir-pattern.h"
+#include "rust-hir.h"
+#include "rust-mapping-common.h"
+#include "rust-system.h"
+#include "rust-tyty.h"
+
+namespace Rust {
+namespace Analysis {
+
+PatternChecker::PatternChecker ()
+  : tyctx (*Resolver::TypeCheckContext::get ()),
+resolver (*Resolver::Resolver::get ()),
+mappings (Analysis::Mappings::get ())
+{}
+
+void
+PatternChecker::go (HIR::Crate &crate)
+{
+  rust_debug ("started pattern check");
+  for (auto &item : crate.get_items ())
+item->accept_vis (*this);
+  rust_debug ("finished pattern check");
+}
+
+void
+PatternChecker::visit (Lifetime &)
+{}
+
+void
+PatternChecker::visit (LifetimeParam &)
+{}
+
+void
+PatternChecker::visit (PathInExpression &path)
+{}
+
+void
+PatternChecker::visit (TypePathSegment &)
+{}
+
+void
+PatternChecker::visit (TypePathSegmentGeneric &)
+{}
+
+void
+PatternChecker::visit (TypePathSegmentFunction &)
+{}
+
+void
+PatternChecker::visit (TypePath &)
+{}
+
+void
+PatternChecker::visit (QualifiedPathInExpression &)
+{}
+
+void
+PatternChecker::visit (QualifiedPathInType &)
+{}
+
+void
+PatternChecker::visit (LiteralExpr &)
+{}
+
+void
+PatternChecker::visit (BorrowExpr &expr)
+{
+  expr.get_expr ()->accept_vis (*this);
+}
+
+void
+PatternChecker::visit (DereferenceExpr &expr)
+{
+  expr.get_expr ()->accept_vis (*this);
+}
+
+void
+PatternChecker::visit (ErrorPropagationExpr &expr)
+{
+  expr.get_expr ()->accept_vis (*this);
+}
+
+void
+PatternChecker::visit (NegationExpr &expr)
+{
+  expr.get_expr ()->accept_vis (*this);
+}
+
+void
+PatternChecker::visit (ArithmeticOrLogicalExpr &expr)
+{
+  expr.get_lhs ()->accept_vis (*this);
+  expr.get_rhs ()->accept_vis (*this);
+}
+
+void
+PatternChecker::visit (ComparisonExpr &expr)
+{
+  expr.get_lhs ()->accept_vis (*this);
+  expr.get_rhs ()->accept_vis (*this);
+}
+
+void
+PatternChecker::visit (LazyBooleanExpr &expr)

[gcc r15-9215] cobol: Set compile-time and run-time signable_e bits the same for RETURN-CODE.

2025-04-04 Thread Robert Dubner via Gcc-cvs
https://gcc.gnu.org/g:6602fc076a883cf0cd20a37655a6bd9c146a2770

commit r15-9215-g6602fc076a883cf0cd20a37655a6bd9c146a2770
Author: Bob Dubner 
Date:   Fri Apr 4 18:33:42 2025 -0400

cobol: Set compile-time and run-time signable_e bits the same for 
RETURN-CODE.

This fix reverts the recent cobol_langhook_post_options change setting
flag_strict_aliasing = 0.  It isn't necessary.

gcc/cobol

* cobol1.cc: Eliminate cobol_langhook_post_options.
* symbols.cc: Definition of RETURN-CODE special register sets
::attr member to signable_e.

Diff:
---
 gcc/cobol/cobol1.cc  | 19 ---
 gcc/cobol/symbols.cc |  2 +-
 2 files changed, 1 insertion(+), 20 deletions(-)

diff --git a/gcc/cobol/cobol1.cc b/gcc/cobol/cobol1.cc
index d175ab11e3f2..0d07c460d416 100644
--- a/gcc/cobol/cobol1.cc
+++ b/gcc/cobol/cobol1.cc
@@ -646,22 +646,6 @@ cobol_get_sarif_source_language(const char *)
 return "cobol";
 }
 
-bool
-cobol_langhook_post_options(const char**)
-  {
-  // This flag, when set to 0, results in calls to gg_exit working properly.
-  // I don't know why it is necessary.  There is something going on with the
-  // definition of  __gg__data_return_code in constants.cc, and with how it
-  // is used through var_decl_return_code in genapi.cc.  Without it, the value
-  // delivered to exit@PLT is zero, and not __gg__data_return_code
-  // Dubner, 2025-04-04.
-  flag_strict_aliasing = 0;
-
-  /* Returning false means that the backend should be used.  */
-  return false;
-  }
-
-
 #undef LANG_HOOKS_BUILTIN_FUNCTION
 #undef LANG_HOOKS_GETDECLS
 #undef LANG_HOOKS_GLOBAL_BINDINGS_P
@@ -676,7 +660,6 @@ cobol_langhook_post_options(const char**)
 #undef LANG_HOOKS_TYPE_FOR_SIZE
 #undef LANG_HOOKS_SET_DECL_ASSEMBLER_NAME
 #undef LANG_HOOKS_GET_SARIF_SOURCE_LANGUAGE
-#undef LANG_HOOKS_POST_OPTIONS
 
 // We use GCC in the name, not GNU, as others do,
 // because "GnuCOBOL" refers to a different GNU project.
@@ -702,8 +685,6 @@ cobol_langhook_post_options(const char**)
 
 #define LANG_HOOKS_GET_SARIF_SOURCE_LANGUAGE cobol_get_sarif_source_language
 
-#define LANG_HOOKS_POST_OPTIONS cobol_langhook_post_options
-
 struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
 
 #include "gt-cobol-cobol1.h"
diff --git a/gcc/cobol/symbols.cc b/gcc/cobol/symbols.cc
index 2373bfe6cc5a..50431251a0f1 100644
--- a/gcc/cobol/symbols.cc
+++ b/gcc/cobol/symbols.cc
@@ -2350,7 +2350,7 @@ symbol_table_init(void) {
   0, {}, {2,2,2,0, NULL}, NULL },
 { 0, FldNumericBin5, FldInvalid, 0, 0, 0, 0, nonarray, 0, "UPSI-0",
   0, {}, {2,2,4,0, NULL}, NULL },
-{ 0, FldNumericBin5, FldInvalid, 0, 0, 0, 0, nonarray, 0, "RETURN-CODE",
+{ 0, FldNumericBin5, FldInvalid, signable_e, 0, 0, 0, nonarray, 0, 
"RETURN-CODE",
   0, {}, {2,2,4,0, NULL}, NULL },
 { 0, FldNumericBin5, FldInvalid, 0, 0, 0, 0, nonarray, 0, "LINAGE-COUNTER",
   0, {}, {2,2,4,0, NULL}, NULL },


[gcc r15-8303] gccrs: Move builtin macro tests to their own directory

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

commit r15-8303-gc5b6e533a1c2912a1b8a6993a413f9377a2762e0
Author: Pierre-Emmanuel Patry 
Date:   Mon Jul 29 14:20:01 2024 +0200

gccrs: Move builtin macro tests to their own directory

We need a finer grain to filter tests and organise them.

gcc/testsuite/ChangeLog:

* rust/compile/builtin_macro_compile_error.rs: Move to...
* rust/compile/macros/builtin/compile_error.rs: ...here.
* rust/compile/builtin_macro_concat.rs: Move to...
* rust/compile/macros/builtin/concat.rs: ...here.
* rust/compile/builtin_macro_eager1.rs: Move to...
* rust/compile/macros/builtin/eager1.rs: ...here.
* rust/compile/builtin_macro_eager2.rs: Move to...
* rust/compile/macros/builtin/eager2.rs: ...here.
* rust/compile/builtin_macro_eager3.rs: Move to...
* rust/compile/macros/builtin/eager3.rs: ...here.
* rust/compile/builtin_macro_env.rs: Move to...
* rust/compile/macros/builtin/env.rs: ...here.
* rust/compile/builtin_macro_include_bytes.rs: Move to...
* rust/compile/macros/builtin/include_bytes.rs: ...here.
* rust/compile/builtin_macro_include_bytes_location_info.rs: Move 
to...
* rust/compile/macros/builtin/include_bytes_location_info.rs: 
...here.
* rust/compile/builtin_macro_include_str.rs: Move to...
* rust/compile/macros/builtin/include_str.rs: ...here.
* rust/compile/builtin_macro_include_str_location_info.rs: Move 
to...
* rust/compile/macros/builtin/include_str_location_info.rs: ...here.
* rust/compile/builtin_macro_not_found.rs: Move to...
* rust/compile/macros/builtin/not_found.rs: ...here.
* rust/compile/builtin_macro_recurse2.rs: Move to...
* rust/compile/macros/builtin/recurse2.rs: ...here.
* rust/compile/macros/builtin/builtin_macro.exp: New test.
* rust/compile/invalid_utf8: Move invalid-utf8 data to...
* rust/compile/macros/builtin/invalid_utf8: ...here.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 .../rust/compile/builtin_macro_include_bytes.rs| 15 --
 .../rust/compile/builtin_macro_include_str.rs  | 16 --
 .../rust/compile/macros/builtin/builtin_macro.exp  | 35 ++
 .../builtin/compile_error.rs}  |  0
 .../builtin/concat.rs} |  0
 .../builtin/eager1.rs} |  0
 .../builtin/eager2.rs} |  0
 .../builtin/eager3.rs} |  0
 .../builtin/env.rs}|  0
 .../rust/compile/macros/builtin/include_bytes.rs   | 15 ++
 .../builtin/include_bytes_location_info.rs}|  0
 .../rust/compile/macros/builtin/include_str.rs | 16 ++
 .../builtin/include_str_location_info.rs}  |  0
 .../rust/compile/{ => macros/builtin}/invalid_utf8 |  0
 .../builtin/not_found.rs}  |  0
 .../builtin/recurse2.rs}   |  0
 16 files changed, 66 insertions(+), 31 deletions(-)

diff --git a/gcc/testsuite/rust/compile/builtin_macro_include_bytes.rs 
b/gcc/testsuite/rust/compile/builtin_macro_include_bytes.rs
deleted file mode 100644
index 9972c10b49a4..
--- a/gcc/testsuite/rust/compile/builtin_macro_include_bytes.rs
+++ /dev/null
@@ -1,15 +0,0 @@
-#![feature(rustc_attrs)]
-
-#[rustc_builtin_macro]
-macro_rules! include_bytes {
-  () => {{}};
-}
-
-fn main () {
-  let file = "include.txt";
-  include_bytes! (file); // { dg-error "argument must be a string literal" "" }
-  include_bytes! (); // { dg-error "macro takes 1 argument" "" }
-  include_bytes! ("foo.txt", "bar.txt"); // { dg-error "macro takes 1 
argument" "" }
-  include_bytes! ("builtin_macro_include_bytes.rs"); // ok
-  include_bytes! ("builtin_macro_include_bytes.rs",); // trailing comma ok
-}
diff --git a/gcc/testsuite/rust/compile/builtin_macro_include_str.rs 
b/gcc/testsuite/rust/compile/builtin_macro_include_str.rs
deleted file mode 100644
index d6d7a76856f4..
--- a/gcc/testsuite/rust/compile/builtin_macro_include_str.rs
+++ /dev/null
@@ -1,16 +0,0 @@
-#![feature(rustc_attrs)]
-
-#[rustc_builtin_macro]
-macro_rules! include_str {
-  () => {{}};
-}
-
-fn main () {
-  let file = "include.txt";
-  include_str! (file); // { dg-error "argument must be a string literal" "" }
-  include_str! (); // { dg-error "macro takes 1 argument" "" }
-  include_str! ("foo.txt", "bar.txt"); // { dg-error "macro takes 1 argument" 
"" }
-  include_str! ("builtin_macro_include_str.rs"); // ok
-  include_str! ("builtin_macro_include_str.rs",); // trailing comma ok
-  include_str! ("invalid_utf8"); // { dg-error "invalid_utf8 was not a valid 
utf-8 file" "" }
-}
diff --git a/gcc/testsuite/rust/compile/

[gcc r15-9218] c++: Fix GC with TU_LOCAL_ENTITY [PR119564]

2025-04-04 Thread Nathaniel Shead via Gcc-cvs
https://gcc.gnu.org/g:337b9ff4854c6a7fa47860ce0acad82ffb4d39be

commit r15-9218-g337b9ff4854c6a7fa47860ce0acad82ffb4d39be
Author: Nathaniel Shead 
Date:   Fri Apr 4 12:24:10 2025 +1100

c++: Fix GC with TU_LOCAL_ENTITY [PR119564]

When adding TU_LOCAL_ENTITY in r15-6379 I neglected to add it to
cp_tree_node_structure, so garbage collection was crashing on it.

PR c++/119564

gcc/cp/ChangeLog:

* decl.cc (cp_tree_node_structure): Add TU_LOCAL_ENTITY; fix
formatting.

gcc/testsuite/ChangeLog:

* g++.dg/modules/gc-3_a.C: New test.
* g++.dg/modules/gc-3_b.C: New test.

Signed-off-by: Nathaniel Shead 
Reviewed-by: Jason Merrill 

Diff:
---
 gcc/cp/decl.cc| 7 ---
 gcc/testsuite/g++.dg/modules/gc-3_a.C | 7 +++
 gcc/testsuite/g++.dg/modules/gc-3_b.C | 4 
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 2ed94fd786ce..4e97093b1341 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -19834,14 +19834,14 @@ cp_tree_node_structure (union lang_tree_node * t)
 {
   switch (TREE_CODE (&t->generic))
 {
-case ARGUMENT_PACK_SELECT:  return TS_CP_ARGUMENT_PACK_SELECT;
+case ARGUMENT_PACK_SELECT: return TS_CP_ARGUMENT_PACK_SELECT;
 case BASELINK: return TS_CP_BASELINK;
-case CONSTRAINT_INFO:   return TS_CP_CONSTRAINT_INFO;
+case CONSTRAINT_INFO:  return TS_CP_CONSTRAINT_INFO;
 case DEFERRED_NOEXCEPT:return TS_CP_DEFERRED_NOEXCEPT;
 case DEFERRED_PARSE:   return TS_CP_DEFERRED_PARSE;
 case IDENTIFIER_NODE:  return TS_CP_IDENTIFIER;
 case LAMBDA_EXPR:  return TS_CP_LAMBDA_EXPR;
-case BINDING_VECTOR:   return TS_CP_BINDING_VECTOR;
+case BINDING_VECTOR:   return TS_CP_BINDING_VECTOR;
 case OVERLOAD: return TS_CP_OVERLOAD;
 case PTRMEM_CST:   return TS_CP_PTRMEM;
 case STATIC_ASSERT:return TS_CP_STATIC_ASSERT;
@@ -19849,6 +19849,7 @@ cp_tree_node_structure (union lang_tree_node * t)
 case TEMPLATE_INFO:return TS_CP_TEMPLATE_INFO;
 case TEMPLATE_PARM_INDEX:  return TS_CP_TPI;
 case TRAIT_EXPR:   return TS_CP_TRAIT_EXPR;
+case TU_LOCAL_ENTITY:  return TS_CP_TU_LOCAL_ENTITY;
 case USERDEF_LITERAL:  return TS_CP_USERDEF_LITERAL;
 default:   return TS_CP_GENERIC;
 }
diff --git a/gcc/testsuite/g++.dg/modules/gc-3_a.C 
b/gcc/testsuite/g++.dg/modules/gc-3_a.C
new file mode 100644
index ..b4adb2aa5a3f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/gc-3_a.C
@@ -0,0 +1,7 @@
+// PR c++/119564
+// { dg-additional-options "-fmodules -Wtemplate-names-tu-local" }
+// { dg-module-cmi M }
+
+export module M;
+static void foo() {};  // { dg-message "declared" }
+template  void bar() { foo(); }  // { dg-warning "TU-local" }
diff --git a/gcc/testsuite/g++.dg/modules/gc-3_b.C 
b/gcc/testsuite/g++.dg/modules/gc-3_b.C
new file mode 100644
index ..1d1dc872eafd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/gc-3_b.C
@@ -0,0 +1,4 @@
+// PR c++/119564
+// { dg-additional-options "-fmodules -fno-module-lazy 
--param=ggc-min-expand=0 --param=ggc-min-heapsize=0" }
+
+import M;


[gcc r15-8116] gccrs: Change crate_num_to_nodeid return type

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

commit r15-8116-g8c5be0dd1c460694a2c8ef78bdadc2c6aea01ad8
Author: Pierre-Emmanuel Patry 
Date:   Thu Apr 25 16:15:42 2024 +0200

gccrs: Change crate_num_to_nodeid return type

Change the function's return type to an optional.

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-toplevel.h: Adapt the code to the new
return type.
* rust-session-manager.cc (Session::load_extern_crate): Likewise.
* util/rust-hir-map.cc (Mappings::crate_num_to_nodeid): Change the
return type.
* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/rust/resolve/rust-ast-resolve-toplevel.h | 11 ---
 gcc/rust/rust-session-manager.cc |  8 +++-
 gcc/rust/util/rust-hir-map.cc|  9 -
 gcc/rust/util/rust-hir-map.h |  2 +-
 4 files changed, 12 insertions(+), 18 deletions(-)

diff --git a/gcc/rust/resolve/rust-ast-resolve-toplevel.h 
b/gcc/rust/resolve/rust-ast-resolve-toplevel.h
index 99fc4f6bfcc8..565ca922e84d 100644
--- a/gcc/rust/resolve/rust-ast-resolve-toplevel.h
+++ b/gcc/rust/resolve/rust-ast-resolve-toplevel.h
@@ -429,8 +429,7 @@ public:
 if (extern_crate.references_self ())
   {
CrateNum crate_num = mappings.get_current_crate ();
-   bool ok = mappings.crate_num_to_nodeid (crate_num, resolved_crate);
-   rust_assert (ok);
+   resolved_crate = mappings.crate_num_to_nodeid (crate_num).value ();
   }
 else
   {
@@ -442,11 +441,9 @@ public:
   extern_crate.get_referenced_crate ().c_str ());
return;
  }
-   auto found_crate_num = cnum.value ();
-
-   bool ok
- = mappings.crate_num_to_nodeid (found_crate_num, resolved_crate);
-   if (!ok)
+   if (auto resolved = mappings.crate_num_to_nodeid (*cnum))
+ resolved_crate = resolved.value ();
+   else
  {
rust_internal_error_at (extern_crate.get_locus (),
"failed to resolve crate to nodeid");
diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc
index da66479d608c..61a76d69a6b8 100644
--- a/gcc/rust/rust-session-manager.cc
+++ b/gcc/rust/rust-session-manager.cc
@@ -1050,12 +1050,10 @@ Session::load_extern_crate (const std::string 
&crate_name, location_t locus)
   // has it already been loaded?
   if (auto crate_num = mappings.lookup_crate_name (crate_name))
 {
-  NodeId resolved_node_id = UNKNOWN_NODEID;
-  bool resolved
-   = mappings.crate_num_to_nodeid (*crate_num, resolved_node_id);
-  rust_assert (resolved);
+  auto resolved_node_id = mappings.crate_num_to_nodeid (*crate_num);
+  rust_assert (resolved_node_id);
 
-  return resolved_node_id;
+  return *resolved_node_id;
 }
 
   std::string relative_import_path = "";
diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index 95d3b3a4d611..76642a1b1320 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -175,15 +175,14 @@ Mappings::lookup_crate_name (const std::string 
&crate_name) const
   return tl::nullopt;
 }
 
-bool
-Mappings::crate_num_to_nodeid (const CrateNum &crate_num, NodeId &node_id) 
const
+tl::optional
+Mappings::crate_num_to_nodeid (const CrateNum &crate_num) const
 {
   auto it = ast_crate_mappings.find (crate_num);
   if (it == ast_crate_mappings.end ())
-return false;
+return tl::nullopt;
 
-  node_id = it->second->get_node_id ();
-  return true;
+  return it->second->get_node_id ();
 }
 
 bool
diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h
index a68d81f34efe..8181abe00a98 100644
--- a/gcc/rust/util/rust-hir-map.h
+++ b/gcc/rust/util/rust-hir-map.h
@@ -85,7 +85,7 @@ public:
   std::string get_current_crate_name () const;
   tl::optional
   lookup_crate_name (const std::string &crate_name) const;
-  bool crate_num_to_nodeid (const CrateNum &crate_num, NodeId &node_id) const;
+  tl::optional crate_num_to_nodeid (const CrateNum &crate_num) const;
   bool node_is_crate (NodeId node_id) const;
 
   NodeId get_next_node_id ();


[gcc r14-11488] libstdc++: Add testcases for resolved bug [PR101527]

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

commit r14-11488-gda6cea6625be011eeda958b096cf35573d2ab7bb
Author: Jonathan Wakely 
Date:   Mon Mar 24 21:36:16 2025 +

libstdc++: Add testcases for resolved bug [PR101527]

These tests were fixed by a front-end change r13-465-g4df735e01e3199 so
this just adds them to the testsuite to be sure we don't regress.

libstdc++-v3/ChangeLog:

PR libstdc++/101527
* testsuite/24_iterators/common_iterator/101527.cc: New test.
* testsuite/24_iterators/counted_iterator/101527.cc: New test.

(cherry picked from commit f7c0b0fc4fdeaf034dc38356830625f7280d325d)

Diff:
---
 .../testsuite/24_iterators/common_iterator/101527.cc   | 14 ++
 .../testsuite/24_iterators/counted_iterator/101527.cc  | 14 ++
 2 files changed, 28 insertions(+)

diff --git a/libstdc++-v3/testsuite/24_iterators/common_iterator/101527.cc 
b/libstdc++-v3/testsuite/24_iterators/common_iterator/101527.cc
new file mode 100644
index ..0a2a5e8dfcca
--- /dev/null
+++ b/libstdc++-v3/testsuite/24_iterators/common_iterator/101527.cc
@@ -0,0 +1,14 @@
+// { dg-do compile { target c++20 } }
+
+// PR libstdc++/101527
+// implementation of std::common_iterator and std::counted_iterator's
+// operator== seems to be wrong
+
+#include 
+
+bool test_pr101527()
+{
+  std::common_iterator it1;
+  std::common_iterator it2;
+  return it1 == it2;
+}
diff --git a/libstdc++-v3/testsuite/24_iterators/counted_iterator/101527.cc 
b/libstdc++-v3/testsuite/24_iterators/counted_iterator/101527.cc
new file mode 100644
index ..51c6e99cd77c
--- /dev/null
+++ b/libstdc++-v3/testsuite/24_iterators/counted_iterator/101527.cc
@@ -0,0 +1,14 @@
+// { dg-do compile { target c++20 } }
+
+// PR libstdc++/101527
+// implementation of std::common_iterator and std::counted_iterator's
+// operator== seems to be wrong
+
+#include 
+
+bool test_pr101527()
+{
+  std::counted_iterator it1;
+  std::counted_iterator it2;
+  return it1 == it2;
+}


[gcc(refs/users/omachota/heads/rtl-ssa-dce)] rtl-ssa-dce: improve prelive conditions (USE, TRAP_IF)

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

commit 037d91e03673f29447d783a54bcf9c2b015e8e2b
Author: Ondřej Machota 
Date:   Tue Mar 18 20:40:21 2025 +0100

rtl-ssa-dce: improve prelive conditions (USE, TRAP_IF)

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

diff --git a/gcc/dce.cc b/gcc/dce.cc
index b11ced743d74..42b63cbcfb81 100644
--- a/gcc/dce.cc
+++ b/gcc/dce.cc
@@ -1317,6 +1317,8 @@ bool sets_global_register(const_rtx rtx) {
 
 // We should mark stack registers
 // use HARD_FRAME_POINTER_REGNUM, REGNO_PTR_FRAME_P
+// muzeme mit parallel, ktery ma napr. dva single sety, nebo asm statement
+// pouzit note_pattern_stores nebo note_stores
 bool sets_global_register(rtx_insn* insn) {
   rtx set = single_set(insn);
   if (!set)
@@ -1337,25 +1339,6 @@ bool sets_global_register(rtx_insn* insn) {
   return false;
 }
 
-bool is_control_flow(rtx_code code) {
-  // What about BARRIERs?
-  switch (code) {
-case JUMP_INSN:
-case JUMP_TABLE_DATA: // Be careful with Table jump addresses - ADDR_VEC, 
ADDR_DIFF_VEC, PREFETCH 
-case TRAP_IF:
-case IF_THEN_ELSE: // Also COMPARE?
-case COND_EXEC: // We might want to check the operation that is under this?
-case RETURN:
-case SIMPLE_RETURN:
-case EH_RETURN:
-case LABEL_REF:
-  return true;
-
-default:
-  return false;
-  }
-}
-
 bool side_effects_with_mem (const_rtx x)
 {
   const RTX_CODE code = GET_CODE (x);
@@ -1396,8 +1379,8 @@ bool side_effects_with_mem (const_rtx x)
return true;
 
 // This should rather by RTX_BODY in is_rtx_insn_prelive - like global 
clobber
-case USE:
-  return true;
+// case USE:
+  // return true;
 
 default:
   break;
@@ -1478,6 +1461,9 @@ bool is_rtx_insn_prelive(rtx_insn *insn) {
   if (GET_CODE(body) == PREFETCH)
 return true;
 
+  if (GET_CODE(body) == USE || GET_CODE(body) == TRAP_IF || GET_CODE(body) == 
UNSPEC)
+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
@@ -1485,7 +1471,8 @@ bool is_rtx_insn_prelive(rtx_insn *insn) {
   // TODO : debug the testcase
   // It seems that the issue was due to trap_if rtl insn and fixed with 
may_trap_or_fault_p
   // What about can_throw_internal?
-  if (side_effects_with_mem(body) || can_throw_internal(body) || 
may_trap_or_fault_p(body))
+  // || can_throw_internal(body) - testy na ntb prochazi
+  if (side_effects_with_mem(body)) // || may_trap_or_fault_p(body))
 return true;
 
   return false;


[gcc r15-9220] c++: __FUNCTION__ in lambda return type [PR118629]

2025-04-04 Thread Jason Merrill via Gcc-cvs
https://gcc.gnu.org/g:7d561820525fd3b9d8f3876333c0584d75e7c053

commit r15-9220-g7d561820525fd3b9d8f3876333c0584d75e7c053
Author: Jason Merrill 
Date:   Fri Apr 4 17:34:08 2025 -0400

c++: __FUNCTION__ in lambda return type [PR118629]

In this testcase, the use of __FUNCTION__ is within a function parameter
scope, the lambda's.  And P1787 changed __func__ to live in the parameter
scope.  But [basic.scope.pdecl] says that the point of declaration of
__func__ is immediately before {, so in the trailing return type it isn't in
scope yet, so this __FUNCTION__ should refer to foo().

Looking first for a block scope, then a function parameter scope, gives us
the right result.

PR c++/118629

gcc/cp/ChangeLog:

* name-lookup.cc (pushdecl_outermost_localscope): Look for an
sk_block.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/lambda/lambda-__func__3.C: New test.

Diff:
---
 gcc/cp/name-lookup.cc| 8 +---
 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-__func__3.C | 6 ++
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc
index 7fadbccfe393..1cd982e12d49 100644
--- a/gcc/cp/name-lookup.cc
+++ b/gcc/cp/name-lookup.cc
@@ -5204,9 +5204,11 @@ pushdecl_outermost_localscope (tree x)
   cp_binding_level *b = NULL;
   auto_cond_timevar tv (TV_NAME_LOOKUP);
 
-  /* Find the scope just inside the function parms.  */
-  for (cp_binding_level *n = current_binding_level;
-   n->kind != sk_function_parms; n = b->level_chain)
+  /* Find the block scope just inside the function parms.  */
+  cp_binding_level *n = current_binding_level;
+  while (n && n->kind != sk_block)
+n = n->level_chain;
+  for (; n && n->kind != sk_function_parms; n = b->level_chain)
 b = n;
 
   return b ? do_pushdecl_with_scope (x, b) : error_mark_node;
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-__func__3.C 
b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-__func__3.C
new file mode 100644
index ..50ad6e55c1b1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-__func__3.C
@@ -0,0 +1,6 @@
+// PR c++/118629
+// { dg-do compile { target c++11 } }
+
+void foo() {
+  []() -> decltype(+__FUNCTION__) { return nullptr; };
+}


[gcc r15-8653] Fortran: Fix typo in error message.

2025-04-04 Thread Jerry DeLisle via Gcc-cvs
https://gcc.gnu.org/g:f45d14b495d603b8d5fbdffe6fced03cb3e2fc10

commit r15-8653-gf45d14b495d603b8d5fbdffe6fced03cb3e2fc10
Author: Jerry DeLisle 
Date:   Fri Mar 21 10:34:08 2025 -0700

Fortran: Fix typo in error message.

PR fortran/119406

gcc/fortran/ChangeLog:

* resolve.cc (resolve_locality_spec): Add space in error
message.

Diff:
---
 gcc/fortran/resolve.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index b9c469a5beca..e016865a6bb4 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -8215,7 +8215,7 @@ resolve_locality_spec (gfc_code *code, gfc_namespace *ns)
{
  if (iter->var->symtree->n.sym == sym)
{
- gfc_error ("Index variable %qs at %L cannot be specified in a"
+ gfc_error ("Index variable %qs at %L cannot be specified in a 
"
 "locality-spec", sym->name, &expr->where);
  continue;
}


[gcc r15-9196] libstdc++: Check feature test macro for std::string_view in

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

commit r15-9196-gaffdef57a45a443ead24f6afb7027a2683028031
Author: Jonathan Wakely 
Date:   Thu Apr 3 13:59:14 2025 +0100

libstdc++: Check feature test macro for std::string_view in 

We can use the __glibcxx_string_view macro to guard the uses of
std::string_view in , instead of just checking the value of
__cplusplus. It makes no practical difference because
__glibcxx_string_view is defined for C++17 and up, but it makes it clear
to readers that the lines guarded by that macro are features that depend
on string_view.

We could be more precise and check __glibcxx_string_view >= 201606L
which is the value for the P0254R2 paper that integrated
std::string_view with std::string, but I think just checking for the
macro being defined is clear enough.

We can also check __glibcxx_variant for the _Never_valueless_alt partial
specialization.

libstdc++-v3/ChangeLog:

* include/bits/basic_string.h: Check __glibcxx_string_view and
__glibcxx_variant instead of __cplusplus >= 2017L.
* include/bits/cow_string.h: Likewise.

Reviewed-by: Tomasz Kamiński 

Diff:
---
 libstdc++-v3/include/bits/basic_string.h | 39 
 libstdc++-v3/include/bits/cow_string.h   | 30 
 2 files changed, 35 insertions(+), 34 deletions(-)

diff --git a/libstdc++-v3/include/bits/basic_string.h 
b/libstdc++-v3/include/bits/basic_string.h
index 86841cb2c5ed..886e7e6b19ec 100644
--- a/libstdc++-v3/include/bits/basic_string.h
+++ b/libstdc++-v3/include/bits/basic_string.h
@@ -45,7 +45,9 @@
 #include 
 #endif
 
-#if __cplusplus >= 201703L
+#include 
+
+#ifdef __glibcxx_string_view // >= C++17
 # include 
 #endif
 
@@ -53,7 +55,6 @@
 # include 
 #endif
 
-#include 
 
 #if ! _GLIBCXX_USE_CXX11_ABI
 # include "cow_string.h"
@@ -146,7 +147,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
return __p;
   }
 
-#if __cplusplus >= 201703L
+#ifdef __glibcxx_string_view // >= C++17
   // A helper type for avoiding boiler-plate.
   typedef basic_string_view<_CharT, _Traits> __sv_type;
 
@@ -788,7 +789,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
 #endif
}
 
-#if __cplusplus >= 201703L
+#ifdef __glibcxx_string_view // >= C++17
   /**
*  @brief  Construct string from a substring of a string_view.
*  @param  __t   Source object convertible to string view.
@@ -944,7 +945,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
   }
 #endif // C++11
 
-#if __cplusplus >= 201703L
+#ifdef __glibcxx_string_view // >= C++17
   /**
*  @brief  Set value to string constructed from a string_view.
*  @param  __svt  An object convertible to string_view.
@@ -1439,7 +1440,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
   { return this->append(__l.begin(), __l.size()); }
 #endif // C++11
 
-#if __cplusplus >= 201703L
+#ifdef __glibcxx_string_view // >= C++17
   /**
*  @brief  Append a string_view.
*  @param __svt  An object convertible to string_view to be appended.
@@ -1556,7 +1557,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
 append(_InputIterator __first, _InputIterator __last)
 { return this->replace(end(), end(), __first, __last); }
 
-#if __cplusplus >= 201703L
+#ifdef __glibcxx_string_view
   /**
*  @brief  Append a string_view.
*  @param __svt  An object convertible to string_view to be appended.
@@ -1809,7 +1810,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
   }
 #endif // C++11
 
-#if __cplusplus >= 201703L
+#ifdef __glibcxx_string_view // >= C++17
   /**
*  @brief  Set value from a string_view.
*  @param __svt  The source object convertible to string_view.
@@ -2090,7 +2091,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
return iterator(_M_data() + __pos);
   }
 
-#if __cplusplus >= 201703L
+#ifdef __glibcxx_string_view // >= C++17
   /**
*  @brief  Insert a string_view.
*  @param __pos  Position in string to insert at.
@@ -2542,7 +2543,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
   { return this->replace(__i1, __i2, __l.begin(), __l.size()); }
 #endif // C++11
 
-#if __cplusplus >= 201703L
+#ifdef __glibcxx_string_view // >= C++17
   /**
*  @brief  Replace range of characters with string_view.
*  @param __pos  The position to replace at.
@@ -2741,7 +2742,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
   _GLIBCXX_NOEXCEPT
   { return this->find(__str.data(), __pos, __str.size()); }
 
-#if __cplusplus >= 201703L
+#ifdef __glibcxx_string_view // >= C++17
   /**
*  @brief  Find position of a string_view.
*  @param __svt  The object convertible to string_view to locate.
@@ -2807,7 +2808,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
   _GLIBCXX_NOEXCEPT
   { return this->rfind(__str.data(), __pos, __str.size()); }
 
-#if __cplusplus >= 201703L
+#ifdef __glibcxx_string_view // >= C++17
   /**
*  @brief

[gcc r15-9199] libstdc++: Replace use of __mindist in ranges::uninitialized_xxx algos [PR101587]

2025-04-04 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:03ac8886e5c1fa16da90276fd721a57fa9435f4f

commit r15-9199-g03ac8886e5c1fa16da90276fd721a57fa9435f4f
Author: Jonathan Wakely 
Date:   Wed Mar 26 11:47:05 2025 +

libstdc++: Replace use of __mindist in ranges::uninitialized_xxx algos 
[PR101587]

In r15-8980-gf4b6acfc36fb1f I introduced a new function object for
finding the smaller of two distances. In bugzilla Hewill Kang pointed
out that we still need to explicitly convert the result back to the
right difference type, because the result might be an integer-like class
type that doesn't convert to an integral type explicitly.

Rather than doing that conversion in the __mindist function object, I
think it's simpler to remove it again and just do a comparison and
assignment. We always want the result to have a specific type, so we can
just check if the value of the other type is smaller, and then convert
that to the other type if so.

libstdc++-v3/ChangeLog:

PR libstdc++/101587
* include/bits/ranges_uninitialized.h (__detail::__mindist):
Remove.
(ranges::uninitialized_copy, ranges::uninitialized_copy_n)
(ranges::uninitialized_move, ranges::uninitialized_move_n): Use
comparison and assignment instead of __mindist.
* 
testsuite/20_util/specialized_algorithms/uninitialized_copy/constrained.cc:
Check with ranges that use integer-like class type for
difference type.
* 
testsuite/20_util/specialized_algorithms/uninitialized_move/constrained.cc:
Likewise.

Reviewed-by: Tomasz Kaminski 
Reviewed-by: Hewill Kang 

Diff:
---
 libstdc++-v3/include/bits/ranges_uninitialized.h   | 46 +++---
 .../uninitialized_copy/constrained.cc  | 30 +-
 .../uninitialized_move/constrained.cc  | 29 +-
 3 files changed, 71 insertions(+), 34 deletions(-)

diff --git a/libstdc++-v3/include/bits/ranges_uninitialized.h 
b/libstdc++-v3/include/bits/ranges_uninitialized.h
index b5580073a6ae..12a714b68aa0 100644
--- a/libstdc++-v3/include/bits/ranges_uninitialized.h
+++ b/libstdc++-v3/include/bits/ranges_uninitialized.h
@@ -263,26 +263,6 @@ namespace ranges
   inline constexpr __uninitialized_value_construct_n_fn
 uninitialized_value_construct_n;
 
-  namespace __detail
-  {
-// This is only intended for finding smaller iterator differences below,
-// not as a general purpose replacement for std::min.
-struct __mindist_fn
-{
-  template
-   constexpr common_type_t<_Dp1, _Dp2>
-   operator()(_Dp1 __d1, _Dp2 __d2) const noexcept
-   {
- // Every C++20 iterator I satisfies weakly_incrementable which
- // requires signed-integer-like>.
- static_assert(std::__detail::__is_signed_integer_like<_Dp1>);
- static_assert(std::__detail::__is_signed_integer_like<_Dp2>);
- return std::min>(__d1, __d2);
-   }
-};
-inline constexpr __mindist_fn __mindist{};
-  }
-
   template
 using uninitialized_copy_result = in_out_result<_Iter, _Out>;
 
@@ -305,10 +285,10 @@ namespace ranges
  && is_trivially_assignable_v<_OutType&,
 iter_reference_t<_Iter>>)
  {
-   auto __d1 = __ilast - __ifirst;
-   auto __d2 = __olast - __ofirst;
-   return ranges::copy_n(std::move(__ifirst),
- __detail::__mindist(__d1, __d2), __ofirst);
+   auto __d = __ilast - __ifirst;
+   if (auto __d2 = __olast - __ofirst; __d2 < __d)
+ __d = static_cast>(__d2);
+   return ranges::copy_n(std::move(__ifirst), __d, __ofirst);
  }
else
  {
@@ -356,9 +336,9 @@ namespace ranges
  && is_trivially_assignable_v<_OutType&,
 iter_reference_t<_Iter>>)
  {
-   auto __d = __olast - __ofirst;
-   return ranges::copy_n(std::move(__ifirst),
- __detail::__mindist(__n, __d), __ofirst);
+   if (auto __d = __olast - __ofirst; __d < __n)
+ __n = static_cast>(__d);
+   return ranges::copy_n(std::move(__ifirst), __n, __ofirst);
  }
else
  {
@@ -397,11 +377,12 @@ namespace ranges
  && is_trivially_assignable_v<_OutType&,
 
iter_rvalue_reference_t<_Iter>>)
  {
-   auto __d1 = __ilast - __ifirst;
-   auto __d2 = __olast - __ofirst;
+   auto __d = __ilast - __ifirst;
+   if (auto __d2 = __olast - __ofirst; __d2 < __d)
+ __d = static_cast>(__d2);
auto [__in, __out]
  = ranges::copy_n(std::make_move_iterator(std::move(__ifirst)),
-  __detail::__mindist(__d1, __d2), _

[gcc r15-9198] libstdc++: Provide formatter for vector::reference [PR109162]

2025-04-04 Thread Tomasz Kaminski via Libstdc++-cvs
https://gcc.gnu.org/g:84d668b0ca67c5d3fe6430f101d61e60aa796a81

commit r15-9198-g84d668b0ca67c5d3fe6430f101d61e60aa796a81
Author: Tomasz Kamiński 
Date:   Thu Apr 3 17:22:39 2025 +0200

libstdc++: Provide formatter for vector::reference [PR109162]

This patch implement formatter for vector::reference which
is part of P2286R8.

To indicate partial support we define __glibcxx_format_ranges macro
value 1, without defining __cpp_lib_format_ranges.

To avoid including the whole content of the  header, we
introduce new bits/formatfwd.h forward declares classes required
for newly introduce formatter.

The signatures of the user-facing parse and format method of the provided
formatters deviate from the standard by constraining types of params:
* _Bit_reference instead T satisfying is-vector-bool-reference
* _CharT is constrained __formatter::__char
* basic_format_parse_context<_CharT> for parse argument
* basic_format_context<_Out, _CharT> for format second argument
The standard specifies last three of above as unconstrained types, which 
leads
to formattable::reference, char32_t> (and any other type as 
char)
being true.

PR libstdc++/109162

libstdc++-v3/ChangeLog:

* include/Makefile.am: Add bits/formatfwd.h.
* include/Makefile.in: Add bits/formatfwd.h.
* include/bits/version.def: Define __glibcxx_format_ranges without
corresponding std name.
* include/bits/version.h: Regenerate.
* include/std/format (basic_format_context, __format::__char):
Move declartions to bits/formatfwd.h.
(formatter<_Tp, _CharT>): Remove default argument for _CharT
parameter, now specified in forward declaration in bits/formatfwd.h.
* include/std/vector (formatter<_Bit_reference, _CharT>): Define.
* include/bits/formatfwd.h: New file with forward declarations
for bits of std/format.
* testsuite/23_containers/vector/bool/format.cc: New test.

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

Diff:
---
 libstdc++-v3/include/Makefile.am   |  1 +
 libstdc++-v3/include/Makefile.in   |  1 +
 libstdc++-v3/include/bits/formatfwd.h  | 71 ++
 libstdc++-v3/include/bits/version.def  | 18 +++---
 libstdc++-v3/include/bits/version.h|  9 +++
 libstdc++-v3/include/std/format| 14 +
 libstdc++-v3/include/std/vector| 32 ++
 .../testsuite/23_containers/vector/bool/format.cc  | 67 
 8 files changed, 192 insertions(+), 21 deletions(-)

diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index 4dc771a540c4..537774c26689 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -195,6 +195,7 @@ bits_headers = \
${bits_srcdir}/cow_string.h \
${bits_srcdir}/deque.tcc \
${bits_srcdir}/erase_if.h \
+   ${bits_srcdir}/formatfwd.h \
${bits_srcdir}/forward_list.h \
${bits_srcdir}/forward_list.tcc \
${bits_srcdir}/fs_dir.h \
diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in
index 0e3d09b3a750..7b96b2207f84 100644
--- a/libstdc++-v3/include/Makefile.in
+++ b/libstdc++-v3/include/Makefile.in
@@ -548,6 +548,7 @@ bits_freestanding = \
 @GLIBCXX_HOSTED_TRUE@  ${bits_srcdir}/cow_string.h \
 @GLIBCXX_HOSTED_TRUE@  ${bits_srcdir}/deque.tcc \
 @GLIBCXX_HOSTED_TRUE@  ${bits_srcdir}/erase_if.h \
+@GLIBCXX_HOSTED_TRUE@  ${bits_srcdir}/formatfwd.h \
 @GLIBCXX_HOSTED_TRUE@  ${bits_srcdir}/forward_list.h \
 @GLIBCXX_HOSTED_TRUE@  ${bits_srcdir}/forward_list.tcc \
 @GLIBCXX_HOSTED_TRUE@  ${bits_srcdir}/fs_dir.h \
diff --git a/libstdc++-v3/include/bits/formatfwd.h 
b/libstdc++-v3/include/bits/formatfwd.h
new file mode 100644
index ..44922cb83fc7
--- /dev/null
+++ b/libstdc++-v3/include/bits/formatfwd.h
@@ -0,0 +1,71 @@
+//  Formatting -*- C++ -*-
+
+// Copyright The GNU Toolchain Authors.
+//
+// This file is part of the GNU ISO C++ Library.  This library 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.
+
+// This library 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.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License

[gcc r15-9193] tailc: Use the IPA-VRP tail call hack even for pointers [PR119614]

2025-04-04 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:08e803aa9becf407eb7ef7cf6af96e3bd0d02d38

commit r15-9193-g08e803aa9becf407eb7ef7cf6af96e3bd0d02d38
Author: Jakub Jelinek 
Date:   Fri Apr 4 08:59:51 2025 +0200

tailc: Use the IPA-VRP tail call hack even for pointers [PR119614]

As the first two testcases show, even with pointers IPA-VRP can optimize
return values from functions if they have singleton ranges into just the
exact value, so we need to virtually undo that for tail calls similarly
to integers and floats.  The third test just adds check that it works
even with floats (which it does).

2025-04-04  Jakub Jelinek  

PR tree-optimization/119614
* tree-tailcall.cc (find_tail_calls): Handle also pointer types in 
the
IPA-VRP workaround.

* c-c++-common/pr119614-1.c: New test.
* c-c++-common/pr119614-2.c: New test.
* c-c++-common/pr119614-3.c: New test.

Diff:
---
 gcc/testsuite/c-c++-common/pr119614-1.c | 28 
 gcc/testsuite/c-c++-common/pr119614-2.c | 28 
 gcc/testsuite/c-c++-common/pr119614-3.c | 28 
 gcc/tree-tailcall.cc|  4 +++-
 4 files changed, 87 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/c-c++-common/pr119614-1.c 
b/gcc/testsuite/c-c++-common/pr119614-1.c
new file mode 100644
index ..89105a317cb1
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/pr119614-1.c
@@ -0,0 +1,28 @@
+/* PR tree-optimization/119614 */
+/* { dg-do compile { target musttail } } */
+/* { dg-options "-O2" } */
+
+volatile int v;
+
+[[gnu::noinline]] const char *
+foo (int x)
+{
+  v += x;
+  return 0;
+}
+
+const char *
+bar (int x)
+{
+  if (x == 42)
+[[gnu::musttail]] return foo (42);
+  [[gnu::musttail]] return foo (32);
+}
+
+const char *
+baz (int x)
+{
+  if (x == 5)
+return foo (42);
+  return foo (32);
+}
diff --git a/gcc/testsuite/c-c++-common/pr119614-2.c 
b/gcc/testsuite/c-c++-common/pr119614-2.c
new file mode 100644
index ..8833eeec8705
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/pr119614-2.c
@@ -0,0 +1,28 @@
+/* PR tree-optimization/119614 */
+/* { dg-do compile { target musttail } } */
+/* { dg-options "-O2" } */
+
+volatile int v;
+
+[[gnu::noinline]] const char *
+foo (int x)
+{
+  v += x;
+  return (const char *) -42;
+}
+
+const char *
+bar (int x)
+{
+  if (x == 42)
+[[gnu::musttail]] return foo (42);
+  [[gnu::musttail]] return foo (32);
+}
+
+const char *
+baz (int x)
+{
+  if (x == 5)
+return foo (42);
+  return foo (32);
+}
diff --git a/gcc/testsuite/c-c++-common/pr119614-3.c 
b/gcc/testsuite/c-c++-common/pr119614-3.c
new file mode 100644
index ..59ed36b0ab53
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/pr119614-3.c
@@ -0,0 +1,28 @@
+/* PR tree-optimization/119614 */
+/* { dg-do compile { target musttail } } */
+/* { dg-options "-O2" } */
+
+volatile int v;
+
+[[gnu::noinline]] double
+foo (int x)
+{
+  v += x;
+  return 0.5;
+}
+
+double
+bar (int x)
+{
+  if (x == 42)
+[[gnu::musttail]] return foo (42);
+  [[gnu::musttail]] return foo (32);
+}
+
+double
+baz (int x)
+{
+  if (x == 5)
+return foo (42);
+  return foo (32);
+}
diff --git a/gcc/tree-tailcall.cc b/gcc/tree-tailcall.cc
index 477729ca2137..c5fac5152254 100644
--- a/gcc/tree-tailcall.cc
+++ b/gcc/tree-tailcall.cc
@@ -1036,7 +1036,9 @@ find_tail_calls (basic_block bb, struct tailcall **ret, 
bool only_musttail,
  && TREE_CONSTANT (ret_var))
if (tree type = gimple_range_type (call))
  if (tree callee = gimple_call_fndecl (call))
-   if ((INTEGRAL_TYPE_P (type) || SCALAR_FLOAT_TYPE_P (type))
+   if ((INTEGRAL_TYPE_P (type)
+|| SCALAR_FLOAT_TYPE_P (type)
+|| POINTER_TYPE_P (type))
&& useless_type_conversion_p (TREE_TYPE (TREE_TYPE (callee)),
  type)
&& useless_type_conversion_p (TREE_TYPE (ret_var), type)


[gcc r15-9194] libstdc++: allow defining version FTMs without standard-named macros

2025-04-04 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:6b7e447503d147e22fa7f38395574beae91b3d8c

commit r15-9194-g6b7e447503d147e22fa7f38395574beae91b3d8c
Author: Arsen Arsenović 
Date:   Wed Mar 26 12:26:39 2025 +0100

libstdc++: allow defining version FTMs without standard-named macros

This is useful to provide libstdc++-internal-only macros.

libstdc++-v3/ChangeLog:

* include/bits/version.tpl: Implement no_stdname.
* include/bits/version.def: Document no_stdname.

Diff:
---
 libstdc++-v3/include/bits/version.def | 4 +++-
 libstdc++-v3/include/bits/version.tpl | 6 --
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/libstdc++-v3/include/bits/version.def 
b/libstdc++-v3/include/bits/version.def
index 1468c0491b71..8569d9fa0add 100644
--- a/libstdc++-v3/include/bits/version.def
+++ b/libstdc++-v3/include/bits/version.def
@@ -30,6 +30,7 @@ AutoGen Definitions version.tpl;
 // ftms = {
 //   name = FTM NAME;
 //   [stdname = FTM STANDARD MACRO NAME;]
+//   [no_stdname = true;]
 //   values = {
 // v = VALUE FOR FTM IF MATCHING;
 // [extra_cond = STRING;]
@@ -56,7 +57,8 @@ AutoGen Definitions version.tpl;
 
 // stdname configures the name of the *standard* macro emitted, i.e. it
 // replaces only the __cpp_lib_ macro in the emitted definition.  Defaults to
-// __cpp_lib_${name}
+// __cpp_lib_${name}.  If no_stdname exists (with any value), the stdname
+// define is not emitted.
 
 // N.B This list needs to be in topological sort order, as later entries in
 // this list can and do use the earlier entries.
diff --git a/libstdc++-v3/include/bits/version.tpl 
b/libstdc++-v3/include/bits/version.tpl
index dd5f8518da14..ccda71d6bcfe 100644
--- a/libstdc++-v3/include/bits/version.tpl
+++ b/libstdc++-v3/include/bits/version.tpl
@@ -143,13 +143,15 @@ h
 
 }*/# /*{(unless (first-for?) "el")}*/if /*{(generate-cond)}*/
 #  define __glibcxx_/*{name}*/ /*{v}*/L
-#  if defined(__glibcxx_want_all) || defined(__glibcxx_want_/*{name}*/)
+#  if defined(__glibcxx_want_all) || defined(__glibcxx_want_/*{name}*/)/*{
+ IF (not (exist? "no_stdname")) }*/
 #   define /*{
 ;; Compute the name for this FTM based on stdname/name.
 (if (exist? "stdname")
 (get "stdname")
 (format #f "__cpp_lib_~a" (get "name")))
-}*/ /*{v}*/L
+}*/ /*{v}*/L/*{
+ ENDIF no_std_name }*/
 #  endif
 /*{ ENDFOR values
   }*/# endif


[gcc r12-11018] tree-optimization/117912 - bogus address equivalences for __builtin_object_size

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

commit r12-11018-g5509544dad81adc21c2e6d9782b0ef1390aa4f7c
Author: Richard Biener 
Date:   Thu Dec 5 10:47:13 2024 +0100

tree-optimization/117912 - bogus address equivalences for 
__builtin_object_size

VN again is the culprit for exploiting address equivalences before
__builtin_object_size got the chance to do its job.  This time
it isn't about union members but adjacent structure fields where
an address to one after the last element of an array field can
spill over to the next field.

The following protects all out-of-bound accesses on the upper bound
side (singling out TYPE_MAX_VALUE + 1 is more expensive).  It
ignores other out-of-bound addresses that would invoke UB.

Zero-sized arrays are a bit awkward because the C++ represents them
with a -1U upper bound.

There's a similar issue for zero-sized components whose address can
be the same as the adjacent field in C.

PR tree-optimization/117912
* tree-ssa-sccvn.cc (copy_reference_ops_from_ref): For addresses
of zero-sized components do not set ->off if the object size pass
didn't run.
For OOB ARRAY_REF accesses in address expressions avoid setting
->off if the object size pass didn't run.
(valueize_refs_1): Likewise.

* c-c++-common/torture/pr117912-1.c: New testcase.
* c-c++-common/torture/pr117912-2.c: Likewise.
* c-c++-common/torture/pr117912-3.c: Likewise.

(cherry picked from commit 233972ab3b5338d7a5d1d7af9108c1f366170e44)

Diff:
---
 gcc/testsuite/c-c++-common/torture/pr117912-1.c | 28 
 gcc/testsuite/c-c++-common/torture/pr117912-2.c | 28 
 gcc/testsuite/c-c++-common/torture/pr117912-3.c | 61 +
 gcc/tree-ssa-sccvn.cc   | 51 +++--
 4 files changed, 164 insertions(+), 4 deletions(-)

diff --git a/gcc/testsuite/c-c++-common/torture/pr117912-1.c 
b/gcc/testsuite/c-c++-common/torture/pr117912-1.c
new file mode 100644
index ..2750585c7f77
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/torture/pr117912-1.c
@@ -0,0 +1,28 @@
+/* { dg-do run } */
+
+struct S { int a; int b[24]; int c[24]; int d; };
+volatile int *p;
+
+void __attribute__((noipa))
+bar (int *q)
+{
+ p = q;
+}
+
+__SIZE_TYPE__ __attribute__((noipa))
+foo (struct S *p)
+{
+  bar (&p->b[24]);
+  bar (&p->c[0]);
+  return __builtin_object_size (&p->c[0], 1);
+}
+
+int
+main()
+{
+  struct S s;
+  __SIZE_TYPE__ x = foo (&s);
+  if (x < sizeof (int) * 24)
+__builtin_abort ();
+  return 0;
+}
diff --git a/gcc/testsuite/c-c++-common/torture/pr117912-2.c 
b/gcc/testsuite/c-c++-common/torture/pr117912-2.c
new file mode 100644
index ..a3a621575635
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/torture/pr117912-2.c
@@ -0,0 +1,28 @@
+/* { dg-do run } */
+
+struct S { int a; int b[0]; int c[24]; int d; };
+volatile int *p;
+
+void __attribute__((noipa))
+bar (int *q)
+{
+ p = q;
+}
+
+__SIZE_TYPE__ __attribute__((noipa))
+foo (struct S *p)
+{
+  bar (&p->b[0]);
+  bar (&p->c[0]);
+  return __builtin_object_size (&p->c[0], 1);
+}
+
+int
+main()
+{
+  struct S s;
+  __SIZE_TYPE__ x = foo (&s);
+  if (x < sizeof (int) * 24)
+__builtin_abort ();
+  return 0;
+}
diff --git a/gcc/testsuite/c-c++-common/torture/pr117912-3.c 
b/gcc/testsuite/c-c++-common/torture/pr117912-3.c
new file mode 100644
index ..64e981d2a5e7
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/torture/pr117912-3.c
@@ -0,0 +1,61 @@
+/* { dg-do run } */
+/* { dg-additional-options "-std=gnu++20" { target c++ } } */
+
+struct B {};
+struct A { int a;
+#ifdef __cplusplus
+  [[no_unique_address]]
+#endif
+  struct B b;
+  char c[]; };
+volatile void *p;
+
+void __attribute__((noipa))
+bar (void *q)
+{
+  p = q;
+}
+
+__SIZE_TYPE__ __attribute__((noipa))
+foo (struct A *p)
+{
+  bar (&p->b);
+  bar (&p->c);
+  return __builtin_object_size (&p->c, 1);
+}
+
+__SIZE_TYPE__ __attribute__((noipa))
+baz (void)
+{
+  struct A *p = (struct A *) __builtin_malloc (__builtin_offsetof (struct A, 
c) + 64);
+  bar (&p->b);
+  bar (&p->c);
+  return __builtin_object_size (&p->c, 1);
+}
+
+__SIZE_TYPE__ __attribute__((noipa))
+qux (struct A *p)
+{
+  bar (&p->b);
+  bar (&p->c);
+  return __builtin_object_size (&p->c, 3);
+}
+
+__SIZE_TYPE__ __attribute__((noipa))
+boo (void)
+{
+  struct A *p = (struct A *) __builtin_malloc (__builtin_offsetof (struct A, 
c) + 64);
+  bar (&p->b);
+  bar (&p->c);
+  return __builtin_object_size (&p->c, 3);
+}
+
+int
+main ()
+{
+  static struct A a = { .a = 1, .b = {}, .c = { 1, 2, 3, 4, 0 } };
+  if (foo (&a) < 5)
+__builtin_abort ();
+  if (baz () < 64)
+__builtin_abort ();
+}
diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc
index cda03e0aa685..60a4826e5801 100644
--- a/gcc/tree-ssa-sccvn.cc

[gcc r12-11019] tree-optimization/117574 - bougs niter lt-to-ne

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

commit r12-11019-g8eeaaec278275db2be81792c833713f64c9d20eb
Author: Richard Biener 
Date:   Fri Nov 15 11:56:14 2024 +0100

tree-optimization/117574 - bougs niter lt-to-ne

When trying to change a IV from IV0 < IV1 to IV0' != IV1' we apply
fancy adjustments to the may_be_zero condition we compute rather
than using the obvious IV0->base >= IV1->base expression (to be
able to use > instead of >=?).  This doesn't seem to go well.

PR tree-optimization/117574
* tree-ssa-loop-niter.cc (number_of_iterations_lt_to_ne):
Use the obvious may_be_zero condition.

* gcc.dg/torture/pr117574-1.c: New testcase.

(cherry picked from commit ff5a14abeb31cd6bd0ca55e7043d05c8141a8c7f)

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr117574-1.c | 20 
 gcc/tree-ssa-loop-niter.cc| 31 +++
 2 files changed, 27 insertions(+), 24 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/torture/pr117574-1.c 
b/gcc/testsuite/gcc.dg/torture/pr117574-1.c
new file mode 100644
index ..2e99cec13b65
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr117574-1.c
@@ -0,0 +1,20 @@
+/* { dg-do run } */
+
+void abort (void);
+int a, c;
+long b;
+short d;
+static long e(long f, long h, long i) {
+  for (long g = f; g <= h; g += i)
+b += g;
+  return b;
+}
+int main() {
+  c = 1;
+  for (; c >= 0; c--)
+;
+  for (; e(d + 40, d + 76, c + 51) < 4;)
+;
+  if (a != 0)
+abort ();
+}
diff --git a/gcc/tree-ssa-loop-niter.cc b/gcc/tree-ssa-loop-niter.cc
index 0353ffd3022a..77798a0fd48b 100644
--- a/gcc/tree-ssa-loop-niter.cc
+++ b/gcc/tree-ssa-loop-niter.cc
@@ -1214,17 +1214,6 @@ number_of_iterations_lt_to_ne (tree type, affine_iv 
*iv0, affine_iv *iv1,
  if (integer_zerop (assumption))
goto end;
}
-  if (mpz_cmp (mmod, bnds->below) < 0)
-   noloop = boolean_false_node;
-  else if (POINTER_TYPE_P (type))
-   noloop = fold_build2 (GT_EXPR, boolean_type_node,
- iv0->base,
- fold_build_pointer_plus (iv1->base, tmod));
-  else
-   noloop = fold_build2 (GT_EXPR, boolean_type_node,
- iv0->base,
- fold_build2 (PLUS_EXPR, type1,
-  iv1->base, tmod));
 }
   else
 {
@@ -1240,21 +1229,15 @@ number_of_iterations_lt_to_ne (tree type, affine_iv 
*iv0, affine_iv *iv1,
  if (integer_zerop (assumption))
goto end;
}
-  if (mpz_cmp (mmod, bnds->below) < 0)
-   noloop = boolean_false_node;
-  else if (POINTER_TYPE_P (type))
-   noloop = fold_build2 (GT_EXPR, boolean_type_node,
- fold_build_pointer_plus (iv0->base,
-  fold_build1 (NEGATE_EXPR,
-   type1, 
tmod)),
- iv1->base);
-  else
-   noloop = fold_build2 (GT_EXPR, boolean_type_node,
- fold_build2 (MINUS_EXPR, type1,
-  iv0->base, tmod),
- iv1->base);
 }
 
+  /* IV0 < IV1 does not loop if IV0->base >= IV1->base.  */
+  if (mpz_cmp (mmod, bnds->below) < 0)
+noloop = boolean_false_node;
+  else
+noloop = fold_build2 (GE_EXPR, boolean_type_node,
+ iv0->base, iv1->base);
+
   if (!integer_nonzerop (assumption))
 niter->assumptions = fold_build2 (TRUTH_AND_EXPR, boolean_type_node,
  niter->assumptions,


[gcc r12-11020] tree-optimization/117119 - ICE with int128 IV in dataref analysis

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

commit r12-11020-gc5e4e7617e6e6453e6b6995fb2e31bfe1dd28fdf
Author: Richard Biener 
Date:   Mon Jan 13 09:12:23 2025 +0100

tree-optimization/117119 - ICE with int128 IV in dataref analysis

Here's another fix for a missing check that an IV value fits in a
HIW.  It's originally from Stefan.

PR tree-optimization/117119
* tree-data-ref.cc (initialize_matrix_A): Check whether
an INTEGER_CST fits in HWI, otherwise return chrec_dont_know.

* gcc.dg/torture/pr117119.c: New testcase.

Co-Authored-By: Stefan Schulze Frielinghaus 
(cherry picked from commit d3904a3ad9d7b4c8e5e536e5166b89548510fd48)

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr117119.c | 10 ++
 gcc/tree-data-ref.cc|  2 +-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/torture/pr117119.c 
b/gcc/testsuite/gcc.dg/torture/pr117119.c
new file mode 100644
index ..0ec4ac1b1802
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr117119.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target int128 } */
+
+unsigned __int128 g_728;
+int func_1_l_5011[8];
+void func_1() {
+  for (;; g_728 += 1)
+func_1_l_5011[g_728] ^= func_1_l_5011[g_728 + 5];
+}
+void main() {}
diff --git a/gcc/tree-data-ref.cc b/gcc/tree-data-ref.cc
index ea55f81a92fc..996f8217e286 100644
--- a/gcc/tree-data-ref.cc
+++ b/gcc/tree-data-ref.cc
@@ -4032,7 +4032,7 @@ initialize_matrix_A (lambda_matrix A, tree chrec, 
unsigned index, int mult)
   }
 
 case INTEGER_CST:
-  return chrec;
+  return cst_and_fits_in_hwi (chrec) ? chrec : chrec_dont_know;
 
 default:
   gcc_unreachable ();


[gcc r12-11024] tree-optimization/114246 - invalid call argument from DSE

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

commit r12-11024-gbfb1b0f8bb9fe76071fb02840002a17ed00a8999
Author: Richard Biener 
Date:   Wed Mar 6 09:02:31 2024 +0100

tree-optimization/114246 - invalid call argument from DSE

The following makes sure to strip type conversions added by
build_fold_addr_expr before placing the result in a call argument.

PR tree-optimization/114246
* tree-ssa-dse.cc (increment_start_addr): Strip useless
type conversions from the adjusted address.

* gcc.dg/torture/pr114246.c: New testcase.

(cherry picked from commit 0249744a9fe0775c2c895727aeebec4c59fd5f95)

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr114246.c | 11 +++
 gcc/tree-ssa-dse.cc |  2 ++
 2 files changed, 13 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/torture/pr114246.c 
b/gcc/testsuite/gcc.dg/torture/pr114246.c
new file mode 100644
index ..eb20db594cd0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr114246.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-w" } */
+
+int a, b;
+
+void
+foo (void)
+{
+  __builtin_memcpy (&a, (char *)&b - 1, 2);
+  __builtin_memcpy (&a, &b, 1);
+}
diff --git a/gcc/tree-ssa-dse.cc b/gcc/tree-ssa-dse.cc
index c373dacd806d..749756d8197b 100644
--- a/gcc/tree-ssa-dse.cc
+++ b/gcc/tree-ssa-dse.cc
@@ -45,6 +45,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "ipa-modref.h"
 #include "target.h"
 #include "tree-ssa-loop-niter.h"
+#include "tree-ssa.h"
 
 /* This file implements dead store elimination.
 
@@ -614,6 +615,7 @@ increment_start_addr (gimple *stmt, tree *where, int 
increment)
  *where,
  build_int_cst (ptr_type_node,
 increment)));
+  STRIP_USELESS_TYPE_CONVERSION (*where);
 }
 
 /* STMT is builtin call that writes bytes in bitmap ORIG, some bytes are dead


[gcc r12-11023] middle-end/115641 - invalid address construction

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

commit r12-11023-gb444c3061a14d12d164d82345a1836f5fbd21939
Author: Richard Biener 
Date:   Thu Jul 18 13:35:33 2024 +0200

middle-end/115641 - invalid address construction

fold_truth_andor_1 via make_bit_field_ref builds an address of
a CALL_EXPR which isn't valid GENERIC and later causes an ICE.
The following simply avoids the folding for f ().a != 1 || f ().b != 2
as it is a premature optimization anyway.  The alternative would
have been to build a TARGET_EXPR around the call.  To get this far
f () has to be const as otherwise the two calls are not semantically
equivalent for the optimization.

PR middle-end/115641
* fold-const.cc (decode_field_reference): If the inner
reference isn't something we can take the address of, fail.

* gcc.dg/torture/pr115641.c: New testcase.

(cherry picked from commit 3670c70c561656a19f6bff36dd229f18120af127)

Diff:
---
 gcc/fold-const.cc   |  3 +++
 gcc/testsuite/gcc.dg/torture/pr115641.c | 29 +
 2 files changed, 32 insertions(+)

diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
index 391f11095408..4e88aa4ef521 100644
--- a/gcc/fold-const.cc
+++ b/gcc/fold-const.cc
@@ -4767,6 +4767,9 @@ decode_field_reference (location_t loc, tree *exp_, 
HOST_WIDE_INT *pbitsize,
   || *pbitsize < 0
   || offset != 0
   || TREE_CODE (inner) == PLACEHOLDER_EXPR
+  /* We eventually want to build a larger reference and need to take
+the address of this.  */
+  || (!REFERENCE_CLASS_P (inner) && !DECL_P (inner))
   /* Reject out-of-bound accesses (PR79731).  */
   || (! AGGREGATE_TYPE_P (TREE_TYPE (inner))
  && compare_tree_int (TYPE_SIZE (TREE_TYPE (inner)),
diff --git a/gcc/testsuite/gcc.dg/torture/pr115641.c 
b/gcc/testsuite/gcc.dg/torture/pr115641.c
new file mode 100644
index ..65fb09ca64fc
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr115641.c
@@ -0,0 +1,29 @@
+/* { dg-do run } */
+
+typedef struct {
+  char hours, day, month;
+  short year;
+} T;
+
+T g (void)
+{
+  T now;
+  now.hours = 1;
+  now.day = 2;
+  now.month = 3;
+  now.year = 4;
+  return now;
+}
+
+__attribute__((const)) T f (void)
+{
+  T virk = g ();
+  return virk;
+}
+
+int main ()
+{
+  if (f ().hours != 1 || f ().day != 2 || f ().month != 3 || f ().year != 4)
+__builtin_abort ();
+  return 0;
+}


[gcc r14-11527] Ada: Fix thinko in Eigensystem for complex Hermitian matrices

2025-04-04 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:a210011c5c7f7be5e7a9aea294947bdc555202ce

commit r14-11527-ga210011c5c7f7be5e7a9aea294947bdc555202ce
Author: Eric Botcazou 
Date:   Fri Apr 4 11:45:23 2025 +0200

Ada: Fix thinko in Eigensystem for complex Hermitian matrices

The implementation solves the eigensystem for a NxN complex Hermitian matrix
by first solving it for a 2Nx2N real symmetric matrix and then interpreting
the 2Nx1 real vectors as Nx1 complex ones, but the last step does not work.

The patch fixes the last step and also performs a small cleanup throughout
the implementation, mostly in the commentary and without functional changes.

gcc/ada/
* libgnat/a-ngcoar.adb (Eigensystem): Adjust notation and fix the
layout of the real symmetric matrix in the main comment.  Adjust
the layout of the associated code accordingly and correctly turn
the 2Nx1 real vectors into Nx1 complex ones.
(Eigenvalues): Minor similar tweaks.
* libgnat/a-ngrear.adb (Jacobi): Minor tweaks in the main comment.
Adjust notation and corresponding parameter names of functions.
Fix call to Unit_Matrix routine.  Adjust the comment describing
the various kinds of iterations to match the implementation.

Diff:
---
 gcc/ada/libgnat/a-ngcoar.adb | 42 +++---
 gcc/ada/libgnat/a-ngrear.adb | 85 
 2 files changed, 66 insertions(+), 61 deletions(-)

diff --git a/gcc/ada/libgnat/a-ngcoar.adb b/gcc/ada/libgnat/a-ngcoar.adb
index 4c9c0ad24134..6c5cbaa1c891 100644
--- a/gcc/ada/libgnat/a-ngcoar.adb
+++ b/gcc/ada/libgnat/a-ngcoar.adb
@@ -1058,19 +1058,21 @@ package body Ada.Numerics.Generic_Complex_Arrays is
is
   N : constant Natural := Length (A);
 
-  --  For a Hermitian matrix C, we convert the eigenvalue problem to a
-  --  real symmetric one: if C = A + i * B, then the (N, N) complex
+  --  For a Hermitian matrix A, we convert the eigenvalue problem to a
+  --  real symmetric one: if A = X + i * Y, then the (N, N) complex
   --  eigenvalue problem:
-  -- (A + i * B) * (u + i * v) = Lambda * (u + i * v)
+  --
+  -- (X + i * Y) * (u + i * v) = Lambda * (u + i * v)
   --
   --  is equivalent to the (2 * N, 2 * N) real eigenvalue problem:
-  -- [  A, B ] [ u ] = Lambda * [ u ]
-  -- [ -B, A ] [ v ][ v ]
   --
-  --  Note that the (2 * N, 2 * N) matrix above is symmetric, as
-  --  Transpose (A) = A and Transpose (B) = -B if C is Hermitian.
+  -- [ X, -Y ] [ u ] = Lambda * [ u ]
+  -- [ Y,  X ] [ v ][ v ]
+  --
+  --  Note that the (2 * N, 2 * N) matrix M above is symmetric, because
+  --  Transpose (X) = X and Transpose (Y) = -Y as A is Hermitian.
 
-  --  We solve this eigensystem using the real-valued algorithms. The final
+  --  We solve this eigensystem using the real-valued algorithm. The final
   --  result will have every eigenvalue twice, so in the sorted output we
   --  just pick every second value, with associated eigenvector u + i * v.
 
@@ -1085,10 +1087,8 @@ package body Ada.Numerics.Generic_Complex_Arrays is
C : constant Complex :=
  (A (A'First (1) + (J - 1), A'First (2) + (K - 1)));
 begin
-   M (J, K) := Re (C);
-   M (J + N, K + N) := Re (C);
-   M (J + N, K) := Im (C);
-   M (J, K + N) := -Im (C);
+   M (J, K) := Re (C); M (J, K + N) := -Im (C);
+   M (J + N, K) := Im (C); M (J + N, K + N) := Re (C);
 end;
  end loop;
   end loop;
@@ -1103,10 +1103,9 @@ package body Ada.Numerics.Generic_Complex_Arrays is
 
 for K in 1 .. N loop
declare
-  Row : constant Integer := Vectors'First (2) + (K - 1);
+  Row : constant Integer := Vectors'First (1) + (K - 1);
begin
-  Vectors (Row, Col)
- := (Vecs (J * 2, Col), Vecs (J * 2, Col + N));
+  Vectors (Row, Col) := (Vecs (K, 2 * J), Vecs (K + N, 2 * J));
end;
 end loop;
  end;
@@ -1118,13 +1117,14 @@ package body Ada.Numerics.Generic_Complex_Arrays is
-
 
function Eigenvalues (A : Complex_Matrix) return Real_Vector is
-  --  See Eigensystem for a description of the algorithm
-
   N : constant Natural := Length (A);
-  R : Real_Vector (A'Range (1));
+
+  --  See Eigensystem for a description of the algorithm
 
   M: Real_Matrix (1 .. 2 * N, 1 .. 2 * N);
+  R: Real_Vector (A'Range (1));
   Vals : Real_Vector (1 .. 2 * N);
+
begin
   for J in 1 .. N loop
  for K in 1 .. N loop
@@ -1132,10 +1132,8 @@ package body Ada.Numerics.Generic_Complex_Arrays is
C : constant 

[gcc r12-11016] Ada: Fix thinko in Eigensystem for complex Hermitian matrices

2025-04-04 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:b65f4fe10996c247751b0636773009659d92ab6c

commit r12-11016-gb65f4fe10996c247751b0636773009659d92ab6c
Author: Eric Botcazou 
Date:   Fri Apr 4 11:45:23 2025 +0200

Ada: Fix thinko in Eigensystem for complex Hermitian matrices

The implementation solves the eigensystem for a NxN complex Hermitian matrix
by first solving it for a 2Nx2N real symmetric matrix and then interpreting
the 2Nx1 real vectors as Nx1 complex ones, but the last step does not work.

The patch fixes the last step and also performs a small cleanup throughout
the implementation, mostly in the commentary and without functional changes.

gcc/ada/
* libgnat/a-ngcoar.adb (Eigensystem): Adjust notation and fix the
layout of the real symmetric matrix in the main comment.  Adjust
the layout of the associated code accordingly and correctly turn
the 2Nx1 real vectors into Nx1 complex ones.
(Eigenvalues): Minor similar tweaks.
* libgnat/a-ngrear.adb (Jacobi): Minor tweaks in the main comment.
Adjust notation and corresponding parameter names of functions.
Fix call to Unit_Matrix routine.  Adjust the comment describing
the various kinds of iterations to match the implementation.

Diff:
---
 gcc/ada/libgnat/a-ngcoar.adb | 42 +++---
 gcc/ada/libgnat/a-ngrear.adb | 85 
 2 files changed, 66 insertions(+), 61 deletions(-)

diff --git a/gcc/ada/libgnat/a-ngcoar.adb b/gcc/ada/libgnat/a-ngcoar.adb
index 8dfbc3b174a1..cbbc6d274aa3 100644
--- a/gcc/ada/libgnat/a-ngcoar.adb
+++ b/gcc/ada/libgnat/a-ngcoar.adb
@@ -1058,19 +1058,21 @@ package body Ada.Numerics.Generic_Complex_Arrays is
is
   N : constant Natural := Length (A);
 
-  --  For a Hermitian matrix C, we convert the eigenvalue problem to a
-  --  real symmetric one: if C = A + i * B, then the (N, N) complex
+  --  For a Hermitian matrix A, we convert the eigenvalue problem to a
+  --  real symmetric one: if A = X + i * Y, then the (N, N) complex
   --  eigenvalue problem:
-  -- (A + i * B) * (u + i * v) = Lambda * (u + i * v)
+  --
+  -- (X + i * Y) * (u + i * v) = Lambda * (u + i * v)
   --
   --  is equivalent to the (2 * N, 2 * N) real eigenvalue problem:
-  -- [  A, B ] [ u ] = Lambda * [ u ]
-  -- [ -B, A ] [ v ][ v ]
   --
-  --  Note that the (2 * N, 2 * N) matrix above is symmetric, as
-  --  Transpose (A) = A and Transpose (B) = -B if C is Hermitian.
+  -- [ X, -Y ] [ u ] = Lambda * [ u ]
+  -- [ Y,  X ] [ v ][ v ]
+  --
+  --  Note that the (2 * N, 2 * N) matrix M above is symmetric, because
+  --  Transpose (X) = X and Transpose (Y) = -Y as A is Hermitian.
 
-  --  We solve this eigensystem using the real-valued algorithms. The final
+  --  We solve this eigensystem using the real-valued algorithm. The final
   --  result will have every eigenvalue twice, so in the sorted output we
   --  just pick every second value, with associated eigenvector u + i * v.
 
@@ -1085,10 +1087,8 @@ package body Ada.Numerics.Generic_Complex_Arrays is
C : constant Complex :=
  (A (A'First (1) + (J - 1), A'First (2) + (K - 1)));
 begin
-   M (J, K) := Re (C);
-   M (J + N, K + N) := Re (C);
-   M (J + N, K) := Im (C);
-   M (J, K + N) := -Im (C);
+   M (J, K) := Re (C); M (J, K + N) := -Im (C);
+   M (J + N, K) := Im (C); M (J + N, K + N) := Re (C);
 end;
  end loop;
   end loop;
@@ -1103,10 +1103,9 @@ package body Ada.Numerics.Generic_Complex_Arrays is
 
 for K in 1 .. N loop
declare
-  Row : constant Integer := Vectors'First (2) + (K - 1);
+  Row : constant Integer := Vectors'First (1) + (K - 1);
begin
-  Vectors (Row, Col)
- := (Vecs (J * 2, Col), Vecs (J * 2, Col + N));
+  Vectors (Row, Col) := (Vecs (K, 2 * J), Vecs (K + N, 2 * J));
end;
 end loop;
  end;
@@ -1118,13 +1117,14 @@ package body Ada.Numerics.Generic_Complex_Arrays is
-
 
function Eigenvalues (A : Complex_Matrix) return Real_Vector is
-  --  See Eigensystem for a description of the algorithm
-
   N : constant Natural := Length (A);
-  R : Real_Vector (A'Range (1));
+
+  --  See Eigensystem for a description of the algorithm
 
   M: Real_Matrix (1 .. 2 * N, 1 .. 2 * N);
+  R: Real_Vector (A'Range (1));
   Vals : Real_Vector (1 .. 2 * N);
+
begin
   for J in 1 .. N loop
  for K in 1 .. N loop
@@ -1132,10 +1132,8 @@ package body Ada.Numerics.Generic_Complex_Arrays is
C : constant 

[gcc r15-9202] always turn return into __builtin_unreachable for noreturn fuctions [PR119599]

2025-04-04 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:ae4c22ab05501940e345ee799be3aa36ffa7269a

commit r15-9202-gae4c22ab05501940e345ee799be3aa36ffa7269a
Author: Andrew Pinski 
Date:   Wed Apr 2 18:18:50 2025 -0700

always turn return into __builtin_unreachable for noreturn fuctions 
[PR119599]

r8-3988-g356fcc67fba52b added code to turn return statements into 
__builtin_unreachable
calls inside noreturn functions but only while optimizing. Since 
-funreachable-traps
was added (r13-1204-gd68d3664253696), it is a good idea to move over to 
using
__builtin_unreachable (and the trap version with this option which defaults 
at -O0 and -0g)
instead of just a follow through even at -O0.

This also fixes a regression when inlining a noreturn function that returns 
at -O0 (due to always_inline)
as we would get an empty bb which has no successor edge instead of one with 
a call to __builtin_unreachable.

I also noticed there was no testcase testing the warning about 
__builtin_return inside a noreturn function
so I added a testcase there.

Bootstrapped and tested on x86_64-linux-gnu.

PR ipa/119599

gcc/ChangeLog:

* tree-cfg.cc (pass_warn_function_return::execute): Turn return 
statements always
into __builtin_unreachable calls.

gcc/testsuite/ChangeLog:

* gcc.dg/torture/pr119599-1.c: New test.
* gcc.dg/builtin-apply5.c: New test.

Signed-off-by: Andrew Pinski 

Diff:
---
 gcc/testsuite/gcc.dg/builtin-apply5.c | 23 +++
 gcc/testsuite/gcc.dg/torture/pr119599-1.c | 27 +++
 gcc/tree-cfg.cc   | 20 +++-
 3 files changed, 61 insertions(+), 9 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/builtin-apply5.c 
b/gcc/testsuite/gcc.dg/builtin-apply5.c
new file mode 100644
index ..16892f76a8a7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/builtin-apply5.c
@@ -0,0 +1,23 @@
+/* { dg-options "-O2 -Wmissing-noreturn -fgnu89-inline" } */
+/* { dg-additional-options "-mno-mmx" { target { { i?86-*-* x86_64-*-* } && 
ia32 } } } */
+/* { dg-do compile } */
+
+extern void abort (void);
+
+double
+foo (int arg)
+{
+  if (arg != 116)
+abort();
+  return arg + 1;
+}
+
+__attribute__((noreturn))
+double
+bar (int arg)
+{
+  foo (arg);
+  __builtin_return (__builtin_apply ((void (*) ()) foo, /* { dg-warning 
"'noreturn' function does return" } */
+__builtin_apply_args (), 16));
+}
+
diff --git a/gcc/testsuite/gcc.dg/torture/pr119599-1.c 
b/gcc/testsuite/gcc.dg/torture/pr119599-1.c
new file mode 100644
index ..4fbd228a3590
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr119599-1.c
@@ -0,0 +1,27 @@
+/* { dg-do compile } */
+/* { dg-options "-fdump-tree-einline" } */
+
+/* PR ipa/119599 */
+/* inlining a noreturn function which returns
+   can cause an ICE when dealing finding an unreachable block.
+   We should get a __builtin_unreachable after the inliing.  */
+
+
+void baz (void);
+
+static inline __attribute__((always_inline, noreturn)) void
+bar (void)
+{
+  static volatile int t = 0;
+  if (t == 0)
+baz ();
+} /* { dg-warning "function does return" } */
+
+void
+foo (void)
+{
+  bar ();
+}
+
+/* After inlining, we should have call to __builtin_unreachable now. */
+/* { dg-final { scan-tree-dump "__builtin_unreachable " "einline" } } */
diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc
index 2fa5678051ad..ecf19d280797 100644
--- a/gcc/tree-cfg.cc
+++ b/gcc/tree-cfg.cc
@@ -9799,18 +9799,20 @@ pass_warn_function_return::execute (function *fun)
   (e = ei_safe_edge (ei)); )
{
  last = *gsi_last_bb (e->src);
- if ((gimple_code (last) == GIMPLE_RETURN
-  || gimple_call_builtin_p (last, BUILT_IN_RETURN))
- && location == UNKNOWN_LOCATION
- && ((location = LOCATION_LOCUS (gimple_location (last)))
- != UNKNOWN_LOCATION)
- && !optimize)
-   break;
- /* When optimizing, replace return stmts in noreturn functions
+ /* Warn about __builtin_return .*/
+ if (gimple_call_builtin_p (last, BUILT_IN_RETURN)
+ && location == UNKNOWN_LOCATION)
+   {
+ location = LOCATION_LOCUS (gimple_location (last));
+ ei_next (&ei);
+   }
+ /* Replace return stmts in noreturn functions
 with __builtin_unreachable () call.  */
- if (optimize && gimple_code (last) == GIMPLE_RETURN)
+ else if (gimple_code (last) == GIMPLE_RETURN)
{
  location_t loc = gimple_location (last);
+ if (location == UNKNOWN_LOCATION)
+   location = LOCATION_LOCUS (loc);
  gimple *new_stmt = gimple_build_builtin_unreachable (loc);
  gimple_stmt_iterator gsi = gsi_for_stmt (last);
  gsi_replace (&gsi, new_stmt, true);


[gcc r15-8545] gccrs: fix crash in hir dump with missing guards

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

commit r15-8545-g42be99fc1ec19c84c03770bef776a7b615839f9a
Author: Philip Herron 
Date:   Mon Nov 25 20:16:42 2024 +

gccrs: fix crash in hir dump with missing guards

gcc/rust/ChangeLog:

* hir/rust-hir-dump.cc (Dump::visit): add missing null checks

Signed-off-by: Philip Herron 

Diff:
---
 gcc/rust/hir/rust-hir-dump.cc | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/hir/rust-hir-dump.cc b/gcc/rust/hir/rust-hir-dump.cc
index 1b48b294008c..be785b9ebec2 100644
--- a/gcc/rust/hir/rust-hir-dump.cc
+++ b/gcc/rust/hir/rust-hir-dump.cc
@@ -1892,7 +1892,8 @@ Dump::visit (TraitItemFunc &e)
 
   do_traitfunctiondecl (e.get_decl ());
 
-  visit_field ("block_expr", e.get_block_expr ());
+  if (e.has_definition ())
+visit_field ("block_expr", e.get_block_expr ());
 
   end ("TraitItemFunc");
 }
@@ -2007,7 +2008,8 @@ Dump::visit (ExternalFunctionItem &e)
 
   put_field ("has_variadics", std::to_string (e.is_variadic ()));
 
-  visit_field ("return_type", e.get_return_type ());
+  if (e.has_return_type ())
+visit_field ("return_type", e.get_return_type ());
 
   end ("ExternalFunctionItem");
 }
@@ -2254,8 +2256,10 @@ Dump::visit (LetStmt &e)
 
   put_field ("variable_pattern", e.get_pattern ().as_string ());
 
-  visit_field ("type", e.get_type ());
-  visit_field ("init_expr", e.get_init_expr ());
+  if (e.has_type ())
+visit_field ("type", e.get_type ());
+  if (e.has_init_expr ())
+visit_field ("init_expr", e.get_init_expr ());
 
   end ("LetStmt");
 }


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

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

commit c09904655c3d8053889e8a8832274dd554b93d42
Author: Michael Meissner 
Date:   Thu Apr 3 16:07:01 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-04-03  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=nativ

[gcc r15-9070] d: Fix error with -Warray-bounds and -O2 [PR117002]

2025-04-04 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:9fadadbbbc2b5352e5e70e0e1a9be9b447176913

commit r15-9070-g9fadadbbbc2b5352e5e70e0e1a9be9b447176913
Author: Iain Buclaw 
Date:   Sat Mar 29 23:16:25 2025 +0100

d: Fix error with -Warray-bounds and -O2 [PR117002]

The record layout of class types in D don't get any tail padding, so it
is possible for the `classInstanceSize' to not be a multiple of the
`classInstanceAlignment'.

Rather than setting the instance alignment on the underlying
RECORD_TYPE, instead give the type an alignment of 1, which will mark it
as TYPE_PACKED.  The value of `classInstanceAlignment' is instead
applied to the DECL_ALIGN of both the static `init' symbol, and the
stack allocated variable used when generating `new' for a `scope' class.

PR d/117002

gcc/d/ChangeLog:

* decl.cc (aggregate_initializer_decl): Set explicit decl alignment 
of
class instance.
* expr.cc (ExprVisitor::visit (NewExp *)): Likewise.
* types.cc (TypeVisitor::visit (TypeClass *)): Mark the record type 
of
classes as packed.

gcc/testsuite/ChangeLog:

* gdc.dg/torture/pr117002.d: New test.

Diff:
---
 gcc/d/decl.cc   |  6 ++
 gcc/d/expr.cc   |  2 ++
 gcc/d/types.cc  |  3 ++-
 gcc/testsuite/gdc.dg/torture/pr117002.d | 28 
 4 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index 9fcfc5681f8c..250d148e56f4 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -2393,6 +2393,12 @@ aggregate_initializer_decl (AggregateDeclaration *decl)
   SET_DECL_ALIGN (sinit, sd->alignment.get () * BITS_PER_UNIT);
   DECL_USER_ALIGN (sinit) = true;
 }
+  else if (sd == NULL)
+{
+  /* Alignment of class is determined its biggest field alignment.  */
+  SET_DECL_ALIGN (sinit, decl->alignsize * BITS_PER_UNIT);
+  DECL_USER_ALIGN (sinit) = true;
+}
 
   decl->sinit = sinit;
   return sinit;
diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc
index 0415763b60d1..46e651457911 100644
--- a/gcc/d/expr.cc
+++ b/gcc/d/expr.cc
@@ -2243,6 +2243,8 @@ public:
   storage class, then the instance is allocated on the stack
   rather than the heap or using the class specific allocator.  */
tree var = build_local_temp (TREE_TYPE (type));
+   SET_DECL_ALIGN (var, cd->alignsize * BITS_PER_UNIT);
+   DECL_USER_ALIGN (var) = 1;
new_call = build_nop (type, build_address (var));
setup_exp = modify_expr (var, aggregate_initializer_decl (cd));
  }
diff --git a/gcc/d/types.cc b/gcc/d/types.cc
index 98074f1fb687..ea62bc9d05e1 100644
--- a/gcc/d/types.cc
+++ b/gcc/d/types.cc
@@ -1278,7 +1278,8 @@ public:
 build_type_decl (basetype, t->sym);
 set_visibility_for_decl (basetype, t->sym);
 apply_user_attributes (t->sym, basetype);
-finish_aggregate_type (t->sym->structsize, t->sym->alignsize, basetype);
+/* The underlying record type of classes are packed.  */
+finish_aggregate_type (t->sym->structsize, 1, basetype);
 
 /* Classes only live in memory, so always set the TREE_ADDRESSABLE bit.  */
 for (tree tv = basetype; tv != NULL_TREE; tv = TYPE_NEXT_VARIANT (tv))
diff --git a/gcc/testsuite/gdc.dg/torture/pr117002.d 
b/gcc/testsuite/gdc.dg/torture/pr117002.d
new file mode 100644
index ..5b8c19e5b12f
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/torture/pr117002.d
@@ -0,0 +1,28 @@
+// { dg-do compile }
+// { dg-additional-options "-Warray-bounds" }
+extern(C++) class C117002
+{
+ubyte[4] not_multiple_of_8;
+}
+
+int pr117002a(void *p)
+{
+auto init = __traits(initSymbol, C117002);
+if (init.ptr + init.length <= p)
+return 1;
+return 0;
+}
+
+void pr117002b(void *p)
+{
+auto init = __traits(initSymbol, C117002);
+p[0 .. init.length] = init[];
+}
+
+void pr117002c()
+{
+scope var = new C117002;
+void *p = cast(void*)var;
+auto init = __traits(initSymbol, C117002);
+p[0 .. __traits(classInstanceSize, C117002)] = init[];
+}


[gcc r15-9182] libgcobol: Only use random_r if it is available [PR119295]

2025-04-04 Thread Iain D Sandoe via Gcc-cvs
https://gcc.gnu.org/g:66a41a0a9626a9b2f8de3cdb6ba82561b50cd9e8

commit r15-9182-g66a41a0a9626a9b2f8de3cdb6ba82561b50cd9e8
Author: Iain Sandoe 
Date:   Sun Mar 16 09:32:12 2025 +

libgcobol: Only use random_r if it is available [PR119295]

We do not have a replacement at the moment, so fall back to using
regular random and friends.

PR cobol/119295

libgcobol/ChangeLog:

* config.h.in: Regenerate.
* configure: Regenerate.
* configure.ac: Configure random_r and friends
* intrinsic.cc (__gg__random): Use random_r when available.
(__gg__random_next): Likewise.

Signed-off-by: Iain Sandoe 

Diff:
---
 libgcobol/config.h.in  | 12 
 libgcobol/configure| 35 +--
 libgcobol/configure.ac |  3 +++
 libgcobol/intrinsic.cc | 27 ++-
 4 files changed, 70 insertions(+), 7 deletions(-)

diff --git a/libgcobol/config.h.in b/libgcobol/config.h.in
index a7e5675c43c8..b201266e0610 100644
--- a/libgcobol/config.h.in
+++ b/libgcobol/config.h.in
@@ -9,6 +9,9 @@
 /* Define if you have the iconv() function and it works. */
 #undef HAVE_ICONV
 
+/* Define to 1 if you have the `initstate_r' function. */
+#undef HAVE_INITSTATE_R
+
 /* Define to 1 if you have the  header file. */
 #undef HAVE_INTTYPES_H
 
@@ -18,6 +21,15 @@
 /* Define to 1 if you have the  header file. */
 #undef HAVE_MEMORY_H
 
+/* Define to 1 if you have the `random_r' function. */
+#undef HAVE_RANDOM_R
+
+/* Define to 1 if you have the `setstate_r' function. */
+#undef HAVE_SETSTATE_R
+
+/* Define to 1 if you have the `srandom_r' function. */
+#undef HAVE_SRANDOM_R
+
 /* Define to 1 if you have the  header file. */
 #undef HAVE_STDINT_H
 
diff --git a/libgcobol/configure b/libgcobol/configure
index 1db4e792e030..44190d7e2fe0 100755
--- a/libgcobol/configure
+++ b/libgcobol/configure
@@ -629,6 +629,7 @@ ac_includes_default="\
 # include 
 #endif"
 
+ac_func_list=
 ac_unique_file="Makefile.am"
 ac_subst_vars='am__EXEEXT_FALSE
 am__EXEEXT_TRUE
@@ -2515,6 +2516,10 @@ $as_echo "$as_me: creating cache $cache_file" >&6;}
   >$cache_file
 fi
 
+as_fn_append ac_func_list " random_r"
+as_fn_append ac_func_list " srandom_r"
+as_fn_append ac_func_list " initstate_r"
+as_fn_append ac_func_list " setstate_r"
 # Check that the precious variables saved in the cache have kept the same
 # value.
 ac_cache_corrupted=false
@@ -12901,7 +12906,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 12904 "configure"
+#line 12909 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -13007,7 +13012,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 13010 "configure"
+#line 13015 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -16354,6 +16359,32 @@ fi
 
 
 
+# These are GLIBC
+
+
+
+  for ac_func in $ac_func_list
+do :
+  as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
+ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
+if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
+  cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+done
+
+
+
+
+
+
+
+
+
+
+
 if test "${multilib}" = "yes"; then
   multilib_arg="--enable-multilib"
 else
diff --git a/libgcobol/configure.ac b/libgcobol/configure.ac
index e27621d03680..383b4134b130 100644
--- a/libgcobol/configure.ac
+++ b/libgcobol/configure.ac
@@ -215,6 +215,9 @@ AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test 
x$enable_darwin_at_rpath = xyes])
 AC_SUBST(enable_shared)
 AC_SUBST(enable_static)
 
+# These are GLIBC
+AC_CHECK_FUNCS_ONCE(random_r srandom_r initstate_r setstate_r)
+
 if test "${multilib}" = "yes"; then
   multilib_arg="--enable-multilib"
 else
diff --git a/libgcobol/intrinsic.cc b/libgcobol/intrinsic.cc
index 16bf84be620b..4bce481b0c04 100644
--- a/libgcobol/intrinsic.cc
+++ b/libgcobol/intrinsic.cc
@@ -44,6 +44,8 @@
 #include 
 #include 
 
+#include "config.h"
+
 #include "ec.h"
 #include "common-defs.h"
 #include "io.h"
@@ -3409,9 +3411,13 @@ __gg__trim( cblc_field_t *dest,
 }
   }
 
+#if HAVE_INITSTATE_R && HAVE_SRANDOM_R && HAVE_RANDOM_R
 static struct random_data *buf = NULL;
 static char *state = NULL;
 static const size_t state_len = 256;
+#else
+static unsigned seed = 0;
+#endif
 
 extern "C"
 void
@@ -3420,6 +3426,9 @@ __gg__random( cblc_field_t *dest,
   size_tinput_offset,
   size_tinput_size)
   {
+  int32_t retval_31;
+  int rdigits;
+#if HAVE_INITSTATE_R && HAVE_SRANDOM_R && HAVE_RANDOM_R
   // This creates a thread-safe pseudo-random number generator
   // using input as the seed
 
@@ -3436,16 +3445,21 @@ __gg__random( cblc_field_t *dest,
 __gg__clock_gettime(CLOCK_REALTIME, &ts);
 initstate_r( ts.tv_nsec, state, state_len, buf);
 }
-
-  int rdigits;
   int see

[gcc r15-9185] Doc: Clean up musttail attribute docs some more

2025-04-04 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:26e9139691ac73f53fad64960a0ea48830adfa52

commit r15-9185-g26e9139691ac73f53fad64960a0ea48830adfa52
Author: Sandra Loosemore 
Date:   Thu Apr 3 05:02:34 2025 +

Doc: Clean up musttail attribute docs some more

Looking over the recently-committed change to the musttail attribute
documentation, it appears the comment in the last example was a paste-o,
as it does not agree with either what the similar example in the
-Wmaybe-musttail-local-addr documentation says, or the actual behavior
observed when running the code.

In addition, the entire section on musttail was in need of copy-editing
to put it in the present tense, avoid reference to "the user", etc.  I've
attempted to clean it up here.

gcc/ChangeLog
* doc/extend.texi (Statement Attributes): Copy-edit the musttail
attribute documentation and correct the comment in the last
example.

Diff:
---
 gcc/doc/extend.texi | 46 +++---
 1 file changed, 23 insertions(+), 23 deletions(-)

diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 4302df76c7fa..16ad83fc510c 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -9314,7 +9314,7 @@ The @code{gnu::musttail} or @code{clang::musttail} 
standard attribute
 or @code{musttail} GNU attribute can be applied to a @code{return} statement
 with a return-value expression that is a function call.  It asserts that the
 call must be a tail call that does not allocate extra stack space, so it is
-safe to use tail recursion to implement long running loops.
+safe to use tail recursion to implement long-running loops.
 
 @smallexample
 [[gnu::musttail]] return foo();
@@ -9324,11 +9324,11 @@ safe to use tail recursion to implement long running 
loops.
 __attribute__((musttail)) return bar();
 @end smallexample
 
-If the compiler cannot generate a @code{musttail} tail call it will report
-an error.  On some targets tail calls may never be supported.
-The user asserts for @code{musttail} tail calls that lifetime of automatic
+If the compiler cannot generate a @code{musttail} tail call it reports
+an error.  On some targets, tail calls may not be supported at all.
+The @code{musttail} attribute asserts that the lifetime of automatic
 variables, function parameters and temporaries (unless they have non-trivial
-destruction) can end before the actual call instruction and that any access
+destruction) can end before the actual call instruction, and that any access
 to those from inside of the called function results is considered undefined
 behavior.  Enabling @option{-O1} or @option{-O2} can improve the success of
 tail calls.
@@ -9344,9 +9344,9 @@ baz (int *x)
   if (*x == 1)
 @{
   int a = 42;
-  /* The call will be tail called (would not be without the
- attribute), dereferencing the pointer in the callee is
- undefined behavior and there will be a warning emitted
+  /* The call is a tail call (would not be without the
+ attribute).  Dereferencing the pointer in the callee is
+ undefined behavior, and there is a warning emitted
  for this by default (@option{-Wmusttail-local-addr}).  */
   [[gnu::musttail]] return foo (&a);
 @}
@@ -9354,9 +9354,9 @@ baz (int *x)
 @{
   int a = 42;
   bar (&a);
-  /* The call will be tail called (would not be without the
- attribute), if bar stores the pointer anywhere, dereferencing
- it in foo will be undefined behavior and there will be a warning
+  /* The call is a tail call (would not be without the
+ attribute).  If bar stores the pointer anywhere, dereferencing
+ it in foo is undefined behavior.  There is a warning
  emitted for this with @option{-Wextra}, which implies
  @option{-Wmaybe-musttail-local-addr}.  */
   [[gnu::musttail]] return foo (nullptr);
@@ -9365,8 +9365,8 @@ baz (int *x)
 @{
   S s;
   /* The s variable requires non-trivial destruction which ought
- to be performed after the foo call returns, so this will
- be rejected.  */
+ to be performed after the foo call returns, so this is
+ rejected.  */
   [[gnu::musttail]] return foo (&s.s);
 @}
 @}
@@ -9374,9 +9374,9 @@ baz (int *x)
 
 To avoid the @option{-Wmaybe-musttail-local-addr} warning in the
 above @code{*x == 2} case and similar code, consider defining the
-maybe escaped variables in a separate scope which will end before the
-return statement if possible to make it clear that the variable is not
-live during the call.  So
+maybe-escaped variables in a separate scope that ends before the
+return statement, if that is possible, to make it clear that the
+variable is not live during the call.  So:
 
 @smallexample
   else if (*x == 2)
@@ -9385,17 +9385,17 @@ live during the call.  So
 int a = 42;
 bar (&a);
   @}
-  /* The call will be tail called

[gcc r15-9200] arm: testsuite: restore dg-do-what-default in mve.exp

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

commit r15-9200-g6e79fa4a25769b2facf519aaf04b2a757dd3c887
Author: Richard Earnshaw 
Date:   Fri Apr 4 13:38:35 2025 +0100

arm: testsuite: restore dg-do-what-default in mve.exp

On Arm, running

make check-gcc RUNTESTFLAGS="dwarf2.exp=pr43190.c"

with a target list of "arm-qemu{,-mthumb}"

results in no errors.  But running it with

make check-gcc RUNTESTFLAGS="{mve,dwarf2}.exp=pr43190.c"

results in unresolved tests while running the thumb variant.  The problem
is that mve.exp is changing dg-do-what-default to "assemble", but failing
to restore the original value once its tests are complete.  The result is
that all subsequent tests run with an incorrect underlying default value.

The fix is easy - save dg-do-what-default and restore it after the tests
are complete.

gcc/testsuite/ChangeLog:

* gcc.target/arm/mve/mve.exp: Save dg-do-what-default before
changing it.  Restore it once done.

Diff:
---
 gcc/testsuite/gcc.target/arm/mve/mve.exp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gcc/testsuite/gcc.target/arm/mve/mve.exp 
b/gcc/testsuite/gcc.target/arm/mve/mve.exp
index a5d8511afdac..9dc56c9b2d9f 100644
--- a/gcc/testsuite/gcc.target/arm/mve/mve.exp
+++ b/gcc/testsuite/gcc.target/arm/mve/mve.exp
@@ -35,6 +35,7 @@ global dg_runtest_extra_prunes
 set dg_runtest_extra_prunes ""
 lappend dg_runtest_extra_prunes "warning: switch '-m(cpu|arch)=.*' conflicts 
with switch '-m(cpu|arch)=.*'"
 
+set saved-dg-do-what-default ${dg-do-what-default}
 set dg-do-what-default "assemble"
 
 # Initialize `dg'.
@@ -53,6 +54,8 @@ dg-runtest [lsort [glob -nocomplain 
$srcdir/$subdir/general-c/*.\[cCS\]]] \
 dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cCS\]]] \
"" $DEFAULT_CFLAGS
 
+set dg-do-what-default ${saved-dg-do-what-default}
+
 # All done.
 set dg_runtest_extra_prunes ""
 dg-finish


[gcc r15-9201] c++, libcpp: Allow some left shifts in the preprocessor [PR119391]

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

commit r15-9201-gaa9d3f17ff359ecad729a9436adbbf644aab2426
Author: Jakub Jelinek 
Date:   Fri Apr 4 17:27:56 2025 +0200

c++, libcpp: Allow some left shifts in the preprocessor [PR119391]

The libcpp left shift handling implements (partially) the C99-C23
wording where shifts are UB if shift count is negative, or too large,
or shifting left a negative value or shifting left non-negative value
results in something not representable in the result type (in the
preprocessor case that is intmax_t).
libcpp actually implements left shift by negative count as right shifts
by negation of the count and similarly right shifts by negative count
as left shifts by negation (not ok), sets overflow for too large shift
count (ok), doesn't check for negative values on left shift (not ok)
and checks correctly for the non-representable ones otherwise (ok).

Now, C++11 to C++17 has different behavior, whereas in C99-C23 1 << 63
in preprocessor is invalid, in C++11-17 it is valid, but 3 << 63 is
not.  The wording is that left shift of negative value is UB (like in C)
and signed non-negative left shift is UB if the result isn't representable
in corresponding unsigned type (so uintmax_t for libcpp).

And then C++20 and newer says all left shifts are well defined with the
exception of bad shift counts.

In -fsanitize=undefined we handle these by
  /* For signed x << y, in C99 and later, the following:
 (unsigned) x >> (uprecm1 - y)
 if non-zero, is undefined.  */
and
  /* For signed x << y, in C++11 to C++17, the following:
 x < 0 || ((unsigned) x >> (uprecm1 - y))
 if > 1, is undefined.  */

Now, we are late in GCC 15 development, so I think making the preprocessor
more strict than it is now is undesirable, so will defer setting overflow
flag for the shifts by negative count, or shifts by negative value left.

The following patch just makes some previously incorrectly rejected or
warned cases valid for C++11-17 and even more for C++20 and later.

2025-04-04  Jakub Jelinek  

PR preprocessor/119391
* expr.cc (num_lshift): Add pfile argument.  Don't set num.overflow
for !num.unsignedp in C++20 or later unless n >= precision.  For
C++11 to C++17 set it if orig >> (precision - 1 - n) as logical
shift results in value > 1.
(num_binary_op): Pass pfile to num_lshift.
(num_div_op): Likewise.

* g++.dg/cpp/pr119391.C: New test.

Diff:
---
 gcc/testsuite/g++.dg/cpp/pr119391.C | 15 +++
 libcpp/expr.cc  | 28 +++-
 2 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/gcc/testsuite/g++.dg/cpp/pr119391.C 
b/gcc/testsuite/g++.dg/cpp/pr119391.C
new file mode 100644
index ..6e70efc0b465
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp/pr119391.C
@@ -0,0 +1,15 @@
+// PR preprocessor/119391
+// { dg-do preprocess }
+// { dg-options "" }
+
+#if (1 << 63) != -9223372036854775807 - 1  // { dg-warning "integer 
overflow in preprocessor expression" "" { target c++98_only } }
+#warning "Unexpected value"
+#endif
+#if (3 << 62) != -4611686018427387904  // { dg-warning "integer 
overflow in preprocessor expression" "" { target c++98_only } }
+#warning "Unexpected value"
+#endif
+#if 1 << 64// { dg-warning "integer 
overflow in preprocessor expression" }
+#endif
+#if (3 << 63) != -9223372036854775807 - 1  // { dg-warning "integer 
overflow in preprocessor expression" "" { target c++17_down } }
+#warning "Unexpected value"
+#endif
diff --git a/libcpp/expr.cc b/libcpp/expr.cc
index 4573752dd5d1..7bb57a340d85 100644
--- a/libcpp/expr.cc
+++ b/libcpp/expr.cc
@@ -53,7 +53,7 @@ static cpp_num num_equality_op (cpp_reader *, cpp_num, 
cpp_num,
 static cpp_num num_mul (cpp_reader *, cpp_num, cpp_num);
 static cpp_num num_div_op (cpp_reader *, cpp_num, cpp_num, enum cpp_ttype,
   location_t);
-static cpp_num num_lshift (cpp_num, size_t, size_t);
+static cpp_num num_lshift (cpp_reader *, cpp_num, size_t, size_t);
 static cpp_num num_rshift (cpp_num, size_t, size_t);
 
 static cpp_num append_digit (cpp_num, int, int, size_t);
@@ -2049,7 +2049,7 @@ num_rshift (cpp_num num, size_t precision, size_t n)
 
 /* Shift NUM, of width PRECISION, left by N bits.  */
 static cpp_num
-num_lshift (cpp_num num, size_t precision, size_t n)
+num_lshift (cpp_reader *pfile, cpp_num num, size_t precision, size_t n)
 {
   if (n >= precision)
 {
@@ -2075,8 +2075,26 @@ num_lshift (cpp_num num, size_t precision, size_t n)
}
   num = num_trim (num, precision);
 
-  if (num.unsignedp)
+  if (num.unsignedp
+ /* For C++20 or later since P1236R1, there is no overflow for signed
+

[gcc r12-11017] tree-optimization/118717 - store commoning vs. abnormals

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

commit r12-11017-g8eca273335750e100efff8f45aee285290be3c46
Author: Richard Biener 
Date:   Mon Feb 3 09:55:50 2025 +0100

tree-optimization/118717 - store commoning vs. abnormals

When we sink common stores in cselim or the sink pass we have to
make sure to not introduce overlapping lifetimes for abnormals
used in the ref.  The easiest is to avoid sinking stmts which
reference abnormals at all which is what the following does.

PR tree-optimization/118717
* tree-ssa-phiopt.cc (cond_if_else_store_replacement_1):
Do not common stores referencing abnormal SSA names.
* tree-ssa-sink.cc (sink_common_stores_to_bb): Likewise.

* gcc.dg/torture/pr118717.c: New testcase.

(cherry picked from commit fbcbbfe2bf83eb8b1347144eeca37b06be5a8bb5)

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr118717.c | 41 +
 gcc/tree-ssa-phiopt.cc  |  4 +++-
 gcc/tree-ssa-sink.cc|  4 +++-
 3 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/torture/pr118717.c 
b/gcc/testsuite/gcc.dg/torture/pr118717.c
new file mode 100644
index ..42dc5ec84f28
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr118717.c
@@ -0,0 +1,41 @@
+/* { dg-do compile } */
+
+void jj(void);
+int ff1(void) __attribute__((__returns_twice__));
+struct s2 {
+  int prev;
+};
+typedef struct s1 {
+  unsigned interrupt_flag;
+  unsigned interrupt_mask;
+  int tag;
+  int state;
+}s1;
+int ff(void);
+static inline
+int mm(s1 *ec) {
+  if (ff())
+if (ec->interrupt_flag & ~(ec)->interrupt_mask)
+  return 0;
+}
+void ll(s1 *ec) {
+  int t = 1;
+  int state;
+  if (t)
+  {
+{
+  s1 *const _ec = ec;
+  struct s2 _tag = {0};
+  if (ff1())
+   state = ec->state;
+  else
+   state = 0;
+  if (!state)
+   mm (ec);
+  _ec->tag = _tag.prev;
+}
+if (state)
+  __builtin_exit(0);
+  }
+  jj();
+}
diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc
index 558d5b4b57db..3ef7d6b28fcd 100644
--- a/gcc/tree-ssa-phiopt.cc
+++ b/gcc/tree-ssa-phiopt.cc
@@ -3293,7 +3293,9 @@ cond_if_else_store_replacement_1 (basic_block then_bb, 
basic_block else_bb,
   || else_assign == NULL
   || !gimple_assign_single_p (else_assign)
   || gimple_clobber_p (else_assign)
-  || gimple_has_volatile_ops (else_assign))
+  || gimple_has_volatile_ops (else_assign)
+  || stmt_references_abnormal_ssa_name (then_assign)
+  || stmt_references_abnormal_ssa_name (else_assign))
 return false;
 
   lhs = gimple_assign_lhs (then_assign);
diff --git a/gcc/tree-ssa-sink.cc b/gcc/tree-ssa-sink.cc
index 8ce4403ddc8f..f747f8adc34f 100644
--- a/gcc/tree-ssa-sink.cc
+++ b/gcc/tree-ssa-sink.cc
@@ -35,6 +35,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-cfg.h"
 #include "cfgloop.h"
 #include "tree-eh.h"
+#include "tree-dfa.h"
 
 /* TODO:
1. Sinking store only using scalar promotion (IE without moving the RHS):
@@ -523,7 +524,8 @@ sink_common_stores_to_bb (basic_block bb)
  gimple *def = SSA_NAME_DEF_STMT (arg);
  if (! is_gimple_assign (def)
  || stmt_can_throw_internal (cfun, def)
- || (gimple_phi_arg_edge (phi, i)->flags & EDGE_ABNORMAL))
+ || (gimple_phi_arg_edge (phi, i)->flags & EDGE_ABNORMAL)
+ || stmt_references_abnormal_ssa_name (def))
{
  /* ???  We could handle some cascading with the def being
 another PHI.  We'd have to insert multiple PHIs for


[gcc r12-11021] tree-optimization/116850 - corrupt post-dom info

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

commit r12-11021-gc62cbe7164765e03a7bc41377452b80b6237d93d
Author: Richard Biener 
Date:   Thu Sep 26 15:41:59 2024 +0200

tree-optimization/116850 - corrupt post-dom info

Path isolation computes post-dominators on demand but can end up
splitting blocks after that, wrecking it.  We can delay splitting
of blocks until we no longer need the post-dom info which is what
the following patch does to solve the issue.

PR tree-optimization/116850
* gimple-ssa-isolate-paths.cc (bb_split_points): New global.
(insert_trap): Delay BB splitting if post-doms are computed.
(find_explicit_erroneous_behavior): Process delayed BB
splitting after releasing post dominators.
(gimple_ssa_isolate_erroneous_paths): Do not free post-dom
info here.

* gcc.dg/pr116850.c: New testcase.

(cherry picked from commit 64163657ba7e70347087a63bb2b32d83b52ea7d9)

Diff:
---
 gcc/gimple-ssa-isolate-paths.cc | 23 ---
 gcc/testsuite/gcc.dg/pr116850.c | 12 
 2 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/gcc/gimple-ssa-isolate-paths.cc b/gcc/gimple-ssa-isolate-paths.cc
index cc0ed9760a03..7613f83da6aa 100644
--- a/gcc/gimple-ssa-isolate-paths.cc
+++ b/gcc/gimple-ssa-isolate-paths.cc
@@ -62,6 +62,8 @@ check_loadstore (gimple *stmt, tree op, tree, void *data)
   return false;
 }
 
+static vec *bb_split_points;
+
 /* Insert a trap after SI and split the block after the trap.  */
 
 static void
@@ -104,14 +106,20 @@ insert_trap (gimple_stmt_iterator *si_p, tree op)
   gsi_insert_after (si_p, seq, GSI_NEW_STMT);
   if (stmt_ends_bb_p (stmt))
{
- split_block (gimple_bb (stmt), stmt);
+ if (dom_info_available_p (CDI_POST_DOMINATORS))
+   bb_split_points->safe_push (stmt);
+ else
+   split_block (gimple_bb (stmt), stmt);
  return;
}
 }
   else
 gsi_insert_before (si_p, seq, GSI_NEW_STMT);
 
-  split_block (gimple_bb (new_stmt), new_stmt);
+  if (dom_info_available_p (CDI_POST_DOMINATORS))
+bb_split_points->safe_push (new_stmt);
+  else
+split_block (gimple_bb (new_stmt), new_stmt);
   *si_p = gsi_for_stmt (stmt);
 }
 
@@ -840,6 +848,8 @@ static void
 find_explicit_erroneous_behavior (void)
 {
   basic_block bb;
+  auto_vec local_bb_split_points;
+  bb_split_points = &local_bb_split_points;
 
   FOR_EACH_BB_FN (bb, cfun)
 {
@@ -881,6 +891,14 @@ find_explicit_erroneous_behavior (void)
warn_return_addr_local (bb, return_stmt);
}
 }
+
+  free_dominance_info (CDI_POST_DOMINATORS);
+
+  /* Perform delayed splitting of blocks.  */
+  for (gimple *stmt : local_bb_split_points)
+split_block (gimple_bb (stmt), stmt);
+
+  bb_split_points = NULL;
 }
 
 /* Search the function for statements which, if executed, would cause
@@ -937,7 +955,6 @@ gimple_ssa_isolate_erroneous_paths (void)
   /* We scramble the CFG and loop structures a bit, clean up
  appropriately.  We really should incrementally update the
  loop structures, in theory it shouldn't be that hard.  */
-  free_dominance_info (CDI_POST_DOMINATORS);
   if (cfg_altered)
 {
   free_dominance_info (CDI_DOMINATORS);
diff --git a/gcc/testsuite/gcc.dg/pr116850.c b/gcc/testsuite/gcc.dg/pr116850.c
new file mode 100644
index ..7ab5da1848bd
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr116850.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-Os -w" } */
+
+int a, b;
+int *c()
+{
+  int d, *e = 0, *f = &d, *g = &a;
+  if (b)
+g = 0;
+  *e = *g;
+  return f;
+}


[gcc r15-9197] Ada: Fix thinko in Eigensystem for complex Hermitian matrices

2025-04-04 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:42d6a4a985a6aa1c8c06daceb66e3408566a2e3a

commit r15-9197-g42d6a4a985a6aa1c8c06daceb66e3408566a2e3a
Author: Eric Botcazou 
Date:   Fri Apr 4 11:45:23 2025 +0200

Ada: Fix thinko in Eigensystem for complex Hermitian matrices

The implementation solves the eigensystem for a NxN complex Hermitian matrix
by first solving it for a 2Nx2N real symmetric matrix and then interpreting
the 2Nx1 real vectors as Nx1 complex ones, but the last step does not work.

The patch fixes the last step and also performs a small cleanup throughout
the implementation, mostly in the commentary and without functional changes.

gcc/ada/
* libgnat/a-ngcoar.adb (Eigensystem): Adjust notation and fix the
layout of the real symmetric matrix in the main comment.  Adjust
the layout of the associated code accordingly and correctly turn
the 2Nx1 real vectors into Nx1 complex ones.
(Eigenvalues): Minor similar tweaks.
* libgnat/a-ngrear.adb (Jacobi): Minor tweaks in the main comment.
Adjust notation and corresponding parameter names of functions.
Fix call to Unit_Matrix routine.  Adjust the comment describing
the various kinds of iterations to match the implementation.

Diff:
---
 gcc/ada/libgnat/a-ngcoar.adb | 42 +++---
 gcc/ada/libgnat/a-ngrear.adb | 85 
 2 files changed, 66 insertions(+), 61 deletions(-)

diff --git a/gcc/ada/libgnat/a-ngcoar.adb b/gcc/ada/libgnat/a-ngcoar.adb
index 41c255f92fa5..9ce6caf1916a 100644
--- a/gcc/ada/libgnat/a-ngcoar.adb
+++ b/gcc/ada/libgnat/a-ngcoar.adb
@@ -1058,19 +1058,21 @@ package body Ada.Numerics.Generic_Complex_Arrays is
is
   N : constant Natural := Length (A);
 
-  --  For a Hermitian matrix C, we convert the eigenvalue problem to a
-  --  real symmetric one: if C = A + i * B, then the (N, N) complex
+  --  For a Hermitian matrix A, we convert the eigenvalue problem to a
+  --  real symmetric one: if A = X + i * Y, then the (N, N) complex
   --  eigenvalue problem:
-  -- (A + i * B) * (u + i * v) = Lambda * (u + i * v)
+  --
+  -- (X + i * Y) * (u + i * v) = Lambda * (u + i * v)
   --
   --  is equivalent to the (2 * N, 2 * N) real eigenvalue problem:
-  -- [  A, B ] [ u ] = Lambda * [ u ]
-  -- [ -B, A ] [ v ][ v ]
   --
-  --  Note that the (2 * N, 2 * N) matrix above is symmetric, as
-  --  Transpose (A) = A and Transpose (B) = -B if C is Hermitian.
+  -- [ X, -Y ] [ u ] = Lambda * [ u ]
+  -- [ Y,  X ] [ v ][ v ]
+  --
+  --  Note that the (2 * N, 2 * N) matrix M above is symmetric, because
+  --  Transpose (X) = X and Transpose (Y) = -Y as A is Hermitian.
 
-  --  We solve this eigensystem using the real-valued algorithms. The final
+  --  We solve this eigensystem using the real-valued algorithm. The final
   --  result will have every eigenvalue twice, so in the sorted output we
   --  just pick every second value, with associated eigenvector u + i * v.
 
@@ -1085,10 +1087,8 @@ package body Ada.Numerics.Generic_Complex_Arrays is
C : constant Complex :=
  (A (A'First (1) + (J - 1), A'First (2) + (K - 1)));
 begin
-   M (J, K) := Re (C);
-   M (J + N, K + N) := Re (C);
-   M (J + N, K) := Im (C);
-   M (J, K + N) := -Im (C);
+   M (J, K) := Re (C); M (J, K + N) := -Im (C);
+   M (J + N, K) := Im (C); M (J + N, K + N) := Re (C);
 end;
  end loop;
   end loop;
@@ -1103,10 +1103,9 @@ package body Ada.Numerics.Generic_Complex_Arrays is
 
 for K in 1 .. N loop
declare
-  Row : constant Integer := Vectors'First (2) + (K - 1);
+  Row : constant Integer := Vectors'First (1) + (K - 1);
begin
-  Vectors (Row, Col) :=
-(Vecs (J * 2, Col), Vecs (J * 2, Col + N));
+  Vectors (Row, Col) := (Vecs (K, 2 * J), Vecs (K + N, 2 * J));
end;
 end loop;
  end;
@@ -1118,13 +1117,14 @@ package body Ada.Numerics.Generic_Complex_Arrays is
-
 
function Eigenvalues (A : Complex_Matrix) return Real_Vector is
-  --  See Eigensystem for a description of the algorithm
-
   N : constant Natural := Length (A);
-  R : Real_Vector (A'Range (1));
+
+  --  See Eigensystem for a description of the algorithm
 
   M: Real_Matrix (1 .. 2 * N, 1 .. 2 * N);
+  R: Real_Vector (A'Range (1));
   Vals : Real_Vector (1 .. 2 * N);
+
begin
   for J in 1 .. N loop
  for K in 1 .. N loop
@@ -1132,10 +1132,8 @@ package body Ada.Numerics.Generic_Complex_Arrays is
C : constant Co

[gcc r15-9121] target/119549 - fixup handling of -mno-sse4 in target attribute

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

commit r15-9121-gae2912748b9913fe9cd198db1b3fa704d0cbc728
Author: Richard Biener 
Date:   Mon Mar 31 14:56:25 2025 +0200

target/119549 - fixup handling of -mno-sse4 in target attribute

The following fixes ix86_valid_target_attribute_inner_p to properly
handle target("no-sse4") via OPT_mno_sse4 rather than as unset OPT_msse4.
I've added asserts to ix86_handle_option that RejectNegative is honored
for both.

PR target/119549
* common/config/i386/i386-common.cc (ix86_handle_option):
Assert that both OPT_msse4 and OPT_mno_sse4 are never unset.
* config/i386/i386-options.cc (ix86_valid_target_attribute_inner_p):
Process negated OPT_msse4 as OPT_mno_sse4.

* gcc.target/i386/pr119549.c: New testcase.

Diff:
---
 gcc/common/config/i386/i386-common.cc|  2 ++
 gcc/config/i386/i386-options.cc  |  7 +++
 gcc/testsuite/gcc.target/i386/pr119549.c | 15 +++
 3 files changed, 24 insertions(+)

diff --git a/gcc/common/config/i386/i386-common.cc 
b/gcc/common/config/i386/i386-common.cc
index 80aec3244bc3..4815fbc4d359 100644
--- a/gcc/common/config/i386/i386-common.cc
+++ b/gcc/common/config/i386/i386-common.cc
@@ -1519,11 +1519,13 @@ ix86_handle_option (struct gcc_options *opts,
   return true;
 
 case OPT_msse4:
+  gcc_assert (value != 0);
   opts->x_ix86_isa_flags |= OPTION_MASK_ISA_SSE4_SET;
   opts->x_ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_SET;
   return true;
 
 case OPT_mno_sse4:
+  gcc_assert (value != 0);
   opts->x_ix86_isa_flags &= ~OPTION_MASK_ISA_SSE4_UNSET;
   opts->x_ix86_isa_flags_explicit |= OPTION_MASK_ISA_SSE4_UNSET;
   opts->x_ix86_isa_flags2 &= ~OPTION_MASK_ISA2_SSE4_UNSET;
diff --git a/gcc/config/i386/i386-options.cc b/gcc/config/i386/i386-options.cc
index 91f59e16fd5c..a9fac011f3d2 100644
--- a/gcc/config/i386/i386-options.cc
+++ b/gcc/config/i386/i386-options.cc
@@ -1271,6 +1271,13 @@ ix86_valid_target_attribute_inner_p (tree fndecl, tree 
args, char *p_strings[],
}
}
 
+  /* Fixup -msse4 which is RejectNegative to -mno-sse4 when negated.  */
+  if (opt == OPT_msse4 && !opt_set_p)
+   {
+ opt = OPT_mno_sse4;
+ opt_set_p = true;
+   }
+
   /* Process the option.  */
   if (opt == N_OPTS)
{
diff --git a/gcc/testsuite/gcc.target/i386/pr119549.c 
b/gcc/testsuite/gcc.target/i386/pr119549.c
new file mode 100644
index ..a465bec3cf00
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr119549.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-msse4" } */
+
+typedef long long v2di __attribute__((vector_size(16)));
+
+static inline __attribute__((always_inline))
+int rte_trace_feature_is_enabled() { return 1; } /* { dg-error "inlining 
failed" } */
+
+void __attribute__((target ("no-sse3"))) __attribute__((target ("no-sse4")))
+rte_eal_trace_generic_void_init(void)
+{
+  if (!rte_trace_feature_is_enabled()) return;
+  __asm__ volatile ("" : : : "memory");
+}
+


[gcc r15-9061] libstdc++: Constrain formatters for chrono types [PR119517]

2025-04-04 Thread Tomasz Kaminski via Gcc-cvs
https://gcc.gnu.org/g:5f2078ca11843e3fe506c2fb72b9260a3cb9853e

commit r15-9061-g5f2078ca11843e3fe506c2fb72b9260a3cb9853e
Author: Tomasz Kamiński 
Date:   Fri Mar 28 16:17:18 2025 +0100

libstdc++: Constrain formatters for chrono types [PR119517]

The formatters for chrono types defined the parse/format methods
as accepting unconstrained types, this in combination with lack
of constrain on _CharT lead to them falsely satisfying formattable
requirements for any type used as character.

This patch adjust the fromatter::parse signature to:
 constexpr typename basic_format_parse_context<_CharT>::iterator
 parse(basic_format_parse_context<_CharT>& __pc);
And formatter::format to:
 template
   typename basic_format_context<_Out, _CharT>::iterator
   format(const T& __t,
  basic_format_context<_Out, _CharT>& __fc) const;

Furthermore we _CharT with __format::__char (char or wchar_t),

PR libstdc++/119517

libstdc++-v3/ChangeLog:

* include/bits/chrono_io.h (formatter):
Add __format::__char for _CharT and adjust parse and format
method signatures.
* testsuite/std/time/format/pr119517.cc: New test.

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

Diff:
---
 libstdc++-v3/include/bits/chrono_io.h  | 448 ++---
 libstdc++-v3/testsuite/std/time/format/pr119517.cc |  43 ++
 2 files changed, 261 insertions(+), 230 deletions(-)

diff --git a/libstdc++-v3/include/bits/chrono_io.h 
b/libstdc++-v3/include/bits/chrono_io.h
index c55b651d0491..3a5bc5695fb0 100644
--- a/libstdc++-v3/include/bits/chrono_io.h
+++ b/libstdc++-v3/include/bits/chrono_io.h
@@ -1785,277 +1785,272 @@ namespace __format
   __format::__formatter_chrono<_CharT> _M_f;
 };
 
-  template
+  template<__format::__char _CharT>
 struct formatter
 {
-  template
-   constexpr typename _ParseContext::iterator
-   parse(_ParseContext& __pc)
-   { return _M_f._M_parse(__pc, __format::_Day); }
+  constexpr typename basic_format_parse_context<_CharT>::iterator
+  parse(basic_format_parse_context<_CharT>& __pc)
+  { return _M_f._M_parse(__pc, __format::_Day); }
 
-  template
-   typename _FormatContext::iterator
-   format(const chrono::day& __t, _FormatContext& __fc) const
+  template
+   typename basic_format_context<_Out, _CharT>::iterator
+   format(const chrono::day& __t,
+  basic_format_context<_Out, _CharT>& __fc) const
{ return _M_f._M_format(__t, __fc); }
 
 private:
   __format::__formatter_chrono<_CharT> _M_f;
 };
 
-  template
+  template<__format::__char _CharT>
 struct formatter
 {
-  template
-   constexpr typename _ParseContext::iterator
-   parse(_ParseContext& __pc)
-   { return _M_f._M_parse(__pc, __format::_Month); }
+  constexpr typename basic_format_parse_context<_CharT>::iterator
+  parse(basic_format_parse_context<_CharT>& __pc)
+  { return _M_f._M_parse(__pc, __format::_Month); }
 
-  template
-   typename _FormatContext::iterator
-   format(const chrono::month& __t, _FormatContext& __fc) const
+  template
+   typename basic_format_context<_Out, _CharT>::iterator
+   format(const chrono::month& __t,
+  basic_format_context<_Out, _CharT>& __fc) const
{ return _M_f._M_format(__t, __fc); }
 
 private:
   __format::__formatter_chrono<_CharT> _M_f;
 };
 
-  template
+  template<__format::__char _CharT>
 struct formatter
 {
-  template
-   constexpr typename _ParseContext::iterator
-   parse(_ParseContext& __pc)
-   { return _M_f._M_parse(__pc, __format::_Year); }
+  constexpr typename basic_format_parse_context<_CharT>::iterator
+  parse(basic_format_parse_context<_CharT>& __pc)
+  { return _M_f._M_parse(__pc, __format::_Year); }
 
-  template
-   typename _FormatContext::iterator
-   format(const chrono::year& __t, _FormatContext& __fc) const
+  template
+   typename basic_format_context<_Out, _CharT>::iterator
+   format(const chrono::year& __t,
+  basic_format_context<_Out, _CharT>& __fc) const
{ return _M_f._M_format(__t, __fc); }
 
 private:
   __format::__formatter_chrono<_CharT> _M_f;
 };
 
-  template
+  template<__format::__char _CharT>
 struct formatter
 {
-  template
-   constexpr typename _ParseContext::iterator
-   parse(_ParseContext& __pc)
-   { return _M_f._M_parse(__pc, __format::_Weekday); }
+  constexpr typename basic_format_parse_context<_CharT>::iterator
+  parse(basic_format_parse_context<_CharT>& __pc)
+  { return _M_f._M_parse(__pc, __format::_Weekday); }
 
-  template
-   typename _FormatContext::iterator
-   format(const chrono::weekday& __t, _FormatContext& __fc) const
+  template
+   typ

[gcc r15-9205] cobol: Eliminate cobolworx UAT errors when compiling with -Os

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

commit r15-9205-ge70fe5ed46ab129a8b1da961c47d3fb75b11b988
Author: Bob Dubner 
Date:   Fri Apr 4 13:48:58 2025 -0400

cobol: Eliminate cobolworx UAT errors when compiling with -Os

Testcases compiled with -Os were failing because static functions and static
variables were being optimized away, because of improper data type casts, 
and
because strict aliasing (whatever that is) was resulting in some loss of 
data.
These changes eliminate those known problems.

gcc/cobol

* cobol1.cc: (cobol_langhook_post_options): Implemented in order to 
set
flag_strict_aliasing to zero.
* genapi.cc: (set_user_status): Add comment.
(parser_intrinsic_subst): Expand SHOW_PARSE information.
(psa_global): Change names of return-code and upsi globals,
(psa_FldLiteralA): Set DECL_PRESERVE_P for FldLiteralA.
* gengen.cc: (show_type): Add POINTER type.
(gg_define_function_with_no_parameters): Set DECL_PRESERVE_P for 
COBOL-
style nested programs.  (gg_array_of_bytes): Fix bad cast.

libgcobol

* charmaps.h: Change __gg__data_return_code to 'short' type.
* constants.cc: Likewise.

Diff:
---
 gcc/cobol/cobol1.cc| 19 +++
 gcc/cobol/genapi.cc| 19 +--
 gcc/cobol/gengen.cc| 12 ++--
 libgcobol/charmaps.h   |  2 +-
 libgcobol/constants.cc | 10 +-
 5 files changed, 52 insertions(+), 10 deletions(-)

diff --git a/gcc/cobol/cobol1.cc b/gcc/cobol/cobol1.cc
index 0d07c460d416..d175ab11e3f2 100644
--- a/gcc/cobol/cobol1.cc
+++ b/gcc/cobol/cobol1.cc
@@ -646,6 +646,22 @@ cobol_get_sarif_source_language(const char *)
 return "cobol";
 }
 
+bool
+cobol_langhook_post_options(const char**)
+  {
+  // This flag, when set to 0, results in calls to gg_exit working properly.
+  // I don't know why it is necessary.  There is something going on with the
+  // definition of  __gg__data_return_code in constants.cc, and with how it
+  // is used through var_decl_return_code in genapi.cc.  Without it, the value
+  // delivered to exit@PLT is zero, and not __gg__data_return_code
+  // Dubner, 2025-04-04.
+  flag_strict_aliasing = 0;
+
+  /* Returning false means that the backend should be used.  */
+  return false;
+  }
+
+
 #undef LANG_HOOKS_BUILTIN_FUNCTION
 #undef LANG_HOOKS_GETDECLS
 #undef LANG_HOOKS_GLOBAL_BINDINGS_P
@@ -660,6 +676,7 @@ cobol_get_sarif_source_language(const char *)
 #undef LANG_HOOKS_TYPE_FOR_SIZE
 #undef LANG_HOOKS_SET_DECL_ASSEMBLER_NAME
 #undef LANG_HOOKS_GET_SARIF_SOURCE_LANGUAGE
+#undef LANG_HOOKS_POST_OPTIONS
 
 // We use GCC in the name, not GNU, as others do,
 // because "GnuCOBOL" refers to a different GNU project.
@@ -685,6 +702,8 @@ cobol_get_sarif_source_language(const char *)
 
 #define LANG_HOOKS_GET_SARIF_SOURCE_LANGUAGE cobol_get_sarif_source_language
 
+#define LANG_HOOKS_POST_OPTIONS cobol_langhook_post_options
+
 struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
 
 #include "gt-cobol-cobol1.h"
diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc
index a0da6476e2a8..fbe0bbc75dc8 100644
--- a/gcc/cobol/genapi.cc
+++ b/gcc/cobol/genapi.cc
@@ -8806,6 +8806,10 @@ static
 void set_user_status(struct cbl_file_t *file)
   {
   // This routine sets the user_status, if any, to the cblc_file_t::status
+
+  // We have to do it this way, because in the case where the file->user_status
+  // is in linkage, the memory addresses can end up pointing to the wrong
+  // places
   if(file->user_status)
 {
 cbl_field_t *user_status = cbl_field_of(symbol_at(file->user_status));
@@ -10111,6 +10115,13 @@ parser_intrinsic_subst( cbl_field_t *f,
   SHOW_PARSE
 {
 SHOW_PARSE_HEADER
+SHOW_PARSE_FIELD(" TO ", f)
+for(size_t i=0; iname, "RETURN-CODE") == 0 )
 {
-strcpy(ach, "__gg___11_return_code6");
+strcpy(ach, "__gg__return_code");
 }
 
   if( strcmp(new_var->name, "UPSI-0") == 0 )
 {
-strcpy(ach, "__gg___6_upsi_04");
+strcpy(ach, "__gg__upsi");
 }
 
   new_var->var_decl_node = gg_declare_variable(cblc_field_type_node, ach, 
NULL, vs_external_reference);
@@ -16156,6 +16167,10 @@ psa_FldLiteralA(struct cbl_field_t *field )
 field->data.initial,
 NULL_TREE,
 field->var_decl_node);
+TREE_READONLY(field->var_decl_node) = 1;
+TREE_USED(field->var_decl_node) = 1;
+TREE_STATIC(field->var_decl_node) = 1;
+DECL_PRESERVE_P (field->var_decl_node) = 1;
 nvar += 1;
 }
   TRACE1
diff --git a/gcc/cobol/gengen.cc b/gcc/cobol/gengen.cc
index ffb64c8993d9..e7a4e3c51653 100644
--- a/gcc/cobol/gengen.cc
+++ b/gcc/cobol/gengen.cc
@@ -375,6 +375,10 @@ show_type(tree type)
   static char ach[1024];
   switch( TREE_CODE(type) )
 {
+case POINTER_TYPE:
+  sprintf(ach, "POINTER");
+  break;
+
 case VOID_TYPE:
  

[gcc r12-11022] tree-optimization/116481 - avoid building function_type[]

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

commit r12-11022-gf1989b50a9141b5bf62275d92b2fa28e9d82ca8b
Author: Richard Biener 
Date:   Sun Oct 13 11:42:27 2024 +0200

tree-optimization/116481 - avoid building function_type[]

The following avoids building an array type with function or method
element type during diagnosing an array bound violation as this
will result in an error, rejecting a program with a not too useful
error message.  Instead build such array type manually.

PR tree-optimization/116481
* pointer-query.cc (build_printable_array_type):
Build an array types with function or method element type
manually to avoid bogus diagnostic.

* gcc.dg/pr116481.c: New testcase.

(cherry picked from commit 1506027347776a2f6ec5b92d56ef192e85944e2e)

Diff:
---
 gcc/pointer-query.cc| 11 +++
 gcc/testsuite/gcc.dg/pr116481.c | 13 +
 2 files changed, 24 insertions(+)

diff --git a/gcc/pointer-query.cc b/gcc/pointer-query.cc
index 9a12bb27c342..fb63546d5638 100644
--- a/gcc/pointer-query.cc
+++ b/gcc/pointer-query.cc
@@ -2574,6 +2574,17 @@ array_elt_at_offset (tree artype, HOST_WIDE_INT off,
 tree
 build_printable_array_type (tree eltype, unsigned HOST_WIDE_INT nelts)
 {
+  /* Cannot build an array type of functions or methods without
+ an error diagnostic.  */
+  if (FUNC_OR_METHOD_TYPE_P (eltype))
+{
+  tree arrtype = make_node (ARRAY_TYPE);
+  TREE_TYPE (arrtype) = eltype;
+  TYPE_SIZE (arrtype) = bitsize_zero_node;
+  TYPE_SIZE_UNIT (arrtype) = size_zero_node;
+  return arrtype;
+}
+
   if (TYPE_SIZE_UNIT (eltype)
   && TREE_CODE (TYPE_SIZE_UNIT (eltype)) == INTEGER_CST
   && !integer_zerop (TYPE_SIZE_UNIT (eltype))
diff --git a/gcc/testsuite/gcc.dg/pr116481.c b/gcc/testsuite/gcc.dg/pr116481.c
new file mode 100644
index ..3ee6d7470876
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr116481.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -Warray-bounds" } */
+
+extern void tramp ();
+
+int is_trampoline (void* function) /* { dg-bogus "arrays of functions are not 
meaningful" } */
+{
+  void* tramp_address = tramp;
+  if (!(((unsigned long)function & 3) == 2))
+return 0;
+  return (((long *) ((char*)function - 2))[0]
+ == ((long *) ((char*)tramp_address-2))[0]); /* { dg-warning "outside 
array bounds" } */
+}


[gcc r15-9203] c++: constraint variable used in evaluated context [PR117849]

2025-04-04 Thread Patrick Palka via Gcc-cvs
https://gcc.gnu.org/g:6e973e87e3fec6f33e97edf8fce2fcd121e53961

commit r15-9203-g6e973e87e3fec6f33e97edf8fce2fcd121e53961
Author: Patrick Palka 
Date:   Fri Apr 4 14:03:58 2025 -0400

c++: constraint variable used in evaluated context [PR117849]

Here we wrongly reject the type-requirement at parse time due to its use
of the constraint variable 't' within a template argument (an evaluated
context).  Fix this simply by refining the "use of parameter outside
function body" error path to exclude constraint variables.

PR c++/104255 tracks the same issue for function parameters, but fixing
that would be more involved, requiring changes to the PARM_DECL case of
tsubst_expr.

PR c++/117849

gcc/cp/ChangeLog:

* semantics.cc (finish_id_expression_1): Allow use of constraint
variable outside an unevaluated context.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/concepts-requires41.C: New test.

Reviewed-by: Jason Merrill 

Diff:
---
 gcc/cp/semantics.cc  |  1 +
 gcc/testsuite/g++.dg/cpp2a/concepts-requires41.C | 25 
 2 files changed, 26 insertions(+)

diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 7d8beb8833d3..a10ef34383c2 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -4755,6 +4755,7 @@ finish_id_expression_1 (tree id_expression,
 body, except inside an unevaluated context (i.e. decltype).  */
   if (TREE_CODE (decl) == PARM_DECL
  && DECL_CONTEXT (decl) == NULL_TREE
+ && !CONSTRAINT_VAR_P (decl)
  && !cp_unevaluated_operand
  && !processing_contract_condition
  && !processing_omp_trait_property_expr)
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-requires41.C 
b/gcc/testsuite/g++.dg/cpp2a/concepts-requires41.C
new file mode 100644
index ..28c976116cad
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-requires41.C
@@ -0,0 +1,25 @@
+// PR c++/117849
+// { dg-do compile { target c++20 } }
+
+template
+struct array {
+  constexpr int size() const { return N; }
+};
+
+struct vector {
+  int _size = 3;
+  constexpr int size() const { return _size; }
+};
+
+template
+struct integral_constant {
+  constexpr operator int() const { return N; }
+};
+
+template
+concept StaticSize = requires (T& t) {
+  typename integral_constant;
+};
+
+static_assert(StaticSize>);
+static_assert(!StaticSize);


[gcc r15-9204] rtlanal, i386: Adjust pattern_cost and x86 constant cost [PR115910]

2025-04-04 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:0520ef274762f100c7297efc4f230fcfc6486987

commit r15-9204-g0520ef274762f100c7297efc4f230fcfc6486987
Author: Jakub Jelinek 
Date:   Fri Apr 4 20:07:37 2025 +0200

rtlanal, i386: Adjust pattern_cost and x86 constant cost [PR115910]

Below is an attempt to fix up RTX costing P1 caused by r15-775
https://gcc.gnu.org/pipermail/gcc-patches/2024-May/thread.html#652446
@@ -21562,7 +21562,8 @@ ix86_rtx_costs (rtx x, machine_mode mode, int 
outer_code_i, int opno,
   if (x86_64_immediate_operand (x, VOIDmode))
*total = 0;
  else
-   *total = 1;
+   /* movabsq is slightly more expensive than a simple instruction. */
+   *total = COSTS_N_INSNS (1) + 1;
   return true;

 case CONST_DOUBLE:
change.  In my understanding this was partially trying to workaround
weird code in pattern_cost, which uses
  return cost > 0 ? cost : COSTS_N_INSNS (1);
That doesn't make sense to me.  All costs smaller than COSTS_N_INSNS (1)
mean we need to have at least one instruction there which has the
COSTS_N_INSNS (1) minimal cost.  So special casing just cost 0 for the
really cheap immediates which can be used pretty much everywhere but not
ones which have just tiny bit larger cost than that (1, 2 or 3) is just
weird.

So, the following patch changes that to MAX (COSTS_N_INSNS (1), cost)
which doesn't have this weird behavior where set_src_cost 0 is considered
more expensive than set_src_cost 1.

Note, pattern_cost isn't the only spot where costs are computed and normally
we often sum the subcosts of different parts of a pattern or just query
rtx costs of different parts of subexpressions, so the jump from
1 to 5 is quite significant.

Additionally, x86_64 doesn't have just 2 kinds of constants with different
costs, it has 3, signed 32-bit ones are the ones which can appear in
almost all instructions and so using cost of 0 for those looks best,
then unsigned 32-bit ones which can be done with still cheap movl
instruction (and I think some others too) and finally full 64-bit ones
which can be done only with a single movabsq instruction and are quite
costly both in instruction size and even more expensive to execute.

The following patch attempts to restore the behavior of GCC 14 with the
pattern_cost hunk fixed for the unsigned 32-bit ones and only keeps the
bigger cost for the 64-bit ones.

2025-04-04  Jakub Jelinek  

PR target/115910
* rtlanal.cc (pattern_cost): Return at least COSTS_N_INSNS (1)
rather than just COSTS_N_INTNS (1) for cost <= 0.
* config/i386/i386.cc (ix86_rtx_costs): Set *total to 1 for
TARGET_64BIT x86_64_zext_immediate_operand constants.

* gcc.target/i386/pr115910.c: New test.

Diff:
---
 gcc/config/i386/i386.cc  |  6 +-
 gcc/rtlanal.cc   |  2 +-
 gcc/testsuite/gcc.target/i386/pr115910.c | 20 
 3 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
index f38e3db41fa9..4f8380c4a58b 100644
--- a/gcc/config/i386/i386.cc
+++ b/gcc/config/i386/i386.cc
@@ -21883,7 +21883,11 @@ ix86_rtx_costs (rtx x, machine_mode mode, int 
outer_code_i, int opno,
 case SYMBOL_REF:
   if (x86_64_immediate_operand (x, VOIDmode))
*total = 0;
- else
+  else if (TARGET_64BIT && x86_64_zext_immediate_operand (x, VOIDmode))
+   /* Consider the zext constants slightly more expensive, as they
+  can't appear in most instructions.  */
+   *total = 1;
+  else
/* movabsq is slightly more expensive than a simple instruction. */
*total = COSTS_N_INSNS (1) + 1;
   return true;
diff --git a/gcc/rtlanal.cc b/gcc/rtlanal.cc
index 7ad67afb9fe8..86a5e4733088 100644
--- a/gcc/rtlanal.cc
+++ b/gcc/rtlanal.cc
@@ -5772,7 +5772,7 @@ pattern_cost (rtx pat, bool speed)
 return 0;
 
   cost = set_src_cost (SET_SRC (set), GET_MODE (SET_DEST (set)), speed);
-  return cost > 0 ? cost : COSTS_N_INSNS (1);
+  return MAX (COSTS_N_INSNS (1), cost);
 }
 
 /* Calculate the cost of a single instruction.  A return value of zero
diff --git a/gcc/testsuite/gcc.target/i386/pr115910.c 
b/gcc/testsuite/gcc.target/i386/pr115910.c
new file mode 100644
index ..5f1cd9aa010a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr115910.c
@@ -0,0 +1,20 @@
+/* PR target/115910 */
+/* { dg-do compile { target { ! ia32 } } } */
+/* { dg-options "-O2 -march=x86-64 -mtune=generic -masm=att" } */
+/* { dg-final { scan-assembler-times {\timulq\t} 2 } } */
+/* { dg-final { scan-assembler-times {\tshrq\t\$33,} 2 } } */
+/* { dg-final { scan-assembler-not {\tsarl\t} } } */
+
+int
+foo (int x)
+{
+  if (x < 0) 
+__builtin_unreachable ();
+  return x / 3U;
+}
+
+int
+bar (int x)
+{
+  re

[gcc r14-11511] libstdc++: Fix ranges::iter_move handling of rvalues [PR106612]

2025-04-04 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:58a2b7f05587485f846490e21e4de3d51d83afb9

commit r14-11511-g58a2b7f05587485f846490e21e4de3d51d83afb9
Author: Jonathan Wakely 
Date:   Fri Feb 28 21:44:41 2025 +

libstdc++: Fix ranges::iter_move handling of rvalues [PR106612]

The specification for std::ranges::iter_move apparently requires us to
handle types which do not satisfy std::indirectly_readable, for example
with overloaded operator* which behaves differently for different value
categories.

libstdc++-v3/ChangeLog:

PR libstdc++/106612
* include/bits/iterator_concepts.h (_IterMove::__iter_ref_t):
New alias template.
(_IterMove::__result): Use __iter_ref_t instead of
std::iter_reference_t.
(_IterMove::__type): Remove incorrect __dereferenceable
constraint.
(_IterMove::operator()): Likewise. Add correct constraints. Use
__iter_ref_t instead of std::iter_reference_t. Forward parameter
as correct value category.
(iter_swap): Add comments.
* testsuite/24_iterators/customization_points/iter_move.cc: Test
that iter_move is found by ADL and that rvalue arguments are
handled correctly.

Reviewed-by: Patrick Palka 

(cherry picked from commit a8ee522c5923ba17851e4b71316a2dff19d6368f)

Diff:
---
 libstdc++-v3/include/bits/iterator_concepts.h  | 36 +---
 .../24_iterators/customization_points/iter_move.cc | 95 ++
 2 files changed, 120 insertions(+), 11 deletions(-)

diff --git a/libstdc++-v3/include/bits/iterator_concepts.h 
b/libstdc++-v3/include/bits/iterator_concepts.h
index e61bc3b87f31..acd8e9d5ae11 100644
--- a/libstdc++-v3/include/bits/iterator_concepts.h
+++ b/libstdc++-v3/include/bits/iterator_concepts.h
@@ -98,32 +98,42 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   namespace ranges
   {
 /// @cond undocumented
+// Implementation of std::ranges::iter_move, [iterator.cust.move].
 namespace __imove
 {
   void iter_move() = delete;
 
+  // Satisfied if _Tp is a class or enumeration type and iter_move
+  // can be found by argument-dependent lookup.
   template
concept __adl_imove
  = (std::__detail::__class_or_enum>)
- && requires(_Tp&& __t) { iter_move(static_cast<_Tp&&>(__t)); };
+ && requires(_Tp&& __t) { iter_move(static_cast<_Tp&&>(__t)); };
 
   struct _IterMove
   {
   private:
+   // The type returned by dereferencing a value of type _Tp.
+   // Unlike iter_reference_t this preserves the value category of _Tp.
+   template
+ using __iter_ref_t = decltype(*std::declval<_Tp>());
+
template
  struct __result
- { using type = iter_reference_t<_Tp>; };
+ { using type = __iter_ref_t<_Tp>; };
 
+   // Use iter_move(E) if that works.
template
  requires __adl_imove<_Tp>
  struct __result<_Tp>
  { using type = decltype(iter_move(std::declval<_Tp>())); };
 
+   // Otherwise, if *E if an lvalue, use std::move(*E).
template
  requires (!__adl_imove<_Tp>)
- && is_lvalue_reference_v>
+   && is_lvalue_reference_v<__iter_ref_t<_Tp>>
  struct __result<_Tp>
- { using type = remove_reference_t>&&; };
+ { using type = remove_reference_t<__iter_ref_t<_Tp>>&&; };
 
template
  static constexpr bool
@@ -137,21 +147,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   public:
// The result type of iter_move(std::declval<_Tp>())
-   template
+   template
  using __type = typename __result<_Tp>::type;
 
-   template
- [[nodiscard]]
+   template
+ requires __adl_imove<_Tp> || requires { typename __iter_ref_t<_Tp>; }
  constexpr __type<_Tp>
- operator()(_Tp&& __e) const
+ operator() [[nodiscard]] (_Tp&& __e) const
  noexcept(_S_noexcept<_Tp>())
  {
if constexpr (__adl_imove<_Tp>)
  return iter_move(static_cast<_Tp&&>(__e));
-   else if constexpr (is_lvalue_reference_v>)
- return static_cast<__type<_Tp>>(*__e);
+   else if constexpr (is_lvalue_reference_v<__iter_ref_t<_Tp>>)
+ return std::move(*static_cast<_Tp&&>(__e));
else
- return *__e;
+ return *static_cast<_Tp&&>(__e);
  }
   };
 } // namespace __imove
@@ -162,6 +172,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 }
   } // namespace ranges
 
+  /// The result type of ranges::iter_move(std::declval<_Tp&>())
   template<__detail::__dereferenceable _Tp>
 requires 
__detail::__can_reference>
 using iter_rvalue_reference_t = ranges::__imove::_IterMove::__type<_Tp&>;
@@ -856,11 +867,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 namespace ranges
 {
   /// @cond undocumented
+  // Implementation of std::ranges::iter_swap, [iterator.cu

[gcc r15-9171] [testsuite] [riscv] limit vwaddsub-1.c to rv64

2025-04-04 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:366dd47dc560a37cdf01a4c49a446596564419a0

commit r15-9171-g366dd47dc560a37cdf01a4c49a446596564419a0
Author: Alexandre Oliva 
Date:   Thu Apr 3 03:06:50 2025 -0300

[testsuite] [riscv] limit vwaddsub-1.c to rv64

The desired vw{add,sub}.wx instructions don't come up on rv32 for the
first two functions, we get v{add,sub}.vx instead.

I suppose this is an oversight, and something about the test is meant
for rv64 only, but the fact that the instruction is spelled out in the
intrinsic name and a different instruction is generated suggests
something may be wrong after all.


for  gcc/testsuite/ChangeLog

* gcc.target/riscv/rvv/base/vwaddsub-1.c: Require rv64.

Diff:
---
 gcc/testsuite/gcc.target/riscv/rvv/base/vwaddsub-1.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/vwaddsub-1.c 
b/gcc/testsuite/gcc.target/riscv/rvv/base/vwaddsub-1.c
index 6e027a555f37..84d3c4cb4c71 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/base/vwaddsub-1.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/vwaddsub-1.c
@@ -1,4 +1,4 @@
-/* { dg-do compile { target { ! riscv_abi_e } } } */
+/* { dg-do compile { target { { ! riscv_abi_e } && rv64 } } } */
 /* { dg-add-options riscv_v } */
 /* { dg-additional-options "-std=gnu99 -O3 -fno-schedule-insns 
-fno-schedule-insns2" } */


[gcc r15-9069] libstdc++: Make operator== for std::tuple convert to bool [PR119545]

2025-04-04 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:b9adf3a4c8112df1d74440157f578a8344ebe166

commit r15-9069-gb9adf3a4c8112df1d74440157f578a8344ebe166
Author: Jonathan Wakely 
Date:   Mon Mar 31 12:17:02 2025 +0100

libstdc++: Make operator== for std::tuple convert to bool [PR119545]

The boolean-testable requirements don't require the type to be copyable,
so we need to convert to bool before it might need to be copied.

libstdc++-v3/ChangeLog:

PR libstdc++/119545
* include/std/tuple (operator==): Convert comparison results to
bool.
* testsuite/20_util/tuple/comparison_operators/119545.cc: New
test.

Reviewed-by: Tomasz Kamiński 

Diff:
---
 libstdc++-v3/include/std/tuple |  2 +-
 .../20_util/tuple/comparison_operators/119545.cc   | 24 ++
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple
index d3deb7bc1241..2e69af13a98b 100644
--- a/libstdc++-v3/include/std/tuple
+++ b/libstdc++-v3/include/std/tuple
@@ -2534,7 +2534,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 {
   return [&](index_sequence<_Inds...>) {
// Fold == over the tuples until non-equal elements are found.
-   return ((std::get<_Inds>(__t) == std::get<_Inds>(__u)) && ...);
+   return (bool(std::get<_Inds>(__t) == std::get<_Inds>(__u)) && ...);
   }(index_sequence_for<_Tps...>{});
 }
 
diff --git 
a/libstdc++-v3/testsuite/20_util/tuple/comparison_operators/119545.cc 
b/libstdc++-v3/testsuite/20_util/tuple/comparison_operators/119545.cc
new file mode 100644
index ..3a65ef53b016
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/tuple/comparison_operators/119545.cc
@@ -0,0 +1,24 @@
+// { dg-do compile { target c++11 } }
+// Bug libstdc++/119545
+// tuple::operator==()'s help lambda does not specify return type as bool
+
+#include 
+
+void
+test_pr119545()
+{
+  struct Bool {
+Bool() = default;
+Bool(const Bool&) = delete;
+operator bool() const { return true; }
+  };
+
+  static Bool b;
+
+  struct Object {
+const Bool& operator==(const Object&) const { return b; }
+  };
+
+  std::tuple t;
+  (void) (t == t);
+}


[gcc r15-9167] LoongArch: Make gen-evolution.awk compatible with FreeBSD awk

2025-04-04 Thread Xi Ruoyao via Gcc-cvs
https://gcc.gnu.org/g:92ca72b41a74aef53978cadbda33dd38b69d3ed3

commit r15-9167-g92ca72b41a74aef53978cadbda33dd38b69d3ed3
Author: Xi Ruoyao 
Date:   Wed Apr 2 10:41:18 2025 +0800

LoongArch: Make gen-evolution.awk compatible with FreeBSD awk

Avoid using gensub that FreeBSD awk lacks, use gsub and split those each
of gawk, mawk, and FreeBSD awk provides.

Reported-by: mp...@vip.163.com
Link: https://man.freebsd.org/cgi/man.cgi?query=awk

gcc/ChangeLog:

* config/loongarch/genopts/gen-evolution.awk: Avoid using gensub
that FreeBSD awk lacks.

Diff:
---
 gcc/config/loongarch/genopts/gen-evolution.awk | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/gcc/config/loongarch/genopts/gen-evolution.awk 
b/gcc/config/loongarch/genopts/gen-evolution.awk
index bf16b26760e0..142b658fe7a3 100644
--- a/gcc/config/loongarch/genopts/gen-evolution.awk
+++ b/gcc/config/loongarch/genopts/gen-evolution.awk
@@ -33,10 +33,12 @@ BEGIN {
 {
 cpucfg_word[NR] = $1
 cpucfg_bit_in_word[NR] = $2
-name[NR] = gensub(/-/, "_", "g", $3)
+name[NR] = $3
+gsub("-", "_", name[NR])
 name_capitalized[NR] = toupper(name[NR])
-isa_version_major[NR] = gensub(/^([1-9][0-9]*)\.([0-9]+)$/, "\\1", 1, $4)
-isa_version_minor[NR] = gensub(/^([1-9][0-9]*)\.([0-9]+)$/, "\\2", 1, $4)
+split($4, isa_ver, "\\.")
+isa_version_major[NR] = isa_ver[1]
+isa_version_minor[NR] = isa_ver[2]
 
 $1 = $2 = $3 = $4 = ""
 sub (/^\s*/, "")


[gcc r15-9184] vect: Relax scan-tree-dump strict pattern matching [PR118597]

2025-04-04 Thread Victor Do Nascimento via Gcc-cvs
https://gcc.gnu.org/g:701bc728c31a84b6eff7d77f48c6ab270af007cf

commit r15-9184-g701bc728c31a84b6eff7d77f48c6ab270af007cf
Author: Victor Do Nascimento 
Date:   Wed Apr 2 14:22:31 2025 +0100

vect: Relax scan-tree-dump strict pattern matching [PR118597]

Using specific SSA names in pattern matching in `dg-final' makes tests
"unstable", in that changes in passes prior to the pass whose dump is
analyzed in the particular test may change the numbering of the SSA
variables, causing the test to start failing spuriously.

We thus switch from specific SSA names to the use of a multi-line
regular expression making use of capture groups for matching particular
variables across different statements, ensuring the test will pass
more consistently across different versions of GCC.

PR testsuite/118597

gcc/testsuite/ChangeLog:

* gcc.dg/vect/vect-fncall-mask.c: Update test directives.

Diff:
---
 gcc/testsuite/gcc.dg/vect/vect-fncall-mask.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/vect/vect-fncall-mask.c 
b/gcc/testsuite/gcc.dg/vect/vect-fncall-mask.c
index 554488e06308..ba1886da5ca9 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-fncall-mask.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-fncall-mask.c
@@ -1,7 +1,7 @@
 /* { dg-do compile { target { aarch64*-*-* } } } */
-/* { dg-additional-options "-march=armv8.2-a+sve -fdump-tree-ifcvt-raw -Ofast" 
{ target { aarch64*-*-* } } } */
+/* { dg-additional-options "-march=armv8.2-a+sve -fdump-tree-ifcvt -Ofast" { 
target { aarch64*-*-* } } } */
 
-extern int __attribute__ ((simd, const)) fn (int);
+extern int __attribute__ ((simd, const)) fn (float);
 
 const int N = 20;
 const float lim = 101.0;
@@ -26,6 +26,4 @@ int main (void)
   return (0);
 }
 
-/* { dg-final { scan-tree-dump {gimple_assign } ifcvt } } */
-/* { dg-final { scan-tree-dump {gimple_assign } ifcvt } } */
-/* { dg-final { scan-tree-dump {gimple_call <.MASK_CALL, _3, fn, _2, _34>} 
ifcvt } } */
+/* { dg-final { scan-tree-dump {(_\d+) = (_\d+) > 1.01e\+2;\n\s*(_\d+) = 
~\1;\n\s*_\d+ = .MASK_CALL \(fn, \2, \3\);} ifcvt } } */


[gcc r14-11508] libstdc++: Fix bogus -Wstringop-overflow in std::vector::insert [PR117983]

2025-04-04 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:4366711d2d66ea9a2d4fe9dd112795ef0c6f785c

commit r14-11508-g4366711d2d66ea9a2d4fe9dd112795ef0c6f785c
Author: Jonathan Wakely 
Date:   Fri Mar 28 22:00:38 2025 +

libstdc++: Fix bogus -Wstringop-overflow in std::vector::insert [PR117983]

This was fixed on trunk by r15-4473-g3abe751ea86e34, but that isn't
suitable for backporting. Instead, just add another unreachable
condition in std::vector::_M_range_insert so the compiler knows this
memcpy doesn't use a length originating from a negative ptrdiff_t
converted to a very positive size_t.

libstdc++-v3/ChangeLog:

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.

Reviewed-by: Tomasz Kamiński 

(cherry picked from commit 878812b6f6905774ab37cb78903e3e11bf1c508c)

Diff:
---
 libstdc++-v3/include/bits/vector.tcc|  2 ++
 .../23_containers/vector/modifiers/insert/117983.cc | 17 +
 2 files changed, 19 insertions(+)

diff --git a/libstdc++-v3/include/bits/vector.tcc 
b/libstdc++-v3/include/bits/vector.tcc
index 0bd1ae411028..200a75a19c3e 100644
--- a/libstdc++-v3/include/bits/vector.tcc
+++ b/libstdc++-v3/include/bits/vector.tcc
@@ -1005,6 +1005,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
// reachable.
pointer __old_start = this->_M_impl._M_start;
pointer __old_finish = this->_M_impl._M_finish;
+   if ((__old_finish - __old_start) < 0)
+ __builtin_unreachable();
 
const size_type __len =
  _M_check_len(__n, "vector::_M_range_insert");
diff --git 
a/libstdc++-v3/testsuite/23_containers/vector/modifiers/insert/117983.cc 
b/libstdc++-v3/testsuite/23_containers/vector/modifiers/insert/117983.cc
new file mode 100644
index ..e6027a677eed
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/insert/117983.cc
@@ -0,0 +1,17 @@
+// { dg-options "-O3 -Werror=stringop-overflow" }
+// { dg-do compile }
+
+// PR libstdc++/117983
+// -Wstringop-overflow false positive for __builtin_memmove from vector::insert
+
+#include 
+
+typedef std::vector bytes;
+
+void push(bytes chunk, bytes& data) {
+  if (data.empty()) {
+data.swap(chunk);
+  } else {
+data.insert(data.end(), chunk.begin(), chunk.end());
+  }
+}


[gcc r15-9088] gccrs: Fix core library test with proper canonical path

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

commit r15-9088-ge545727c840b7359fa27543c598cfa6e4a32e0ff
Author: Pierre-Emmanuel Patry 
Date:   Wed Mar 26 15:22:28 2025 +0100

gccrs: Fix core library test with proper canonical path

Import from core library was wrong, it misses several crate directives
since we're no longer dealing with multiple files.

gcc/testsuite/ChangeLog:

* rust/compile/issue-2905-2.rs: Import from core library into a 
single
file misses the crate directives.

Signed-off-by: Pierre-Emmanuel Patry 

Diff:
---
 gcc/testsuite/rust/compile/issue-2905-2.rs | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/testsuite/rust/compile/issue-2905-2.rs 
b/gcc/testsuite/rust/compile/issue-2905-2.rs
index 83c54ed92e5f..1c9516df9461 100644
--- a/gcc/testsuite/rust/compile/issue-2905-2.rs
+++ b/gcc/testsuite/rust/compile/issue-2905-2.rs
@@ -17,10 +17,10 @@ pub mod core {
 }
 
 pub mod slice {
-use core::marker::PhantomData;
-use core::option::Option;
+use crate::core::marker::PhantomData;
+use crate::core::option::Option;
 
-impl core::iter::IntoIterator for &[T] {
+impl crate::core::iter::IntoIterator for &[T] {
 type Item = &T;
 type IntoIter = Weird;
 
@@ -108,7 +108,7 @@ pub mod core {
 }
 
 pub mod iter {
-use option::Option;
+use crate::core::option::Option;
 
 pub trait IntoIterator {
 type Item;


[gcc r15-9108] gccrs: Fix SEGV when type path resolver fails outright

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

commit r15-9108-gc5d96fd5279fee47f455bd760fb0d1198a782e1e
Author: Philip Herron 
Date:   Fri Mar 28 18:59:33 2025 +

gccrs: Fix SEGV when type path resolver fails outright

When we resolve paths we resolve to Types first we walk each segment to
the last module which has no type but then in the event that the child
of a module is not found we have a null root_tyty which needs to be caught
and turned into an ErrorType node.

Fixes Rust-GCC#3613

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-type.cc 
(TypeCheckType::resolve_root_path):
catch nullptr root_tyty

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron 

Diff:
---
 gcc/rust/typecheck/rust-hir-type-check-type.cc |  7 +++
 gcc/testsuite/rust/compile/issue-3613.rs   | 18 ++
 2 files changed, 25 insertions(+)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc 
b/gcc/rust/typecheck/rust-hir-type-check-type.cc
index e56fa397e2af..54f50ec41f18 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc
@@ -360,6 +360,13 @@ TypeCheckType::resolve_root_path (HIR::TypePath &path, 
size_t *offset,
 seg->as_string ().c_str ());
  return new TyTy::ErrorType (path.get_mappings ().get_hirid ());
}
+ else if (root_tyty == nullptr)
+   {
+ rust_error_at (seg->get_locus (),
+"unknown reference for resolved name: %qs",
+seg->as_string ().c_str ());
+ return new TyTy::ErrorType (path.get_mappings ().get_hirid ());
+   }
  return root_tyty;
}
 
diff --git a/gcc/testsuite/rust/compile/issue-3613.rs 
b/gcc/testsuite/rust/compile/issue-3613.rs
new file mode 100644
index ..f2e10921f671
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3613.rs
@@ -0,0 +1,18 @@
+mod m1 {
+pub enum Baz4 {
+foo1,
+foo2,
+}
+}
+
+fn bar(x: m1::foo) {
+// { dg-error "unknown reference for resolved name: .foo." "" { target 
*-*-* } .-1 }
+match x {
+m1::foo::foo1 => {}
+// { dg-error "failed to type resolve root segment" "" { target *-*-* 
} .-1 }
+m1::NodePosition::foo2 => {}
+// { dg-error "failed to type resolve root segment" "" { target *-*-* 
} .-1 }
+}
+}
+
+pub fn main() {}


[gcc r15-8689] toplevel, Makefile: Add missing CXX_FOR_TARGET export [PR88319].

2025-04-04 Thread Iain D Sandoe via Gcc-cvs
https://gcc.gnu.org/g:70bc553e1b565d2e162894ea29a223b44e9133e3

commit r15-8689-g70bc553e1b565d2e162894ea29a223b44e9133e3
Author: Iain Sandoe 
Date:   Sun Mar 23 11:45:17 2025 +

toplevel, Makefile: Add missing CXX_FOR_TARGET export [PR88319].

Actually, the issue is not local to the libitm case, it currently affects
any 'cxx=true' top-level configured target library.

The issue is a missing export of CXX_FOR_TARGET.

PR libitm/88319

ChangeLog:

* Makefile.in: Regenerate.
* Makefile.tpl: Add CXX_FOR_TARGET to NORMAL_TARGET_EXPORTS.

Signed-off-by: Iain Sandoe 

Diff:
---
 Makefile.in  | 1 +
 Makefile.tpl | 1 +
 2 files changed, 2 insertions(+)

diff --git a/Makefile.in b/Makefile.in
index 87880c62ad20..a5e6e11aece0 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -339,6 +339,7 @@ RAW_CXX_TARGET_EXPORTS = \
 
 NORMAL_TARGET_EXPORTS = \
$(BASE_TARGET_EXPORTS) \
+   CXX_FOR_TARGET="$(CXX_FOR_TARGET)"; export CXX_FOR_TARGET; \
CXX="$(CXX_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS"; export CXX;
 
 # Where to find GMP
diff --git a/Makefile.tpl b/Makefile.tpl
index da38dca697ad..7dccf91ed8ec 100644
--- a/Makefile.tpl
+++ b/Makefile.tpl
@@ -342,6 +342,7 @@ RAW_CXX_TARGET_EXPORTS = \
 
 NORMAL_TARGET_EXPORTS = \
$(BASE_TARGET_EXPORTS) \
+   CXX_FOR_TARGET="$(CXX_FOR_TARGET)"; export CXX_FOR_TARGET; \
CXX="$(CXX_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS"; export CXX;
 
 # Where to find GMP


[gcc r15-8501] gccrs: Use name resolver 2.0 in CompileTraitItem

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

commit r15-8501-gf86a35bb1729ada851ab8b79a3fcee8b091976f9
Author: Owen Avery 
Date:   Sat Oct 26 19:53:42 2024 -0400

gccrs: Use name resolver 2.0 in CompileTraitItem

gcc/rust/ChangeLog:

* backend/rust-compile-implitem.cc
(CompileTraitItem::visit): Use name resolver 2.0 (when enabled)
to obtain canonical paths for instances of TraitItemConst and
TraitItemFunc.

Signed-off-by: Owen Avery 

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

diff --git a/gcc/rust/backend/rust-compile-implitem.cc 
b/gcc/rust/backend/rust-compile-implitem.cc
index 4c7d8e821a19..98337c8f9bb4 100644
--- a/gcc/rust/backend/rust-compile-implitem.cc
+++ b/gcc/rust/backend/rust-compile-implitem.cc
@@ -27,8 +27,22 @@ CompileTraitItem::visit (HIR::TraitItemConst &constant)
   rust_assert (concrete != nullptr);
   TyTy::BaseType *resolved_type = concrete;
 
-  auto canonical_path = ctx->get_mappings ().lookup_canonical_path (
-constant.get_mappings ().get_nodeid ());
+  tl::optional canonical_path;
+  if (flag_name_resolution_2_0)
+{
+  auto &nr_ctx
+   = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+  canonical_path = nr_ctx.values.to_canonical_path (
+   constant.get_mappings ().get_nodeid ());
+}
+  else
+{
+  canonical_path = ctx->get_mappings ().lookup_canonical_path (
+   constant.get_mappings ().get_nodeid ());
+}
+
+  rust_assert (canonical_path);
 
   HIR::Expr *const_value_expr = constant.get_expr ().get ();
   tree const_expr
@@ -75,8 +89,22 @@ CompileTraitItem::visit (HIR::TraitItemFunc &func)
   fntype->override_context ();
 }
 
-  auto canonical_path = ctx->get_mappings ().lookup_canonical_path (
-func.get_mappings ().get_nodeid ());
+  tl::optional canonical_path;
+  if (flag_name_resolution_2_0)
+{
+  auto &nr_ctx
+   = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+  canonical_path
+   = nr_ctx.values.to_canonical_path (func.get_mappings ().get_nodeid ());
+}
+  else
+{
+  canonical_path = ctx->get_mappings ().lookup_canonical_path (
+   func.get_mappings ().get_nodeid ());
+}
+
+  rust_assert (canonical_path);
 
   // FIXME: How do we get the proper visibility here?
   auto vis = HIR::Visibility (HIR::Visibility::VisType::PUBLIC);


[gcc r15-8632] gccrs: ast-builder: Add new methods around type paths.

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

commit r15-8632-gf6cdae89d1bcef7610471a6181c7cf2b41cae9af
Author: Arthur Cohen 
Date:   Thu Dec 26 22:09:46 2024 +

gccrs: ast-builder: Add new methods around type paths.

gcc/rust/ChangeLog:

* ast/rust-ast-builder.cc: New functions.
* ast/rust-ast-builder.h: Declare them.

Diff:
---
 gcc/rust/ast/rust-ast-builder.cc | 57 ++--
 gcc/rust/ast/rust-ast-builder.h  | 13 -
 2 files changed, 67 insertions(+), 3 deletions(-)

diff --git a/gcc/rust/ast/rust-ast-builder.cc b/gcc/rust/ast/rust-ast-builder.cc
index 55d59c94b52c..fe80924fece7 100644
--- a/gcc/rust/ast/rust-ast-builder.cc
+++ b/gcc/rust/ast/rust-ast-builder.cc
@@ -23,6 +23,7 @@
 #include "rust-expr.h"
 #include "rust-path.h"
 #include "rust-item.h"
+#include "rust-path.h"
 #include "rust-token.h"
 
 namespace Rust {
@@ -101,12 +102,27 @@ Builder::type_path_segment (std::string seg) const
 }
 
 std::unique_ptr
-Builder::generic_type_path_segment (std::string seg, GenericArgs args) const
+Builder::type_path_segment (LangItem::Kind lang_item) const
+{
+  return std::unique_ptr (
+new TypePathSegment (lang_item, loc));
+}
+
+std::unique_ptr
+Builder::type_path_segment_generic (std::string seg, GenericArgs args) const
 {
   return std::unique_ptr (
 new TypePathSegmentGeneric (PathIdentSegment (seg, loc), false, args, 
loc));
 }
 
+std::unique_ptr
+Builder::type_path_segment_generic (LangItem::Kind lang_item,
+   GenericArgs args) const
+{
+  return std::unique_ptr (
+new TypePathSegmentGeneric (lang_item, args, loc));
+}
+
 std::unique_ptr
 Builder::single_type_path (std::string type) const
 {
@@ -116,15 +132,52 @@ Builder::single_type_path (std::string type) const
   return std::unique_ptr (new TypePath (std::move (segments), loc));
 }
 
+std::unique_ptr
+Builder::single_type_path (LangItem::Kind lang_item) const
+{
+  return std::unique_ptr (new TypePath (lang_item, {}, loc));
+}
+
 std::unique_ptr
 Builder::single_generic_type_path (std::string type, GenericArgs args) const
 {
   auto segments = std::vector> ();
-  segments.emplace_back (generic_type_path_segment (type, args));
+  segments.emplace_back (type_path_segment_generic (type, args));
 
   return std::unique_ptr (new TypePath (std::move (segments), loc));
 }
 
+std::unique_ptr
+Builder::single_generic_type_path (LangItem::Kind lang_item,
+  GenericArgs args) const
+{
+  auto segments = std::vector> ();
+  segments.emplace_back (type_path_segment_generic (lang_item, args));
+
+  return std::unique_ptr (new TypePath (std::move (segments), loc));
+}
+
+TypePath
+Builder::type_path (std::unique_ptr &&segment) const
+{
+  auto segments = std::vector> ();
+  segments.emplace_back (std::move (segment));
+
+  return TypePath (std::move (segments), loc);
+}
+
+TypePath
+Builder::type_path (std::string type) const
+{
+  return type_path (type_path_segment (type));
+}
+
+TypePath
+Builder::type_path (LangItem::Kind lang_item) const
+{
+  return type_path (type_path_segment (lang_item));
+}
+
 PathInExpression
 Builder::path_in_expression (std::vector &&segments) const
 {
diff --git a/gcc/rust/ast/rust-ast-builder.h b/gcc/rust/ast/rust-ast-builder.h
index 36c0da2cff21..624cd715181d 100644
--- a/gcc/rust/ast/rust-ast-builder.h
+++ b/gcc/rust/ast/rust-ast-builder.h
@@ -114,16 +114,27 @@ public:
 
   /* And similarly for type path segments */
   std::unique_ptr type_path_segment (std::string seg) const;
+  std::unique_ptr
+  type_path_segment (LangItem::Kind lang_item) const;
 
   std::unique_ptr
-  generic_type_path_segment (std::string seg, GenericArgs args) const;
+  type_path_segment_generic (std::string seg, GenericArgs args) const;
+  std::unique_ptr
+  type_path_segment_generic (LangItem::Kind lang_item, GenericArgs args) const;
 
   /* Create a Type from a single string - the most basic kind of type in our 
AST
*/
   std::unique_ptr single_type_path (std::string type) const;
+  std::unique_ptr single_type_path (LangItem::Kind lang_item) const;
 
   std::unique_ptr single_generic_type_path (std::string type,
  GenericArgs args) const;
+  std::unique_ptr single_generic_type_path (LangItem::Kind lang_item,
+ GenericArgs args) const;
+
+  TypePath type_path (std::unique_ptr &&segment) const;
+  TypePath type_path (std::string type) const;
+  TypePath type_path (LangItem::Kind lang_item) const;
 
   /**
* Create a path in expression from multiple segments (`Clone::clone`). You


[gcc r15-9120] OpenMP: Reorder diagnostic in modify_call_for_omp_dispatch [PR119559]

2025-04-04 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:de92ac6f11e605987421fe1443b5b81ff172dbb6

commit r15-9120-gde92ac6f11e605987421fe1443b5b81ff172dbb6
Author: Tobias Burnus 
Date:   Tue Apr 1 10:29:27 2025 +0200

OpenMP: Reorder diagnostic in modify_call_for_omp_dispatch [PR119559]

gcc/ChangeLog:

PR middle-end/119559
* gimplify.cc (modify_call_for_omp_dispatch): Reorder checks to 
avoid
asserts and bogus diagnostic.

Diff:
---
 gcc/gimplify.cc | 36 
 1 file changed, 16 insertions(+), 20 deletions(-)

diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc
index a8399dc83631..02ad3981adf0 100644
--- a/gcc/gimplify.cc
+++ b/gcc/gimplify.cc
@@ -3933,25 +3933,9 @@ modify_call_for_omp_dispatch (tree expr, tree 
dispatch_clauses,
  the split between early/late resolution, etc instead of the code
  as written by the user.  */
   if (dispatch_interop)
-{
-  for (tree t = dispatch_interop; t; t = TREE_CHAIN (t))
-   if (OMP_CLAUSE_CODE (t) == OMP_CLAUSE_INTEROP)
- ninterop++;
-  if (nappend < ninterop)
-   {
- error_at (OMP_CLAUSE_LOCATION (dispatch_interop),
-   "number of list items in % clause (%d) "
-   "exceeds the number of % items (%d) for "
-   "% candidate %qD",
-   ninterop, nappend, fndecl);
- inform (dispatch_append_args
- ? EXPR_LOCATION (TREE_PURPOSE (dispatch_append_args))
- : DECL_SOURCE_LOCATION (fndecl),
- "% candidate %qD declared here",
- fndecl);
- ninterop = nappend;
-   }
-}
+for (tree t = dispatch_interop; t; t = TREE_CHAIN (t))
+  if (OMP_CLAUSE_CODE (t) == OMP_CLAUSE_INTEROP)
+   ninterop++;
   if (dispatch_interop && !dispatch_device_num)
 {
   gcc_checking_assert (ninterop > 1);
@@ -3959,7 +3943,19 @@ modify_call_for_omp_dispatch (tree expr, tree 
dispatch_clauses,
"the % clause must be present if the % "
"clause has more than one list item");
 }
-  else if (dispatch_append_args)
+  if (nappend < ninterop)
+{
+  error_at (OMP_CLAUSE_LOCATION (dispatch_interop),
+   "number of list items in % clause (%d) "
+   "exceeds the number of % items (%d) for "
+   "% candidate %qD", ninterop, nappend, fndecl);
+  inform (dispatch_append_args
+ ? EXPR_LOCATION (TREE_PURPOSE (dispatch_append_args))
+ : DECL_SOURCE_LOCATION (fndecl),
+ "% candidate %qD declared here", fndecl);
+  ninterop = nappend;
+}
+  if (dispatch_append_args)
 {
   tree *buffer = XALLOCAVEC (tree, nargs + nappend);
   tree arg = TYPE_ARG_TYPES (TREE_TYPE (fndecl));


[gcc r15-9113] MAINTAINERS: Update my name

2025-04-04 Thread Andrew Carlotti via Gcc-cvs
https://gcc.gnu.org/g:ca354b174e6dbdd1ee14b75d5e36b7e80ab78483

commit r15-9113-gca354b174e6dbdd1ee14b75d5e36b7e80ab78483
Author: Alice Carlotti 
Date:   Mon Mar 31 22:50:23 2025 +0100

MAINTAINERS: Update my name

ChangeLog:

* MAINTAINERS: Update my name.

Diff:
---
 MAINTAINERS | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 90c8e2aa9950..756227e0a506 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -396,7 +396,7 @@ Tobias Burnus   burnus  

 Adam Butcherabutcher
 Andrew Cagney   cagney  
 Paolo Carlini   paolo   
-Andrew Carlotti acarlotti   
+Alice Carlotti  acarlotti   
 Daniel Carrera  dcarrera
 Stephane Carrez ciceron 
 Gabriel Charettegchare  


[gcc r15-9206] libgcobol: Check if the target needs libm.

2025-04-04 Thread Iain D Sandoe via Gcc-cvs
https://gcc.gnu.org/g:8f1f35f1cb1c31e2822e241e56e0a04927e1b78a

commit r15-9206-g8f1f35f1cb1c31e2822e241e56e0a04927e1b78a
Author: Iain Sandoe 
Date:   Fri Mar 21 10:22:58 2025 +

libgcobol: Check if the target needs libm.

Use the libtool config check and $(LIBM).

libgcobol/ChangeLog:

* Makefile.am: Use $(LIBM) to add the math lib when
it is needed.
* Makefile.in: Regenerate.
* configure: Regenerate.
* configure.ac: Check if the target wants libm.

Signed-off-by: Iain Sandoe 

Diff:
---
 libgcobol/Makefile.am  |   2 +-
 libgcobol/Makefile.in  |   3 +-
 libgcobol/configure| 146 -
 libgcobol/configure.ac |   1 +
 4 files changed, 148 insertions(+), 4 deletions(-)

diff --git a/libgcobol/Makefile.am b/libgcobol/Makefile.am
index cafb733dde1d..45217421b1c0 100644
--- a/libgcobol/Makefile.am
+++ b/libgcobol/Makefile.am
@@ -48,7 +48,7 @@ libgcobol_la_LINK = $(LIBTOOL) --mode=link --tag=CXX $(CXX)   
\
-Wc,-shared-libgcc  \
-version-info $(LIBGCOBOL_VERSION)  \
-lstdc++\
-   $(LTLDFLAGS) $(LTLIBICONV)
+   $(LTLDFLAGS) $(LTLIBICONV) $(LIBM)
 
 WARN_CFLAGS = -W -Wall -Wwrite-strings
 
diff --git a/libgcobol/Makefile.in b/libgcobol/Makefile.in
index c4a562a80585..0f0d9b687f13 100644
--- a/libgcobol/Makefile.in
+++ b/libgcobol/Makefile.in
@@ -305,6 +305,7 @@ LD = @LD@
 LDFLAGS = @LDFLAGS@
 LIBGCOBOL_VERSION = @LIBGCOBOL_VERSION@
 LIBICONV = @LIBICONV@
+LIBM = @LIBM@
 LIBOBJS = @LIBOBJS@
 LIBS = @LIBS@
 LIBTOOL = @LIBTOOL@
@@ -428,7 +429,7 @@ libgcobol_la_LINK = $(LIBTOOL) --mode=link --tag=CXX $(CXX) 
\
-Wc,-shared-libgcc  \
-version-info $(LIBGCOBOL_VERSION)  \
-lstdc++\
-   $(LTLDFLAGS) $(LTLIBICONV)
+   $(LTLDFLAGS) $(LTLIBICONV) $(LIBM)
 
 WARN_CFLAGS = -W -Wall -Wwrite-strings
 AM_CXXFLAGS = $(CXXFLAGS_FOR_TARGET)
diff --git a/libgcobol/configure b/libgcobol/configure
index e12b72e0817c..e7b3b8308908 100755
--- a/libgcobol/configure
+++ b/libgcobol/configure
@@ -646,6 +646,7 @@ enable_static
 enable_shared
 ENABLE_DARWIN_AT_RPATH_FALSE
 ENABLE_DARWIN_AT_RPATH_TRUE
+LIBM
 CXXCPP
 OTOOL64
 OTOOL
@@ -12908,7 +12909,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 12911 "configure"
+#line 12912 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -13014,7 +13015,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 13017 "configure"
+#line 13018 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -16348,6 +16349,147 @@ enable_dlopen=yes
 
 
 
+LIBM=
+case $host in
+*-*-beos* | *-*-cegcc* | *-*-cygwin* | *-*-haiku* | *-*-pw32* | *-*-darwin*)
+  # These system don't have libm, or don't need it
+  ;;
+*-ncr-sysv4.3*)
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for _mwvalidcheckl in 
-lmw" >&5
+$as_echo_n "checking for _mwvalidcheckl in -lmw... " >&6; }
+if ${ac_cv_lib_mw__mwvalidcheckl+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lmw  $LIBS"
+if test x$gcc_no_link = xyes; then
+  as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." 
"$LINENO" 5
+fi
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char _mwvalidcheckl ();
+int
+main ()
+{
+return _mwvalidcheckl ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_mw__mwvalidcheckl=yes
+else
+  ac_cv_lib_mw__mwvalidcheckl=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_mw__mwvalidcheckl" 
>&5
+$as_echo "$ac_cv_lib_mw__mwvalidcheckl" >&6; }
+if test "x$ac_cv_lib_mw__mwvalidcheckl" = xyes; then :
+  LIBM="-lmw"
+fi
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for cos in -lm" >&5
+$as_echo_n "checking for cos in -lm... " >&6; }
+if ${ac_cv_lib_m_cos+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lm  $LIBS"
+if test x$gcc_no_link = xyes; then
+  as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." 
"$LINENO" 5
+fi
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type

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

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

commit 70afce512eb54928227a8a173f5a3d5f90e1506a
Author: Michael Meissner 
Date:   Thu Apr 3 15:26:36 2025 -0400

Add ChangeLog.sha and update REVISION.

2025-04-03  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 ..6829dd35cdc4
--- /dev/null
+++ b/gcc/ChangeLog.sha
@@ -0,0 +1,5 @@
+ Branch work199-sha, baseline 
+
+2025-04-03   Michael Meissner  
+
+   Clone branch
diff --git a/gcc/REVISION b/gcc/REVISION
index 113e419bda0d..9f6440bbc70e 100644
--- a/gcc/REVISION
+++ b/gcc/REVISION
@@ -1 +1 @@
-work199 branch
+work199-sha branch


[gcc r15-9046] Doc: Clean up New/Delete Builtins manual section

2025-04-04 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:37f35ebc7c50afdc9aeb4774b7d0ca7e7f32bbf1

commit r15-9046-g37f35ebc7c50afdc9aeb4774b7d0ca7e7f32bbf1
Author: Sandra Loosemore 
Date:   Wed Mar 26 18:25:51 2025 +

Doc: Clean up New/Delete Builtins manual section

I noticed that the "New/Delete Builtins" section failed to explicitly
name or describe the arguments of the builtin functions it purported
to document, outside of using them in an example.  I've fixed that
and cleaned up the whole section.

gcc/ChangeLog
* doc/extend.texi (New/Delete Builtins): Cleanup up the text and
explicitly list the builtins being documented.

Diff:
---
 gcc/doc/extend.texi | 41 +
 1 file changed, 29 insertions(+), 12 deletions(-)

diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index f0bbff6dd042..a49b1cdd1e35 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -16985,18 +16985,20 @@ is called and the @var{flag} argument passed to it.
 
 @node New/Delete Builtins
 @section Built-in functions for C++ allocations and deallocations
-@findex __builtin_operator_new
-@findex __builtin_operator_delete
-Calling these C++ built-in functions is similar to calling
-@code{::operator new} or @code{::operator delete} with the same arguments,
-except that it is an error if the selected @code{::operator new} or
-@code{::operator delete} overload is not a replaceable global operator
-and for optimization purposes calls to pairs of these functions can be
-omitted if access to the allocation is optimized out, or could be replaced
-with implementation provided buffer on the stack, or multiple allocation
-calls can be merged into a single allocation.  In C++ such optimizations
-are normally allowed just for calls to such replaceable global operators
-from @code{new} and @code{delete} expressions.
+@cindex builtins for C++ @code{new} and @code{delete} operators
+@cindex @code{new} and @code{delete} builtins
+
+GNU C++ provides builtins that are equivalent to calling
+@code{::operator new} or @code{::operator delete} with the same arguments.
+It is an error if the selected @code{::operator new} or
+@code{::operator delete} overload is not a replaceable global operator.
+For optimization purposes, calls to pairs of these
+builtins can be omitted if access to the allocation is optimized out,
+or could be replaced with an implementation-provided buffer on the stack,
+or multiple allocation calls can be merged into a single allocation.
+In C++ such optimizations are normally allowed just for calls to such
+replaceable global operators from @code{new} and @code{delete}
+expressions.
 
 @smallexample
 void foo () @{
@@ -17010,6 +17012,21 @@ void foo () @{
 @}
 @end smallexample
 
+These built-ins are only available in C++.
+
+@defbuiltin{{void *} __builtin_operator_new (std::size_t @var{size}, ...)}
+This is the built-in form of @code{operator new}.  It accepts the same
+argument forms as a ``usual allocation function'', as described in the
+C++ standard.
+@enddefbuiltin
+
+@defbuiltin{void __builtin_operator_delete (void * @var{ptr}, ...)}
+This is the built-in form of @code{operator delete}.  It accepts the same
+argument forms as a ``usual deallocation function'', as described in the
+C++ standard.
+@enddefbuiltin
+
+
 @node Other Builtins
 @section Other Built-in Functions Provided by GCC


[gcc r15-9169] [testsuite] [riscv] xfail some [PR113281] tests

2025-04-04 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:6f72af0c2e389e9252b6994643155e51ef68821b

commit r15-9169-g6f72af0c2e389e9252b6994643155e51ef68821b
Author: Alexandre Oliva 
Date:   Thu Apr 3 03:06:44 2025 -0300

[testsuite] [riscv] xfail some [PR113281] tests

Some of the tests regressed with a fix for the vectorization of
shifts.  The riscv cost models need to be adjusted to avoid the
unprofitable optimization.  The failure of these tests has been known
since 2024-03-13, without a forthcoming fix, so I suggest we consider
it expected by now.  Adjust the tests to reflect that expectation.


for  gcc/testsuite/ChangeLog

PR tree-optimization/113281
* gcc.dg/vect/costmodel/riscv/rvv/pr113281-1.c: XFAIL.
* gcc.dg/vect/costmodel/riscv/rvv/pr113281-2.c: Likewise.
* gcc.dg/vect/costmodel/riscv/rvv/pr113281-5.c: Likewise.

Diff:
---
 gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr113281-1.c | 2 +-
 gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr113281-2.c | 2 +-
 gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr113281-5.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr113281-1.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr113281-1.c
index fdf6ed0334b7..683533fe9562 100644
--- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr113281-1.c
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr113281-1.c
@@ -15,4 +15,4 @@ int main() {
 return 1;
 }
 
-/* { dg-final { scan-assembler-not {vset} } } */
+/* { dg-final { scan-assembler-not {vset} { xfail *-*-* } } } */
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr113281-2.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr113281-2.c
index acc70810b4b2..94435d332bd7 100644
--- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr113281-2.c
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr113281-2.c
@@ -15,4 +15,4 @@ int main() {
 return 1;
 }
 
-/* { dg-final { scan-assembler-not {vset} } } */
+/* { dg-final { scan-assembler-not {vset} { xfail *-*-* } } } */
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr113281-5.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr113281-5.c
index 0163129be187..415c4bdd137c 100644
--- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr113281-5.c
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr113281-5.c
@@ -15,4 +15,4 @@ int main() {
 return 1;
 }
 
-/* { dg-final { scan-assembler-not {vset} } } */
+/* { dg-final { scan-assembler-not {vset} { xfail *-*-* } } } */


[gcc(refs/users/jmelcr/heads/omp-cp)] omp-cp: Fix one segfault, introduce a different one

2025-04-04 Thread Josef Melcr via Gcc-cvs
https://gcc.gnu.org/g:86ef6c04591ed9b8deda7f1c86ff7f88e1efd734

commit 86ef6c04591ed9b8deda7f1c86ff7f88e1efd734
Author: Josef Melcr 
Date:   Mon Mar 31 20:48:52 2025 +0200

omp-cp: Fix one segfault, introduce a different one

gcc/ChangeLog:

* attr-callback.h (callback_fetch_fn_position): Rewrite with the
new function below.
(callback_fetch_attr_by_decl): New function.
(callback_remove_callback_edge): New function.
* cgraph.cc (cgraph_edge::get_callback_parent_edge): Add
lto_stmt_uid check.
(cgraph_edge::first_callback_target): Likewise.
(cgraph_edge::next_callback_target): Likewise.
(cgraph_node::verify_node): Likewise.
* ipa-cp.cc (purge_useless_callback_edges): Reformat, use the
new remove function.
(ipcp_decision_stage): Add back purge function.
* ipa-fnsummary.cc (analyze_function_body): Set call stmt size
and time to 0 for callback edges.

Signed-off-by: Josef Melcr 

Diff:
---
 gcc/attr-callback.h  | 58 +++-
 gcc/cgraph.cc| 21 +++
 gcc/ipa-cp.cc| 34 +-
 gcc/ipa-fnsummary.cc |  2 ++
 4 files changed, 82 insertions(+), 33 deletions(-)

diff --git a/gcc/attr-callback.h b/gcc/attr-callback.h
index b6a1a0c4106c..622949c03ac3 100644
--- a/gcc/attr-callback.h
+++ b/gcc/attr-callback.h
@@ -86,18 +86,13 @@ callback_get_arg_mapping (tree decl)
   return res;
 }
 
-/* Given a call statement of the parent, it's attribute list and
-   a decl of the callback, returns a 0-based index of the callback
-   function in the parameters of it's caller function. Arguments
-   are extracted from the call statement. If kernel_decl is a decl
-   of a clone, it's parent decl will be considered as well. */
-inline int
-callback_fetch_fn_position (gcall *call, tree attr_list, tree kernel_decl)
+inline tree
+callback_fetch_attr_by_decl(gcall *call, tree attr_list, tree kernel_decl)
 {
   tree original_decl = DECL_ORIGIN (kernel_decl);
   tree cb_attr = lookup_attribute ("callback", attr_list);
   gcc_checking_assert (cb_attr);
-  int res = -1;
+  tree res = NULL_TREE;
   for (; cb_attr; cb_attr = lookup_attribute ("callback", TREE_CHAIN 
(cb_attr)))
 {
   int idx = callback_get_fn_index (cb_attr);
@@ -108,15 +103,27 @@ callback_fetch_fn_position (gcall *call, tree attr_list, 
tree kernel_decl)
  if (pointee != NULL_TREE
  && (pointee == kernel_decl || pointee == original_decl))
{
- res = idx;
+ res = cb_attr;
  break;
}
}
 }
-  gcc_checking_assert (res != -1);
+  gcc_checking_assert (res != NULL_TREE);
   return res;
 }
 
+/* Given a call statement of the parent, it's attribute list and
+   a decl of the callback, returns a 0-based index of the callback
+   function in the parameters of it's caller function. Arguments
+   are extracted from the call statement. If kernel_decl is a decl
+   of a clone, it's parent decl will be considered as well. */
+inline int
+callback_fetch_fn_position (gcall *call, tree attr_list, tree kernel_decl)
+{
+  tree attr = callback_fetch_attr_by_decl(call, attr_list, kernel_decl);
+  return callback_get_fn_index(attr);
+}
+
 /* Returns the element at index idx in the list or NULL_TREE if
the list isn't long enough. NULL_TREE is used as the endpoint. */
 static tree
@@ -281,4 +288,35 @@ callback_edge_useful_p (cgraph_edge *e)
   return true;
 }
 
+inline void
+callback_remove_callback_edge (cgraph_edge *e)
+{
+  gcc_checking_assert (e->callback);
+  cgraph_edge *parent = e->get_callback_parent_edge ();
+  tree offload_decl = parent->callee->decl;
+  if (parent->call_stmt)
+{
+  tree attr = callback_fetch_attr_by_decl (parent->call_stmt,
+  DECL_ATTRIBUTES (offload_decl),
+  e->callee->decl);
+
+  tree *p;
+  tree list = DECL_ATTRIBUTES (offload_decl);
+  for (p = &list; *p;)
+   {
+ tree l = *p;
+
+ if (l == attr)
+   {
+ *p = TREE_CHAIN (l);
+ continue;
+   }
+ p = &TREE_CHAIN (l);
+   }
+
+  DECL_ATTRIBUTES (offload_decl) = list;
+}
+  cgraph_edge::remove (e);
+}
+
 #endif /* ATTR_CALLBACK_H  */
diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc
index 3bcfe1f2da12..60a4f49014c3 100644
--- a/gcc/cgraph.cc
+++ b/gcc/cgraph.cc
@@ -1212,7 +1212,8 @@ cgraph_edge::get_callback_parent_edge ()
   cgraph_edge *e;
   for (e = caller->callees; e; e = e->next_callee)
 {
-  if (e->has_callback && e->call_stmt == call_stmt)
+  if (e->has_callback && e->call_stmt == call_stmt
+ && e->lto_stmt_uid == lto_stmt_uid)
break;
 }
   return e;
@@ -1225,7 +1226,8 @@ cgraph_edge::first_callback_target ()
   cgraph_edge 

[gcc r15-9209] profile: Another musttail fix [PR119618]

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

commit r15-9209-gc89714d9df3ad8dd6b79946da85f5e276aba83db
Author: Jakub Jelinek 
Date:   Fri Apr 4 20:53:19 2025 +0200

profile: Another musttail fix [PR119618]

As the following testcase shows, sometimes we can have debug stmts
after a musttail call and profile.cc in that case would incorrectly
allow the edge from that, causing musttail error and -fcompare-debug
failure (because if there are no debug stmts after it, then musttail
is found there and the edge is ignored).

The following patch uses gsi_last_nondebug_bb instead of gsi_last_bb
to find the musttail call.  And so that we don't uselessly skip over
debug stmts at the end of many bbs, the patch limits it to
cfun->has_musttail functions.

2025-04-04  Jakub Jelinek  

PR gcov-profile/119618
* profile.cc (branch_prob): Only check for musttail calls if
cfun->has_musttail.  Use gsi_last_nondebug_bb instead of 
gsi_last_bb.

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

Diff:
---
 gcc/profile.cc|  5 +++--
 gcc/testsuite/c-c++-common/pr119618.c | 21 +
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/gcc/profile.cc b/gcc/profile.cc
index 550c85b9742c..6234dd2d4e2d 100644
--- a/gcc/profile.cc
+++ b/gcc/profile.cc
@@ -1341,9 +1341,10 @@ branch_prob (bool thunk)
  ignored_edges++;
}
   /* Ignore edges after musttail calls.  */
-  if (e->src != ENTRY_BLOCK_PTR_FOR_FN (cfun))
+  if (cfun->has_musttail
+ && e->src != ENTRY_BLOCK_PTR_FOR_FN (cfun))
{
- gimple_stmt_iterator gsi = gsi_last_bb (e->src);
+ gimple_stmt_iterator gsi = gsi_last_nondebug_bb (e->src);
  gimple *stmt = gsi_stmt (gsi);
  if (stmt
  && is_gimple_call (stmt)
diff --git a/gcc/testsuite/c-c++-common/pr119618.c 
b/gcc/testsuite/c-c++-common/pr119618.c
new file mode 100644
index ..a56e6695cf5a
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/pr119618.c
@@ -0,0 +1,21 @@
+/* PR gcov-profile/119618 */
+/* { dg-do compile { target musttail } } */
+/* { dg-options "-fcompare-debug -fprofile-generate -O1" } */
+/* { dg-require-profiling "-fprofile-generate" } */
+
+struct S { char s; };
+int foo (void);
+int *(*fn) (void);
+
+int *
+bar (void)
+{
+  if (foo ())
+return 0;
+  {
+struct S s;
+do
+  [[gnu::musttail]] return fn ();
+while (0);
+  }
+}


[gcc r15-9207] cfgrtl: Remove REG_EH_REGION notes from tail calls [PR119613]

2025-04-04 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:77e0c0df0907657a7d72bbba9e6329d93ec65edb

commit r15-9207-g77e0c0df0907657a7d72bbba9e6329d93ec65edb
Author: Jakub Jelinek 
Date:   Fri Apr 4 20:51:50 2025 +0200

cfgrtl: Remove REG_EH_REGION notes from tail calls [PR119613]

In PR119491 r15-9154 I've allowed some useless EH regions for musttail
calls (if there are no non-debug/clobber stmts before resx which resumes
external throwing).
Now, for -O1+ (but not -O0/-Og) there is a cleanup_eh pass after it
which should optimize that way.
The following testcase ICEs at -O0 though, the cleanup_eh in that case
is before the musttail pass and dunno why it didn't actually optimize
it away.

The following patch catches that during expansion and just removes the note,
which causes EH cleanups to do the rest.  A tail call, even when it throws,
will not throw while the musttail caller's frame is still on the stack,
will throw after that and so REG_EH_REGION for it is irrelevant (like it
would be never set before the r15-9154 changes).

2025-04-04  Jakub Jelinek  

PR middle-end/119613
* cfgrtl.cc (purge_dead_edges): Remove REG_EH_REGION notes from
tail calls.

* g++.dg/opt/pr119613.C: New test.

Diff:
---
 gcc/cfgrtl.cc   | 10 ++
 gcc/testsuite/g++.dg/opt/pr119613.C | 22 ++
 2 files changed, 32 insertions(+)

diff --git a/gcc/cfgrtl.cc b/gcc/cfgrtl.cc
index d206c0d53a72..310028f1719b 100644
--- a/gcc/cfgrtl.cc
+++ b/gcc/cfgrtl.cc
@@ -3213,6 +3213,16 @@ purge_dead_edges (basic_block bb)
  && ! may_trap_p (XEXP (eqnote, 0
remove_note (insn, note);
 }
+  /* A tail call cannot trap either.  The tailc/musttail pass could have
+ allowed a tail call if it could throw internally, but perform no
+ actual statements and then caused the exception to be thrown externally
+ in the hope that it is cleaned up later.  If it is not, just
+ remove REG_EH_REGION note.  While the call maybe can throw, the
+ current function's frame will not be there anymore when it does.  */
+   if (CALL_P (insn)
+   && SIBLING_CALL_P (insn)
+   && (note = find_reg_note (insn, REG_EH_REGION, NULL)))
+ remove_note (insn, note);
 
   /* Cleanup abnormal edges caused by exceptions or non-local gotos.  */
   for (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); )
diff --git a/gcc/testsuite/g++.dg/opt/pr119613.C 
b/gcc/testsuite/g++.dg/opt/pr119613.C
new file mode 100644
index ..432a30cdcdb0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/opt/pr119613.C
@@ -0,0 +1,22 @@
+// PR middle-end/119613
+// { dg-do compile { target { musttail && { c || c++11 } } } }
+// { dg-options "-O0" }
+
+struct S { S () {} };
+char *foo (S);
+void bar (int);
+
+[[gnu::always_inline]] inline char *
+baz (S x)
+{
+  unsigned i;
+  &i;
+  bar (i);
+  [[gnu::musttail]] return foo (x);
+}
+
+char *
+qux (S)
+{
+  [[gnu::musttail]] return baz (S {});
+}


[gcc r14-11529] c++: constraint variable used in evaluated context [PR117849]

2025-04-04 Thread Patrick Palka via Gcc-cvs
https://gcc.gnu.org/g:49b6308d2596f7334011f84bae8d35d68c302a3c

commit r14-11529-g49b6308d2596f7334011f84bae8d35d68c302a3c
Author: Patrick Palka 
Date:   Fri Apr 4 14:03:58 2025 -0400

c++: constraint variable used in evaluated context [PR117849]

Here we wrongly reject the type-requirement at parse time due to its use
of the constraint variable 't' within a template argument (an evaluated
context).  Fix this simply by refining the "use of parameter outside
function body" error path to exclude constraint variables.

PR c++/104255 tracks the same issue for function parameters, but fixing
that would be more involved, requiring changes to the PARM_DECL case of
tsubst_expr.

PR c++/117849

gcc/cp/ChangeLog:

* semantics.cc (finish_id_expression_1): Allow use of constraint
variable outside an unevaluated context.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/concepts-requires41.C: New test.

Reviewed-by: Jason Merrill 
(cherry picked from commit 6e973e87e3fec6f33e97edf8fce2fcd121e53961)

Diff:
---
 gcc/cp/semantics.cc  |  1 +
 gcc/testsuite/g++.dg/cpp2a/concepts-requires41.C | 25 
 2 files changed, 26 insertions(+)

diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 9ebe35dbaffe..3e75b5887506 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -4386,6 +4386,7 @@ finish_id_expression_1 (tree id_expression,
 body, except inside an unevaluated context (i.e. decltype).  */
   if (TREE_CODE (decl) == PARM_DECL
  && DECL_CONTEXT (decl) == NULL_TREE
+ && !CONSTRAINT_VAR_P (decl)
  && !cp_unevaluated_operand
  && !processing_contract_condition)
{
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-requires41.C 
b/gcc/testsuite/g++.dg/cpp2a/concepts-requires41.C
new file mode 100644
index ..28c976116cad
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-requires41.C
@@ -0,0 +1,25 @@
+// PR c++/117849
+// { dg-do compile { target c++20 } }
+
+template
+struct array {
+  constexpr int size() const { return N; }
+};
+
+struct vector {
+  int _size = 3;
+  constexpr int size() const { return _size; }
+};
+
+template
+struct integral_constant {
+  constexpr operator int() const { return N; }
+};
+
+template
+concept StaticSize = requires (T& t) {
+  typename integral_constant;
+};
+
+static_assert(StaticSize>);
+static_assert(!StaticSize);


[gcc r15-8513] gccrs: Use name resolver 2.0 in VisibilityResolver

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

commit r15-8513-gb1e6a3f76e10d7d9ee3574b7abd9d0281ea2d22d
Author: Owen Avery 
Date:   Mon Nov 4 21:52:14 2024 -0500

gccrs: Use name resolver 2.0 in VisibilityResolver

gcc/rust/ChangeLog:

* checks/errors/privacy/rust-visibility-resolver.cc:
Add includes.
(VisibilityResolver::resolve_module_path): Use name resolver 2.0
(when enabled) to lookup path resolutions.

Signed-off-by: Owen Avery 

Diff:
---
 .../errors/privacy/rust-visibility-resolver.cc  | 21 -
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc 
b/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc
index 464ce86e1778..f0da74560768 100644
--- a/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc
+++ b/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc
@@ -20,6 +20,10 @@
 #include "rust-ast.h"
 #include "rust-hir.h"
 #include "rust-hir-item.h"
+#include "rust-immutable-name-resolution-context.h"
+
+// for flag_name_resolution_2_0
+#include "options.h"
 
 namespace Rust {
 namespace Privacy {
@@ -61,7 +65,22 @@ VisibilityResolver::resolve_module_path (const 
HIR::SimplePath &restriction,
 "cannot use non-module path as privacy restrictor");
 
   NodeId ref_node_id = UNKNOWN_NODEID;
-  if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id))
+  if (flag_name_resolution_2_0)
+{
+  auto &nr_ctx
+   = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+  if (auto id = nr_ctx.lookup (ast_node_id))
+   {
+ ref_node_id = *id;
+   }
+  else
+   {
+ invalid_path.emit ();
+ return false;
+   }
+}
+  else if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id))
 {
   invalid_path.emit ();
   return false;


[gcc r14-11528] c++: P2280R4 and speculative constexpr folding [PR119387]

2025-04-04 Thread Patrick Palka via Gcc-cvs
https://gcc.gnu.org/g:9a747094ac623bfd5c5d90eecf2d920f231de1c0

commit r14-11528-g9a747094ac623bfd5c5d90eecf2d920f231de1c0
Author: Patrick Palka 
Date:   Thu Apr 3 16:33:46 2025 -0400

c++: P2280R4 and speculative constexpr folding [PR119387]

Compiling the testcase in this PR uses 2.5x more memory and 6x more
time ever since r14-5979 which implements P2280R4.  This is because
our speculative constexpr folding now does a lot more work trying to
fold ultimately non-constant calls to constexpr functions, and in turn
produces a lot of garbage.  We do sometimes successfully fold more
thanks to P2280R4, but it seems to be trivial stuff like calls to
std::array::size or std::addressof.  The benefit of P2280 therefore
doesn't seem worth the cost during speculative constexpr folding, so
this patch restricts the paper to only manifestly-constant evaluation.

PR c++/119387

gcc/cp/ChangeLog:

* constexpr.cc (p2280_active_p): New.
(cxx_eval_constant_expression) : Use it to
restrict P2280 relaxations.
: Likewise.

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

Diff:
---
 gcc/cp/constexpr.cc | 22 +++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index d3b9fe08e1a5..2da5ddfffe37 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -1286,6 +1286,22 @@ struct constexpr_ctx {
   mce_value manifestly_const_eval;
 };
 
+/* True if the constexpr relaxations afforded by P2280R4 for unknown
+   references and objects are in effect.  */
+
+static bool
+p2280_active_p (const constexpr_ctx *ctx)
+{
+  if (ctx->manifestly_const_eval != mce_true)
+/* Disable these relaxations during speculative constexpr folding,
+   as it can significantly increase compile time/memory use
+   (PR119387).  */
+return false;
+
+  /* P2280R4 was accepted as a DR against C++11.  */
+  return cxx_dialect >= cxx11;
+}
+
 /* Remove T from the global values map, checking for attempts to destroy
a value that has already finished its lifetime.  */
 
@@ -7526,7 +7542,7 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, 
tree t,
r = TARGET_EXPR_INITIAL (r);
   if (DECL_P (r)
  /* P2280 allows references to unknown.  */
- && !(VAR_P (t) && TYPE_REF_P (TREE_TYPE (t
+ && !(p2280_active_p (ctx) && VAR_P (t) && TYPE_REF_P (TREE_TYPE (t
{
  if (!ctx->quiet)
non_const_var_error (loc, r, /*fundef_p*/false);
@@ -7578,9 +7594,9 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, 
tree t,
  r = build_constructor (TREE_TYPE (t), NULL);
  TREE_CONSTANT (r) = true;
}
-  else if (TYPE_REF_P (TREE_TYPE (t)))
+  else if (p2280_active_p (ctx) && TYPE_REF_P (TREE_TYPE (t)))
/* P2280 allows references to unknown...  */;
-  else if (is_this_parameter (t))
+  else if (p2280_active_p (ctx) && is_this_parameter (t))
/* ...as well as the this pointer.  */;
   else
{


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

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

commit 1f62b1271f08313b0654720d555f2dfe47ec8c85
Author: Michael Meissner 
Date:   Thu Mar 27 15:06:17 2025 -0400

Add ChangeLog.vpair and update REVISION.

2025-03-27  Michael Meissner  

gcc/

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

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

diff --git a/gcc/ChangeLog.vpair b/gcc/ChangeLog.vpair
new file mode 100644
index ..beb88b594e39
--- /dev/null
+++ b/gcc/ChangeLog.vpair
@@ -0,0 +1,5 @@
+ Branch work197-vpair, baseline 
+
+2025-03-27   Michael Meissner  
+
+   Clone branch
diff --git a/gcc/REVISION b/gcc/REVISION
new file mode 100644
index ..b256b03deaf8
--- /dev/null
+++ b/gcc/REVISION
@@ -0,0 +1 @@
+work197-vpair branch


[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Sauvegarde spacing compilation OK

2025-04-04 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:3a34dc4c0f63c13976d827048591b54972f9c364

commit 3a34dc4c0f63c13976d827048591b54972f9c364
Author: Mikael Morin 
Date:   Thu Apr 3 15:34:46 2025 +0200

Sauvegarde spacing compilation OK

Diff:
---
 gcc/fortran/trans-array.cc  | 399 +++-
 gcc/fortran/trans-array.h   |   3 +-
 gcc/fortran/trans-decl.cc   |  10 +-
 gcc/fortran/trans-descriptor.cc | 317 +++
 gcc/fortran/trans-descriptor.h  |   5 +-
 gcc/fortran/trans-expr.cc   |  10 +-
 gcc/fortran/trans-intrinsic.cc  |  17 +-
 gcc/fortran/trans-io.cc |  11 +-
 gcc/fortran/trans-openmp.cc |  42 +++--
 gcc/fortran/trans-types.cc  |  61 --
 gcc/fortran/trans.cc| 111 +--
 gcc/fortran/trans.h |  27 +--
 12 files changed, 472 insertions(+), 541 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index b33ba5730f24..8d48d8e05a95 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -932,7 +932,7 @@ gfc_trans_create_temp_array (stmtblock_t * pre, stmtblock_t 
* post, gfc_ss * ss,
   gfc_loopinfo *loop;
   gfc_ss *s;
   gfc_array_info *info;
-  tree from[GFC_MAX_DIMENSIONS], to[GFC_MAX_DIMENSIONS], 
sm[GFC_MAX_DIMENSIONS];
+  tree from[GFC_MAX_DIMENSIONS], to[GFC_MAX_DIMENSIONS], 
spacing[GFC_MAX_DIMENSIONS];
   tree type;
   tree desc;
   tree tmp;
@@ -1149,7 +1149,9 @@ gfc_trans_create_temp_array (stmtblock_t * pre, 
stmtblock_t * post, gfc_ss * ss,
 
   info->descriptor = desc;
   info->array_access = array_access;
-  size = elemsize;
+  size = fold_build2_loc (input_location, EXACT_DIV_EXPR, gfc_array_index_type,
+ elemsize, build_int_cst (gfc_array_index_type,
+  TYPE_ALIGN_UNIT (eltype)));
 
   /*
  Fill in the bounds and stride.  This is a packed array, so:
@@ -1193,7 +1195,7 @@ gfc_trans_create_temp_array (stmtblock_t * pre, 
stmtblock_t * post, gfc_ss * ss,
 {
   for (n = 0; n < total_dim; n++)
{
- sm[n] = size;
+ spacing[n] = size;
 
  tree extent = to[n];
  if (!shift_bounds && !integer_zerop (from[n]))
@@ -1245,8 +1247,9 @@ gfc_trans_create_temp_array (stmtblock_t * pre, 
stmtblock_t * post, gfc_ss * ss,
nelem, initial, dynamic,
dealloc);
 
-  gfc_set_temporary_descriptor (pre, desc, class_expr, elemsize, data_ptr,
-   from, to, sm, total_dim, !bounds_known,
+  gfc_set_temporary_descriptor (pre, desc, class_expr, elemsize,
+   GFC_TYPE_ARRAY_ALIGN (desc), data_ptr,
+   from, to, spacing, total_dim, !bounds_known,
rank_changer, shift_bounds);
 
   while (ss->parent)
@@ -1393,7 +1396,7 @@ gfc_trans_array_ctor_element (stmtblock_t * pblock, tree 
desc,
   /* Store the value.  */
   tmp = build_fold_indirect_ref_loc (input_location,
 gfc_conv_descriptor_data_get (desc));
-  tmp = gfc_build_array_ref (tmp, offset, NULL);
+  tmp = gfc_build_array_ref (tmp, offset, NULL_TREE, NULL_TREE);
 
   if (expr->expr_type == EXPR_FUNCTION && expr->ts.type == BT_DERIVED
   && expr->ts.u.derived->attr.alloc_comp)
@@ -1724,7 +1727,7 @@ gfc_trans_array_constructor_value (stmtblock_t * pblock,
  tmp = gfc_conv_descriptor_data_get (desc);
  tmp = build_fold_indirect_ref_loc (input_location,
 tmp);
- tmp = gfc_build_array_ref (tmp, *poffset, NULL);
+ tmp = gfc_build_array_ref (tmp, *poffset, NULL_TREE, NULL_TREE);
  tmp = gfc_build_addr_expr (NULL_TREE, tmp);
  init = gfc_build_addr_expr (NULL_TREE, init);
 
@@ -2830,7 +2833,7 @@ gfc_add_loop_ss_code (gfc_loopinfo * loop, gfc_ss * ss, 
bool subscript,
 
  info->stride[dim] = gfc_index_one_node;
 
- tree spacing = gfc_conv_descriptor_sm_get (tmp, tree_dim);
+ tree spacing = gfc_conv_descriptor_spacing_get (tmp, 
tree_dim);
  spacing = gfc_evaluate_now (spacing, &outer_loop->pre);
  info->spacing[dim] = spacing;
}
@@ -2988,7 +2991,6 @@ gfc_conv_ss_descriptor (stmtblock_t * block, gfc_ss * ss, 
int base)
  && !ss->is_alloc_lhs)
data = gfc_evaluate_now (data, block);
   info->data = data;
-  info->saved_data = data;
 
   tmp = gfc_conv_array_offset (se.expr);
   if (!ss->is_alloc_lhs)
@@ -2999,6 +3001,11 @@ gfc_conv_ss_descriptor (stmtblock_t * block, gfc_ss * 
ss, int base)
 so that the variable is still accessible after the loops
 are translated.  */
   info->saved_offset = info->offset;
+
+  tmp = gfc_conv_array_align (se.expr);
+  if (!ss->is_alloc_lhs)
+  

[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Correction actual_array_constructor_1.f90

2025-04-04 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:137fe54b5c5d42ef4ce1c5186755eb690105fa0a

commit 137fe54b5c5d42ef4ce1c5186755eb690105fa0a
Author: Mikael Morin 
Date:   Thu Apr 3 20:59:45 2025 +0200

Correction actual_array_constructor_1.f90

Diff:
---
 gcc/fortran/trans-array.cc | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index f09a1f6130dd..717176c01056 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -3509,6 +3509,7 @@ conv_array_index_offset (gfc_se * se, gfc_ss * ss, int 
dim, int i,
 {
   gfc_array_info *info;
   tree index;
+  tree descriptor;
   tree data;
 
   info = &ss->info->data.array;
@@ -3544,14 +3545,15 @@ conv_array_index_offset (gfc_se * se, gfc_ss * ss, int 
dim, int i,
   gfc_array_index_type,
   se->loop->loopvar[i], se->loop->from[i]);
 
- data = info->subscript[dim]->info->data.array.data;
+ descriptor = info->subscript[dim]->info->data.array.descriptor; 
  index = fold_convert_loc (input_location, gfc_array_index_type, 
index);
 
  /* Read the vector to get an index into info->descriptor.  */
- data = build_fold_indirect_ref_loc (input_location, data);
+ data = build_fold_indirect_ref_loc (input_location, 
+ gfc_conv_array_data (descriptor));
  index = gfc_build_array_ref (data, index,
-  
info->subscript[dim]->info->data.array.spacing[0],
-  
info->subscript[dim]->info->data.array.align);
+  gfc_conv_array_spacing (descriptor, 0),
+  gfc_conv_array_align (descriptor));
  index = gfc_evaluate_now (index, &se->pre);
  index = fold_convert (gfc_array_index_type, index);


[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Correction régressions, y compris aliasing_dummy_1.f90

2025-04-04 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:55ab3ee1158fd34891cb60b79528d47d635a70f1

commit 55ab3ee1158fd34891cb60b79528d47d635a70f1
Author: Mikael Morin 
Date:   Thu Apr 3 20:38:00 2025 +0200

Correction régressions, y compris aliasing_dummy_1.f90

Diff:
---
 gcc/fortran/trans-array.cc | 24 +-
 gcc/fortran/trans-expr.cc  | 50 +-
 gcc/fortran/trans-types.cc | 45 +
 3 files changed, 44 insertions(+), 75 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 8d48d8e05a95..f09a1f6130dd 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -1248,9 +1248,9 @@ gfc_trans_create_temp_array (stmtblock_t * pre, 
stmtblock_t * post, gfc_ss * ss,
dealloc);
 
   gfc_set_temporary_descriptor (pre, desc, class_expr, elemsize,
-   GFC_TYPE_ARRAY_ALIGN (desc), data_ptr,
-   from, to, spacing, total_dim, !bounds_known,
-   rank_changer, shift_bounds);
+   GFC_TYPE_ARRAY_ALIGN (TREE_TYPE (desc)),
+   data_ptr, from, to, spacing, total_dim,
+   !bounds_known, rank_changer, shift_bounds);
 
   while (ss->parent)
 ss = ss->parent;
@@ -1396,7 +1396,7 @@ gfc_trans_array_ctor_element (stmtblock_t * pblock, tree 
desc,
   /* Store the value.  */
   tmp = build_fold_indirect_ref_loc (input_location,
 gfc_conv_descriptor_data_get (desc));
-  tmp = gfc_build_array_ref (tmp, offset, NULL_TREE, NULL_TREE);
+  tmp = gfc_build_array_ref (tmp, offset, true);
 
   if (expr->expr_type == EXPR_FUNCTION && expr->ts.type == BT_DERIVED
   && expr->ts.u.derived->attr.alloc_comp)
@@ -3637,7 +3637,8 @@ gfc_conv_scalarized_array_ref (gfc_se * se, gfc_array_ref 
* ar,
   bool non_negative_stride = tmp_array
 || non_negative_strides_array_p (info->descriptor);
   se->expr = gfc_build_array_ref (base, index, non_negative_stride,
- gfc_index_one_node, info->align);
+ tmp_array ? NULL_TREE : gfc_index_one_node,
+ tmp_array ? NULL_TREE : info->align);
 }
 
 
@@ -6224,9 +6225,11 @@ gfc_trans_array_bounds (tree type, gfc_symbol * sym, 
tree * poffset,
   as = IS_CLASS_COARRAY_OR_ARRAY (sym) ? CLASS_DATA (sym)->as : sym->as;
 
   tree eltype = gfc_get_element_type (type);
+  tree elem_len = fold_convert_loc (input_location, gfc_array_index_type,
+   TYPE_SIZE_UNIT (eltype));
 
   size = fold_build2_loc (input_location, EXACT_DIV_EXPR, gfc_array_index_type,
- TYPE_SIZE_UNIT (eltype), GFC_TYPE_ARRAY_ALIGN (type));
+ elem_len, GFC_TYPE_ARRAY_ALIGN (type));
   offset = gfc_index_zero_node;
   for (dim = 0; dim < as->rank; dim++)
 {
@@ -6619,10 +6622,13 @@ gfc_trans_dummy_array_bias (gfc_symbol * sym, tree 
tmpdesc,
   if (no_repack)
 {
   /* Set the first stride.  */
-  spacing = gfc_conv_descriptor_spacing_get (dumdesc, gfc_rank_cst[0]);
-  tmp = gfc_evaluate_now (spacing, &init);
   spacing = GFC_TYPE_ARRAY_SPACING (type, 0);
-  gfc_add_modify (&init, spacing, tmp);
+  if (!INTEGER_CST_P (spacing))
+   {
+ tmp = gfc_conv_descriptor_spacing_get (dumdesc, gfc_rank_cst[0]);
+ tmp = gfc_evaluate_now (tmp, &init);
+ gfc_add_modify (&init, spacing, tmp);
+   }
 
   /* Allow the user to disable array repacking.  */
   stmt_unpacked = NULL_TREE;
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index acd6ee937d28..2c0961888e84 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -5337,8 +5337,6 @@ gfc_conv_subref_array_arg (gfc_se *se, gfc_expr * expr, 
int g77,
   gfc_loopinfo loop;
   gfc_loopinfo loop2;
   gfc_array_info *info;
-  tree offset;
-  tree tmp_index;
   tree tmp;
   tree base_type;
   stmtblock_t body;
@@ -5493,55 +5491,9 @@ gfc_conv_subref_array_arg (gfc_se *se, gfc_expr * expr, 
int g77,
   gfc_mark_ss_chain_used (lss, 1);
   gfc_mark_ss_chain_used (loop.temp_ss, 1);
 
-  /* Declare the variable to hold the temporary offset and start the
- scalarized loop body.  */
-  offset = gfc_create_var (gfc_array_index_type, NULL);
   gfc_start_scalarized_body (&loop2, &body);
 
-  /* Build the offsets for the temporary from the loop variables.  The
- temporary array has lbounds of zero and strides of one in all
- dimensions, so this is very simple.  The offset is only computed
- outside the innermost loop, so the overall transfer could be
- optimized further.  */
-  info = &rse.ss->info->data.array;
-
-  tmp_index = gfc_index_zero_node;
-  for (n = dimen - 1; n > 0; n--)
-{
-  tree tmp_str;
-  tmp = rse.loop->loopvar[n];
-

[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Correction régression y compris PR100094

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

commit d63b964d7985ea297ecc11b99c616ac5cfb193fa
Author: Mikael Morin 
Date:   Fri Apr 4 11:42:19 2025 +0200

Correction régression y compris PR100094

Diff:
---
 gcc/fortran/trans-array.cc  |  6 +++---
 gcc/fortran/trans-descriptor.cc |  2 +-
 gcc/fortran/trans-expr.cc   |  4 +++-
 gcc/fortran/trans-intrinsic.cc  | 16 
 gcc/fortran/trans-io.cc |  4 +++-
 gcc/fortran/trans-openmp.cc | 16 
 gcc/fortran/trans-stmt.cc   | 32 
 gcc/fortran/trans-types.cc  |  2 +-
 8 files changed, 51 insertions(+), 31 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 717176c01056..fa7afc938e58 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -1727,7 +1727,7 @@ gfc_trans_array_constructor_value (stmtblock_t * pblock,
  tmp = gfc_conv_descriptor_data_get (desc);
  tmp = build_fold_indirect_ref_loc (input_location,
 tmp);
- tmp = gfc_build_array_ref (tmp, *poffset, NULL_TREE, NULL_TREE);
+ tmp = gfc_build_array_ref (tmp, *poffset, true);
  tmp = gfc_build_addr_expr (NULL_TREE, tmp);
  init = gfc_build_addr_expr (NULL_TREE, init);
 
@@ -8860,13 +8860,13 @@ structure_alloc_comps (gfc_symbol * der_type, tree 
decl, tree dest,
   /* Build the body of the loop.  */
   gfc_init_block (&loopbody);
 
-  vref = gfc_build_array_ref (var, index, NULL_TREE, NULL_TREE);
+  vref = gfc_build_array_ref (var, index, true);
 
   if (purpose == COPY_ALLOC_COMP || purpose == COPY_ONLY_ALLOC_COMP)
{
  tmp = build_fold_indirect_ref_loc (input_location,
 gfc_conv_array_data (dest));
- dref = gfc_build_array_ref (tmp, index, NULL_TREE, NULL_TREE);
+ dref = gfc_build_array_ref (tmp, index, true);
  tmp = structure_alloc_comps (der_type, vref, dref, rank,
   COPY_ALLOC_COMP, caf_mode, args,
   no_finalization);
diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 1f35b6722998..747e98d05df5 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -3104,7 +3104,7 @@ gfc_set_descriptor (stmtblock_t *block, tree dest, tree 
src, gfc_expr *src_expr,
 gfc_conv_descriptor_span_set (block, dest, tmp);
 
   tree eltype = gfc_get_element_type (TREE_TYPE (dest));
-  gfc_conv_descriptor_align_set (block, dest, TYPE_ALIGN (eltype));
+  gfc_conv_descriptor_align_set (block, dest, TYPE_ALIGN_UNIT (eltype));
 
   /* The following can be somewhat confusing.  We have two
  descriptors, a new one and the original array.
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 2c0961888e84..0da3bf971a27 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -1629,7 +1629,9 @@ gfc_copy_class_to_class (tree from, tree to, tree nelems, 
bool unlimited)
  tmp = gfc_conv_array_data (to);
  tmp = build_fold_indirect_ref_loc (input_location, tmp);
  to_ref = gfc_build_addr_expr (NULL_TREE,
-   gfc_build_array_ref (tmp, index, to));
+   gfc_build_array_ref (tmp, index, false,
+
GFC_TYPE_ARRAY_SPACING (to, 0),
+
GFC_TYPE_ARRAY_ALIGN (to)));
}
   vec_safe_push (args, to_ref);
 
diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc
index 9b8874910cee..ca61dcda5ff4 100644
--- a/gcc/fortran/trans-intrinsic.cc
+++ b/gcc/fortran/trans-intrinsic.cc
@@ -2154,7 +2154,9 @@ trans_image_index (gfc_se * se, gfc_expr *expr)
  thus we need explicitly check this - and return 0 if they are exceeded.  
*/
 
   lbound = gfc_conv_descriptor_lbound_get (desc, gfc_rank_cst[rank+corank-1]);
-  tmp = gfc_build_array_ref (subdesc, gfc_rank_cst[corank-1], NULL);
+  tmp = gfc_build_array_ref (subdesc, gfc_rank_cst[corank-1], false,
+GFC_TYPE_ARRAY_SPACING (subse.expr, 0),
+GFC_TYPE_ARRAY_ALIGN (subse.expr));
   invalid_bound = fold_build2_loc (input_location, LT_EXPR, logical_type_node,
 fold_convert (gfc_array_index_type, tmp),
 lbound);
@@ -2163,7 +2165,9 @@ trans_image_index (gfc_se * se, gfc_expr *expr)
 {
   lbound = gfc_conv_descriptor_lbound_get (desc, gfc_rank_cst[codim]);
   ubound = gfc_conv_descriptor_ubound_get (desc, gfc_rank_cst[codim]);
-  tmp = gfc_build_array_ref (subdesc, gfc_rank_cst[codim-rank], NULL);
+  tmp = gfc_build_array_ref (subdesc, gfc_rank_cst[codim-rank], false,
+

[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Sauvegarde correction régressions.

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

commit a1657ba13a58d906b7dcd3376000504b9cba2453
Author: Mikael Morin 
Date:   Fri Apr 4 20:46:14 2025 +0200

Sauvegarde correction régressions.

Diff:
---
 gcc/fortran/trans-descriptor.cc | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 747e98d05df5..b1516e640625 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -614,7 +614,9 @@ conv_spacing_get (tree desc, tree dim)
  || GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_ASSUMED_RANK_ALLOCATABLE
  || GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_ASSUMED_RANK_POINTER_CONT
  || GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_POINTER_CONT))
-return conv_span_get (desc);
+return fold_build2_loc (input_location, EXACT_DIV_EXPR,
+   gfc_array_index_type, conv_span_get (desc),
+   GFC_TYPE_ARRAY_ALIGN (TREE_TYPE (desc)));
 
   return non_lvalue_loc (input_location, get_spacing (desc, dim));
 }
@@ -3539,7 +3541,7 @@ gfc_descr_init_count (tree descriptor, int rank, int 
corank, gfc_expr ** lower,
   gfc_conv_descriptor_span_set (descriptor_block, descriptor, tmp);
 
   gfc_conv_descriptor_align_set (descriptor_block, descriptor,
-TYPE_ALIGN (gfc_get_element_type (TREE_TYPE 
(descriptor;
+TYPE_ALIGN_UNIT(gfc_get_element_type 
(TREE_TYPE (descriptor;
 
   return gfc_evaluate_now (stride, pblock);
 }


[gcc] Created branch 'mikael/heads/refactor_descriptor_v05' in namespace 'refs/users'

2025-04-04 Thread Mikael Morin via Gcc-cvs
The branch 'mikael/heads/refactor_descriptor_v05' was created in namespace 
'refs/users' pointing to:

 a1657ba13a58... Sauvegarde correction régressions.


[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Correction ICE aliasing_dummy_4.f90

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

commit c0d838ccb356c69e86013cc9cb68139945f15fcc
Author: Mikael Morin 
Date:   Thu Apr 3 21:11:20 2025 +0200

Correction ICE aliasing_dummy_4.f90

Diff:
---
 gcc/fortran/trans-stmt.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/fortran/trans-stmt.cc b/gcc/fortran/trans-stmt.cc
index bb8b3443d7ea..c31602e0fed6 100644
--- a/gcc/fortran/trans-stmt.cc
+++ b/gcc/fortran/trans-stmt.cc
@@ -4372,7 +4372,7 @@ generate_loop_for_temp_to_lhs (gfc_expr *expr, tree tmp1, 
tree count3,
   gfc_conv_expr (&lse, expr);
 
   /* Form the expression of the temporary.  */
-  rse.expr = gfc_build_array_ref (tmp1, count1, NULL);
+  rse.expr = gfc_build_array_ref (tmp1, count1, true);
 }
 
   /* Use the scalar assignment.  */
@@ -4478,7 +4478,7 @@ generate_loop_for_rhs_to_temp (gfc_expr *expr2, tree 
tmp1, tree count3,
   gfc_conv_expr (&rse, expr2);
 
   /* Form the expression of the temporary.  */
-  lse.expr = gfc_build_array_ref (tmp1, count1, NULL);
+  lse.expr = gfc_build_array_ref (tmp1, count1, true);
 }
 
   /* Use the scalar assignment.  */


[gcc(refs/users/meissner/heads/work199)] Change TARGET_POPCNTB to TARGET_POWER5.

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

commit 31d79660cff89e90de6fa48ca9bc8769849a3528
Author: Michael Meissner 
Date:   Thu Apr 3 15:56:09 2025 -0400

Change TARGET_POPCNTB to TARGET_POWER5.

This patch changes TARGET_POPCNTB to TARGET_POWER5.  The -mpopcntb switch 
is not
being changed in this patch, just the name of the macros used to determine 
if
the PowerPC processor supports ISA 2.2 (Power5).

2025-04-03  Michael Meissner  

gcc/

* gcc/config/rs6000/rs6000-builtin.cc (rs6000_builtin_is_supported):
Change TARGET_POPCNTB to TARGET_POWER5.
* gcc/config/rs6000/rs6000.cc (rs6000_option_override_internal):
Likewise.
* gcc/config/rs6000/rs6000.h (TARGET_FCFID): Likewise.
(TARGET_POWER5): New macro.
(TARGET_EXTRA_BUILTINS): Change TARGET_POPCNTB to TARGET_POWER5.
(TARGET_FRE): Likewise.
(TARGET_FRSQRTES): Likewise.
* gcc/config/rs6000/rs6000.md (enabled attribute): Likewise.

Diff:
---
 gcc/config/rs6000/rs6000-builtin.cc |  2 +-
 gcc/config/rs6000/rs6000.cc |  2 +-
 gcc/config/rs6000/rs6000.h  | 11 +++
 gcc/config/rs6000/rs6000.md |  2 +-
 4 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/gcc/config/rs6000/rs6000-builtin.cc 
b/gcc/config/rs6000/rs6000-builtin.cc
index 111802381acb..4ed2bc1ca89e 100644
--- a/gcc/config/rs6000/rs6000-builtin.cc
+++ b/gcc/config/rs6000/rs6000-builtin.cc
@@ -155,7 +155,7 @@ rs6000_builtin_is_supported (enum rs6000_gen_builtins 
fncode)
 case ENB_ALWAYS:
   return true;
 case ENB_P5:
-  return TARGET_POPCNTB;
+  return TARGET_POWER5;
 case ENB_P6:
   return TARGET_CMPB;
 case ENB_P6_64:
diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index 737c3d6f7c75..a5ed93702494 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -3926,7 +3926,7 @@ rs6000_option_override_internal (bool global_init_p)
 rs6000_isa_flags |= (ISA_2_5_MASKS_EMBEDDED & ~ignore_masks);
   else if (TARGET_FPRND)
 rs6000_isa_flags |= (ISA_2_4_MASKS & ~ignore_masks);
-  else if (TARGET_POPCNTB)
+  else if (TARGET_POWER5)
 rs6000_isa_flags |= (ISA_2_2_MASKS & ~ignore_masks);
   else if (TARGET_ALTIVEC)
 rs6000_isa_flags |= (OPTION_MASK_PPC_GFXOPT & ~ignore_masks);
diff --git a/gcc/config/rs6000/rs6000.h b/gcc/config/rs6000/rs6000.h
index db6112a09e11..d9a0ffe9f5b2 100644
--- a/gcc/config/rs6000/rs6000.h
+++ b/gcc/config/rs6000/rs6000.h
@@ -448,7 +448,7 @@ extern int rs6000_vector_align[];
Enable 32-bit fcfid's on any of the switches for newer ISA machines.  */
 #define TARGET_FCFID   (TARGET_POWERPC64   \
 || TARGET_PPC_GPOPT/* 970/power4 */\
-|| TARGET_POPCNTB  /* ISA 2.02 */  \
+|| TARGET_POWER5   /* ISA 2.02 */  \
 || TARGET_CMPB /* ISA 2.05 */  \
 || TARGET_POPCNTD) /* ISA 2.06 */
 
@@ -499,6 +499,9 @@ extern int rs6000_vector_align[];
 #define TARGET_MINMAX  (TARGET_HARD_FLOAT && TARGET_PPC_GFXOPT \
 && (TARGET_P9_MINMAX || !flag_trapping_math))
 
+/* Convert ISA bits like POPCNTB to PowerPC processors like POWER5.  */
+#define TARGET_POWER5  TARGET_POPCNTB
+
 /* In switching from using target_flags to using rs6000_isa_flags, the options
machinery creates OPTION_MASK_ instead of MASK_.  The MASK_
options that have not yet been replaced by their OPTION_MASK_
@@ -525,7 +528,7 @@ extern int rs6000_vector_align[];
 
 #define TARGET_EXTRA_BUILTINS  (TARGET_POWERPC64\
 || TARGET_PPC_GPOPT /* 970/power4 */\
-|| TARGET_POPCNTB   /* ISA 2.02 */  \
+|| TARGET_POWER5/* ISA 2.02 */  \
 || TARGET_CMPB  /* ISA 2.05 */  \
 || TARGET_POPCNTD   /* ISA 2.06 */  \
 || TARGET_ALTIVEC   \
@@ -541,9 +544,9 @@ extern int rs6000_vector_align[];
 #define TARGET_FRES(TARGET_HARD_FLOAT && TARGET_PPC_GFXOPT)
 
 #define TARGET_FRE (TARGET_HARD_FLOAT \
-&& (TARGET_POPCNTB || VECTOR_UNIT_VSX_P (DFmode)))
+&& (TARGET_POWER5 || VECTOR_UNIT_VSX_P (DFmode)))
 
-#define TARGET_FRSQRTES(TARGET_HARD_FLOAT && TARGET_POPCNTB \
+#define TARGET_FRSQRTES(TARGET_HARD_FLOAT && TARGET_POWER5 \
 && TARGET_PPC_GFXOPT)
 
 #define TARGET_FRSQRTE (TARGET_HARD_FLOAT \
diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index 9c718ca2a226..c5bd273be8b3 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs6

[gcc r15-8587] gccrs: ast: Add EnumItem::Kind

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

commit r15-8587-ge9a3e00c1be9ae548faa9baffec355de3d3cf589
Author: Arthur Cohen 
Date:   Thu Jan 2 18:31:54 2025 +

gccrs: ast: Add EnumItem::Kind

gcc/rust/ChangeLog:

* ast/rust-item.h: Add EnumItem::Kind for differentiating all 
variants that may be
used inside an enum declaration.

Diff:
---
 gcc/rust/ast/rust-item.h | 52 
 1 file changed, 52 insertions(+)

diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index 6b77449eb8d4..ecd355f6b8ae 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -1994,6 +1994,41 @@ class EnumItem : public VisItem
   location_t locus;
 
 public:
+  enum class Kind
+  {
+Identifier,
+Tuple,
+Struct,
+
+// FIXME: In the future, we'll need to remove this possibility as well as
+// remove the EnumItemDiscriminant class. The feature for arbitrary
+// discriminants on all kinds of variants has been stabilized, and a
+// "discriminant" is no longer an enum item variant - it's simply an
+// optional part of all variants.
+//
+// Per the reference:
+//
+// EnumItem :
+//OuterAttribute* Visibility?
+//IDENTIFIER ( EnumItemTuple | EnumItemStruct )? EnumItemDiscriminant?
+//
+// EnumItemTuple :
+//( TupleFields? )
+//
+// EnumItemStruct :
+//{ StructFields? }
+//
+// EnumItemDiscriminant :
+//= Expression
+//
+// So we instead need to remove the class, and add an optional expression 
to
+// the base EnumItem class
+//
+// gccrs#3340
+
+Discriminant,
+  };
+
   virtual ~EnumItem () {}
 
   EnumItem (Identifier variant_name, Visibility vis,
@@ -2002,6 +2037,8 @@ public:
   variant_name (std::move (variant_name)), locus (locus)
   {}
 
+  virtual Kind get_enum_item_kind () const { return Kind::Identifier; }
+
   // Unique pointer custom clone function
   std::unique_ptr clone_enum_item () const
   {
@@ -2043,6 +2080,11 @@ public:
   tuple_fields (std::move (tuple_fields))
   {}
 
+  EnumItem::Kind get_enum_item_kind () const override
+  {
+return EnumItem::Kind::Tuple;
+  }
+
   std::string as_string () const override;
 
   void accept_vis (ASTVisitor &vis) override;
@@ -2080,6 +2122,11 @@ public:
   struct_fields (std::move (struct_fields))
   {}
 
+  EnumItem::Kind get_enum_item_kind () const override
+  {
+return EnumItem::Kind::Struct;
+  }
+
   std::string as_string () const override;
 
   void accept_vis (ASTVisitor &vis) override;
@@ -2133,6 +2180,11 @@ public:
   EnumItemDiscriminant (EnumItemDiscriminant &&other) = default;
   EnumItemDiscriminant &operator= (EnumItemDiscriminant &&other) = default;
 
+  EnumItem::Kind get_enum_item_kind () const override
+  {
+return EnumItem::Kind::Discriminant;
+  }
+
   std::string as_string () const override;
 
   void accept_vis (ASTVisitor &vis) override;


[gcc r13-9482] aarch64: Use PAUTH instead of V8_3A in some places

2025-04-04 Thread Alfie Richards via Gcc-cvs
https://gcc.gnu.org/g:070296e6c313a7748efe053feacade4905901b5e

commit r13-9482-g070296e6c313a7748efe053feacade4905901b5e
Author: Andrew Carlotti 
Date:   Tue Jul 30 16:26:04 2024 +0100

aarch64: Use PAUTH instead of V8_3A in some places

gcc/ChangeLog:

* config/aarch64/aarch64.cc
(aarch64_expand_epilogue): Use TARGET_PAUTH.
* config/aarch64/aarch64.md: Update comment.

(cherry-picked from commit 20385cb92cbd4a1934661ab97a162c1e25935836)

Diff:
---
 gcc/config/aarch64/aarch64.cc | 6 +++---
 gcc/config/aarch64/aarch64.md | 8 
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index 0a98f005b71c..b211f9abd60a 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -10363,12 +10363,12 @@ aarch64_expand_epilogue (bool for_sibcall)
1) Sibcalls don't return in a normal way, so if we're about to call one
   we must authenticate.
 
-   2) The RETAA instruction is not available before ARMv8.3-A, so if we are
-  generating code for !TARGET_ARMV8_3 we can't use it and must
+   2) The RETAA instruction is not available without FEAT_PAuth, so if we
+  are generating code for !TARGET_PAUTH we can't use it and must
   explicitly authenticate.
 */
   if (aarch64_return_address_signing_enabled ()
-  && (for_sibcall || !TARGET_ARMV8_3))
+  && (for_sibcall || !TARGET_PAUTH))
 {
   switch (aarch_ra_sign_key)
{
diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md
index b585604cbe04..ff74e7dcef65 100644
--- a/gcc/config/aarch64/aarch64.md
+++ b/gcc/config/aarch64/aarch64.md
@@ -7280,11 +7280,11 @@
   [(set_attr "type" "f_cvtf2i")]
 )
 
-;; Pointer authentication patterns are always provided.  In architecture
-;; revisions prior to ARMv8.3-A these HINT instructions operate as NOPs.
+;; Pointer authentication patterns are always provided.  On targets that
+;; don't implement FEAT_PAuth these HINT instructions operate as NOPs.
 ;; This lets the user write portable software which authenticates pointers
-;; when run on something which implements ARMv8.3-A, and which runs
-;; correctly, but does not authenticate pointers, where ARMv8.3-A is not
+;; when run on something which implements FEAT_PAuth, and which runs
+;; correctly, but does not authenticate pointers, where FEAT_PAuth is not
 ;; implemented.
 
 ;; Signing/Authenticating R30 using SP as the salt.


[gcc r15-9087] gccrs: fix unconstrained infer vars on generic associated type

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

commit r15-9087-g766d89d962fb7529e358ae46c760a3539e65aa93
Author: Philip Herron 
Date:   Wed Mar 26 14:05:03 2025 +

gccrs: fix unconstrained infer vars on generic associated type

The trick here is that when Bar::test is resolved it resolves to the
trait method:

  fn , T> (placeholder) -> placeholder

Which is fine so we need to setup the associated types for Bar which
means looking up the associated impl block then setting up the projection
of A = T so it becomes:

  fn , T> (placeholder: projection:T)
-> placeholder: projection:T

But previously it was auto injecting inference variables so it became:

  fn , T> (placeholder: projection:?T)
-> placeholder: projection:?T

The issue is that the binding of the generics was still T so this caused
inference variables to be injected again but unlinked. A possible tweak
would be that we are substituting again with new infer vars to actually
just unify them enplace so they are all part of the chain. This still
might be needed but lets hold off for now.

So basically when we are Path probing we dont allow GAT's to generate new
inference vars because they wont be bound to this current segment which
just causes confusion.

Fixes Rust-GCC#3242

gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-reference.h: add default infer arg
* typecheck/rust-hir-trait-resolve.cc: dont add new infer vars
* typecheck/rust-hir-type-check-path.cc 
(TypeCheckExpr::resolve_segments): dont infer

gcc/testsuite/ChangeLog:

* rust/compile/issue-3242.rs: no longer skip the test

Signed-off-by: Philip Herron 

Diff:
---
 gcc/rust/typecheck/rust-hir-trait-reference.h  | 7 +++
 gcc/rust/typecheck/rust-hir-trait-resolve.cc   | 8 
 gcc/rust/typecheck/rust-hir-type-check-path.cc | 4 ++--
 gcc/testsuite/rust/compile/issue-3242.rs   | 1 -
 4 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-trait-reference.h 
b/gcc/rust/typecheck/rust-hir-trait-reference.h
index 6a570ed0fdbe..8b1ac7daf7f1 100644
--- a/gcc/rust/typecheck/rust-hir-trait-reference.h
+++ b/gcc/rust/typecheck/rust-hir-trait-reference.h
@@ -254,10 +254,9 @@ public:
 
   void setup_raw_associated_types ();
 
-  TyTy::BaseType *
-  setup_associated_types (const TyTy::BaseType *self,
- const TyTy::TypeBoundPredicate &bound,
- TyTy::SubstitutionArgumentMappings *args = nullptr);
+  TyTy::BaseType *setup_associated_types (
+const TyTy::BaseType *self, const TyTy::TypeBoundPredicate &bound,
+TyTy::SubstitutionArgumentMappings *args = nullptr, bool infer = true);
 
   void reset_associated_types ();
 
diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc 
b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
index c07425d48b7a..e4a61bdb0629 100644
--- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc
+++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
@@ -485,7 +485,7 @@ AssociatedImplTrait::setup_raw_associated_types ()
 TyTy::BaseType *
 AssociatedImplTrait::setup_associated_types (
   const TyTy::BaseType *self, const TyTy::TypeBoundPredicate &bound,
-  TyTy::SubstitutionArgumentMappings *args)
+  TyTy::SubstitutionArgumentMappings *args, bool infer)
 {
   // compute the constrained impl block generic arguments based on self and the
   // higher ranked trait bound
@@ -545,7 +545,7 @@ AssociatedImplTrait::setup_associated_types (
   std::vector subst_args;
   for (auto &p : substitutions)
 {
-  if (p.needs_substitution ())
+  if (p.needs_substitution () && infer)
{
  TyTy::TyVar infer_var = TyTy::TyVar::get_implicit_infer_var (locus);
  subst_args.push_back (
@@ -619,7 +619,7 @@ AssociatedImplTrait::setup_associated_types (
= unify_site_and (a->get_ref (), TyTy::TyWithLocation (a),
  TyTy::TyWithLocation (b), impl_predicate.get_locus (),
  true /*emit-errors*/, true /*commit-if-ok*/,
- false /*infer*/, true /*cleanup-on-fail*/);
+ true /*infer*/, true /*cleanup-on-fail*/);
   rust_assert (result->get_kind () != TyTy::TypeKind::ERROR);
 }
 
@@ -632,7 +632,7 @@ AssociatedImplTrait::setup_associated_types (
TyTy::TyWithLocation (impl_self_infer),
impl_predicate.get_locus (),
true /*emit-errors*/, true /*commit-if-ok*/,
-   false /*infer*/, true /*cleanup-on-fail*/);
+   true /*infer*/, true /*cleanup-on-fail*/);
   rust_assert (result->get_kind () != TyTy::TypeKind::ERROR);
   TyTy::BaseType *self_result = result;
 
diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc 
b

[gcc r15-8635] gccrs: derive(Clone): Improve existing testcase

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

commit r15-8635-g5ec40be008abda062c95daf61bce79bfb39055a5
Author: Arthur Cohen 
Date:   Thu Jan 2 11:00:21 2025 +

gccrs: derive(Clone): Improve existing testcase

gcc/testsuite/ChangeLog:

* rust/compile/derive_macro4.rs: Mark Copy and Clone as lang items.

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

diff --git a/gcc/testsuite/rust/compile/derive_macro4.rs 
b/gcc/testsuite/rust/compile/derive_macro4.rs
index b20043ba927b..8bf1bcaf5f7b 100644
--- a/gcc/testsuite/rust/compile/derive_macro4.rs
+++ b/gcc/testsuite/rust/compile/derive_macro4.rs
@@ -1,7 +1,10 @@
 #[lang = "sized"]
 pub trait Sized {}
 
+#[lang = "copy"]
 pub trait Copy {}
+
+#[lang = "clone"]
 pub trait Clone {
 fn clone(&self) -> Self;
 }


[gcc r15-8566] gccrs: hir: Start adapting visitors to accept multiple kinds of Paths

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

commit r15-8566-g5d79fbd65ccaf51afa90cab5454b3f6f5b0e6f75
Author: Arthur Cohen 
Date:   Wed Nov 6 16:32:35 2024 +0100

gccrs: hir: Start adapting visitors to accept multiple kinds of Paths

gcc/rust/ChangeLog:

* ast/rust-item.h: Add new method to specifically get a type-path.
* ast/rust-path.cc (LangItemPath::as_string): Implement properly.
* hir/rust-ast-lower-type.cc (ASTLowerTypePath::translate): Adapt
visitor to use the new LangItemPath.
* hir/rust-ast-lower-type.h: Likewise.
* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Likewise.
* resolve/rust-ast-resolve-type.h: Likewise.

Diff:
---
 gcc/rust/ast/rust-item.h  |  7 +++
 gcc/rust/ast/rust-path.cc |  3 +--
 gcc/rust/hir/rust-ast-lower-type.cc   |  9 +
 gcc/rust/hir/rust-ast-lower-type.h|  1 +
 gcc/rust/resolve/rust-ast-resolve-item.cc |  2 +-
 gcc/rust/resolve/rust-ast-resolve-type.h  | 28 
 6 files changed, 47 insertions(+), 3 deletions(-)

diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index a6276a72d8df..dca4aab45c83 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -3264,6 +3264,13 @@ public:
 return *trait_path;
   }
 
+  Type &get_trait_path_type ()
+  {
+rust_assert (trait_path->get_path_kind () == Path::Kind::Type);
+
+return (AST::Type &) static_cast (*trait_path);
+  }
+
 protected:
   /* Use covariance to implement clone function as returning this object
* rather than base */
diff --git a/gcc/rust/ast/rust-path.cc b/gcc/rust/ast/rust-path.cc
index 06c98cdcc2de..94cf2bb15141 100644
--- a/gcc/rust/ast/rust-path.cc
+++ b/gcc/rust/ast/rust-path.cc
@@ -152,8 +152,7 @@ RegularPath::as_string () const
 std::string
 LangItemPath::as_string () const
 {
-  // FIXME: Handle #[lang] paths
-  rust_unreachable ();
+  return "#[lang = \"" + LangItem::ToString (kind) + "\"]";
 }
 
 SimplePath
diff --git a/gcc/rust/hir/rust-ast-lower-type.cc 
b/gcc/rust/hir/rust-ast-lower-type.cc
index 58c93b9e25dd..c09d60fafc6f 100644
--- a/gcc/rust/hir/rust-ast-lower-type.cc
+++ b/gcc/rust/hir/rust-ast-lower-type.cc
@@ -19,10 +19,19 @@
 #include "rust-ast-lower-type.h"
 #include "optional.h"
 #include "rust-attribute-values.h"
+#include "rust-path.h"
 
 namespace Rust {
 namespace HIR {
 
+HIR::TypePath *
+ASTLowerTypePath::translate (AST::Path &type)
+{
+  rust_assert (type.get_path_kind () == AST::Path::Kind::Type);
+
+  return ASTLowerTypePath::translate (static_cast (type));
+}
+
 HIR::TypePath *
 ASTLowerTypePath::translate (AST::TypePath &type)
 {
diff --git a/gcc/rust/hir/rust-ast-lower-type.h 
b/gcc/rust/hir/rust-ast-lower-type.h
index 5bb9a7e5f7c6..72c6b29d7dd0 100644
--- a/gcc/rust/hir/rust-ast-lower-type.h
+++ b/gcc/rust/hir/rust-ast-lower-type.h
@@ -31,6 +31,7 @@ protected:
   using Rust::HIR::ASTLoweringBase::visit;
 
 public:
+  static HIR::TypePath *translate (AST::Path &type);
   static HIR::TypePath *translate (AST::TypePath &type);
 
   void visit (AST::TypePathSegmentFunction &segment) override;
diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc 
b/gcc/rust/resolve/rust-ast-resolve-item.cc
index 245523ae5aa8..a330541b6828 100644
--- a/gcc/rust/resolve/rust-ast-resolve-item.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-item.cc
@@ -680,7 +680,7 @@ ResolveItem::visit (AST::TraitImpl &impl_block)
 
   // setup paths
   CanonicalPath canonical_trait_type = CanonicalPath::create_empty ();
-  bool ok = ResolveTypeToCanonicalPath::go (impl_block.get_trait_path (),
+  bool ok = ResolveTypeToCanonicalPath::go (impl_block.get_trait_path_type (),
canonical_trait_type);
   if (!ok)
 {
diff --git a/gcc/rust/resolve/rust-ast-resolve-type.h 
b/gcc/rust/resolve/rust-ast-resolve-type.h
index 561948e85b83..ed055a1f04ea 100644
--- a/gcc/rust/resolve/rust-ast-resolve-type.h
+++ b/gcc/rust/resolve/rust-ast-resolve-type.h
@@ -21,6 +21,8 @@
 
 #include "rust-ast-resolve-base.h"
 #include "rust-ast-resolve-expr.h"
+#include "rust-hir-map.h"
+#include "rust-path.h"
 
 namespace Rust {
 namespace Resolver {
@@ -56,6 +58,32 @@ class ResolveType : public ResolverBase
   using Rust::Resolver::ResolverBase::visit;
 
 public:
+  static NodeId go (AST::TypePath &type_path)
+  {
+return ResolveType::go ((AST::Type &) type_path);
+  }
+
+  static NodeId go (AST::Path &type_path)
+  {
+if (type_path.get_path_kind () == AST::Path::Kind::LangItem)
+  {
+   auto &type = static_cast (type_path);
+
+   Analysis::Mappings::get_lang_item (type);
+
+   type.get_node_id ();
+  }
+
+rust_assert (type_path.get_path_kind () == AST::Path::Kind::Type);
+
+// We have to do this dance to first downcast to a typepath, and then 
upcast
+// to a Type. The altnernative is to split `go` into `go` and `go_inner` o

[gcc r15-8649] arm: testsuite: make unaligned-memcpy-*.c executable tests [PR91614]

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

commit r15-8649-g1d2257dc850d088f6d9267b4624ba08533ab2475
Author: Richard Earnshaw 
Date:   Fri Mar 21 15:20:03 2025 +

arm: testsuite: make unaligned-memcpy-*.c executable tests [PR91614]

These tests have been looking for a very specific instruction sequence
which has the tendency to be fairly unstable as a result.  But what is
more interesting is that the the tests must not contain instructions
that can't be used for unaligned data, and whether or not the copy is
executed correctly.

So make these tests executable and scan the assembler only to confirm
the absence of instructions that must not be used when the data is not
aligned.

These tests also used to be restricted to targets that support
unaligned accesses (because you get very different code otherwise).
But now we've made the tests executable and to check for the absence
of problem instructions, just falling back to memcpy *is* an
acceptable implementation.  So remove the requirement for unaligned
accesses.

gcc/testsuite:
PR target/91614
* gcc.target/arm/unaligned-memcpy-1.c: Make the test executable.
Only scan for the absence of instructions that cannot access
misaligned data.  Remove constraint of having unaligned accesses.
* gcc.target/arm/unaligned-memcpy-2.c: Likewise.
* gcc.target/arm/unaligned-memcpy-3.c: Likewise.
* gcc.target/arm/unaligned-memcpy-4.c: Likewise.

Diff:
---
 gcc/testsuite/gcc.target/arm/unaligned-memcpy-1.c | 34 +++
 gcc/testsuite/gcc.target/arm/unaligned-memcpy-2.c | 33 --
 gcc/testsuite/gcc.target/arm/unaligned-memcpy-3.c | 33 --
 gcc/testsuite/gcc.target/arm/unaligned-memcpy-4.c | 32 +++--
 4 files changed, 77 insertions(+), 55 deletions(-)

diff --git a/gcc/testsuite/gcc.target/arm/unaligned-memcpy-1.c 
b/gcc/testsuite/gcc.target/arm/unaligned-memcpy-1.c
index c4f564042252..0d883e3c1739 100644
--- a/gcc/testsuite/gcc.target/arm/unaligned-memcpy-1.c
+++ b/gcc/testsuite/gcc.target/arm/unaligned-memcpy-1.c
@@ -1,19 +1,31 @@
-/* { dg-do compile } */
-/* { dg-require-effective-target arm_unaligned } */
-/* { dg-options "-O2" } */
+/* { dg-do run } */
+/* { dg-options "-O2 -save-temps" } */
 
 #include 
 
-void unknown_alignment (char *dest, char *src)
+char src[17] __attribute__ ((aligned(8))) = "abcdefghijklmnopq";
+char result[17] __attribute__ ((aligned(8))) = {0};
+
+void __attribute__ ((noinline,noclone))
+unknown_alignment (char *dest, char *src)
 {
   memcpy (dest, src, 15);
 }
 
-/* We should see three unaligned word loads and store pairs, one unaligned
-   ldrh/strh pair, and an ldrb/strb pair.  Sanity check that.  */
+int main ()
+{
+  int i;
+  unknown_alignment (result+1, src+2);
+  for (i = 0; i < 15; i++)
+if (result[i+1] != src[i+2])
+  __builtin_abort ();
+  if (result[16] != 0)
+__builtin_abort ();
+  return 0;
+}
+
+/* Check that we don't use any instructions that assume an aligned source.  */
+/* { dg-final { scan-assembler-not {(ldm(ia)?\tr[0-9]|ldrd\t.*\[r[0-9]|vldr)} 
} } */
 
-/* { dg-final { scan-assembler-times "@ unaligned" 8 } } */
-/* { dg-final { scan-assembler-times "ldrh" 1 } } */
-/* { dg-final { scan-assembler-times "strh" 1 } } */
-/* { dg-final { scan-assembler-times "ldrb" 1 } } */
-/* { dg-final { scan-assembler-times "strb" 1 } } */
+/* Check that we don't use any instructions that assume an aligned dest.  */
+/* { dg-final { scan-assembler-not {(stm(ia)?\tr[0-9]|strd\t.*\[r[0-9]|vstr)} 
} } */
diff --git a/gcc/testsuite/gcc.target/arm/unaligned-memcpy-2.c 
b/gcc/testsuite/gcc.target/arm/unaligned-memcpy-2.c
index 1ad730d6407f..0da0bcd1c247 100644
--- a/gcc/testsuite/gcc.target/arm/unaligned-memcpy-2.c
+++ b/gcc/testsuite/gcc.target/arm/unaligned-memcpy-2.c
@@ -1,24 +1,27 @@
-/* { dg-do compile } */
-/* { dg-require-effective-target arm_unaligned } */
-/* { dg-options "-O2" } */
+/* { dg-do run } */
+/* { dg-options "-O2 -save-temps" } */
 
 #include 
 
-char dest[16] = { 0 };
+char dest[16] __attribute__((aligned(8))) = { 0 } ;
+char input[17] __attribute__ ((aligned(8))) = "abcdefghijklmnop";
 
-void aligned_dest (char *src)
+void __attribute__ ((noinline,noclone)) aligned_dest (char *src)
 {
   memcpy (dest, src, 15);
 }
 
-/* Expect a multi-word store for the main part of the copy, but subword
-   loads/stores for the remainder.  */
+int main ()
+{
+  int i;
+  aligned_dest (input+1);
+  for (i = 0; i < 15; i++)
+if (dest[i] != input[i+1])
+  __builtin_abort ();
+  if (dest[15] != 0)
+__builtin_abort ();
+  return 0;
+}
 
-/* { dg-final { scan-assembler-times "ldmia" 0 } } */
-/* { dg-final { scan-assembler-times "ldrd" 0 } } */
-/* { dg-final { scan-assembler-times "stmia" 1 { target { ! { 
arm_prefer_ldrd_strd } } } } } */
-/* { dg-final { scan-assembler

[gcc r15-8670] Darwin: We do not need libdl, it is provided in libSystem.

2025-04-04 Thread Iain D Sandoe via Gcc-cvs
https://gcc.gnu.org/g:4f9e72dd364915dafc03202cc6ad9ddffaee93f3

commit r15-8670-g4f9e72dd364915dafc03202cc6ad9ddffaee93f3
Author: Iain Sandoe 
Date:   Fri Mar 21 15:31:21 2025 +

Darwin: We do not need libdl, it is provided in libSystem.

Darwin provides this support as part of libSystem which is always
linked with user-space DSOs (including exes).

gcc/ChangeLog:

* config/darwin.h (DL_LIBRARY): New.

Signed-off-by: Iain Sandoe 

Diff:
---
 gcc/config/darwin.h | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h
index 3d2ced5fca31..8c164fd4b75b 100644
--- a/gcc/config/darwin.h
+++ b/gcc/config/darwin.h
@@ -45,9 +45,12 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If 
not, see
 
 #define OBJECT_FORMAT_MACHO 1
 
-/* Suppress g++ attempt to link in the math library automatically. */
+/* Suppress language-specific specs attempt to link in libm automatically. */
 #define MATH_LIBRARY ""
 
+/* Likewise libdl.  */
+#define DL_LIBRARY ""
+
 /* We have atexit.  */
 
 #define HAVE_ATEXIT


[gcc r15-8589] gccrs: lower: Correctly lower parenthesized types

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

commit r15-8589-gcd8547f85e53b42eff5a7c7572b466c023c75daf
Author: Arthur Cohen 
Date:   Wed Dec 25 17:55:09 2024 +

gccrs: lower: Correctly lower parenthesized types

This is useful for handling multiple trait bounds, and required for better 
handling of auto traits.

gcc/rust/ChangeLog:

* hir/rust-ast-lower-type.cc (ASTLoweringType::visit): Add 
implementation for
ParenthesizedType.
* hir/rust-ast-lower-type.h: Declare that new visitor.

gcc/testsuite/ChangeLog:

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

Diff:
---
 gcc/rust/hir/rust-ast-lower-type.cc| 19 +++
 gcc/rust/hir/rust-ast-lower-type.h |  2 ++
 gcc/testsuite/rust/compile/auto_traits1.rs | 27 +++
 3 files changed, 48 insertions(+)

diff --git a/gcc/rust/hir/rust-ast-lower-type.cc 
b/gcc/rust/hir/rust-ast-lower-type.cc
index df06e48b801d..d1f95edc3456 100644
--- a/gcc/rust/hir/rust-ast-lower-type.cc
+++ b/gcc/rust/hir/rust-ast-lower-type.cc
@@ -19,6 +19,7 @@
 #include "rust-ast-lower-type.h"
 #include "rust-hir-map.h"
 #include "rust-hir-path.h"
+#include "rust-hir-type.h"
 #include "rust-path.h"
 #include "rust-pattern.h"
 
@@ -471,6 +472,24 @@ ASTLoweringType::visit (AST::TraitObjectType &type)
 type.get_locus (), type.is_dyn ());
 }
 
+void
+ASTLoweringType::visit (AST::ParenthesisedType &type)
+{
+  auto *inner = ASTLoweringType::translate (*type.get_type_in_parens (),
+   default_to_static_lifetime);
+
+  auto crate_num = mappings.get_current_crate ();
+  Analysis::NodeMapping mapping (crate_num, type.get_node_id (),
+mappings.get_next_hir_id (crate_num),
+mappings.get_next_localdef_id (crate_num));
+
+  // FIXME: Do we actually need to know if a type is parenthesized in the HIR?
+  // or can we just use the type in parens?
+  translated
+= new HIR::ParenthesisedType (mapping, std::unique_ptr (inner),
+ type.get_locus ());
+}
+
 HIR::GenericParam *
 ASTLowerGenericParam::translate (AST::GenericParam ¶m)
 {
diff --git a/gcc/rust/hir/rust-ast-lower-type.h 
b/gcc/rust/hir/rust-ast-lower-type.h
index 0429e3fcf986..26ca8684083c 100644
--- a/gcc/rust/hir/rust-ast-lower-type.h
+++ b/gcc/rust/hir/rust-ast-lower-type.h
@@ -22,6 +22,7 @@
 #include "rust-ast-lower-base.h"
 #include "rust-ast-lower-expr.h"
 #include "rust-hir-path.h"
+#include "rust-type.h"
 
 namespace Rust {
 namespace HIR {
@@ -83,6 +84,7 @@ public:
   void visit (AST::NeverType &type) override;
   void visit (AST::TraitObjectTypeOneBound &type) override;
   void visit (AST::TraitObjectType &type) override;
+  void visit (AST::ParenthesisedType &type) override;
 
 private:
   ASTLoweringType (bool default_to_static_lifetime)
diff --git a/gcc/testsuite/rust/compile/auto_traits1.rs 
b/gcc/testsuite/rust/compile/auto_traits1.rs
new file mode 100644
index ..192052d48151
--- /dev/null
+++ b/gcc/testsuite/rust/compile/auto_traits1.rs
@@ -0,0 +1,27 @@
+// { dg-additional-options "-frust-compile-until=typecheck" }
+
+#![feature(optin_builtin_traits)]
+
+pub unsafe auto trait Send {}
+#[lang = "sync"]
+pub unsafe auto trait Sync {}
+
+trait A {
+fn a_method(&self) {}
+}
+
+fn foo(a: &(dyn A + Send + Sync)) {
+a.a_method();
+}
+
+struct S;
+
+impl A for S {
+fn a_method(&self) {}
+}
+
+fn main() {
+let s = S;
+
+foo(&s);
+}


[gcc r15-8562] gccrs: type-check: Remove unused capture in nr2.0

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

commit r15-8562-g9f1086da1060e87784118901bba826317ddedd46
Author: Arthur Cohen 
Date:   Fri Nov 29 12:03:59 2024 +0100

gccrs: type-check: Remove unused capture in nr2.0

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-type.cc 
(TypeCheckType::resolve_root_path):
Remove unused capture in lambda.

Diff:
---
 gcc/rust/typecheck/rust-hir-type-check-type.cc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc 
b/gcc/rust/typecheck/rust-hir-type-check-type.cc
index 89ede4e3013c..e9859a71f832 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc
@@ -19,6 +19,7 @@
 #include "rust-hir-type-check-type.h"
 #include "options.h"
 #include "optional.h"
+#include "rust-hir-map.h"
 #include "rust-hir-trait-resolve.h"
 #include "rust-hir-type-check-expr.h"
 #include "rust-hir-path-probe.h"
@@ -394,11 +395,10 @@ TypeCheckType::resolve_root_path (HIR::TypePath &path, 
size_t *offset,
{
  auto nr_ctx
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
  // assign the ref_node_id if we've found something
  nr_ctx.lookup (path.get_mappings ().get_nodeid ())
-   .map ([&ref_node_id, &path] (NodeId resolved) {
- ref_node_id = resolved;
-   });
+   .map ([&ref_node_id] (NodeId resolved) { ref_node_id = resolved; });
}
   else if (!resolver->lookup_resolved_name (ast_node_id, &ref_node_id))
resolver->lookup_resolved_type (ast_node_id, &ref_node_id);


[gcc r15-9187] c++/modules: inline loaded at eof

2025-04-04 Thread Jason Merrill via Gcc-cvs
https://gcc.gnu.org/g:acfe19f03bccd1f3183fd5d70d7a3c8c85e62fac

commit r15-9187-gacfe19f03bccd1f3183fd5d70d7a3c8c85e62fac
Author: Jason Merrill 
Date:   Tue Apr 1 19:22:18 2025 -0400

c++/modules: inline loaded at eof

std/format/string.cc and a few other libstdc++ tests were failing with
module std with undefined references to __failed_to_parse_format_spec.  This
turned out to be because since r15-8012 we don't end up calling
note_vague_linkage_fn for functions loaded after at_eof is set.

But once import_export_decl decides on COMDAT linkage, we should be able to
just clear DECL_EXTERNAL and let cgraph take it from there.

I initially made this change in import_export_decl, but decided that for GCC
15 it would be safer to limit the change to modules.  For GCC 16 I'd like to
do away with DECL_NOT_REALLY_EXTERN entirely, it's been obsolete since
cgraphunit in 2003.

gcc/cp/ChangeLog:

* module.cc (module_state::read_cluster)
(post_load_processing): Clear DECL_EXTERNAL if DECL_COMDAT.

Diff:
---
 gcc/cp/module.cc | 13 +
 1 file changed, 13 insertions(+)

diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index ce22b2ece3f0..89deabbfee37 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -16679,6 +16679,15 @@ module_state::read_cluster (unsigned snum)
 #endif
  cfun->returns_struct = aggr;
  expand_or_defer_fn (decl);
+
+ /* If we first see this function after at_eof, it doesn't get
+note_vague_linkage_fn from tentative_decl_linkage, so the loop in
+c_parse_final_cleanups won't consider it.  But with DECL_COMDAT we
+can just clear DECL_EXTERNAL and let cgraph decide.
+FIXME handle this outside module.cc after GCC 15.  */
+ if (at_eof && DECL_COMDAT (decl) && DECL_EXTERNAL (decl)
+ && DECL_NOT_REALLY_EXTERN (decl))
+   DECL_EXTERNAL (decl) = false;
}
 
 }
@@ -19159,6 +19168,10 @@ post_load_processing ()
 
   gcc_checking_assert (DECL_MAYBE_IN_CHARGE_CDTOR_P (decl));
   expand_or_defer_fn (decl);
+  /* As in module_state::read_cluster.  */
+  if (at_eof && DECL_COMDAT (decl) && DECL_EXTERNAL (decl)
+ && DECL_NOT_REALLY_EXTERN (decl))
+   DECL_EXTERNAL (decl) = false;
 }
 
   cfun = old_cfun;


[gcc r15-8894] OpenMP: interop - fix Fortran test

2025-04-04 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:e0a1d0e044c6eb129d1133d5af51818129a4d4e0

commit r15-8894-ge0a1d0e044c6eb129d1133d5af51818129a4d4e0
Author: Paul-Antoine Arras 
Date:   Mon Mar 24 15:53:36 2025 +0100

OpenMP: interop - fix Fortran test

This fixes up commit r15-8654-g99e2906ae255fc:
* Do not use omp_lib in Fortran compile test; instead, provide needed
declarations explicitly.
* Update scan-dump patterns to be compatible with 32-bit architectures.

gcc/testsuite/ChangeLog:

* gfortran.dg/gomp/interop-5.f90: Declare omp_interop_kind 
explicitly
instead of use'ing omp_lib. Update scan-dumps to allow for 4-byte
pointers.

Diff:
---
 gcc/testsuite/gfortran.dg/gomp/interop-5.f90 | 14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/gcc/testsuite/gfortran.dg/gomp/interop-5.f90 
b/gcc/testsuite/gfortran.dg/gomp/interop-5.f90
index a6a2d719189c..a08eeb83f716 100644
--- a/gcc/testsuite/gfortran.dg/gomp/interop-5.f90
+++ b/gcc/testsuite/gfortran.dg/gomp/interop-5.f90
@@ -1,7 +1,13 @@
 ! { dg-additional-options "-fdump-tree-omplower" }
 
 subroutine sub1 (a1, a2, a3, a4)
-   use omp_lib, only: omp_interop_kind
+   use iso_c_binding
+   implicit none
+
+   ! The following definitions are in omp_lib, which cannot be included
+   ! in gcc/testsuite/
+   integer, parameter :: omp_interop_kind = c_intptr_t
+
integer(omp_interop_kind) :: a1  ! by ref
integer(omp_interop_kind), optional :: a2 ! as pointer
integer(omp_interop_kind), allocatable :: a3 ! ref to pointer
@@ -9,13 +15,13 @@ subroutine sub1 (a1, a2, a3, a4)
integer(omp_interop_kind) :: b
 
!$omp interop init(target : a1, a2, a3, a4, b)
-   ! { dg-final { scan-tree-dump-times "void \\* 
interopobjs\.\[0-9\]+\\\[5\\\];\[\r\n ]*integer\\(kind=4\\) 
tgt_tgtsync\.\[0-9\]+\\\[5\\\];\[\r\n ]*integer\\(kind=8\\) \\* & 
a3\.\[0-9\]+;\[\r\n ]*integer\\(kind=8\\) \\* D\.\[0-9\]+;\[\r\n 
]*integer\\(kind=8\\) \\* a2\.\[0-9\]+;\[\r\n ]*integer\\(kind=8\\) & 
a1\.\[0-9\]+;\[\r\n ]*interopobjs\.\[0-9\]+\\\[0\\\] = &b;\[\r\n 
]*tgt_tgtsync\.\[0-9\]+\\\[0\\\] = 1;\[\r\n ]*interopobjs\.\[0-9\]+\\\[1\\\] = 
&a4;\[\r\n ]*tgt_tgtsync\.\[0-9\]+\\\[1\\\] = 1;\[\r\n ]*a3\.\[0-9\]+ = 
a3;\[\r\n ]*D\.\[0-9\]+ = \\*a3\.\[0-9\]+;\[\r\n 
]*interopobjs\.\[0-9\]+\\\[2\\\] = D\.\[0-9\]+;\[\r\n 
]*tgt_tgtsync\.\[0-9\]+\\\[2\\\] = 1;\[\r\n ]*a2\.\[0-9\]+ = a2;\[\r\n 
]*interopobjs\.\[0-9\]+\\\[3\\\] = a2\.\[0-9\]+;\[\r\n 
]*tgt_tgtsync\.\[0-9\]+\\\[3\\\] = 1;\[\r\n ]*a1\.\[0-9\]+ = a1;\[\r\n 
]*interopobjs\.\[0-9\]+\\\[4\\\] = a1\.\[0-9\]+;\[\r\n 
]*tgt_tgtsync\.\[0-9\]+\\\[4\\\] = 1;\[\r\n ]*__builtin_GOMP_interop \\(-5, 5, 
&interopobjs\.\[0-9\]+, &tgt_tgtsync\
 .\[0-9\]+, 0B, 0, 0B, 0, 0B, 0, 0B\\);" 1 "omplower" } }
+   ! { dg-final { scan-tree-dump-times "void \\* 
interopobjs\.\[0-9\]+\\\[5\\\];\[\r\n ]*integer\\(kind=4\\) 
tgt_tgtsync\.\[0-9\]+\\\[5\\\];\[\r\n ]*integer\\(kind=\[48\]\\) \\* & 
a3\.\[0-9\]+;\[\r\n ]*integer\\(kind=\[48\]\\) \\* D\.\[0-9\]+;\[\r\n 
]*integer\\(kind=\[48\]\\) \\* a2\.\[0-9\]+;\[\r\n ]*integer\\(kind=\[48\]\\) & 
a1\.\[0-9\]+;\[\r\n ]*interopobjs\.\[0-9\]+\\\[0\\\] = &b;\[\r\n 
]*tgt_tgtsync\.\[0-9\]+\\\[0\\\] = 1;\[\r\n ]*interopobjs\.\[0-9\]+\\\[1\\\] = 
&a4;\[\r\n ]*tgt_tgtsync\.\[0-9\]+\\\[1\\\] = 1;\[\r\n ]*a3\.\[0-9\]+ = 
a3;\[\r\n ]*D\.\[0-9\]+ = \\*a3\.\[0-9\]+;\[\r\n 
]*interopobjs\.\[0-9\]+\\\[2\\\] = D\.\[0-9\]+;\[\r\n 
]*tgt_tgtsync\.\[0-9\]+\\\[2\\\] = 1;\[\r\n ]*a2\.\[0-9\]+ = a2;\[\r\n 
]*interopobjs\.\[0-9\]+\\\[3\\\] = a2\.\[0-9\]+;\[\r\n 
]*tgt_tgtsync\.\[0-9\]+\\\[3\\\] = 1;\[\r\n ]*a1\.\[0-9\]+ = a1;\[\r\n 
]*interopobjs\.\[0-9\]+\\\[4\\\] = a1\.\[0-9\]+;\[\r\n 
]*tgt_tgtsync\.\[0-9\]+\\\[4\\\] = 1;\[\r\n ]*__builtin_GOMP_interop \\(-5, 5, 
&interopobjs\.\[0
 -9\]+, &tgt_tgtsync\.\[0-9\]+, 0B, 0, 0B, 0, 0B, 0, 0B\\);" 1 "omplower" } }
 
!$omp interop use(a1, a2, a3, a4, b)
-   ! { dg-final { scan-tree-dump-times "void \\* 
interopobjs\.\[0-9\]+\\\[5\\\];\[\r\n ]*integer\\(kind=8\\) b\.\[0-9\]+;\[\r\n 
]*void \\* b\.\[0-9\]+;\[\r\n ]*integer\\(kind=8\\) a4\.\[0-9\]+;\[\r\n ]*void 
\\* a4\.\[0-9\]+;\[\r\n ]*integer\\(kind=8\\) \\* & a3\.\[0-9\]+;\[\r\n 
]*integer\\(kind=8\\) \\* D\.\[0-9\]+;\[\r\n ]*integer\\(kind=8\\) 
D\.\[0-9\]+;\[\r\n ]*void \\* D\.\[0-9\]+;\[\r\n ]*integer\\(kind=8\\) \\* 
a2\.\[0-9\]+;\[\r\n ]*integer\\(kind=8\\) D\.\[0-9\]+;\[\r\n ]*void \\* 
D\.\[0-9\]+;\[\r\n ]*integer\\(kind=8\\) & a1\.\[0-9\]+;\[\r\n 
]*integer\\(kind=8\\) D\.\[0-9\]+;\[\r\n ]*void \\* D\.\[0-9\]+;\[\r\n 
]*b\.\[0-9\]+ = b;\[\r\n ]*b\.\[0-9\]+ = \\(void \\*\\) b\.\[0-9\]+;\[\r\n 
]*interopobjs\.\[0-9\]+\\\[0\\\] = b\.\[0-9\]+;\[\r\n ]*a4\.\[0-9\]+ = 
a4;\[\r\n ]*a4\.\[0-9\]+ = \\(void \\*\\) a4\.\[0-9\]+;\[\r\n 
]*interopobjs\.\[0-9\]+\\\[1\\\] = a4\.\[0-9\]+;\[\r\n ]*a3\.\[0-9\]+ = 
a3;\[\r\n ]*D\.\[0-9\]+ = \\*a3\.\[0-9\]+;\[\r\n ]*D\.\[0-9\]+ = 
\\*D\.\[0-9\]+;\[\r\n ]*D
 \.\[0-9\]+ = \\(void \\*\\) D\.\[0-9\]+;\[\r\n 
]*interopobjs\.

[gcc r15-8318] gccrs: [gccrs#2324] Add error message for E0532

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

commit r15-8318-g04bc5a98a1da2e5cceefede34950d088e7923f06
Author: Liam Naddell 
Date:   Sat Aug 3 01:36:06 2024 -0400

gccrs: [gccrs#2324] Add error message for E0532

gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-pattern.cc:
Emit E0532 when trying to reference a Tuple or Struct variant
using a non Tuple or Struct pattern.

gcc/testsuite/ChangeLog:
* rust/compile/issue-2324-1.rs:
add test for E0532 with tuple enum variant
* rust/compile/issue-2324-2.rs:
add test for E0532 with struct enum variant

Signed-off-by: Liam Naddell 

Diff:
---
 gcc/rust/typecheck/rust-hir-type-check-pattern.cc | 25 +++
 gcc/testsuite/rust/compile/issue-2324-1.rs| 19 +
 gcc/testsuite/rust/compile/issue-2324-2.rs| 19 +
 3 files changed, 63 insertions(+)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-pattern.cc 
b/gcc/rust/typecheck/rust-hir-type-check-pattern.cc
index c469f6095d80..1a3d0ecd1859 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-pattern.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-pattern.cc
@@ -44,6 +44,31 @@ void
 TypeCheckPattern::visit (HIR::PathInExpression &pattern)
 {
   infered = TypeCheckExpr::Resolve (&pattern);
+
+  /*
+   * We are compiling a PathInExpression, which can't be a Struct or Tuple
+   * pattern. We should check that the declaration we are referencing IS NOT a
+   * struct pattern or tuple with values.
+   */
+
+  rust_assert (infered->get_kind () == TyTy::TypeKind::ADT);
+  TyTy::ADTType *adt = static_cast (infered);
+
+  HirId variant_id = UNKNOWN_HIRID;
+  bool ok
+= context->lookup_variant_definition (pattern.get_mappings ().get_hirid (),
+ &variant_id);
+  rust_assert (ok);
+
+  TyTy::VariantDef *variant = nullptr;
+  ok = adt->lookup_variant_by_id (variant_id, &variant);
+
+  TyTy::VariantDef::VariantType vty = variant->get_variant_type ();
+
+  if (vty != TyTy::VariantDef::VariantType::NUM)
+rust_error_at (
+  pattern.get_final_segment ().get_locus (), ErrorCode::E0532,
+  "expected unit struct, unit variant or constant, found tuple variant");
 }
 
 void
diff --git a/gcc/testsuite/rust/compile/issue-2324-1.rs 
b/gcc/testsuite/rust/compile/issue-2324-1.rs
new file mode 100644
index ..afce1f3b570c
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-2324-1.rs
@@ -0,0 +1,19 @@
+enum State {
+Succeeded,
+Failed(u32),
+}
+
+fn print_on_failure(state: &State) {
+match *state {
+State::Succeeded => (),
+State::Failed => (), // { dg-error "expected unit struct, unit variant 
or constant, found tuple variant" }
+_ => ()
+}
+}
+
+fn main() {
+let b = State::Failed(1);
+
+print_on_failure(&b);
+
+}
diff --git a/gcc/testsuite/rust/compile/issue-2324-2.rs 
b/gcc/testsuite/rust/compile/issue-2324-2.rs
new file mode 100644
index ..5ef40147961a
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-2324-2.rs
@@ -0,0 +1,19 @@
+enum State {
+Succeeded,
+Failed { x: u32 },
+}
+
+fn print_on_failure(state: &State) {
+match *state {
+State::Succeeded => (),
+State::Failed => (), // { dg-error "expected unit struct, unit variant 
or constant, found tuple variant" }
+_ => ()
+}
+}
+
+fn main() {
+let b = State::Failed{x: 1};
+
+print_on_failure(&b);
+
+}


[gcc r15-9210] lto: lto-opts fixes [PR119625]

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

commit r15-9210-gd25728c98682c058bfda79333c94b0a8cf2a3f49
Author: Jakub Jelinek 
Date:   Fri Apr 4 20:57:09 2025 +0200

lto: lto-opts fixes [PR119625]

I can reproduce a really weird error in our distro i686 trunk gcc
(but haven't managed to reproduce it with vanilla trunk yet).
echo 'void foo (void) {}' > a.c; gcc -O2 -flto=auto -m32 -march=i686 
-ffat-lto-objects -fhardened -o a.o -c a.c; gcc -O2 -flto=auto -m32 -march=i686 
-r -o a.lo a.o
lto1: fatal error: open  failed: No such file or directory
compilation terminated.
lto-wrapper: fatal error: gcc returned 1 exit status
The error is because
cat ./a.lo.lto.o-args.0
""
a.o
My suspicion is that this "" in there is caused by weird .gnu.lto_.opts
section content during
gcc -O2 -flto=auto -m32 -march=i686 -ffat-lto-objects -fhardened -S -o a.s 
-c a.c
compilation (and I can reproduce that one with vanilla trunk).
The above results in
.section.gnu.lto_.opts,"e",@progbits
.string "'-fno-openmp' '-fno-openacc' '-fPIC' '' '-m32' 
'-march=i686' '-O2' '-flto=auto' '-ffat-lto-objects'"
There are two weird things, one (IMHO the cause of the "" later on) is
the '' part, I think it comes from lto_write_options doing
append_to_collect_gcc_options (&temporary_obstack, &first_p, "");
IMHO it shouldn't call append_to_collect_gcc_options at all for that case.

The -fhardened option causes global_options.x_flag_cf_protection
to be set to CF_FULL and later on the backend option processing
sets it to CF_FULL | CF_SET (i.e. 7, a value not handled in
lto_write_options).

The following patch fixes it by not emitting anything there if
flag_cf_protection is one of the unhandled values.

Perhaps it could incrementally use
switch (global_options.x_flag_cf_protection & ~CF_SET)
instead, dunno.

And the other problem is that the -fPIC in there is really weird.
Our distro compiler or vanilla configured trunk certainly doesn't
default to -fPIC and -fhardened uses -fPIE when
-fPIC/-fpic/-fno-pie/-fno-pic is not specified, so I was expecting
-fPIE in there.
The thing is that the -fpie option causes setting of both
global_options.x_flag_pi{c,e} to 1, -fPIE both to 2:
  /* If -fPIE or -fpie is used, turn on PIC.  */
  if (opts->x_flag_pie)
opts->x_flag_pic = opts->x_flag_pie;
  else if (opts->x_flag_pic == -1)
opts->x_flag_pic = 0;
  if (opts->x_flag_pic && !opts->x_flag_pie)
opts->x_flag_shlib = 1;
so checking first for flag_pic == 2 and then flag_pic == 1
and only afterwards for flag_pie means we never print
-fPIE/-fpie.

Or do you want something further (like
switch (global_options.x_flag_cf_protection & ~CF_SET)
)?

2025-04-04  Jakub Jelinek  

PR lto/119625
* lto-opts.cc (lto_write_options): If neither flag_pic nor
flag_pie are set, check first for flag_pie and only later
for flag_pic rather than the other way around, use a temporary
variable.  If flag_cf_protection is not set, don't append anything
if flag_cf_protection is none of CF_{NONE,FULL,BRANCH,RETURN} and
use a temporary variable.

Diff:
---
 gcc/lto-opts.cc | 43 ++-
 1 file changed, 22 insertions(+), 21 deletions(-)

diff --git a/gcc/lto-opts.cc b/gcc/lto-opts.cc
index dee1caafc558..3959598b497c 100644
--- a/gcc/lto-opts.cc
+++ b/gcc/lto-opts.cc
@@ -82,31 +82,32 @@ lto_write_options (void)
  subject of merging in lto-wrapper.  */
   if (!OPTION_SET_P (flag_pic) && !OPTION_SET_P (flag_pie))
 {
-   append_to_collect_gcc_options (&temporary_obstack, &first_p,
- global_options.x_flag_pic == 2
- ? "-fPIC"
- : global_options.x_flag_pic == 1
- ? "-fpic"
- : global_options.x_flag_pie == 2
- ? "-fPIE"
- : global_options.x_flag_pie == 1
- ? "-fpie"
- : "-fno-pie");
+  const char *pic = "-fno-pie";
+  if (global_options.x_flag_pie == 2)
+   pic = "-fPIE";
+  else if (global_options.x_flag_pie == 1)
+   pic = "-fpie";
+  else if (global_options.x_flag_pic == 2)
+   pic = "-fPIC";
+  else if (global_options.x_flag_pic == 1)
+   pic = "-fpic";
+  append_to_collect_gcc_options (&temporary_obstack, &first_p, pic);
 }
 
   if (!OPTION_SET_P (flag_cf_protection))
 {
-  append_to_collect_gcc_options (
-   &temporary_obstack, &first_p,
-   global_options.x_flag_cf_protectio

[gcc r15-9195] libstdc++: Fix whitespace in std::basic_string::_M_construct

2025-04-04 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:4b884f3d6335539447d32c6462cc4ef52e30e273

commit r15-9195-g4b884f3d6335539447d32c6462cc4ef52e30e273
Author: Jonathan Wakely 
Date:   Thu Apr 3 14:15:51 2025 +0100

libstdc++: Fix whitespace in std::basic_string::_M_construct

libstdc++-v3/ChangeLog:

* include/bits/basic_string.tcc: Fix whitespace.

Diff:
---
 libstdc++-v3/include/bits/basic_string.tcc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/bits/basic_string.tcc 
b/libstdc++-v3/include/bits/basic_string.tcc
index a5df7cb1f4bc..02230aca5d27 100644
--- a/libstdc++-v3/include/bits/basic_string.tcc
+++ b/libstdc++-v3/include/bits/basic_string.tcc
@@ -279,11 +279,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // Length of string constructed is easier to propagate inter-procedurally
   // than difference between iterators.
   template
- template
+template
 _GLIBCXX20_CONSTEXPR 
 void
 basic_string<_CharT, _Traits, _Alloc>::
-_M_construct(const _CharT *__str, size_type __n)
+_M_construct(const _CharT* __str, size_type __n)
 {
   if (__n > size_type(_S_local_capacity))
{


[gcc r15-9211] libstdc++: Avoid redundant value_type object in flat_set::emplace [PR119620]

2025-04-04 Thread Patrick Palka via Libstdc++-cvs
https://gcc.gnu.org/g:2a36d22ab52d6ffce9a1fcaf7aca83336679e111

commit r15-9211-g2a36d22ab52d6ffce9a1fcaf7aca83336679e111
Author: Patrick Palka 
Date:   Fri Apr 4 15:05:09 2025 -0400

libstdc++: Avoid redundant value_type object in flat_set::emplace [PR119620]

flat_set::emplace (and flat_multiset's) currently unconditionally
constructs an object outside of the container, but if we're passed
a value_type object we can and should avoid that.

PR libstdc++/119620

libstdc++-v3/ChangeLog:

* include/std/flat_set (_Flat_set_impl::_M_try_emplace): Split
out into two overloads, one taking at least one argument and one
taking zero arguments.  Turn __k into an auto&& reference bound
to __arg if it's already a value_type and otherwise bound to a
lifetime-extended value_type temporary.
* testsuite/23_containers/flat_multiset/1.cc (test08): New test.
* testsuite/23_containers/flat_set/1.cc (test08): New test.

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

Diff:
---
 libstdc++-v3/include/std/flat_set  | 20 
 .../testsuite/23_containers/flat_multiset/1.cc | 22 ++
 libstdc++-v3/testsuite/23_containers/flat_set/1.cc | 20 
 3 files changed, 58 insertions(+), 4 deletions(-)

diff --git a/libstdc++-v3/include/std/flat_set 
b/libstdc++-v3/include/std/flat_set
index a7b0b8aef151..3e15d1af4162 100644
--- a/libstdc++-v3/include/std/flat_set
+++ b/libstdc++-v3/include/std/flat_set
@@ -350,12 +350,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   { return _M_cont.max_size(); }
 
   // modifiers
-  template
+  template
pair
-   _M_try_emplace(optional __hint, _Args&&... __args)
+   _M_try_emplace(optional __hint, _Arg&& __arg, 
_Args&&... __args)
{
  // TODO: Simplify and audit the hint handling.
- value_type __k(std::forward<_Args>(__args)...);
+ auto&& __k = [&] -> decltype(auto) {
+   if constexpr (sizeof...(_Args) == 0
+ && same_as, value_type>)
+ return std::forward<_Arg>(__arg);
+   else
+ return value_type(std::forward<_Arg>(__arg),
+   std::forward<_Args>(__args)...);
+ }();
  typename container_type::iterator __it;
  int __r = -1, __s = -1;
  if (__hint.has_value()
@@ -397,11 +404,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
  return {__it, false};
 
  auto __guard = _M_make_clear_guard();
- __it = _M_cont.insert(__it, std::move(__k));
+ __it = _M_cont.insert(__it, std::forward(__k));
  __guard._M_disable();
  return {__it, true};
}
 
+  template
+   pair
+   _M_try_emplace(optional __hint)
+   { return _M_try_emplace(__hint, value_type()); }
+
   template
requires is_constructible_v
__emplace_result_t
diff --git a/libstdc++-v3/testsuite/23_containers/flat_multiset/1.cc 
b/libstdc++-v3/testsuite/23_containers/flat_multiset/1.cc
index dc3cecd9720c..7d9a33c6b000 100644
--- a/libstdc++-v3/testsuite/23_containers/flat_multiset/1.cc
+++ b/libstdc++-v3/testsuite/23_containers/flat_multiset/1.cc
@@ -214,6 +214,27 @@ void test07()
 #endif
 }
 
+void
+test08()
+{
+  // PR libstdc++/119620 -- flat_set::emplace always constructs element on the 
stack
+  static int copy_counter;
+  struct A {
+A() { }
+A(const A&) { ++copy_counter; }
+A& operator=(const A&) { ++copy_counter; return *this; }
+auto operator<=>(const A&) const = default;
+  };
+  std::vector v;
+  v.reserve(2);
+  std::flat_multiset s(std::move(v));
+  A a;
+  s.emplace(a);
+  VERIFY( copy_counter == 1 );
+  s.emplace(a);
+  VERIFY( copy_counter == 2 );
+}
+
 int
 main()
 {
@@ -225,4 +246,5 @@ main()
   test05();
   test06();
   test07();
+  test08();
 }
diff --git a/libstdc++-v3/testsuite/23_containers/flat_set/1.cc 
b/libstdc++-v3/testsuite/23_containers/flat_set/1.cc
index 90f5855859f7..ed24fab785b5 100644
--- a/libstdc++-v3/testsuite/23_containers/flat_set/1.cc
+++ b/libstdc++-v3/testsuite/23_containers/flat_set/1.cc
@@ -229,6 +229,25 @@ void test07()
 #endif
 }
 
+void
+test08()
+{
+  // PR libstdc++/119620 -- flat_set::emplace always constructs element on the 
stack
+  static int copy_counter;
+  struct A {
+A() { }
+A(const A&) { ++copy_counter; }
+A& operator=(const A&) { ++copy_counter; return *this; }
+auto operator<=>(const A&) const = default;
+  };
+  std::flat_set s;
+  A a;
+  s.emplace(a);
+  VERIFY( copy_counter == 1 );
+  s.emplace(a);
+  VERIFY( copy_counter == 1 );
+}
+
 int
 main()
 {
@@ -240,4 +259,5 @@ main()
   test05();
   test06();
   test07();
+  test08();
 }


[gcc r15-9163] Doc: Improve wording of -Werror documentation [PR58973]

2025-04-04 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:0acac6c432aef97222f14a1b87b9e9f9ee94c9e8

commit r15-9163-g0acac6c432aef97222f14a1b87b9e9f9ee94c9e8
Author: Sandra Loosemore 
Date:   Wed Apr 2 21:29:33 2025 +

Doc: Improve wording of -Werror documentation [PR58973]

gcc/ChangeLog
PR driver/58973
* common.opt (Werror, Werror=): Use less awkward wording in
description.
(pedantic-errors): Likewise.
* doc/invoke.texi (Warning Options): Likewise for -Werror and
-Werror= here.

Co-Authored-By: GUO Yixuan 

Diff:
---
 gcc/common.opt  | 6 +++---
 gcc/doc/invoke.texi | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/gcc/common.opt b/gcc/common.opt
index 9400c4b94e88..b9e74cd3ac41 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -614,11 +614,11 @@ Warn when an optimization pass is disabled.
 
 Werror
 Common Var(warnings_are_errors)
-Treat all warnings as errors.
+Turn all warnings into errors.
 
 Werror=
 Common Joined
-Treat specified warning as error.
+Turn the specified warning into an error.
 
 Wextra
 Common Var(extra_warnings) Warning
@@ -3805,7 +3805,7 @@ Common Alias(Wpedantic)
 
 pedantic-errors
 Common Var(flag_pedantic_errors)
-Like -pedantic but issue them as errors.
+Like -pedantic but issue errors instead of warnings.
 
 pg
 Driver
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index b2b9b37ca83a..4c9af429ab08 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -6145,12 +6145,12 @@ Inhibit all warning messages.
 @opindex Werror
 @opindex Wno-error
 @item -Werror
-Make all warnings into errors.
+Turn all warnings into errors.
 
 @opindex Werror=
 @opindex Wno-error=
 @item -Werror=
-Make the specified warning into an error.  The specifier for a warning
+Turn the specified warning into an error.  The specifier for a warning
 is appended; for example @option{-Werror=switch} turns the warnings
 controlled by @option{-Wswitch} into errors.  This switch takes a
 negative form, to be used to negate @option{-Werror} for specific


[gcc/devel/omp/gcc-14] GCN, nvptx: Don't default-disable libstdc++ build

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

commit a3e8f61a2f56032767b70f252c58aab94327f872
Author: Thomas Schwinge 
Date:   Mon Jul 11 22:36:39 2022 +0200

GCN, nvptx: Don't default-disable libstdc++ build

In addition to making libstdc++ itself available, this, via enabling
'build-gcc/*/libstdc++-v3/scripts/testsuite_flags', in particular also makes
the standard C++ headers available to 'make check-gcc-c++'.  With that, 
there
are a lot of FAIL/UNRESOLVED -> PASS progressions, where we previously ran
into, for example:

FAIL: g++.dg/coroutines/co-await-syntax-00-needs-expr.C  (test for 
errors, line 6)
FAIL: g++.dg/coroutines/co-await-syntax-00-needs-expr.C (test for 
excess errors)
Excess errors:
[...]/gcc/testsuite/g++.dg/coroutines/coro.h:132:10: fatal error: 
cstdlib: No such file or directory

Similarly, there are a lot of FAIL/UNRESOLVED -> UNSUPPORTED "progressions" 
due
to 'sorry, unimplemented: exception handling not supported'.

The 'make check-target-libstdc++-v3' results don't look too bad, either.

This also reverts Subversion r221362
(Git commit d94fae044da071381b73a2ee8afa874b14fa3820) "No libstdc++ for 
nvptx",
and commit 2f4f3c0e9345805160ecacd6de527b519a8c9206 "No libstdc++ for GCN".

With libstdc++ now available, libgrust gets enabled, which we in turn again
have to disable, for 'sorry, unimplemented: exception handling not 
supported'
reasons.

PR target/92713
PR target/101544
* configure.ac [GCN, nvptx] (noconfigdirs): Don't add
'target-libstdc++-v3'.  Add 'target-libgrust'.
* configure: Regenerate.
gcc/
* config/gcn/gcn.h (LIBSTDCXX): Don't set.
* config/nvptx/nvptx.h (LIBSTDCXX): Likewise.

(cherry picked from commit c650b557cb01f97bebb894aa68e5e74c2147c395)

Diff:
---
 ChangeLog.omp| 11 +++
 configure| 16 +++-
 configure.ac | 16 +++-
 gcc/ChangeLog.omp| 10 ++
 gcc/config/gcn/gcn.h |  4 
 gcc/config/nvptx/nvptx.h |  4 
 6 files changed, 43 insertions(+), 18 deletions(-)

diff --git a/ChangeLog.omp b/ChangeLog.omp
index 8caf51a64e58..6a0f75409039 100644
--- a/ChangeLog.omp
+++ b/ChangeLog.omp
@@ -1,3 +1,14 @@
+2025-03-19  Thomas Schwinge  
+
+   Backported from trunk:
+   2025-03-14  Thomas Schwinge  
+
+   PR target/92713
+   PR target/101544
+   * configure.ac [GCN, nvptx] (noconfigdirs): Don't add
+   'target-libstdc++-v3'.  Add 'target-libgrust'.
+   * configure: Regenerate.
+
 2025-02-20  Thomas Schwinge  
 
Backported from trunk:
diff --git a/configure b/configure
index 81ac2cf87a6a..a4da7d165fdf 100755
--- a/configure
+++ b/configure
@@ -3423,10 +3423,6 @@ if test "${ENABLE_LIBSTDCXX}" = "default" ; then
   # VxWorks uses the Dinkumware C++ library.
   noconfigdirs="$noconfigdirs target-libstdc++-v3"
   ;;
-amdgcn*-*-*)
-  # Not ported/fails to build when using newlib.
-  noconfigdirs="$noconfigdirs target-libstdc++-v3"
-  ;;
 arm*-wince-pe*)
   # the C++ libraries don't build on top of CE's C libraries
   noconfigdirs="$noconfigdirs target-libstdc++-v3"
@@ -4066,7 +4062,7 @@ case "${target}" in
 noconfigdirs="$noconfigdirs gprof"
 ;;
   nvptx*-*-*)
-noconfigdirs="$noconfigdirs target-libssp target-libstdc++-v3"
+noconfigdirs="$noconfigdirs target-libssp"
 ;;
   sh-*-*)
 case "${target}" in
@@ -9400,6 +9396,16 @@ case ,${enable_languages}, in
 # Disable target libgrust if we're not building target libstdc++.
 noconfigdirs="$noconfigdirs target-libgrust"
 ;;
+  *)
+   case "${target}" in
+ amdgcn*-*-* \
+ | nvptx*-*-* )
+   # Build fails in 'libgrust/libproc_macro_internal/':
+   # sorry, unimplemented: exception handling not supported
+   noconfigdirs="$noconfigdirs target-libgrust"
+   ;;
+   esac
+   ;;
 esac
 ;;
 esac
diff --git a/configure.ac b/configure.ac
index 9b338c4c5861..17cf51a33001 100644
--- a/configure.ac
+++ b/configure.ac
@@ -655,10 +655,6 @@ if test "${ENABLE_LIBSTDCXX}" = "default" ; then
   # VxWorks uses the Dinkumware C++ library.
   noconfigdirs="$noconfigdirs target-libstdc++-v3"
   ;;
-amdgcn*-*-*)
-  # Not ported/fails to build when using newlib.
-  noconfigdirs="$noconfigdirs target-libstdc++-v3"
-  ;;
 arm*-wince-pe*)
   # the C++ libraries don't build on top of CE's C libraries
   noconfigdirs="$noconfigdirs target-libstdc++-v3"
@@ -1292,7 +1288,7 @@ case "${target}" in
 noconfigdirs="$noconfigdirs gprof"
 ;;
   nvptx*-*-*)
-noconfigdirs="$noconfigdirs target-libssp target-libstdc++-v3"
+noconfigdirs="$noconfigdirs target-libssp"
 ;;
   sh-*-*)
 case "

[gcc r15-8625] gccrs: ast-collector: Adapt to lang item type path segments

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

commit r15-8625-g1c9cd6a60128dc860ef7879222fddf91790e4515
Author: Arthur Cohen 
Date:   Tue Dec 31 17:36:50 2024 +

gccrs: ast-collector: Adapt to lang item type path segments

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): Fix collector 
to better
handle lang item type path segments.

Diff:
---
 gcc/rust/ast/rust-ast-collector.cc | 23 +++
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/gcc/rust/ast/rust-ast-collector.cc 
b/gcc/rust/ast/rust-ast-collector.cc
index f493da3fa3fc..4c9c360c04d2 100644
--- a/gcc/rust/ast/rust-ast-collector.cc
+++ b/gcc/rust/ast/rust-ast-collector.cc
@@ -543,10 +543,14 @@ TokenCollector::visit (TypePathSegment &segment)
 {
   // Syntax:
   //PathIdentSegment
-  auto ident_segment = segment.get_ident_segment ();
-  auto id = ident_segment.as_string ();
-  push (
-Rust::Token::make_identifier (ident_segment.get_locus (), std::move (id)));
+
+  auto locus = segment.is_lang_item ()
+? segment.get_locus ()
+: segment.get_ident_segment ().get_locus ();
+  auto segment_string = segment.is_lang_item ()
+ ? LangItem::PrettyString (segment.get_lang_item ())
+ : segment.get_ident_segment ().as_string ();
+  push (Rust::Token::make_identifier (locus, std::move (segment_string)));
 }
 
 void
@@ -558,10 +562,13 @@ TokenCollector::visit (TypePathSegmentGeneric &segment)
   //`<` `>`
   //| `<` ( GenericArg `,` )* GenericArg `,`? `>`
 
-  auto ident_segment = segment.get_ident_segment ();
-  auto id = ident_segment.as_string ();
-  push (
-Rust::Token::make_identifier (ident_segment.get_locus (), std::move (id)));
+  auto locus = segment.is_lang_item ()
+? segment.get_locus ()
+: segment.get_ident_segment ().get_locus ();
+  auto segment_string = segment.is_lang_item ()
+ ? LangItem::PrettyString (segment.get_lang_item ())
+ : segment.get_ident_segment ().as_string ();
+  push (Rust::Token::make_identifier (locus, std::move (segment_string)));
 
   if (segment.get_separating_scope_resolution ())
 push (Rust::Token::make (SCOPE_RESOLUTION, UNDEF_LOCATION));


  1   2   >