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

2025-04-05 Thread Sandra Loosemore
gcc/ChangeLog
PR middle-end/78874
* doc/invoke.texi (Warning Options): Fix description of
-Wno-aggressive-loop-optimizations to reflect that this turns
off the warning, and the default is for it to be enabled.
---
 gcc/doc/invoke.texi | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

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



Re: combine: Re-enable 2->2 combinations, with limits [PR116398]

2025-04-05 Thread Sam James
Richard Sandiford  writes:

> This series is an update of:
>
>   https://gcc.gnu.org/pipermail/gcc-patches/2025-April/679924.html
>
> As discussed in that thread, the changes since last time are to make
> distribute_links start from the last use, where easy, and to avoid
> an unnecessary insn walk for split_i2i3.
>

FWIW, I've regtested the series on x86_64 so far (will do the other
targets we support downstream too) and started building
packages and had no problems, with
https://inbox.sourceware.org/gcc-patches/mpt7c443wm7@arm.com/ on
top.


Re: [PATCH 2/2] cobol: use ldirname in cdf-copy.cc

2025-04-05 Thread Jose E. Marchesi


> On Mon, Mar 17, 2025 at 7:45 PM Jose E. Marchesi
>  wrote:
>>
>> This patch changes gcc/cobol/cdf-copy.cc to use the new ldirname from
>> libibertay rather than the host's dirname.  This removes an include
>> for libgen.h.
>>
>> Regtested in x86_64-linux-gnu by running make check-cobol.
>
> OK to both patches of the series.

Pushed.
Thanks.

> Thanks,
> Richard.
>
>> gcc/cobol/ChangeLog
>>
>> * cdf-copy.cc (copybook_elem_t::open_file): Use ldirname rather
>> than dirname.
>> ---
>>  gcc/cobol/cdf-copy.cc | 24 
>>  1 file changed, 16 insertions(+), 8 deletions(-)
>>
>> diff --git a/gcc/cobol/cdf-copy.cc b/gcc/cobol/cdf-copy.cc
>> index dfa3f57315d..179dbacea93 100644
>> --- a/gcc/cobol/cdf-copy.cc
>> +++ b/gcc/cobol/cdf-copy.cc
>> @@ -40,7 +40,6 @@
>>  #include "copybook.h"
>>
>>  #include 
>> -#include 
>>
>>  #define COUNT_OF(X) (sizeof(X) / sizeof(X[0]))
>>
>> @@ -268,24 +267,33 @@ int
>>  copybook_elem_t::open_file( const char directory[], bool literally ) {
>>int erc;
>>char  *pattern, *copier = xstrdup(cobol_filename());
>> -  if( ! directory ) {
>> -directory = dirname(copier);
>> -if( 0 == strcmp(".", directory) ) directory = NULL;
>> +  char *dname = NULL;
>> +
>> +  if ( directory ) {
>> +dname = xstrdup(directory);
>> +  } else {
>> +dname = ldirname(copier);
>> +gcc_assert (dname != NULL); /* out of memory  */
>> +if( '\0' == dname[0] ) {
>> +  free (dname);
>> +  dname = NULL;
>> +}
>>}
>>
>>char *path = NULL;
>>
>> -  if( directory || library.name ) {
>> -if( directory && library.name ) {
>> -  path = xasprintf( "%s/%s/%s", directory, library.name, source.name );
>> +  if( dname || library.name ) {
>> +if( dname && library.name ) {
>> +  path = xasprintf( "%s/%s/%s", dname, library.name, source.name );
>>  } else {
>> -  const char *dir = directory? directory : library.name;
>> +  const char *dir = dname? dname : library.name;
>>path = xasprintf( "%s/%s", dir, source.name );
>>  }
>>} else {
>>  path = xasprintf( "%s", source.name );
>>}
>>
>> +  free(dname);
>>gcc_assert(path);
>>
>>if( literally ) {
>> --
>> 2.30.2
>>


Re: [PATCH] icf: Punt for musttail call flag differences in ICF [PR119376]

2025-04-05 Thread Richard Biener
On Fri, 21 Mar 2025, Jakub Jelinek wrote:

> Hi!
> 
> The following testcase shows we were ignoring musttail flags on calls
> when deciding if two functions are the same.
> That can result in problems in both directions, either we silently
> lose musttail attribute because there is a similar function without it
> earlier and then we e.g. don't diagnose if it can't be tail called
> or don't try harder to do a tail call, or we get it even in functions
> which didn't have it before.
> 
> The following patch for now just punts if it differs.  Perhaps we could
> just merge it and get musttail flag if any of the merged functions had
> one in such position, but it feels to me that it is now too late in GCC 15
> cycle to play with this.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

Richard.

> 2025-03-20  Jakub Jelinek  
> 
>   PR ipa/119376
>   * ipa-icf-gimple.cc (func_checker::compare_gimple_call): Return false
>   for gimple_call_must_tail_p mismatches.
> 
>   * c-c++-common/musttail27.c: New test.
> 
> --- gcc/ipa-icf-gimple.cc.jj  2025-02-27 22:04:06.082435026 +0100
> +++ gcc/ipa-icf-gimple.cc 2025-03-20 15:33:38.996614656 +0100
> @@ -708,7 +708,8 @@ func_checker::compare_gimple_call (gcall
>|| gimple_call_from_thunk_p (s1) != gimple_call_from_thunk_p (s2)
>|| gimple_call_from_new_or_delete (s1) != 
> gimple_call_from_new_or_delete (s2)
>|| gimple_call_va_arg_pack_p (s1) != gimple_call_va_arg_pack_p (s2)
> -  || gimple_call_alloca_for_var_p (s1) != gimple_call_alloca_for_var_p 
> (s2))
> +  || gimple_call_alloca_for_var_p (s1) != gimple_call_alloca_for_var_p 
> (s2)
> +  || gimple_call_must_tail_p (s1) != gimple_call_must_tail_p (s2))
>  return false;
>  
>unsigned check_arg_types_from = 0;
> --- gcc/testsuite/c-c++-common/musttail27.c.jj2025-03-20 
> 15:42:30.200261715 +0100
> +++ gcc/testsuite/c-c++-common/musttail27.c   2025-03-20 15:44:24.990674296 
> +0100
> @@ -0,0 +1,31 @@
> +/* PR ipa/119376 */
> +/* { dg-do compile { target musttail } } */
> +/* { dg-options "-O2 -fdump-tree-optimized" } */
> +/* { dg-final { scan-tree-dump-times "  \[^\n\r]* = foo \\\(\[^\n\r]*\\\); 
> \\\[tail call\\\] \\\[must tail call\\\]" 2 "optimized" } } */
> +/* { dg-final { scan-tree-dump-times "  \[^\n\r]* = foo \\\(\[^\n\r]*\\\); 
> \\\[tail call\\\]" 4 "optimized" } } */
> +
> +int foo (int);
> +
> +int
> +bar (int x)
> +{
> +  [[gnu::musttail]] return foo (x + 1);
> +}
> +
> +int
> +baz (int x)
> +{
> +  return foo (x + 1);
> +}
> +
> +int
> +qux (int x)
> +{
> +  return foo (x + 2);
> +}
> +
> +int
> +corge (int x)
> +{
> +  [[gnu::musttail]] return foo (x + 2);
> +}
> 
>   Jakub
> 
> 

-- 
Richard Biener 
SUSE Software Solutions Germany GmbH,
Frankenstrasse 146, 90461 Nuernberg, Germany;
GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)


[COMMITTED 060/146] gccrs: Remove bad assertion in name resolution

2025-04-05 Thread arthur . cohen
From: Philip Herron 

This was a handy debug assertion but only works for valid rust code. This
needs to handle the case where the type is not resolved which is a valid
case.

Fixes Rust-GCC#2423

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): remove 
assertions

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron 
---
 gcc/rust/resolve/rust-ast-resolve-item.cc | 30 ++-
 gcc/testsuite/rust/compile/issue-2423.rs  | 14 +++
 gcc/testsuite/rust/compile/nr2/exclude|  1 +
 3 files changed, 39 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/rust/compile/issue-2423.rs

diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc 
b/gcc/rust/resolve/rust-ast-resolve-item.cc
index 2861fb94d9f..245523ae5aa 100644
--- a/gcc/rust/resolve/rust-ast-resolve-item.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-item.cc
@@ -582,7 +582,14 @@ ResolveItem::visit (AST::InherentImpl &impl_block)
   // Setup paths
   CanonicalPath self_cpath = CanonicalPath::create_empty ();
   bool ok = ResolveTypeToCanonicalPath::go (impl_block.get_type (), 
self_cpath);
-  rust_assert (ok);
+  if (!ok)
+{
+  resolver->get_name_scope ().pop ();
+  resolver->get_type_scope ().pop ();
+  resolver->get_label_scope ().pop ();
+  return;
+}
+
   rust_debug ("AST::InherentImpl resolve Self: {%s}",
  self_cpath.get ().c_str ());
 
@@ -671,12 +678,17 @@ ResolveItem::visit (AST::TraitImpl &impl_block)
   return;
 }
 
-  bool ok;
   // setup paths
   CanonicalPath canonical_trait_type = CanonicalPath::create_empty ();
-  ok = ResolveTypeToCanonicalPath::go (impl_block.get_trait_path (),
-  canonical_trait_type);
-  rust_assert (ok);
+  bool ok = ResolveTypeToCanonicalPath::go (impl_block.get_trait_path (),
+   canonical_trait_type);
+  if (!ok)
+{
+  resolver->get_name_scope ().pop ();
+  resolver->get_type_scope ().pop ();
+  resolver->get_label_scope ().pop ();
+  return;
+}
 
   rust_debug ("AST::TraitImpl resolve trait type: {%s}",
  canonical_trait_type.get ().c_str ());
@@ -684,7 +696,13 @@ ResolveItem::visit (AST::TraitImpl &impl_block)
   CanonicalPath canonical_impl_type = CanonicalPath::create_empty ();
   ok = ResolveTypeToCanonicalPath::go (impl_block.get_type (),
   canonical_impl_type);
-  rust_assert (ok);
+  if (!ok)
+{
+  resolver->get_name_scope ().pop ();
+  resolver->get_type_scope ().pop ();
+  resolver->get_label_scope ().pop ();
+  return;
+}
 
   rust_debug ("AST::TraitImpl resolve self: {%s}",
  canonical_impl_type.get ().c_str ());
diff --git a/gcc/testsuite/rust/compile/issue-2423.rs 
b/gcc/testsuite/rust/compile/issue-2423.rs
new file mode 100644
index 000..ae7897c1170
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-2423.rs
@@ -0,0 +1,14 @@
+impl NonExistant {
+// { dg-error "failed to resolve" "" { target *-*-* } .-1 }
+fn test() {}
+}
+
+impl NotFound for NonExistant {
+// { dg-error "failed to resolve" "" { target *-*-* } .-1 }
+fn test() {}
+}
+
+trait A {}
+
+impl A for NotFound {}
+// { dg-error "failed to resolve" "" { target *-*-* } .-1 }
diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index 00ac704fec2..bf4506f25d2 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -206,4 +206,5 @@ issue-1773.rs
 issue-2905-1.rs
 issue-2905-2.rs
 issue-2907.rs
+issue-2423.rs
 # please don't delete the trailing newline
-- 
2.45.2



[COMMITTED 2/2] rust: force cargo to build offline

2025-04-05 Thread arthur . cohen
From: Marc Poulhiès 

gcc/rust/Changelog:
PR rust/119333

* Make-lang.in: Force offline mode for cargo

Signed-off-by: Marc Poulhiès 
---
 gcc/rust/Make-lang.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index efa630927fa..c892fa3091e 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -503,5 +503,5 @@ rust/%.o: rust/metadata/%.cc
 rust/libffi_polonius.a: \
rust/checks/errors/borrowck/ffi-polonius/Cargo.toml \
$(wildcard $(srcdir)/rust/checks/errors/borrowck/ffi-polonius/src/*)
-   cargo build --manifest-path 
$(srcdir)/rust/checks/errors/borrowck/ffi-polonius/Cargo.toml --release 
--target-dir rust/ffi-polonius
+   cd $(srcdir)/rust/checks/errors/borrowck/ffi-polonius/ && cargo build 
--offline --release --target-dir $(objdir)/rust/ffi-polonius
cp rust/ffi-polonius/release/libffi_polonius.a rust/libffi_polonius.a
-- 
2.45.2



[committed] MAINTAINERS: Update my name

2025-04-05 Thread Alice Carlotti
ChangeLog:

* MAINTAINERS: Update my name.


diff --git a/MAINTAINERS b/MAINTAINERS
index 
90c8e2aa99506da1cd7955c90808401b8df051b5..756227e0a5064ab996f3d5e245f585138104cb97
 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  



[PATCH] fold-const, cobol: Add native_encode_wide_int and use it in COBOL FE [PR119242]

2025-04-05 Thread Jakub Jelinek
Hi!

As has been mentioned earlier, various parts of the COBOL FE and the library
aren't endian clean.  In the library that means that for now we have to
live with no support for big endian targets, but in the FE that means
that as well as not being able to build cross-compilers from big endian
or pdp endian hosts to little endian targets which are otherwise supported.

The following patch attempts to fix one such spot, where it wants to encode
in target byte ordering wide_int constants into 1, 2, 4, 8 or 16 bytes.

We could wide_int_to_tree and then native_encode_expr, but so that we don't
need to build the constants, the following patch exports from fold-const.cc
a variant to native_encode_int which takes type and wide_int reference
rather than an expression.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2025-04-02  Jakub Jelinek  

PR cobol/119242
* fold-const.h (native_encode_wide_int): Declare.
* fold-const.cc (native_encode_wide_int_1): New function template.
(native_encode_wide_int): New function.
(native_encode_int): Use native_encode_wide_int_1.

* cobol/genapi.cc (binary_initial_from_float128): Use
native_encode_wide_int.

--- gcc/fold-const.h.jj 2025-03-28 10:38:23.165538304 +0100
+++ gcc/fold-const.h2025-04-02 14:31:22.921136606 +0200
@@ -35,6 +35,8 @@ extern bool folding_cxx_constexpr;
 extern int native_encode_expr (const_tree, unsigned char *, int, int off = -1);
 extern int native_encode_initializer (tree, unsigned char *, int,
  int off = -1, unsigned char * = nullptr);
+extern int native_encode_wide_int (tree, const wide_int_ref &,
+  unsigned char *, int, int off = -1);
 extern int native_encode_real (scalar_float_mode, const REAL_VALUE_TYPE *,
   unsigned char *, int, int off = -1);
 extern tree native_interpret_expr (tree, const unsigned char *, int);
--- gcc/fold-const.cc.jj2025-03-28 10:38:23.148538537 +0100
+++ gcc/fold-const.cc   2025-04-02 14:30:15.072074312 +0200
@@ -7465,15 +7465,17 @@ fold_plusminus_mult_expr (location_t loc
   return NULL_TREE;
 }
 
-/* Subroutine of native_encode_expr.  Encode the INTEGER_CST
-   specified by EXPR into the buffer PTR of length LEN bytes.
+
+/* Subroutine of native_encode_int and native_encode_wide_int.  Encode the
+   integer VAL with type TYPE into the buffer PTR of length LEN bytes.
Return the number of bytes placed in the buffer, or zero
upon failure.  */
 
+template 
 static int
-native_encode_int (const_tree expr, unsigned char *ptr, int len, int off)
+native_encode_wide_int_1 (tree type, const T &val,
+ unsigned char *ptr, int len, int off)
 {
-  tree type = TREE_TYPE (expr);
   int total_bytes;
   if (TREE_CODE (type) == BITINT_TYPE)
 {
@@ -7516,7 +7518,7 @@ native_encode_int (const_tree expr, unsi
   int bitpos = byte * BITS_PER_UNIT;
   /* Extend EXPR according to TYPE_SIGN if the precision isn't a whole
 number of bytes.  */
-  value = wi::extract_uhwi (wi::to_widest (expr), bitpos, BITS_PER_UNIT);
+  value = wi::extract_uhwi (val, bitpos, BITS_PER_UNIT);
 
   if (total_bytes > UNITS_PER_WORD)
{
@@ -7537,6 +7539,31 @@ native_encode_int (const_tree expr, unsi
   return MIN (len, total_bytes - off);
 }
 
+/* Encode the integer VAL with type TYPE into the buffer PTR of length LEN
+   bytes.
+   Return the number of bytes placed in the buffer, or zero
+   upon failure.  */
+
+int
+native_encode_wide_int (tree type, const wide_int_ref &val,
+   unsigned char *ptr, int len, int off)
+{
+  return native_encode_wide_int_1 (type, val, ptr, len, off);
+}
+
+
+/* Subroutine of native_encode_expr.  Encode the INTEGER_CST
+   specified by EXPR into the buffer PTR of length LEN bytes.
+   Return the number of bytes placed in the buffer, or zero
+   upon failure.  */
+
+static int
+native_encode_int (const_tree expr, unsigned char *ptr, int len, int off)
+{
+  return native_encode_wide_int_1 (TREE_TYPE (expr), wi::to_widest (expr),
+  ptr, len, off);
+}
+
 
 /* Subroutine of native_encode_expr.  Encode the FIXED_CST
specified by EXPR into the buffer PTR of length LEN bytes.
--- gcc/cobol/genapi.cc.jj  2025-04-02 10:36:25.517574640 +0200
+++ gcc/cobol/genapi.cc 2025-04-02 14:31:36.373950683 +0200
@@ -15216,25 +15216,19 @@ binary_initial_from_float128(cbl_field_t
   FIXED_WIDE_INT(128) i
 = FIXED_WIDE_INT(128)::from (real_to_integer (&value, &fail, 128), SIGNED);
 
-  /* ???  Use native_encode_* below.  */
   retval = (char *)xmalloc(field->data.capacity);
   switch(field->data.capacity)
 {
+  tree type;
 case 1:
-  *(signed char *)retval = (signed char)i.slow ();
-  break;
 case 2:
-  *(signed short *)retval = (signed short)i.slow ();
-  break;
 case 4:
-  *(signed int *)retval = (s

[COMMITTED 033/146] gccrs: Refactor HIR with optionals, references & newtypes

2025-04-05 Thread arthur . cohen
From: Pierre-Emmanuel Patry 

The HIR made heavy use of pair and other unamed types which can be
difficult to read.

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc: Use FnParam getter.
* backend/rust-compile-expr.cc (CompileExpr::visit): Likewise.
* backend/rust-compile-intrinsic.cc: Likewise.
* backend/rust-compile-type.cc: Likewise.
* checks/errors/privacy/rust-privacy-reporter.cc 
(PrivacyReporter::visit):
Only visit childrens if not missing.
* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Use
a reference instead of a raw pointer.
* hir/tree/rust-hir-expr.h: Add presence function for return
expression.
* hir/tree/rust-hir-item.h: Remove take_param_name.
* hir/tree/rust-hir.h: Make mapping getter const.
* typecheck/rust-hir-dot-operator.cc (MethodResolver::Select): Use
getter.
* typecheck/rust-hir-type-check-expr.cc: Likewise.
* typecheck/rust-hir-type-check-implitem.cc: Use FnParam vector instead
of std::pair of Pattern and BaseType.
* typecheck/rust-hir-type-check-item.cc: Likewise.
* typecheck/rust-hir-type-check.cc: Likewise.
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Use getters.
(TypeCheckMethodCallExpr::check): Likewise.
* typecheck/rust-tyty-cmp.h: Likewise.
* typecheck/rust-tyty.cc: Use FnParam.
* typecheck/rust-tyty.h (class FnParam): Add FnParam to handle function
parameters instead of handling std::pairs.
* typecheck/rust-unify.cc (UnifyRules::expect_fndef): Use getters.
(UnifyRules::expect_fnptr): Likewise.

Signed-off-by: Pierre-Emmanuel Patry 
---
 gcc/rust/backend/rust-compile-base.cc |  2 +-
 gcc/rust/backend/rust-compile-expr.cc |  4 +-
 gcc/rust/backend/rust-compile-intrinsic.cc| 17 ++---
 gcc/rust/backend/rust-compile-type.cc |  4 +-
 .../errors/privacy/rust-privacy-reporter.cc   | 11 +--
 gcc/rust/checks/errors/rust-unsafe-checker.cc |  2 +-
 gcc/rust/hir/tree/rust-hir-expr.h |  2 +
 gcc/rust/hir/tree/rust-hir-item.h |  2 -
 gcc/rust/hir/tree/rust-hir.h  |  5 +-
 gcc/rust/typecheck/rust-hir-dot-operator.cc   |  2 +-
 .../typecheck/rust-hir-type-check-expr.cc |  4 +-
 .../typecheck/rust-hir-type-check-implitem.cc | 28 +++-
 .../typecheck/rust-hir-type-check-item.cc |  6 +-
 gcc/rust/typecheck/rust-hir-type-check.cc | 18 ++---
 gcc/rust/typecheck/rust-tyty-call.cc  | 16 ++---
 gcc/rust/typecheck/rust-tyty-cmp.h|  6 +-
 gcc/rust/typecheck/rust-tyty.cc   | 30 
 gcc/rust/typecheck/rust-tyty.h| 69 ---
 gcc/rust/typecheck/rust-unify.cc  |  6 +-
 19 files changed, 122 insertions(+), 112 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-base.cc 
b/gcc/rust/backend/rust-compile-base.cc
index 598f2e2e451..80ea7a4ec95 100644
--- a/gcc/rust/backend/rust-compile-base.cc
+++ b/gcc/rust/backend/rust-compile-base.cc
@@ -711,7 +711,7 @@ HIRCompileBase::compile_function (
   for (auto &referenced_param : function_params)
 {
   auto &tyty_param = fntype->param_at (i++);
-  auto param_tyty = tyty_param.second;
+  auto param_tyty = tyty_param.get_type ();
   auto compiled_param_type = TyTyResolveCompile::compile (ctx, param_tyty);
 
   location_t param_locus = referenced_param.get_locus ();
diff --git a/gcc/rust/backend/rust-compile-expr.cc 
b/gcc/rust/backend/rust-compile-expr.cc
index c46bda954ad..107ca2eadf5 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -1267,7 +1267,7 @@ CompileExpr::visit (HIR::CallExpr &expr)
 
 const TyTy::FnType *fn = static_cast (base);
 auto ¶m = fn->param_at (index);
-*result = param.second;
+*result = param.get_type ();
 
 return true;
   };
@@ -1401,7 +1401,7 @@ CompileExpr::visit (HIR::MethodCallExpr &expr)
   // assignments are coercion sites so lets convert the rvalue if
   // necessary, offset from the already adjusted implicit self
   bool ok;
-  TyTy::BaseType *expected = fntype->param_at (i + 1).second;
+  TyTy::BaseType *expected = fntype->param_at (i + 1).get_type ();
 
   TyTy::BaseType *actual = nullptr;
   ok = ctx->get_tyctx ()->lookup_type (
diff --git a/gcc/rust/backend/rust-compile-intrinsic.cc 
b/gcc/rust/backend/rust-compile-intrinsic.cc
index bf595e4fb87..16447b29a51 100644
--- a/gcc/rust/backend/rust-compile-intrinsic.cc
+++ b/gcc/rust/backend/rust-compile-intrinsic.cc
@@ -315,13 +315,13 @@ compile_fn_params (Context *ctx, TyTy::FnType *fntype, 
tree fndecl,
 {
   for (auto &parm : fntype->get_params ())
 {
-  auto &referenced_param = parm.first;
-  auto ¶m_tyty = parm.second;
+  auto &referenced_param = parm.get_pattern ();
+  auto param_tyty = parm.get_type ();
   auto compiled_param_type = 

Re: [PATCH][RFC] [cobol] change cbl_field_data_t::etc_t::value from _Float128 to tree

2025-04-05 Thread Simon Sobisch

> Now a question on COBOL:
>
> 77 var8 PIC 999V9(8) COMP-5
>
> what precision/digits does this specify?  When then doing
>
>  add 0.0001 TO var555 giving var8 rounded
>
> what's the precision/digit specification for the literal floating
> point values and how does that or that of var555 or var8
> "promote" or "demote" to a common specification for the arithmetic
> operation?
>
> Does the COBOL standard expect a literal floating point value to
> be represented exactly?  Maybe rounding then only applies at the
> "giving var8 rounded" point, forcing the exact value to the
> specification of var8?
>
> Richard.

That's NOT a floating-point in COBOL, but a fixed-point numeric literal.
It is best understood with the following explanation from the standard:

> An integer literal is a fixed-point numeric literal that contains no 
decimal point.


--> it is to be used as integer with an implied decimal point after the 
first position, as if it would be defined with a PIC 9v



floating-point literals in COBOL would have the following most important 
difference:


> A floating-point numeric literal is formed from two fixed-point 
numeric literals separated by the letter 'E' without intervening spaces.



The requested *minimal* precision - "stored exactly" is:
* 31 digits for fixed-point numeric literals (and effectively all
  calculations with those, before rounding/truncation applies)
* up to 36 digits of significand with up to 4 digits in exponent for
  floating-point literals


Back to your arithmetic question: COBOL standard expects that to be 
exact for an intermediate value up to these sizes.
If the sizes get bigger and cannot be stored (the maximum is 
implementor-defined = "should be documented in the user-documentation") 
then there's the option to specify which INTERMEDIATE ROUNDING should 
apply (= per program), which includes ROUNDING/TRUNCATION/PROHIBITED 
(=an exception raised).


The default for INTERMEDIATE ROUNDING dependens on which arithmetic is 
in effect (also per program defined, NATIVE is default where rounding is 
implementor-defined, STANDARD-BINARY and STANDARD-DECIMAL can be chosen).


> If the NATIVE phrase is specified [or implied], the techniques used 
in handling arithmetic expressions and intrinsic functions shall be 
those specified by the implementor, [as well as] the techniques used in 
handling arithmetic statements [mostly for rounding/truncation].


--> note that STANDARD-DECIMAL arithmetic is no optional feature, so for 
full compliance that has to be considered - but can also be "ignored in 
detail" for now; note that the OPTIONS paragraph (support for the 
paragraph is required since COBOL2002) is only supported by GnuCOBOL 
(neither IBM nor Micro Focus nor Fujitsu support it and all go with 
"native arithmetic" only).


also mind that COBOL2014 has a note:
> Implementors are strongly encouraged to provide support for the 
STANDARD-DECIMAL phrase of the ARITHMETIC clause



... sorry for another "background-drift", getting to your question again:

* intermediate values need to cover at least the sizes outlined above
* for bigger sizes truncation/rounding may apply - the rules that IBM,
  MF and GnuCOBOL applies are different (with GnuCOBOL being nearly
  infinite using GMP with an internal scale as intermediate
  representation)
* the truncation/rounding that applies for a statement can be specified
  at the statement (as in your example where "rounded" only applies to
  this final "store to the receiving item") with the default being able
  to be configured in the OPTIONS paragraph "DEFAULT ROUNDED MODE"


Hope this helps with some background and answers your questions,
Simon


Re: [PATCH 3/4] combine: Optimise distribute_links search [PR116398]

2025-04-05 Thread Richard Sandiford
Richard Biener  writes:
> On Fri, 4 Apr 2025, Richard Sandiford wrote:
>
>> Another problem in PR101523 was that, after each successful 2->2
>> combination attempt, distribute_links would search further and further
>> for the next combinable use of the i2 destination.  Each search would
>> start at i2 itself, making the search quadratic in the worst case.
>> 
>> In a 2->2 combination, if i2 is unchanged, the search can start at i3
>> instead of i2.  The same thing applies to i2 when distributing i2's
>> links, since the only changes to earlier instructions are the deletion
>> of i0 and i1.
>> 
>> This change, combined with the previous split_i2i3 patch, gives a
>> 34.6% speedup in combine for the testcase in PR101523.  Combine
>> goes from being 41% to 34% of compile time.
>
> From my analysis this patch is OK (I do wonder why not always
> starting from iN when distributing links for iN, but I guess
> that combining into parallel & splitting can actually move
> link sources/destinations in odd ways

Right.  In particular, if we split part of i3 into i2, some log
links can move up from i3 to i2.  I think it would be safe to
pass iN unconditionally and then use LUIDs to check whether the
passed-in instruction is before or after the definition, picking
the later of the two.  But that felt like too much of a rabiit hole.

Richard


> - I don't claim I fully understand this).
>
> Richard.
>
>> gcc/
>>  PR testsuite/116398
>>  * combine.cc (distribute_links): Take an optional start point.
>>  (try_combine): If only i3 has changed, only distribute i3's links,
>>  not i2's.  Start the search for the new use from i3 rather than
>>  from the definition instruction.  Likewise start the search for
>>  the new use from i2 when distributing i2's links.
>> ---
>>  gcc/combine.cc | 27 +++
>>  1 file changed, 19 insertions(+), 8 deletions(-)
>> 
>> diff --git a/gcc/combine.cc b/gcc/combine.cc
>> index 0664f8dd433..9eae1a0111e 100644
>> --- a/gcc/combine.cc
>> +++ b/gcc/combine.cc
>> @@ -472,7 +472,7 @@ static void move_deaths (rtx, rtx, int, rtx_insn *, rtx 
>> *);
>>  static bool reg_bitfield_target_p (rtx, rtx);
>>  static void distribute_notes (rtx, rtx_insn *, rtx_insn *, rtx_insn *,
>>rtx, rtx, rtx);
>> -static void distribute_links (struct insn_link *);
>> +static void distribute_links (struct insn_link *, rtx_insn * = nullptr);
>>  static void mark_used_regs_combine (rtx);
>>  static void record_promoted_value (rtx_insn *, rtx);
>>  static bool unmentioned_reg_p (rtx, rtx);
>> @@ -4590,10 +4590,15 @@ try_combine (rtx_insn *i3, rtx_insn *i2, rtx_insn 
>> *i1, rtx_insn *i0,
>>  NULL_RTX, NULL_RTX, NULL_RTX);
>>}
>>  
>> -distribute_links (i3links);
>> -distribute_links (i2links);
>> -distribute_links (i1links);
>> -distribute_links (i0links);
>> +if (only_i3_changed)
>> +  distribute_links (i3links, i3);
>> +else
>> +  {
>> +distribute_links (i3links);
>> +distribute_links (i2links, i2);
>> +distribute_links (i1links);
>> +distribute_links (i0links);
>> +  }
>>  
>>  if (REG_P (i2dest))
>>{
>> @@ -14984,10 +14989,13 @@ distribute_notes (rtx notes, rtx_insn *from_insn, 
>> rtx_insn *i3, rtx_insn *i2,
>>  
>>  /* Similarly to above, distribute the LOG_LINKS that used to be present on
>> I3, I2, and I1 to new locations.  This is also called to add a link
>> -   pointing at I3 when I3's destination is changed.  */
>> +   pointing at I3 when I3's destination is changed.
>> +
>> +   If START is nonnull and an insn, we know that the next location for each
>> +   link is no earlier than START.  */
>>  
>>  static void
>> -distribute_links (struct insn_link *links)
>> +distribute_links (struct insn_link *links, rtx_insn *start)
>>  {
>>struct insn_link *link, *next_link;
>>  
>> @@ -15053,7 +15061,10 @@ distribute_links (struct insn_link *links)
>>   I3 to I2.  Also note that not much searching is typically done here
>>   since most links don't point very far away.  */
>>  
>> -  for (insn = NEXT_INSN (link->insn);
>> +  insn = start;
>> +  if (!insn || NOTE_P (insn))
>> +insn = NEXT_INSN (link->insn);
>> +  for (;
>> (insn && (this_basic_block->next_bb == EXIT_BLOCK_PTR_FOR_FN (cfun)
>>   || BB_HEAD (this_basic_block->next_bb) != insn));
>> insn = NEXT_INSN (insn))
>> 


Re: cobol: flags for choosing reference-format (Re: [PATCH]cobol: create new gcc/testsuite/cobol.dg/group1/check_88.cob test)

2025-04-05 Thread James K. Lowden
On Sun, 16 Mar 2025 21:07:39 +0100
Simon Sobisch  wrote:

> This gives three reference-formats: "fixed" "free" and "extended". For
> two of those we have seen the flags -ffixed-form and -ffree-form, so
> I'd _guess_ the last one would be -fextended-form.
> 
> Question: Is there a reason to have multiple flags for that? 

[I think this thread belongs in gcc@ because there's no patch to
discuss.  I'm answering here for the sake of continuity.]

-ffixed-form and -ffree-form are the names gfortran uses.   To get
"logical reference format" -- unlimited lines with the first 6 columns
ignored and indicator column 7, we have 

-findicator-column=7

It's not a great name, not least because it seems
invertible but is not.  ("-fno-indicator-column=n" makes no sense.)
OTHO it says what it means: the location of the indicator column, with
no mention of a line length limit (because there isn't one). 

> -fformat=fixed/free/extended/.../auto

The problem here IMO is the burden of names.  Each combination of
left/right margin needs a name, all of which are arbitrary.  "Extended"
from what, and to what?  Every compiler seems to have its own
variation. 

If -- if -- we were to support other formats I'd be inclined to use 

-source-format from[-to]

so the user says where the indicator column is, and what the maximum
length is, if any.  So, 

-ffixed-formis  -source-format 7-72
-ffree-form is  -source-format 1
(logical ref)   is  -source-format 7
(no indicator)  is  -source-format 0

with the implied rule that, if the first column is 1, then '*' is
honored as a comment, else the character is part of the COBOL text.  

> Side-note: auto-choosing "extended" was at least confusing for me (and
> the NIST suite initial compile-try). That likely confused me most,
> because of not knowing another compiler choosing _that_ format
> automatically.

There must be some default, and auto-detection is a good one.  It can
be improved without changing the command-line options.  :-)   I'm
looking forward to more examples before tweaking it.  

--jkl


RE: [PATCH] change cbl_field_data_t::etc_t::value from _Float128 to tree

2025-04-05 Thread Richard Biener
On Fri, 21 Mar 2025, Robert Dubner wrote:

> I am stepping my way through the code that initializes the COBOL variable
> 
> 01  FLOATLONG FLOAT-LONG VALUE 12345678.
> 
> In the version created by Richard's patch, I arrive at line 15721, which I
> have flagged with /**/.  (My editor lacks the ability too prepend line
> numbers, sadly.)
> 
> case FldFloat:
>   {
>   retval = (char *)xmalloc(field->data.capacity);
>   switch( field->data.capacity )
> {
> case 4:
>   value = real_value_truncate (TYPE_MODE (FLOAT), value);
>   real_to_target ((long *)retval, &value, TYPE_MODE (FLOAT));
>   break;
> case 8:
> /**/  value = real_value_truncate (TYPE_MODE (DOUBLE), value);
>   real_to_target ((long *)retval, &value, TYPE_MODE (DOUBLE));
>   break;
> case 16:
>   value = real_value_truncate (TYPE_MODE (FLOAT128), value);
>   real_to_target ((long *)retval, &value, TYPE_MODE (FLOAT128));
>   break;
> }
>   break;
>   }
> 
> Here is the debug session:
> 
> Breakpoint 6, initial_from_float128 (field=0x77415a10) at
> ../../gcc/cobol/genapi.cc:15721
> 15721 value = real_value_truncate (TYPE_MODE (DOUBLE), value);
> (gdb) print string_of(value)
> $17 = 0x55967e0 "1.2345678", '0' , "e+7"
> (gdb) next
> 15722 real_to_target ((long *)retval, &value, TYPE_MODE
> (DOUBLE));
> (gdb) print string_of(value)
> $18 = 0x5596930 "1.2345678", '0' , "e+7"
> (gdb) next
> 15723 break;
> (gdb) print *(double *)retval
> $19 = 1.5914968432239542e-314
> (gdb)
> 
> The two results of string_of(value) are what I expect.
> 
> The result of "print *(double)retval" is not.  It is the same value
> printed by the executable:
> 
> 1.59149684322395424E-314
> 
> I am now off to see that the routine real_to_target() thinks it is being
> asked to do.

Our mails crossed here.  I figured I misunderstood real_to_target.  I
have updated the full patch attached to PR119241 and posted an incremental
fix as followup to the mail where you posted the testcase failing.

Richard.

> > -Original Message-
> > From: Richard Biener 
> > Sent: Friday, March 21, 2025 08:57
> > To: gcc-patches@gcc.gnu.org
> > Cc: rdub...@symas.com; Jakub Jelinek 
> > Subject: [PATCH] change cbl_field_data_t::etc_t::value from _Float128 to
> > tree
> > 
> > The following removes the main instance of _Float128 use in the cobol
> > frontend and replaces it with a tree for cbl_field_data_t::etc_t::value
> > and with REAL_VALUE_TYPE in some helpers.
> > 
> > The default value is changed to a float128_type_node zero from 0.0.
> > 
> > get_power_of_ten was picked from Jakubs PR119242 patch, it doesn't build
> > on
> > its own so I've included it here.
> > 
> > This builds and tests OK on x86_64-linux with the in-tree testsuite.
> > Please give it extended testing.  All prerequesites have been pushed
> > to master already.
> > 
> > Thanks,
> > Richard.
> > 
> > PR cobol/119241
> > PR cobol/119242
> > * genutil.h (get_power_of_ten): Return FIXED_WIDE_INT(128).
> > * genutil.cc (get_power_of_ten): Produce FIXED_WIDE_INT(128)
> > instead of __int128.
> > (scale_by_power_of_ten_N): Adjust.
> > (copy_little_endian_into_place): Likewise.
> > * genapi.cc (mh_source_is_literalN): Likewise.
> > * symbols.h (cbl_field_data_t::etc_t::value): Make a tree.
> > (cbl_field_data_t::etc_t::etc_t): Adjust.
> > (cbl_field_data_t::cbl_field_data_t): Likewise.
> > (cbl_field_data_t::value_of): Likewise.
> > (cbl_field_data_t::operator=): Likewise.
> > (cbl_field_data_t::valify): Likewise.
> > * symbols.cc (cbl_occurs_t::subscript_ok): Likewise.
> > * genapi.h (initial_from_float128): Remove.
> > * genapi.cc (initial_from_float128): Make local and adjust.
> > (initialize_variable_internal): Adjust.
> > (get_binary_value_from_float): Likewise.
> > (psa_FldLiteralN): Simplify.
> > (parser_display_internal): Adjust.
> > (mh_source_is_literalN): Likewise.
> > (real_powi10): New helper.
> > (binary_initial_from_float128): Adjust.
> > (digits_from_float128): Likewise.
> > (parser_symbol_add): Likewise.
> > * parse.y (YYVAL): Use REAL_VALUE_TYPE instead of _Float128.
> > (string_of): Adjust and add overload from tree.
> > (field): Adjust.
> > (const_value): Likewise.
> > (value78): Likewise.
> > (data_descr1): Likewise.
> > (value_clause): Likewise.
> > (allocate): Likewise.
> > (move_tgt): Likewise.
> > (cc_expr): Likewise.
> > (cce_factor): Likewise.
> > (literal_refmod_valid): Likewise.
> > 
> > gcc/testsuite/
> > * cobol.dg/literal1.cob: New testcase.
> > * cobol.dg/output1.cob: Likewise.
> > Co-authored-by: Jakub Jelinek 
> > ---
> >  gcc/cobol/genapi.cc | 222 +++-
> >  gcc/cobol/genapi.h  |   3 -
> >  gcc/cobol/genutil.c

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

2025-04-05 Thread Iain Sandoe



> On 23 Mar 2025, at 20:09, Jeff Law  wrote:
> 
> 
> 
> On 3/23/25 8:28 AM, Iain Sandoe wrote:
>> Hi Jeff,
>>> On 23 Mar 2025, at 14:25, Jeff Law  wrote:
>>> On 3/23/25 8:03 AM, Iain Sandoe wrote:
 Tested on x86_64-Linux, Darwin,
 OK for trunk?
 backports?
 thanks
 Iain
 --- 8< ---
 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.
>>> So how does one trigger this failure?   ISTM that every libitm build should 
>>> be failing.  I think the patch is likely fine, but struggle to see why this 
>>> hasn't been more widely reported.
>> take your current build, and then delete /{,mlib}/libitm
>> then try
>> “make ….. all-target-libitm”  .. I believe it will fail with a libtool error 
>> (because the compiler is not passed - only the options)
>> That was certainly failing on both x86_64 linux/darwin before the patch.
> To be clear, I don't doubt it was failing, just trying to understand the 
> failure mode.  So it only pops up during a rebuild in an existing tree which 
> explains why we haven't been seeing this reported more often.

plus it only shows up for “cxx=true” libraries which, until libcobol was added 
was only libitm (and libffi)
[I noticed that the failure mode was the same while working on libcobol]

the other cxx cases are "raw_cxx=true” which already had the CXX_FOR_TARGET 
added;

> Thanks.  Ok for the trunk.

do you think it’s worth backporting (after some bake time)?

thanks
Iain



[COMMITTED 125/144] gccrs: Fix ICE when typechecking non-trait item when we expect one

2025-04-05 Thread arthur . cohen
From: Philip Herron 

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

Fixes #2499

gcc/rust/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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

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

[COMMITTED 044/146] gccrs: Handle type path segments during late resolution 2.0

2025-04-05 Thread arthur . cohen
From: Owen Avery 

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Call DefaultResolver::visit when visiting
TypePath.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery 
---
 gcc/rust/resolve/rust-late-name-resolver-2.0.cc | 2 ++
 gcc/testsuite/rust/compile/nr2/exclude  | 2 --
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
index 850f96aef89..3af8496288d 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -263,6 +263,8 @@ Late::visit (AST::TypePath &type)
   Definition (resolved->get_node_id ()));
   else
 rust_unreachable ();
+
+  DefaultResolver::visit (type);
 }
 
 void
diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index 2e956960dad..3dbebc703c4 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -42,7 +42,6 @@ generics3.rs
 generics4.rs
 generics5.rs
 generics6.rs
-generics7.rs
 generics8.rs
 generics9.rs
 if_let_expr.rs
@@ -83,7 +82,6 @@ issue-2165.rs
 issue-2166.rs
 issue-2190-1.rs
 issue-2190-2.rs
-issue-2195.rs
 issue-2238.rs
 issue-2304.rs
 issue-2330.rs
-- 
2.45.2



Re: [PATCH 2/1] c++/modules: Handle gnu_inline, again [PR119154]

2025-04-05 Thread Jason Merrill

On 3/22/25 8:37 AM, Nathaniel Shead wrote:

On Mon, Mar 17, 2025 at 09:42:13AM -0400, Jason Merrill wrote:

On 3/14/25 9:28 AM, Nathaniel Shead wrote:

Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk?

Alternatively, could still mark gnu_inline functions as non-vague, we
just need to do so more aggressively; but given this is specifically to
solve a modules issue I felt may as well keep it confined to there given
your previous comments.


I think we want a function import_interface_unknown or import_might_emit or
something that is vague_linkage_p with additional restrictions.

As I think of it, an explicitly instantiated template is still vague
linkage, but vague linkage is subject to various heuristics and controls
like explicit instantiation and the ABI tinfo rule.  The ABI spec recently
drifted away from this interpretation toward vague linkage meaning COMDAT,
but I think that was a conceptual mistake.



Makes sense.


gnu_inline seems borderline to me, but I lean toward the change in this
patch to treat all inlines as vague linkage and check gnu_inline in the new
function.

Jason



I found the clearest way to go was to make the function a tristate
(vague, always external, always emitted by importer) to handle header
units more naturally.

Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk?


OK.


-- >8 --

Subject: [PATCH] c++/modules: Fix explicit instantiations and gnu_inlines
  [PR119154]

My change in r15-8012 for PR c++/119154 exposed a bug with explicit
instantation declarations.  The change cleared DECL_INTERFACE_KNOWN for
all vague-linkage entities, including explicit instantiations.  When we
then perform lazy loading at EOF (due to processing deferred function
bodies), expand_or_defer_fn ends up calling import_export_decl which
will error because DECL_INTERFACE_KNOWN is still unset but no definition
is available in the file, violating some assertions.

It turns out that for function templates marked inline we would not
respect an 'extern template' imported in general, either; this patch
fixes both of these issues by always treating explicit instantiations as
external, and so marking DECL_INTERFACE_KNOWN eagerly.

For an explicit instantiation declaration we don't want to emit the body
of the function as it must be emitted in a different TU anyway.  And for
explicit instantiation definitions we similarly know that it will have
been emitted in the interface TU we streamed it in from, so there's
no need to emit it.

The same error can happen with lazy-loaded gnu_inlines at EOF; in some
cases they'll be marked DECL_COMDAT and pass through the vague_linkage_p
check anyway.  This patch reworks the handling of gnu_inlines to ensure
that both DECL_INTERFACE_KNOWN is always correctly set and that
importing a gnu_inline function over the top of an existing forward
declaration works correctly.

The other case that duplicate_decls handles (importing a regular
definition over the top of a gnu_inline function) doesn't seem like
something we need to handle specially in modules; we'll just use the
existing gnu_inline function and rely on the guarantee that there is a
single non-inline function definition provided elsewhere.

PR c++/119154

gcc/cp/ChangeLog:

* decl2.cc (vague_linkage_p): Revert gnu_linkage handling.
* module.cc (importer_interface): New enumeration.
(get_importer_interface): New function.
(trees_out::core_bools): Use it to determine interface.
(trees_in::is_matching_decl): Propagate gnu_inline handling onto
existing forward declarations.
(trees_in::read_var_def): Also note explicit instantiation
definitions of variable templates to be emitted.

gcc/testsuite/ChangeLog:

* g++.dg/modules/pr119154_a.C: Move to...
* g++.dg/modules/gnu-inline-1_a.C: ...here, and add decl.
* g++.dg/modules/pr119154_b.C: Move to...
* g++.dg/modules/gnu-inline-1_b.C: here, and add check.
* g++.dg/modules/gnu-inline-1_c.C: New test.
* g++.dg/modules/gnu-inline-1_d.C: New test.
* g++.dg/modules/gnu-inline-2_a.C: New test.
* g++.dg/modules/gnu-inline-2_b.C: New test.
* g++.dg/modules/extern-tpl-3_a.C: New test.
* g++.dg/modules/extern-tpl-3_b.C: New test.
* g++.dg/modules/extern-tpl-4_a.H: New test.
* g++.dg/modules/extern-tpl-4_b.C: New test.
* g++.dg/modules/extern-tpl-4_c.C: New test.

Signed-off-by: Nathaniel Shead 
---
  gcc/cp/decl2.cc   |  4 +-
  gcc/cp/module.cc  | 69 +++-
  gcc/testsuite/g++.dg/modules/extern-tpl-3_a.C | 11 +++
  gcc/testsuite/g++.dg/modules/extern-tpl-3_b.C | 12 +++
  gcc/testsuite/g++.dg/modules/extern-tpl-4_a.H | 22 +
  gcc/testsuite/g++.dg/modules/extern-tpl-4_b.C | 24 ++
  gcc/testsuite/g++.dg/modules/extern-tpl-4_c.C | 80 +++
  gcc/testsuite/g++.dg/modules/gnu-inline-1_a.C |  7 ++
  gcc/tests

[PATCH v2 1/1] aarch64: Use PAUTH instead of V8_3A in some places

2025-04-05 Thread Alfie Richards

gcc/ChangeLog:

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

(cherry-picked from commit 20385cb92cbd4a1934661ab97a162c1e25935836)
---
 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 cd2f4053a1a..1e74d9b81fa 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -10047,12 +10047,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 (aarch64_ra_sign_key)
 	{
diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md
index 47b70feff02..0b205b43d97 100644
--- a/gcc/config/aarch64/aarch64.md
+++ b/gcc/config/aarch64/aarch64.md
@@ -7124,11 +7124,11 @@ (define_insn "aarch64_fjcvtzs"
   [(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.


[PATCH] c++: Properly fold .* [PR114525]

2025-04-05 Thread Simon Martin
We've been miscompiling the following since r0-51314-gd6b4ea8592e338 (I
did not go compile something that old, and identified this change via
git blame, so might be wrong)

=== cut here ===
struct Foo { int x; };
Foo& get (Foo &v) { return v; }
void bar () {
  Foo v; v.x = 1;
  (true ? get (v) : get (v)).*(&Foo::x) = 2;
  // v.x still equals 1 here...
}
=== cut here ===

The problem lies in build_m_component_ref, that computes the address of
the COND_EXPR using build_address to build the representation of
  (true ? get (v) : get (v)).*(&Foo::x);
and gets something like
  &(true ? get (v) : get (v))  // #1
instead of
  (true ? &get (v) : &get (v)) // #2
and the write does not go where want it to, hence the miscompile.

This patch replaces the call to build_address by a call to
cp_build_addr_expr, which gives #2, that is properly handled.

Successfully tested on x86_64-pc-linux-gnu. OK for trunk? And for active
branches after 2-3 weeks since it's a nasty one (albeit very old)?

PR c++/114525

gcc/cp/ChangeLog:

* typeck2.cc (build_m_component_ref): Call cp_build_addr_expr
instead of build_address.

gcc/testsuite/ChangeLog:

* g++.dg/parse/pr114525.C: New test.

---
 gcc/cp/typeck2.cc |  2 +-
 gcc/testsuite/g++.dg/parse/pr114525.C | 36 +++
 2 files changed, 37 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/parse/pr114525.C

diff --git a/gcc/cp/typeck2.cc b/gcc/cp/typeck2.cc
index 1adc05aa86d..45edd180173 100644
--- a/gcc/cp/typeck2.cc
+++ b/gcc/cp/typeck2.cc
@@ -2387,7 +2387,7 @@ build_m_component_ref (tree datum, tree component, 
tsubst_flags_t complain)
  (cp_type_quals (type)
   | cp_type_quals (TREE_TYPE (datum;
 
-  datum = build_address (datum);
+  datum = cp_build_addr_expr (datum, complain);
 
   /* Convert object to the correct base.  */
   if (binfo)
diff --git a/gcc/testsuite/g++.dg/parse/pr114525.C 
b/gcc/testsuite/g++.dg/parse/pr114525.C
new file mode 100644
index 000..326985eed50
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/pr114525.C
@@ -0,0 +1,36 @@
+/* PR c++/114525 */
+/* { dg-do run } */
+
+struct Foo {
+  int x;
+};
+
+Foo& get (Foo& v) {
+  return v;
+}
+
+int main () {
+  bool cond = true;
+
+  /* Testcase from PR; v.x would wrongly remain equal to 1.  */
+  Foo v_ko;
+  v_ko.x = 1;
+  (cond ? get (v_ko) : get (v_ko)).*(&Foo::x) = 2;
+  if (v_ko.x != 2)
+__builtin_abort ();
+
+  /* Those would already work, i.e. x be changed to 2.  */
+  Foo v_ok_1;
+  v_ok_1.x = 1;
+  (cond ? get (v_ok_1) : get (v_ok_1)).x = 2;
+  if (v_ok_1.x != 2)
+__builtin_abort ();
+
+  Foo v_ok_2;
+  v_ok_2.x = 1;
+  get (v_ok_2).*(&Foo::x) = 2;
+  if (v_ok_2.x != 2)
+__builtin_abort ();
+
+  return 0;
+}
-- 
2.44.0



Re: [RFC] [C]New syntax for the argument of counted_by attribute for C language

2025-04-05 Thread Bill Wendling
I'd like to offer up this to solve the issues we're facing. This is a
combination of everything that's been discussed here (or at least that
I've been able to read in the centi-thread :-).

---

1. The use of '__self' isn't feasible, so we won't use it. Instead,
we'll rely upon the current behavior—resolving any identifiers to the
"instance scope". This new scope is used __only__ in attributes, and
resolves identifiers to those in the least enclosing, non-anonymous
struct. For example:

struct foo {
  char count;
  struct bar {
struct {
  int len;
};
struct {
  struct {
int *valid_use __counted_by(len); // Valid.
  };
};
int *invalid_use __counted_by(count); // Invalid.
  } b;
};

Rationale: This is how '__guarded_by' currently resolves identifiers,
so there's precedence. And if we can't force its usage in all
situations, it's less a feature and more a "nicety" which will lead to
a massive discrepancy between compiler implementations. Despite the
fact that this introduces a new scoping mechanism to C, its use is not
as extensive as C++'s instance scoping and will apply only to
attributes. In the case where we have two different resolution
techniquest happening within the same structure (e.g. VLAs), we can
issue warnings as outlined in Yeoul's RFC[1].

2. A method of forward declaring variables will be added for variables
that occur in the struct after the attribute. For example:

A: Necessary usage:

struct foo {
  int *buf __counted_by(char count; count);
  char count;
};

B: Unnecessary, but still valid, usage:

struct foo {
  char count;
  int *buf __counted_by(char count; count);
};

* The forward declaration is required in (A) but not in (B).
* The type of 'count' as declared in '__counted_by' *must* match the real type.

Rationale: This alleviates the issues of "double parsing" for
compilers that aren't able to handle it. (We can also remove the
'-fexperimental-late-parse-attributes' flag in Clang.)

3. A new builtin '__builtin_global_ref()' (or similarly named) is
added to refer to variables outside of the most-enclosing structure.
Example:

int count_that_will_never_change_we_promise;

struct foo {
  int *bar 
__counted_by(__builtin_global_ref(count_that_will_never_change_we_promise));
  unsigned flags;
};

As Yeoul pointed out, there isn't a way to refer to variables that
have been shadowed, so the 'global' in '__builtin_global_ref' is a bit
of a misnomer as it could refer to a local variable.

Rationale: For those who need the flexibility to use variables outside
of the struct, this is an acceptable escape route. It does make bounds
checking less strict, though, as we can't track any modifications to
the global, so caution must be used.

Bonus suggestion (by yours truly):

I'd like the option to allow functions to calculate expressions (it
can be used for a single identifier too, but that's too heavy-handed).
It won't be required for an expression, but is a good way to avoid any
issues regarding '__builtin_global_ref', like variables shadowing the
global variable. Example:

int global;

struct foo;
static int counted_by_calc(struct foo *);

struct foo {
  char count;
  int fnord;
  int *buf __counted_by(counted_by_calc);
};

static int counted_by_calc(struct foo *ptr) __attribute__((pure)) {
  return ptr->count * (global << 42) - ptr->fnord;
}

A pointer to the current least enclosing, non-anonymous struct is
passed into 'counted_by_calc' by the compiler.

Rationale: This gets rid of all ambiguities when calculating an
expression. It's marked 'pure' so there should be no side-effects.

---

I believe these suggestions cover everything we've discussed. Please
comment with anything I missed and your opinions on each.

[1] 
https://discourse.llvm.org/t/rfc-forward-referencing-a-struct-member-within-bounds-annotations/85510

Share and enjoy!
-bw


Re: Please Ignore -- testing email

2025-04-05 Thread Mark Wielaard
Hi Matthew,

On Tue, 2025-04-01 at 09:38 +0100, Matthew Malcomson wrote:
> One more time -- trying to figure out email difficulties.

I see the date (but hope it isn't a joke) and the "Please ignore".
But just in case you haven't found the issue and need to do more
testing or if someone else needs a "testing" mailinglist.

There is test-l...@sourceware.org
https://sourceware.org/mailman/listinfo/test-list

With archives also on https://inbox.sourceware.org/test-list/ (where
you can get the /raw message as received on the server (before mailing
list handling).

Cheers,

Mark

> On 2/5/25 08:41, Matthew Malcomson wrote:
> > Again -- apologies for the noise
> > 
> > On 1/22/25 16:16, Matthew Malcomson wrote:
> > > *External email: Use caution opening links or attachments*
> > > 
> > > 
> > > Apologies for the noise.
> > 
> 



[PATCH] phiprop: Avoid proping loads into loops [PR116835]

2025-04-05 Thread Andrew Pinski
phiprop can sometimes prop loads back into loops
and in some cases cause wrong code when the load
was from a weak symbol as now it becomes an unconditional
load before the loop.

Bootstrapped and tested on x86_64-linux-gnu with no regressions.

PR tree-optimization/116835

gcc/ChangeLog:

* tree-ssa-phiprop.cc (propagate_with_phi): Check
the use is at the same or deeper loop depth than
the phi node.
(pass_phiprop::execute): Initialize loops.

gcc/testsuite/ChangeLog:

* gcc.dg/torture/pr116835.c: New test.

Signed-off-by: Andrew Pinski 
---
 gcc/testsuite/gcc.dg/torture/pr116835.c | 33 +
 gcc/tree-ssa-phiprop.cc | 14 ++-
 2 files changed, 46 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr116835.c

diff --git a/gcc/testsuite/gcc.dg/torture/pr116835.c 
b/gcc/testsuite/gcc.dg/torture/pr116835.c
new file mode 100644
index 000..31d3b59d945
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr116835.c
@@ -0,0 +1,33 @@
+/* { dg-do run { target { weak_undefined } } } */
+/* { dg-add-options weak_undefined } */
+
+/* PR tree-optimization/116835 */
+/* phiprop would prop into the loop the load of b
+   and also prop the load of a before the loop.
+   Which is incorrect as a is a weak symbol.  */
+
+struct s1
+{
+  int t;
+  int t1;
+};
+typedef struct s1 type;
+extern type a __attribute__((weak));
+int t;
+type b;
+type bar (int c) __attribute__((noipa, noinline));
+type 
+bar (int c)
+{
+  t = 1;
+  type *p = &a;
+  for (int j = 0; j < c; ++j)
+p = &b;
+  return *p;
+}
+
+int main(void)
+{
+ if (bar(&a == nullptr).t)
+   __builtin_abort();
+}
diff --git a/gcc/tree-ssa-phiprop.cc b/gcc/tree-ssa-phiprop.cc
index a2e1fb16a30..c5fe231d3e9 100644
--- a/gcc/tree-ssa-phiprop.cc
+++ b/gcc/tree-ssa-phiprop.cc
@@ -35,6 +35,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-ssa-loop.h"
 #include "tree-cfg.h"
 #include "tree-ssa-dce.h"
+#include "cfgloop.h"
 
 /* This pass propagates indirect loads through the PHI node for its
address to make the load source possibly non-addressable and to
@@ -348,11 +349,17 @@ propagate_with_phi (basic_block bb, gphi *phi, struct 
phiprop_d *phivn,
calculate_dominance_info (CDI_POST_DOMINATORS);
 
   /* Only replace loads in blocks that post-dominate the PHI node.  That
- makes sure we don't end up speculating loads.  */
+makes sure we don't end up speculating loads.  */
   if (!dominated_by_p (CDI_POST_DOMINATORS,
   bb, gimple_bb (use_stmt)))
continue;
 
+  /* Only replace loads in blocks are in the same loop
+are inside an deeper loop.  This is to make sure not
+to prop back into the loop.  */
+  if (bb_loop_depth (gimple_bb (use_stmt)) < bb_loop_depth (bb))
+   continue;
+
   /* Check whether this is a load of *ptr.  */
   if (!(is_gimple_assign (use_stmt)
&& gimple_assign_rhs_code (use_stmt) == MEM_REF
@@ -520,6 +527,10 @@ pass_phiprop::execute (function *fun)
   size_t n;
   auto_bitmap dce_ssa_names;
 
+  /* Find the loops, so that we can prevent moving loads in
+ them.  */
+  loop_optimizer_init (AVOID_CFG_MODIFICATIONS);
+
   calculate_dominance_info (CDI_DOMINATORS);
 
   n = num_ssa_names;
@@ -548,6 +559,7 @@ pass_phiprop::execute (function *fun)
   free (phivn);
 
   free_dominance_info (CDI_POST_DOMINATORS);
+  loop_optimizer_finalize ();
 
   return did_something ? TODO_update_ssa_only_virtuals : 0;
 }
-- 
2.43.0



[COMMITTED 126/146] gccrs: lower: Properly lower non-generic lang item type path segments.

2025-04-05 Thread arthur . cohen
From: Arthur Cohen 

gcc/rust/ChangeLog:

* hir/rust-ast-lower-type.cc (ASTLowerTypePath::visit): Adapt code to 
lang item
type path segments.
---
 gcc/rust/hir/rust-ast-lower-type.cc | 40 ++---
 1 file changed, 14 insertions(+), 26 deletions(-)

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



New French PO file for 'cpplib' (version 15.1-b20250316)

2025-04-05 Thread Translation Project Robot
Hello, gentle maintainer.

This is a message from the Translation Project robot.

A revised PO file for textual domain 'cpplib' has been submitted
by the French team of translators.  The file is available at:

https://translationproject.org/latest/cpplib/fr.po

(This file, 'cpplib-15.1-b20250316.fr.po', has just now been sent to you in
a separate email.)

All other PO files for your package are available in:

https://translationproject.org/latest/cpplib/

Please consider including all of these in your next release, whether
official or a pretest.

Whenever you have a new distribution with a new version number ready,
containing a newer POT file, please send the URL of that distribution
tarball to the address below.  The tarball may be just a pretest or a
snapshot, it does not even have to compile.  It is just used by the
translators when they need some extra translation context.

The following HTML page has been updated:

https://translationproject.org/domain/cpplib.html

If any question arises, please contact the translation coordinator.

Thank you for all your work,

The Translation Project robot, in the
name of your translation coordinator.




Re: [PATCH] libstdc++: Fix up string _M_constructor exports [PR103827]

2025-04-05 Thread Rainer Orth
Hi Jonathan,

>> Indeed, I can build on Solaris 11 with this patch and it passes 'make
>> check-abi' on sparc-solaris and x86_64-linux. I'll push it.
>
> Pushed as r15-9071-g44289d258a970e

Last night's bootstraps finished without regressions.

Thanks for the quick fix.

Rainer

-- 
-
Rainer Orth, Center for Biotechnology, Bielefeld University


Re: [RFC 0/4] Doc: Reorganize the "C Extensions" chapter [PR42270]

2025-04-05 Thread Sandra Loosemore

On 3/13/25 20:39, Sandra Loosemore wrote:

This series of patches attempts to bring some organization to the
current random order of topics within the "C Extensions" chapter of
the manual.  [snip]

I've now pushed these patches.

-Sandra


RE: [PATCH 2/2] [cobol] make sources coretypes.h and tree.h clean

2025-04-05 Thread Robert Dubner
> -Original Message-
> From: Jakub Jelinek 
> Sent: Wednesday, March 19, 2025 13:08
> To: Robert Dubner 
> Cc: Richard Biener ; gcc-patches@gcc.gnu.org
> Subject: Re: [PATCH 2/2] [cobol] make sources coretypes.h and tree.h
clean
> 
> On Wed, Mar 19, 2025 at 12:04:05PM -0500, Robert Dubner wrote:
> > This message appears to have been posted twice, and I don't see a
[PATCH
> > 1/2]
> 
> One copy went to you, one to gcc-patches, which is why you got two
copies.
> The 1/2 patch was https://gcc.gnu.org/pipermail/gcc-patches/2025-
> March/678260.html
> and didn't touch the cobol FE, just generic code and C++ FE, I've
already
> approved that.
> 
>   Jakub

Thanks.

I applied the patch and I am trying to compile it; there is a problem.


In file included from ../../gcc/cobol/scan.l:42:
cobol/parse.h:932:12: error: 'NONE' conflicts with a previous declaration
  932 | NONE = 881,/* NONE  */
  |^~~
In file included from ../../gcc/tree.h:23,
 from ../../gcc/cobol/scan.l:34:
../../gcc/tree-core.h:2028:3: note: previous declaration
'function_decl_type NONE'
 2028 |   NONE,
  |   ^~~~
===

I'll see what I can do about that.  

I have an engagement at 1:30 my time; that might delay my response.


[PATCH] OpenMP: 'interop' construct - add ME support + target-independent libgomp

2025-04-05 Thread Paul-Antoine Arras
This patch partially enables use of the OpenMP interop construct by adding
middle end support, mostly in the omplower pass, and in the target-independent
part of the libgomp runtime. It follows up on previous patches for C, C++ and
Fortran front ends support. The full interop feature requires another patch to
enable foreign runtime support in libgomp plugins.

gcc/ChangeLog:

* builtin-types.def
(BT_FN_VOID_INT_INT_PTR_PTR_PTR_INT_PTR_INT_PTR_UINT_PTR): New.
* gimple-low.cc (lower_stmt): Handle GIMPLE_OMP_INTEROP.
* gimple-pretty-print.cc (dump_gimple_omp_interop): New function.
(pp_gimple_stmt_1): Handle GIMPLE_OMP_INTEROP.
* gimple.cc (gimple_build_omp_interop): New function.
(gimple_copy): Handle GIMPLE_OMP_INTEROP.
* gimple.def (GIMPLE_OMP_INTEROP): Define.
* gimple.h (gimple_build_omp_interop): Declare.
(gimple_omp_interop_clauses): New function.
(gimple_omp_interop_clauses_ptr): Likewise.
(gimple_omp_interop_set_clauses): Likewise.
(gimple_return_set_retval): Handle GIMPLE_OMP_INTEROP.
* gimplify.cc (gimplify_scan_omp_clauses): Handle OMP_CLAUSE_INIT,
OMP_CLAUSE_USE and OMP_CLAUSE_DESTROY.
(gimplify_omp_interop): New function.
(gimplify_expr): Replace sorry with call to gimplify_omp_interop.
* omp-builtins.def (BUILT_IN_GOMP_INTEROP): Define.
* omp-low.cc (scan_sharing_clauses): Handle OMP_CLAUSE_INIT,
OMP_CLAUSE_USE and OMP_CLAUSE_DESTROY.
(scan_omp_1_stmt): Handle GIMPLE_OMP_INTEROP.
(lower_omp_interop_action_clauses): New function.
(lower_omp_interop): Likewise.
(lower_omp_1): Handle GIMPLE_OMP_INTEROP.

gcc/c/ChangeLog:

* c-parser.cc (c_parser_omp_clause_destroy): Make addressable.
(c_parser_omp_clause_init): Make addressable.

gcc/cp/ChangeLog:

* parser.cc (cp_parser_omp_clause_init): Make addressable.

gcc/fortran/ChangeLog:

* trans-openmp.cc (gfc_trans_omp_clauses): Make OMP_CLAUSE_DESTROY and
OMP_CLAUSE_INIT addressable.
* types.def (BT_FN_VOID_INT_INT_PTR_PTR_PTR_INT_PTR_INT_PTR_UINT_PTR):
New.

include/ChangeLog:

* gomp-constants.h (GOMP_DEVICE_DEFAULT_OMP_61): Define.
(GOMP_INTEROP_FLAG_TARGET): Define.
(GOMP_INTEROP_FLAG_TARGETSYNC): Define.

libgomp/ChangeLog:

* icv-device.c (omp_set_default_device): Check
GOMP_DEVICE_DEFAULT_OMP_61.
* libgomp-plugin.h (struct interop_obj_t): New.
(enum gomp_interop_flag): New.
(GOMP_OFFLOAD_interop): Declare.
(GOMP_OFFLOAD_get_interop_int): Declare.
(GOMP_OFFLOAD_get_interop_ptr): Declare.
(GOMP_OFFLOAD_get_interop_str): Declare.
(GOMP_OFFLOAD_get_interop_type_desc): Declare.
* libgomp.h (_LIBGOMP_OMP_LOCK_DEFINED): Define.
(struct gomp_device_descr): Add interop_func, get_interop_int_func,
get_interop_ptr_func, get_interop_str_func, get_interop_type_desc_func.
* libgomp.map: Add GOMP_interop.
* libgomp_g.h (GOMP_interop): Declare.
* target.c (resolve_device): Handle GOMP_DEVICE_DEFAULT_OMP_61.
(omp_get_interop_int): Replace stub with actual implementation.
(omp_get_interop_ptr): Likewise.
(omp_get_interop_str): Likewise.
(omp_get_interop_type_desc): Likewise.
(struct interop_data_t): Define.
(gomp_interop_internal): New function.
(GOMP_interop): Likewise.
(gomp_load_plugin_for_device): Load symbols for get_interop_int,
get_interop_ptr, get_interop_str and get_interop_type_desc.
* testsuite/libgomp.c-c++-common/interop-1.c: New test.

gcc/testsuite/ChangeLog:

* c-c++-common/gomp/interop-1.c: Remove dg-prune-output "sorry".
* c-c++-common/gomp/interop-2.c: Likewise.
* c-c++-common/gomp/interop-3.c: Likewise.
* c-c++-common/gomp/interop-4.c: Remove dg-message "not supported".
* g++.dg/gomp/interop-5.C: Likewise.
* gfortran.dg/gomp/interop-4.f90: Likewise.
* c-c++-common/gomp/interop-5.c: New test.
* gfortran.dg/gomp/interop-5.f90: New test.
---
 gcc/builtin-types.def |   3 +
 gcc/c/c-parser.cc |   6 +-
 gcc/cp/parser.cc  |   1 +
 gcc/fortran/trans-openmp.cc   |  20 +-
 gcc/fortran/types.def |   3 +
 gcc/gimple-low.cc |   1 +
 gcc/gimple-pretty-print.cc|  23 ++
 gcc/gimple.cc |  18 ++
 gcc/gimple.def|   4 +
 gcc/gimple.h  |  33 ++-
 gcc/gimplify.cc   |  20 +-
 gcc/omp-builtins.def  |   3 +
 gcc/omp-low.cc| 274 ++
 gcc/testsuite/c-c++-common/gomp/interop-1.c   |   2 -

Re: [Pushed] Fix r15-8073 (Pass -macos_version_min to the linker)

2025-04-05 Thread Iain Sandoe



> On 18 Mar 2025, at 01:27, Andrew Pinski  wrote:
> 
> So what is happening is gcc_cv_ld64_macosx_version_min is being
> used for the replacement and being set in a few locations but
> gcc_cv_ld64_macos_version_min is set in others.
> Since the auto-host.h variable is named LD64_HAS_MACOS_VERSION_MIN,
> I changed over to remove the x from the name.
> 
> Committed as obvious after a quick test to make sure 
> LD64_HAS_MACOS_VERSION_MIN
> was not set to empty.

Thanks - I did not spot this in my testing, I think because I always build with 
a linker available.

ld64 used to accept -macosx_version_min to pass the OS version, it was changed 
recently
to accept ‘-macos_version_min’ and it is very easy to typo.

It would have been nice if Apple had dropped the tautologous “X” from macOS 
when they
transitioned to ’11’ … and it was discussed - but I guess “macosx” is too 
deeply embedded
in the toolchains - so the ld64 change is, I think, the only one.

thanks
Iain



Re: [PATCH] RISC-V: Fixbug for slli + addw + zext.w into sh[123]add + zext.w

2025-04-05 Thread Jeff Law




On 4/1/25 12:20 AM, Jin Ma wrote:

Assuming we have the following variables:

unsigned long long a0, a1;
unsigned int a2;

For the expression:

a0 = (a0 << 50) >> 49;  // slli a0, a0, 50 + srli a0, a0, 49
a2 = a1 + a0;   // addw a2, a1, a0 + slli a2, a2, 32 + srli a2, a2, 32

In the optimization process of ZBA (combine pass), it would be optimized to:

a2 = a0 << 1 + a1;  // sh1add a2, a0, a1 + zext.w a2, a2

This is clearly incorrect, as it overlooks the fact that a0=a0&0x7ffe, meaning
that the bits a0[32:14] are set to zero.

gcc/ChangeLog:

* config/riscv/bitmanip.md: The optimization can only be applied if
the high bit of operands[3] is set to 1.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/zba-shNadd-09.c: New test.
* gcc.target/riscv/zba-shNadd-10.c: New test.
---
  gcc/config/riscv/bitmanip.md  |  3 ++-
  .../gcc.target/riscv/zba-shNadd-09.c  | 12 +++
  .../gcc.target/riscv/zba-shNadd-10.c  | 20 +++
  3 files changed, 34 insertions(+), 1 deletion(-)
  create mode 100644 gcc/testsuite/gcc.target/riscv/zba-shNadd-09.c
  create mode 100644 gcc/testsuite/gcc.target/riscv/zba-shNadd-10.c

diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md
index b29c127bcb8..9091c48b106 100644
--- a/gcc/config/riscv/bitmanip.md
+++ b/gcc/config/riscv/bitmanip.md
@@ -80,7 +80,8 @@ (define_split
(match_operand:DI 3 
"consecutive_bits_operand")) 0)
 (subreg:SI (match_operand:DI 4 
"register_operand") 0]
"TARGET_64BIT && TARGET_ZBA
-   && riscv_shamt_matches_mask_p (INTVAL (operands[2]), INTVAL (operands[3]))"
+   && riscv_shamt_matches_mask_p (INTVAL (operands[2]), INTVAL (operands[3]))
+   && ((INTVAL (operands[3]) & (1 << 31)) != 0)"
[(set (match_dup 0) (plus:DI (ashift:DI (match_dup 1) (match_dup 2)) 
(match_dup 4)))
 (set (match_dup 0) (zero_extend:DI (subreg:SI (match_dup 0) 0)))])

So I would add a comment to that new condition.  Something like
/* Ensure the mask includes all the bits in SImode.  */

We need to be careful with constants like 1 << 31.  Something like
(HOST_WIDE_INT_1U << 31) would be better from a type safety standpoint 
(INTVAL returns a HOST_WIDE_INT object).








+#include 
In general, avoid #includes if you can in tests.  Remove the  
include.





+  printf("%llu\n", d);
Instead of a printf and using dg-output, the standard way we test for 
correctness is by either aborting or calling exit (0).  So rather than 
the printf use


  if (d != 3023282)
__builtin_abort ();
  __builtin_exit (0);

And drop the dg-output line.


With those changes this patch is probably OK.  We'd want to post the V2 
so that the pre-commit tester can chew on it.


Thanks!
Jeff


RE: [PATCH][RFC] [cobol] change cbl_field_data_t::etc_t::value from _Float128 to tree

2025-04-05 Thread Robert Dubner



> -Original Message-
> From: Richard Biener 
> Sent: Thursday, March 20, 2025 10:16
> To: gcc-patches@gcc.gnu.org
> Cc: Jakub Jelinek ; rdub...@symas.com
> Subject: Re: [PATCH][RFC] [cobol] change cbl_field_data_t::etc_t::value
> from _Float128 to tree
> 
> On Thu, 20 Mar 2025, Richard Biener wrote:
> 
> > The following removes the main instance of _Float128 use in the cobol
> > frontend and replaces it with a tree for
cbl_field_data_t::etc_t::value
> > and with REAL_VALUE_TYPE in some helpers.
> >
> > The default value is changed to a float128_type_node zero from 0.0.
> >
> > get_power_of_ten was picked from Jakubs PR119242 patch, it doesn't
build
> on
> > its own so I've included it here.
> >
> > Together with the other two pending changes (the one already approved
> > and '[cobol] move global data to symbol_table_init'), this compiles
> > and passes the majority of cobol tests.  As expected there is some
> > fallout which is at the moment
> >
> > FAIL: cobol.dg/group1/display2.cob   -O0  output pattern test
> >
> > (fails at all optimization levels), probably related to the
> > _Float128 <-> string conversions.  The failure is
> >
> > Output was:
> > 1.e+0
> > 2.e+0
> >
> > Should match:
> > 1 2
> >
> > I don't know which of the many _Float128 <-> string conversions is
> > guilty here.
> 
> I've fixed that now, the following patch ontop of
> '[cobol] make sources coretypes.h and tree.h clean' and
> '[cobol] move global data to symbol_table_init' passes build and
> the cobol testsuite as it is in GCC right now.
> 
> Can you possibly test this on the full testsuite?

Of course.  I am sorry I didn't notice this earlier; I am up to my armpits
in Python.

I am not totally sure on where to find the current patch.  Can someone
advise me?

Bob Dubner




> 
> Thanks,
> Richard.
> 
> From 0cb5fae11f109a7fcd94da98e203a730c3ecfee4 Mon Sep 17 00:00:00 2001
> From: Richard Biener 
> Date: Thu, 20 Mar 2025 11:08:01 +0100
> Subject: [PATCH] [cobol] change cbl_field_data_t::etc_t::value from
> _Float128
>  to tree
> To: gcc-patches@gcc.gnu.org
> 
> The following removes the main instance of _Float128 use in the cobol
> frontend and replaces it with a tree for cbl_field_data_t::etc_t::value
> and with REAL_VALUE_TYPE in some helpers.
> 
> The default value is changed to a float128_type_node zero from 0.0.
> 
> get_power_of_ten was picked from Jakubs PR119242 patch, it doesn't build
> on
> its own so I've included it here.
> 
>   PR cobol/119241
>   PR cobol/119242
>   * genutil.h (get_power_of_ten): Return FIXED_WIDE_INT(128).
>   * genutil.cc (get_power_of_ten): Produce FIXED_WIDE_INT(128)
>   instead of __int128.
>   (scale_by_power_of_ten_N): Adjust.
>   (copy_little_endian_into_place): Likewise.
>   * genapi.cc (mh_source_is_literalN): Likewise.
>   * symbols.h (cbl_field_data_t::etc_t::value): Make a tree.
>   (cbl_field_data_t::etc_t::etc_t): Adjust.
>   (cbl_field_data_t::cbl_field_data_t): Likewise.
>   (cbl_field_data_t::value_of): Likewise.
>   (cbl_field_data_t::operator=): Likewise.
>   (cbl_field_data_t::valify): Likewise.
>   * symbols.cc (cbl_occurs_t::subscript_ok): Likewise.
>   * genapi.h (initial_from_float128): Remove.
>   * genapi.cc (initial_from_float128): Make local and adjust.
>   (initialize_variable_internal): Adjust.
>   (get_binary_value_from_float): Likewise.
>   (psa_FldLiteralN): Simplify.
>   (parser_display_internal): Adjust.
>   (mh_source_is_literalN): Likewise.
>   (real_powi10): New helper.
>   (binary_initial_from_float128): Adjust.
>   (digits_from_float128): Likewise.
>   (parser_symbol_add): Likewise.
>   * parse.y (YYVAL): Use REAL_VALUE_TYPE instead of _Float128.
>   (string_of): Adjust and add overload from tree.
>   (field): Adjust.
>   (const_value): Likewise.
>   (value78): Likewise.
>   (data_descr1): Likewise.
>   (value_clause): Likewise.
>   (allocate): Likewise.
>   (move_tgt): Likewise.
>   (cc_expr): Likewise.
>   (cce_factor): Likewise.
>   (literal_refmod_valid): Likewise.
> 
> Co-authored-by: Jakub Jelinek 
> ---
>  gcc/cobol/genapi.cc  | 218 +++
>  gcc/cobol/genapi.h   |   3 -
>  gcc/cobol/genutil.cc |  26 +++---
>  gcc/cobol/genutil.h  |   2 +-
>  gcc/cobol/parse.y| 118 +--
>  gcc/cobol/symbols.cc |  15 ++-
>  gcc/cobol/symbols.h  |  21 +++--
>  7 files changed, 220 insertions(+), 183 deletions(-)
> 
> diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc
> index 8f4f9b21370..7f1b78dbf9a 100644
> --- a/gcc/cobol/genapi.cc
> +++ b/gcc/cobol/genapi.cc
> @@ -52,6 +52,7 @@
>  #include "../../libgcobol/charmaps.h"
>  #include "../../libgcobol/valconv.h"
>  #include "show_parse.h"
> +#include "fold-const.h"
> 
>  extern int yylineno;
> 
> @@ -1041,7 +1042,9 @@ initialize_variable_

Re: [Patch] testsuite/lib/libgomp.exp: compile with -fdiagnostics-plain-output

2025-04-05 Thread Jakub Jelinek
On Fri, Mar 21, 2025 at 01:10:44PM +0100, Tobias Burnus wrote:
> I tried to match in dg-warning the whole string, including [-OpenMP], but it 
> failed.
> 
> I turned out that that was because of -fdiagnostics-urls ...
> 
> Solution do what other testsuites do: Use -fdiagnostics-plain-output.
> 
> Unless there are further comments, I intent to commit the attached patch 
> later today.
> 
> Thanks,
> 
> Tobias

> testsuite/lib/libgomp.exp: compile with -fdiagnostics-plain-output
> 
> libgomp.exp added -fno-diagnostics-show-caret and -fdiagnostics-color=never
> as 'additional_flags' for compilation. However, it turned out that this now
> is insufficient as the [...] part of diagnostics have a hyperlink URL.
> 
> Solution: Use the -fdiagnostics-plain-output flag instead, added in commit
> r11-2701-g129a1319c0ab73. This flag currently implies the following flags:
>-fno-diagnostics-show-caret
>-fno-diagnostics-show-line-numbers
>-fdiagnostics-color=never
>-fdiagnostics-urls=never
>-fdiagnostics-path-format=separate-events
>-fdiagnostics-text-art-charset=none
>-fno-diagnostics-show-event-links
> 
> libgomp/ChangeLog:
> 
>   * testsuite/lib/libgomp.exp (libgomp_init): Add
>   -fdiagnostics-plain-output to additional_flags; remove
>   -fno-diagnostics-show-caret and -fdiagnostics-color=never.

LGTM.
Though, generally tests with dg-warning/dg-error/dg-message should generally
go into gcc/testsuite/*/gomp/ rather than libgomp if possible.

> --- a/libgomp/testsuite/lib/libgomp.exp
> +++ b/libgomp/testsuite/lib/libgomp.exp
> @@ -233,11 +233,8 @@ proc libgomp_init { args } {
>  # error-message parsing machinery.
>  lappend ALWAYS_CFLAGS "additional_flags=-fmessage-length=0"
>  
> -# Disable caret
> -lappend ALWAYS_CFLAGS "additional_flags=-fno-diagnostics-show-caret"
> -
> -# Disable color diagnostics
> -lappend ALWAYS_CFLAGS "additional_flags=-fdiagnostics-color=never"
> +# Disable caret, color, URL diagnostics
> +lappend ALWAYS_CFLAGS "additional_flags=-fdiagnostics-plain-output"
>  
>  # Help GCC to find offload compilers' 'mkoffload'.
>  global offload_additional_options


Jakub



[PUSHED] Add 'g++.target/nvptx/alias-g++.dg_init_dtor2-2.C'

2025-04-05 Thread Thomas Schwinge
... next to '-malias' variant: commit a1865fd33897bc6c6e0109df0a12ee73ce386315
"Add 'g++.target/nvptx/alias-g++.dg_init_dtor2-1.C'", to document what we're
doing to '-mno-alias'.

gcc/testsuite/
* g++.target/nvptx/alias-g++.dg_init_dtor2-2.C: New.
---
 .../nvptx/alias-g++.dg_init_dtor2-2.C | 33 +++
 1 file changed, 33 insertions(+)
 create mode 100644 gcc/testsuite/g++.target/nvptx/alias-g++.dg_init_dtor2-2.C

diff --git a/gcc/testsuite/g++.target/nvptx/alias-g++.dg_init_dtor2-2.C 
b/gcc/testsuite/g++.target/nvptx/alias-g++.dg_init_dtor2-2.C
new file mode 100644
index 000..f00575e023e
--- /dev/null
+++ b/gcc/testsuite/g++.target/nvptx/alias-g++.dg_init_dtor2-2.C
@@ -0,0 +1,33 @@
+/* Reduced from 'g++.dg/init/dtor2.C'.  */
+
+/* { dg-do link } */
+/* { dg-additional-options -mno-alias } */
+/* { dg-additional-options -save-temps } */
+/* Via the magic string "-std=*++" indicate that testing one (the default) C++ 
standard is sufficient.  */
+
+struct B
+{
+  ~B();
+};
+
+B::~B () {
+}
+
+int main()
+{
+  B b;
+  return 0;
+}
+
+/* { dg-final { scan-assembler-times {(?n)^// BEGIN GLOBAL FUNCTION DECL: 
_ZN1BD2Ev$} 1 } }
+   { dg-final { scan-assembler-times {(?n)^\.visible \.func _ZN1BD2Ev 
\(\.param\.u64 %in_ar0\);$} 1 } }
+   { dg-final { scan-assembler-times {(?n)^// BEGIN GLOBAL FUNCTION DEF: 
_ZN1BD2Ev$} 1 } }
+   { dg-final { scan-assembler-times {(?n)^\.visible \.func _ZN1BD2Ev 
\(\.param\.u64 %in_ar0\)$} 1 } } */
+
+/* { dg-final { scan-assembler-times {(?n)^// BEGIN GLOBAL FUNCTION DECL: 
_ZN1BD1Ev$} 1 } }
+   { dg-final { scan-assembler-times {(?n)^\.visible \.func _ZN1BD1Ev 
\(\.param\.u64 %in_ar0\);$} 1 } }
+   { dg-final { scan-assembler-times {(?n)^// BEGIN GLOBAL FUNCTION DEF: 
_ZN1BD1Ev$} 1 } }
+   { dg-final { scan-assembler-times {(?n)^\.visible \.func _ZN1BD1Ev 
\(\.param\.u64 %in_ar0\)$} 1 } } */
+
+/* { dg-final { scan-assembler-times {(?n)\tcall _ZN1BD1Ev, \(} 1 } }
+   { dg-final { scan-assembler-times {(?n)\tcall _ZN1BD2Ev, \(} 0 } } */
-- 
2.34.1



Re: [PATCH] RISC-V: xtheadmemidx: Split slli.uw pattern [combine question]

2025-04-05 Thread Christoph Müllner
On Wed, Apr 2, 2025 at 5:35 AM Jeff Law  wrote:
>
>
> Segher -- there's a combine question near the end...

I've created PR119587 to keep track of this issue.

BR
Christoph

>
>
> On 3/23/25 8:43 PM, Bohan Lei wrote:
> > The combine pass can generate an index like (and:DI (mult:DI (reg:DI)
> > (const_int scale)) (const_int mask)) when XTheadMemIdx is available.
> > LRA may pull it out, and thus a splitter is needed when Zba is not
> > available.
> >
> > A similar splitter were introduced when XTheadMemIdx support was added,
> > but removed in commit 31c3c5d.  The new splitter in this new patch is
> > based on the removed one.
> >
> > gcc/ChangeLog:
> >
> >  * config/riscv/thead.md (*th_memidx_operand): New splitter.
> >
> > gcc/testsuite/ChangeLog:
> >
> >  * gcc.target/riscv/xtheadmemidx-bug.c: New test.
> > ---
> >   gcc/config/riscv/thead.md | 21 +++
> >   .../gcc.target/riscv/xtheadmemidx-bug.c   | 13 
> >   2 files changed, 34 insertions(+)
> >   create mode 100644 gcc/testsuite/gcc.target/riscv/xtheadmemidx-bug.c
> >
> > diff --git a/gcc/config/riscv/thead.md b/gcc/config/riscv/thead.md
> > index d816f3b86dd..20e82e68df2 100644
> > --- a/gcc/config/riscv/thead.md
> > +++ b/gcc/config/riscv/thead.md
> > @@ -458,6 +458,27 @@ (define_insn "*th_mempair_load_zero_extendsidi2"
> >
> >   ;; XTheadMemIdx
> >
> > +;; Help reload to add a displacement for the base register.
> > +;; In the case `zext(*(uN*))(base+((rN<<1)&0x1fffe))` LRA splits
> > +;; off two new instructions: a) `new_base = base + disp`, and
> > +;; b) `index = (rN<<1)&0x1fffe`.  The index calculation has no
> > +;; corresponding instruction pattern and needs this insn_and_split
> > +;; to recover.
> > +
> > +(define_insn_and_split "*th_memidx_operand"
> > +  [(set (match_operand:DI 0 "register_operand" "=r")
> > + (and:DI (ashift:DI (match_operand:DI 1 "register_operand" "r")
> > +(match_operand:QI 2 "imm123_operand" "Ds3"))
> > + (match_operand 3 "const_int_operand" "n")))]
> > +  "TARGET_64BIT && TARGET_XTHEADMEMIDX && (lra_in_progress || 
> > reload_completed)
> > +   && (INTVAL (operands[3]) >> INTVAL (operands[2])) == 0x"
> So this is a nasty little problem and touches on a deeper issue.
>
> The core problem is that combine doesn't know anything about
> constraints.  It works with predicates and conditions.So combine has
> no idea if it's creating an ASM with operands that can't be handled.  As
> a result combine has to be careful with ASMs.
>
> In can_combine_p we have:
>
>
> >  /* Can't merge an ASM_OPERANDS.  */
> >   || GET_CODE (src) == ASM_OPERANDS
>
> Which is part of a large conditional indicating when we can't combine
> two insns together.  So I would have expected it to reject this insn for
> combining:
>
> > (insn 12 11 0 2 (set (mem/f:DI (reg/v/f:DI 138 [ e ]) [2 *e_6+0 S8 A64])
> > (asm_operands:DI ("") ("=A") 0 [
> > (mem/f:DI (reg/v/f:DI 138 [ e ]) [2 *e_6+0 S8 A64])
> > ]
> >  [
> > (asm_input:DI ("A") j.c:8)
> > ]
> >  [] j.c:8)) "j.c":8:3 -1
> >  (expr_list:REG_DEAD (reg/v/f:DI 138 [ e ])
> > (nil)))
>
> So the natural question is why did insn 12 participate in combination at
> all:
>
> > Trying 11 -> 12:
> >11: r138:DI=r145:DI+r144:DI
> >   REG_DEAD r145:DI
> >   REG_DEAD r144:DI
> >12: [r138:DI]=asm_operands
> >   REG_DEAD r138:DI
> > Failed to match this instruction:
> > (set (mem/f:DI (plus:DI (reg/f:DI 145 [ b ])
> > (reg:DI 144 [ _4 ])) [2 *e_6+0 S8 A64])
> > (asm_operands:DI ("") ("=A") 0 [
> > (mem/f:DI (plus:DI (reg/f:DI 145 [ b ])
> > (reg:DI 144 [ _4 ])) [2 *e_6+0 S8 A64])
> > ]
> >  [
> > (asm_input:DI ("A") j.c:8)
> > ]
> >  [] j.c:8))
> > allowing combination of insns 11 and 12
> > original costs 4 + 36 = 40
> > replacement cost 36
> > deferring deletion of insn with uid = 11.
> > modifying insn i312: [r145:DI+r144:DI]=asm_operands
> >   REG_DEAD r144:DI
> >   REG_DEAD r145:DI
> > deferring rescan insn with uid = 12.
>
> So without a deep dive, my question is should this have been rejected
> for combination before we even got here?  I just don't see how combine
> can do anything with asms other than replacing one pseudo with another
> since combine doesn't have any notion of constraints.
>
> Segher, comments?
>
> jeff
>
>


[COMMITTED 040/146] gccrs: Add optional template arguments to please GCC4.8

2025-04-05 Thread arthur . cohen
From: Pierre-Emmanuel Patry 

Clang on macos as well as GCC 4.8 complains when those templates are
missing.

gcc/rust/ChangeLog:

* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Add template
to tl::optional.
* hir/rust-ast-lower-type.cc (ASTLowerGenericParam::visit): Likewise.
* typecheck/rust-hir-type-check-type.cc 
(TypeResolveGenericParam::visit):
Likewise.

Signed-off-by: Pierre-Emmanuel Patry 
---
 gcc/rust/hir/rust-ast-lower-expr.cc| 5 +++--
 gcc/rust/hir/rust-ast-lower-type.cc| 8 +---
 gcc/rust/typecheck/rust-hir-type-check-type.cc | 4 +++-
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/gcc/rust/hir/rust-ast-lower-expr.cc 
b/gcc/rust/hir/rust-ast-lower-expr.cc
index 2954a31d9f4..b45b5f925df 100644
--- a/gcc/rust/hir/rust-ast-lower-expr.cc
+++ b/gcc/rust/hir/rust-ast-lower-expr.cc
@@ -517,8 +517,9 @@ ASTLoweringExpr::visit (AST::StructExprStructFields 
&struct_expr)
 {
   HIR::Expr *translated_base = ASTLoweringExpr::translate (
struct_expr.get_struct_base ().get_base_struct ());
-  base = tl::optional (Rust::make_unique (
-   std::unique_ptr (translated_base)));
+  base = tl::optional> (
+   Rust::make_unique (
+ std::unique_ptr (translated_base)));
 }
 
   auto const &in_fields = struct_expr.get_fields ();
diff --git a/gcc/rust/hir/rust-ast-lower-type.cc 
b/gcc/rust/hir/rust-ast-lower-type.cc
index 5836c1ac148..58c93b9e25d 100644
--- a/gcc/rust/hir/rust-ast-lower-type.cc
+++ b/gcc/rust/hir/rust-ast-lower-type.cc
@@ -503,9 +503,11 @@ ASTLowerGenericParam::visit (AST::TypeParam ¶m)
}
 }
 
-  auto type = param.has_type () ? tl::optional (std::unique_ptr (
-   ASTLoweringType::translate (param.get_type (
-   : tl::nullopt;
+  tl::optional> type = tl::nullopt;
+  if (param.has_type ())
+type
+  = tl::optional> (std::unique_ptr (
+   ASTLoweringType::translate (param.get_type (;
 
   auto crate_num = mappings.get_current_crate ();
   Analysis::NodeMapping mapping (crate_num, param.get_node_id (),
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc 
b/gcc/rust/typecheck/rust-hir-type-check-type.cc
index 089a5af121a..6e859e5d719 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc
@@ -829,7 +829,9 @@ TypeResolveGenericParam::visit (HIR::TypeParam ¶m)
HIR::TraitBound &b = static_cast (*bound);
 
TyTy::TypeBoundPredicate predicate = get_predicate_from_bound (
- b.get_path (), tl::optional (std::ref (*implicit_self_bound)),
+ b.get_path (),
+ tl::optional> (
+   std::ref (*implicit_self_bound)),
  b.get_polarity ());
if (!predicate.is_error ())
  {
-- 
2.45.2



Re: [PATCH] APX: add nf counterparts for rotl split pattern [PR 119539]

2025-04-05 Thread Hongyu Wang
> Can we just change the output in original pattern, I think combine
> will still match the pattern even w/ clobber flags.

Yes, adjusted and updated the patch in attachment.

Liu, Hongtao  于2025年4月2日周三 08:57写道:
>
>
>
> > -Original Message-
> > From: Uros Bizjak 
> > Sent: Tuesday, April 1, 2025 5:24 PM
> > To: Hongtao Liu 
> > Cc: Wang, Hongyu ; gcc-patches@gcc.gnu.org; Liu,
> > Hongtao 
> > Subject: Re: [PATCH] APX: add nf counterparts for rotl split pattern [PR
> > 119539]
> >
> > On Tue, Apr 1, 2025 at 10:55 AM Hongtao Liu  wrote:
> > >
> > > On Tue, Apr 1, 2025 at 4:40 PM Hongyu Wang 
> > wrote:
> > > >
> > > > Hi,
> > > >
> > > > For spiltter after 3_mask it now splits the
> > > > pattern to *3_mask, causing the splitter doesn't
> > > > generate nf variant. Add corresponding nf counterpart for
> > > > define_insn_and_split to make the splitter also works for nf insn.
> > > >
> > > > Bootstrapped & regtested on x86-64-pc-linux-gnu.
> > > >
> > > > Ok for trunk?
> > > >
> > > > gcc/ChangeLog:
> > > >
> > > > PR target/119539
> > > > * config/i386/i386.md (*3_mask_nf): New
> > > > define_insn_and_split.
> > > > (*3_mask_1_nf): Likewise.
> > > > (*3_mask): Use force_lowpart_subreg.
> > > >
> > > > gcc/testsuite/ChangeLog:
> > > >
> > > > PR target/119539
> > > > * gcc.target/i386/apx-nf-pr119539.c: New test.
> > > > ---
> > > >  gcc/config/i386/i386.md   | 46 ++-
> > > >  .../gcc.target/i386/apx-nf-pr119539.c |  6 +++
> > > >  2 files changed, 50 insertions(+), 2 deletions(-)  create mode
> > > > 100644 gcc/testsuite/gcc.target/i386/apx-nf-pr119539.c
> > > >
> > > > diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index
> > > > f7f790d2aeb..42312f0c330 100644
> > > > --- a/gcc/config/i386/i386.md
> > > > +++ b/gcc/config/i386/i386.md
> > > > @@ -18131,6 +18131,30 @@ (define_expand "3"
> > > >DONE;
> > > >  })
> > > >
> > > > +;; Avoid useless masking of count operand.
> > > > +(define_insn_and_split "*3_mask_nf"
> > > > +  [(set (match_operand:SWI 0 "nonimmediate_operand")
> > > > +   (any_rotate:SWI
> > > > + (match_operand:SWI 1 "nonimmediate_operand")
> > > > + (subreg:QI
> > > > +   (and
> > > > + (match_operand 2 "int248_register_operand" "c")
> > > > + (match_operand 3 "const_int_operand")) 0)))]
> > > > +  "TARGET_APX_NF
> > > > +   && ix86_binary_operator_ok (, mode, operands)
> > > > +   && (INTVAL (operands[3]) & (GET_MODE_BITSIZE (mode)-1))
> > > > +  == GET_MODE_BITSIZE (mode)-1
> > > > +   && ix86_pre_reload_split ()"
> > > > +  "#"
> > > > +  "&& 1"
> > > > +  [(set (match_dup 0)
> > > > +   (any_rotate:SWI (match_dup 1)
> > > > +   (match_dup 2)))] {
> > > > +  operands[2] = force_lowpart_subreg (QImode, operands[2],
> > > > + GET_MODE (operands[2]));
> > > > +})
> > > Can we just change the output in original pattern, I think combine
> > > will still match the pattern even w/ clobber flags.
> > >
> > > like
> > >
> > > @@ -17851,8 +17851,17 @@ (define_insn_and_split
> > "*3_mask"
> > > (match_dup 2)))
> > >(clobber (reg:CC FLAGS_REG))])]  {
> > > -  operands[2] = force_reg (GET_MODE (operands[2]), operands[2]);
> > > -  operands[2] = gen_lowpart (QImode, operands[2]);
> > > +  if (TARGET_APX_F)
> > > +{
> > > +  emit_move_insn (operands[0],
> > > +gen_rtx_ (mode, operands[1], 
> > > operands[2]));
> > > +  DONE;
> > > +}
> > > +  else
> > > +{
> > > +  operands[2] = force_reg (GET_MODE (operands[2]), operands[2]);
> > > +  operands[2] = gen_lowpart (QImode, operands[2]);
> >
> > Please note we have a new "force_lowpart_subreg" function that operates on
> > a register operand and (if possible) simplifies a subreg of a subreg, 
> > otherwise it
> > forces the operand to register and creates a subreg of the temporary. 
> > Similar
> > to the above combination, with a possibility to avoid a temporary reg.
> >
> > > Also we can remove constraint "c" in the original pattern.
> >
> > The constraint is here to handle corner case, where combine propagated an
> > insn RTX with fixed register, other than %ecx, into shift RTX.
> > Register allocator was not able to fix the combination, so
> > TARGET_LEGITIMATE_COMBINED_INSN hook was introduced that rejected
> > unwanted combinations. Please see the comment in
> > ix86_legitimate_combined_insn function.
> Oh, thanks for the explanation.
> >
> > Perhaps the above is not relevant anymore with the new register allocator
> > (LRA), and the constraint can indeed be removed. But please take some
> > caution.
> >
> > Uros.
From 5b84547eca93ae32b92c3787521f96a3568aeefb Mon Sep 17 00:00:00 2001
From: Hongyu Wang 
Date: Mon, 31 Mar 2025 16:39:23 +0800
Subject: [PATCH] APX: Emit nf variant for rotl splitter with mask [PR 119539]

For spiltter

Re: [PATCH] inline: Add a call to unreachable to the return block for noreturn calls [PR119599]

2025-04-05 Thread Andrew Pinski
On Thu, Apr 3, 2025 at 12:14 AM Richard Biener
 wrote:
>
> On Thu, Apr 3, 2025 at 9:04 AM Andrew Pinski  wrote:
> >
> > On Wed, Apr 2, 2025 at 11:52 PM Richard Biener
> >  wrote:
> > >
> > > On Thu, Apr 3, 2025 at 7:10 AM Andrew Pinski  
> > > wrote:
> > > >
> > > > builtin_unreachable_bb_p exacts empty basic blocks to have only one 
> > > > successor edge but
> > > > in the case after inliing a noreturn function that actually returns, we 
> > > > end up with an
> > > > empty basic block with no successor edge. fixup_cfg fixes this up by 
> > > > placing a call to
> > > > __builtin_unreachable but we don't do that before getting the function 
> > > > summary
> > > > (after einiline). So the fix is to have the inliner insert the call
> > > > to __builtin_unreachable (or the trap version) and not depend on the 
> > > > fixup if the return
> > > > block is reachable after inlining a noreturn function.
> > > >
> > > > A small optimization is done not to insert the call if the block is NOT 
> > > > simplely reachable.
> > > > This should prevent inserting the call just to remove it during 
> > > > cleanupcfg.
> > > >
> > > > Note this shows up only at -O0 with always_inline because when 
> > > > optimizations are turned on
> > > > returns are turned into __builtin_unreachable inside noreturn functions.
> > >
> > > Where's that done?  IMO we should do this at -O0 as well (possibly 
> > > defaulting to
> > > use the trapping variant there).
> >
> > It is done inside pass_warn_function_return::execute and that was
> > added by r8-3988-g356fcc67fba52b .
> > Since it already uses gimple_build_builtin_unreachable,
> > BUILT_IN_UNREACHABLE_TRAP is already used when flag_unreachable_traps
> > is on (which defaults being on for -O0 and -gg).
> > So should we just change that to be always on instead of being blocked
> > for !optimized?
>
> Yes, I think so.

Ok testing that patch and will post an update soon.

Thanks,
Andrew

>
> Richard.
>
> >
> > Thanks,
> > Andrew Pinski
> >
> > >
> > > >
> > > > Bootstrapped and tested on x86_64-linux-gnu.
> > > >
> > > > PR ipa/119599
> > > >
> > > > gcc/ChangeLog:
> > > >
> > > > * tree-inline.cc (expand_call_inline): Add a 
> > > > __builtin_unreachable call
> > > > to the return block if it is still reachable and the call that 
> > > > was inlined
> > > > was a noreturn function.
> > > >
> > > > gcc/testsuite/ChangeLog:
> > > >
> > > > * gcc.dg/torture/pr119599-1.c: New test.
> > > >
> > > > Signed-off-by: Andrew Pinski 
> > > > ---
> > > >  gcc/testsuite/gcc.dg/torture/pr119599-1.c | 27 +++
> > > >  gcc/tree-inline.cc| 15 +
> > > >  2 files changed, 42 insertions(+)
> > > >  create mode 100644 gcc/testsuite/gcc.dg/torture/pr119599-1.c
> > > >
> > > > 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 000..4fbd228a359
> > > > --- /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-inline.cc b/gcc/tree-inline.cc
> > > > index 05843b8ccf0..da403cd1456 100644
> > > > --- a/gcc/tree-inline.cc
> > > > +++ b/gcc/tree-inline.cc
> > > > @@ -4832,6 +4832,7 @@ expand_call_inline (basic_block bb, gimple *stmt, 
> > > > copy_body_data *id,
> > > >gimple *simtenter_stmt = NULL;
> > > >vec *simtvars_save;
> > > >tree save_stack = NULL_TREE;
> > > > +  bool was_noreturn;
> > > >
> > > >/* The gimplifier uses input_location in too many places, such as
> > > >   internal_get_tmp_var ().  */
> > > > @@ -4843,6 +4844,8 @@ expand_call_inline (basic_block bb, gimple *stmt, 
> > > > copy_body_data *id,
> > > >if (!call_stmt)
> > > >  goto egress;
> > > >
> > > > +  was_noreturn = gimple_call_noreturn_p (call_stmt);
> > > > +
> > > >cg_edge = id->dst_node->get_edge (stmt);
> > > >gcc_checking_assert (cg_edge);
> > > >/* First, see if we can figure out what function is being called.
> > > > @@ -5376,6 +5379,18 @@ expand_call_inlin

[PATCH] libstdc++: Add P1206R7 range operations to std::deque [PR111055]

2025-04-05 Thread Tomasz Kamiński
This is another piece of P1206R7, adding from_range constructor, append_range,
prepend_range, insert_range, and assign_range members to std::deque.

For insert_range, the handling of insertion in the middle of input-only ranges
that are sized could be optimized, we still insert nodes one-by-one in such 
case.
For forward and stronger ranges, we reduce them to common_range case,
by computing the iterator when computing the distance.
This is slightly suboptimal, as it require range to be iterated for non-common
forward ranges that are sized.

This patch extract a set of  helper functions that accepts (iterator, sentinel) 
pair:
_M_range_prepend, _M_range_append, _M_range_empl.
To make them usable in all standard modes, _M_emplace_aux is defined for c++98
as accepting const value_type&, and _M_insert_aux forwards to it.

PR libstdc++/111055

libstdc++-v3/ChangeLog:

* include/bits/deque.tcc (deque::insert_range, 
__detail::__advance_dist):
Define.
(deque::_M_range_prepend, deque::_M_range_append):
Extract from _M_range_insert_aux for _ForwardIterator(s).
(deque::_M_range_empl): Define.
(deque::_M_emplace_aux(iterator, const value_type&)): Renamed 
_M_insert_aux
in c++98.
* include/bits/stl_deque.h (deque::prepend_range, deque::append_range),
(deque::assing_range):Define.
deque(from_range_t, _Rg&&, const allocator_type&): Define constructor
and deduction guide.
* include/debug/deque (prepend_range, append_range, assing_range):
Define.
deque(from_range_t, _Rg&&, const allocator_type&): Define constructor
and deduction guide.
(deque::_M_insert_qux): Define using _M_emplace_aux also for c++98.
(deque::_M_range_insert(iterator, _InputIterator, _InputIterator,
std::input_iterator_tag)): Forward to _M_range_empl.
* testsuite/23_containers/deque/cons/from_range.cc: New test.
* testsuite/23_containers/deque/modifiers/append_range.cc: New test.
* testsuite/23_containers/deque/modifiers/assign/assign_range.cc: New 
test.
* testsuite/23_containers/deque/modifiers/prepend_range.cc: New test.
---
 Testing on x86_64-linux. Tests in 23_containers passed with each of:
 -std=c++98, GLIBCXX_DEBUG and no-PCH.
 OK for trunk?

 In the __advance_dist I branch between __it += __n and ranges::advance(__it, 
ranges::end(__rg)),
 instead of just calling ranges::advance(__it, __n), as the former will handle 
nearly
 common ranges, like `int const*` and `int*`.

 libstdc++-v3/include/bits/deque.tcc   | 170 ++
 libstdc++-v3/include/bits/stl_deque.h | 148 ++-
 libstdc++-v3/include/debug/deque  |  52 ++
 .../23_containers/deque/cons/from_range.cc|  99 ++
 .../deque/modifiers/append_range.cc   |  88 +
 .../deque/modifiers/assign/assign_range.cc| 109 +++
 .../deque/modifiers/insert/insert_range.cc| 116 
 .../deque/modifiers/prepend_range.cc  |  90 ++
 8 files changed, 829 insertions(+), 43 deletions(-)
 create mode 100644 
libstdc++-v3/testsuite/23_containers/deque/cons/from_range.cc
 create mode 100644 
libstdc++-v3/testsuite/23_containers/deque/modifiers/append_range.cc
 create mode 100644 
libstdc++-v3/testsuite/23_containers/deque/modifiers/assign/assign_range.cc
 create mode 100644 
libstdc++-v3/testsuite/23_containers/deque/modifiers/insert/insert_range.cc
 create mode 100644 
libstdc++-v3/testsuite/23_containers/deque/modifiers/prepend_range.cc

diff --git a/libstdc++-v3/include/bits/deque.tcc 
b/libstdc++-v3/include/bits/deque.tcc
index fcbecca55b4..8444d810e03 100644
--- a/libstdc++-v3/include/bits/deque.tcc
+++ b/libstdc++-v3/include/bits/deque.tcc
@@ -584,13 +584,72 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 }
 
   template 
-template 
+template 
   void
   deque<_Tp, _Alloc>::
-  _M_range_insert_aux(iterator __pos,
- _InputIterator __first, _InputIterator __last,
- std::input_iterator_tag)
-  { std::copy(__first, __last, std::inserter(*this, __pos)); }
+  _M_range_prepend(_InputIterator __first, _Sentinel __last,
+ size_type __n)
+  {
+iterator __new_start = _M_reserve_elements_at_front(__n);
+__try
+  {
+std::__uninitialized_copy_a(_GLIBCXX_MOVE(__first), __last,
+__new_start, _M_get_Tp_allocator());
+this->_M_impl._M_start = __new_start;
+  }
+__catch(...)
+  {
+_M_destroy_nodes(__new_start._M_node,
+ this->_M_impl._M_start._M_node);
+__throw_exception_again;
+  }
+  }
+
+  template 
+template 
+  void
+  deque<_Tp, _Alloc>::
+  _M_range_append(_InputIterator __first, _Sentinel __last,
+ size_type __n)
+ {
+ 

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

2025-04-05 Thread Jonathan Wakely
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.

(cherry picked from commit 878812b6f6905774ab37cb78903e3e11bf1c508c)
---

Tested x86_64-linux.

This warning is a regression on 12/13/14 so this is needed on all
release branches.

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

diff --git a/libstdc++-v3/include/bits/vector.tcc 
b/libstdc++-v3/include/bits/vector.tcc
index 0458d560075..b7f472ae09c 100644
--- a/libstdc++-v3/include/bits/vector.tcc
+++ b/libstdc++-v3/include/bits/vector.tcc
@@ -1002,6 +1002,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 000..e6027a677ee
--- /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());
+  }
+}
-- 
2.49.0



Re: [committed] testsuite: Fix up atomic-inst-ldlogic.c

2025-04-05 Thread Sam James
Jakub Jelinek  writes:

> Hi!
>
> r15-8956 changed in the test:
> -/* { dg-final { scan-assembler-times "ldclr\t" 16} */
> +/* { dg-final { scan-assembler-times "ldclr\t" 16 } */
> which made it even worse than before, when the directive has
> been silently ignored because it didn't match the regex for
> directives.  Now it matches it but is unbalanced.
> So now I'm getting
> ERROR: tcl error sourcing 
> /builddir/build/BUILD/gcc-15.0.1-build/gcc-15.0.1-20250329/gcc/testsuite/gcc.target/aarch64/aarch64.exp.
> ERROR: tcl error code NONE
> ERROR: unmatched open brace in list
> while executing
> "foreach op $tmp {
> verbose "Processing option: $op" 3
> set status [catch $op errmsg]
> if { $status != 0 } {
> if { 0 && [info exists errorInfo] } {..."
> (procedure "saved-dg-test" line 76)
> invoked from within
> "saved-dg-test 
> /builddir/build/BUILD/gcc-15.0.1-build/gcc-15.0.1-20250329/gcc/testsuite/gcc.target/aarch64/atomic-inst-ldlogic.c
>  {} { -ansi -pedantic-e..."
> ("eval" body line 1)
> invoked from within
> etc.
>
> The following patch fixes it and adds space after all the
> other scan-assembler-times counts in the file.
>
> Tested on x86_64-linux -> aarch64-linux cross, committed to
> trunk as obvious.

Thank you! I'm sorry, I thought I'd caught that one. I'll take extra
care with the next round (which won't be until after release now).


RE: [PATCH] fold-const, cobol: Add native_encode_wide_int and use it in COBOL FE [PR119242]

2025-04-05 Thread Robert Dubner



> -Original Message-
> From: Jakub Jelinek 
> Sent: Wednesday, April 2, 2025 12:36
> To: Richard Biener ; Robert Dubner
;
> James K. Lowden ; Richard Sandiford
> 
> Cc: gcc-patches@gcc.gnu.org
> Subject: [PATCH] fold-const, cobol: Add native_encode_wide_int and use
it
> in COBOL FE [PR119242]
> 
> Hi!
> 
> As has been mentioned earlier, various parts of the COBOL FE and the
> library
> aren't endian clean.  In the library that means that for now we have to
> live with no support for big endian targets, but in the FE that means
> that as well as not being able to build cross-compilers from big endian
> or pdp endian hosts to little endian targets which are otherwise
> supported.
> 
> The following patch attempts to fix one such spot, where it wants to
> encode
> in target byte ordering wide_int constants into 1, 2, 4, 8 or 16 bytes.
> 
> We could wide_int_to_tree and then native_encode_expr, but so that we
> don't
> need to build the constants, the following patch exports from fold-
> const.cc
> a variant to native_encode_int which takes type and wide_int reference
> rather than an expression.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

I patched this into the cobolworx environment, and ran my full suite of
tests.

Everything passed.  LGTM

> 
> 2025-04-02  Jakub Jelinek  
> 
>   PR cobol/119242
>   * fold-const.h (native_encode_wide_int): Declare.
>   * fold-const.cc (native_encode_wide_int_1): New function template.
>   (native_encode_wide_int): New function.
>   (native_encode_int): Use native_encode_wide_int_1.
> 
>   * cobol/genapi.cc (binary_initial_from_float128): Use
>   native_encode_wide_int.
> 
> --- gcc/fold-const.h.jj   2025-03-28 10:38:23.165538304 +0100
> +++ gcc/fold-const.h  2025-04-02 14:31:22.921136606 +0200
> @@ -35,6 +35,8 @@ extern bool folding_cxx_constexpr;
>  extern int native_encode_expr (const_tree, unsigned char *, int, int
off
> = -1);
>  extern int native_encode_initializer (tree, unsigned char *, int,
> int off = -1, unsigned char * =
nullptr);
> +extern int native_encode_wide_int (tree, const wide_int_ref &,
> +unsigned char *, int, int off = -1);
>  extern int native_encode_real (scalar_float_mode, const REAL_VALUE_TYPE
> *,
>  unsigned char *, int, int off = -1);
>  extern tree native_interpret_expr (tree, const unsigned char *, int);
> --- gcc/fold-const.cc.jj  2025-03-28 10:38:23.148538537 +0100
> +++ gcc/fold-const.cc 2025-04-02 14:30:15.072074312 +0200
> @@ -7465,15 +7465,17 @@ fold_plusminus_mult_expr (location_t loc
>return NULL_TREE;
>  }
> 
> -/* Subroutine of native_encode_expr.  Encode the INTEGER_CST
> -   specified by EXPR into the buffer PTR of length LEN bytes.
> +
> +/* Subroutine of native_encode_int and native_encode_wide_int.  Encode
> the
> +   integer VAL with type TYPE into the buffer PTR of length LEN bytes.
> Return the number of bytes placed in the buffer, or zero
> upon failure.  */
> 
> +template 
>  static int
> -native_encode_int (const_tree expr, unsigned char *ptr, int len, int
off)
> +native_encode_wide_int_1 (tree type, const T &val,
> +   unsigned char *ptr, int len, int off)
>  {
> -  tree type = TREE_TYPE (expr);
>int total_bytes;
>if (TREE_CODE (type) == BITINT_TYPE)
>  {
> @@ -7516,7 +7518,7 @@ native_encode_int (const_tree expr, unsi
>int bitpos = byte * BITS_PER_UNIT;
>/* Extend EXPR according to TYPE_SIGN if the precision isn't a
> whole
>number of bytes.  */
> -  value = wi::extract_uhwi (wi::to_widest (expr), bitpos,
> BITS_PER_UNIT);
> +  value = wi::extract_uhwi (val, bitpos, BITS_PER_UNIT);
> 
>if (total_bytes > UNITS_PER_WORD)
>   {
> @@ -7537,6 +7539,31 @@ native_encode_int (const_tree expr, unsi
>return MIN (len, total_bytes - off);
>  }
> 
> +/* Encode the integer VAL with type TYPE into the buffer PTR of length
> LEN
> +   bytes.
> +   Return the number of bytes placed in the buffer, or zero
> +   upon failure.  */
> +
> +int
> +native_encode_wide_int (tree type, const wide_int_ref &val,
> + unsigned char *ptr, int len, int off)
> +{
> +  return native_encode_wide_int_1 (type, val, ptr, len, off);
> +}
> +
> +
> +/* Subroutine of native_encode_expr.  Encode the INTEGER_CST
> +   specified by EXPR into the buffer PTR of length LEN bytes.
> +   Return the number of bytes placed in the buffer, or zero
> +   upon failure.  */
> +
> +static int
> +native_encode_int (const_tree expr, unsigned char *ptr, int len, int
off)
> +{
> +  return native_encode_wide_int_1 (TREE_TYPE (expr), wi::to_widest
> (expr),
> +ptr, len, off);
> +}
> +
> 
>  /* Subroutine of native_encode_expr.  Encode the FIXED_CST
> specified by EXPR into the buffer PTR of length LEN bytes.
> --- gcc/cobol/genapi.cc.jj2025-04-02 10:36:25.51757464

[COMMITTED 141/146] gccrs: derive(Clone): Add deriving of simple enum variants

2025-04-05 Thread arthur . cohen
From: Arthur Cohen 

gcc/rust/ChangeLog:

* expand/rust-derive-clone.cc: Clone enum identifier variants properly
* expand/rust-derive-clone.h: Declare new functions used.
---
 gcc/rust/expand/rust-derive-clone.cc | 52 ++--
 gcc/rust/expand/rust-derive-clone.h  |  3 ++
 2 files changed, 53 insertions(+), 2 deletions(-)

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



[COMMITTED 036/146] gccrs: Fix Generic type retrieval

2025-04-05 Thread arthur . cohen
From: Pierre-Emmanuel Patry 

gcc/rust/ChangeLog:

* hir/rust-ast-lower-type.cc (ASTLowerGenericParam::visit): Forward
an optional to the constructor.
* hir/tree/rust-hir-item.cc (TypeParam::TypeParam): Use an optional
in the constructor.
(TypeParam::operator=): Ensure the TypeParam has a type properly.
(TypeParam::get_type_mappings): Likewise.
* hir/tree/rust-hir-item.h: Wrap the type smart pointer into an
optional.
* hir/tree/rust-hir.cc (TypeParam::as_string): Unwrap optional type
correctly.

Signed-off-by: Pierre-Emmanuel Patry 
---
 gcc/rust/hir/rust-ast-lower-type.cc | 10 +-
 gcc/rust/hir/tree/rust-hir-item.cc  | 19 +++
 gcc/rust/hir/tree/rust-hir-item.h   | 14 --
 gcc/rust/hir/tree/rust-hir.cc   |  2 +-
 4 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/gcc/rust/hir/rust-ast-lower-type.cc 
b/gcc/rust/hir/rust-ast-lower-type.cc
index 7d6ac5ddffa..5836c1ac148 100644
--- a/gcc/rust/hir/rust-ast-lower-type.cc
+++ b/gcc/rust/hir/rust-ast-lower-type.cc
@@ -17,6 +17,7 @@
 // .
 
 #include "rust-ast-lower-type.h"
+#include "optional.h"
 #include "rust-attribute-values.h"
 
 namespace Rust {
@@ -502,9 +503,9 @@ ASTLowerGenericParam::visit (AST::TypeParam ¶m)
}
 }
 
-  HIR::Type *type = param.has_type ()
- ? ASTLoweringType::translate (param.get_type ())
- : nullptr;
+  auto type = param.has_type () ? tl::optional (std::unique_ptr (
+   ASTLoweringType::translate (param.get_type (
+   : tl::nullopt;
 
   auto crate_num = mappings.get_current_crate ();
   Analysis::NodeMapping mapping (crate_num, param.get_node_id (),
@@ -514,8 +515,7 @@ ASTLowerGenericParam::visit (AST::TypeParam ¶m)
   translated
 = new HIR::TypeParam (mapping, param.get_type_representation (),
  param.get_locus (), std::move (type_param_bounds),
- std::unique_ptr (type),
- param.get_outer_attrs ());
+ std::move (type), param.get_outer_attrs ());
 }
 
 HIR::TypeParamBound *
diff --git a/gcc/rust/hir/tree/rust-hir-item.cc 
b/gcc/rust/hir/tree/rust-hir-item.cc
index f81f1eae134..cff06d35269 100644
--- a/gcc/rust/hir/tree/rust-hir-item.cc
+++ b/gcc/rust/hir/tree/rust-hir-item.cc
@@ -17,6 +17,7 @@
 // .
 
 #include "rust-hir-item.h"
+#include "optional.h"
 
 namespace Rust {
 namespace HIR {
@@ -25,7 +26,7 @@ TypeParam::TypeParam (
   Analysis::NodeMapping mappings, Identifier type_representation,
   location_t locus,
   std::vector> type_param_bounds,
-  std::unique_ptr, AST::AttrVec outer_attrs)
+  tl::optional> type, AST::AttrVec outer_attrs)
   : GenericParam (mappings), outer_attrs (std::move (outer_attrs)),
 type_representation (std::move (type_representation)),
 type_param_bounds (std::move (type_param_bounds)), type (std::move (type)),
@@ -37,8 +38,10 @@ TypeParam::TypeParam (TypeParam const &other)
 type_representation (other.type_representation), locus (other.locus)
 {
   // guard to prevent null pointer dereference
-  if (other.type != nullptr)
-type = other.type->clone_type ();
+  if (other.has_type ())
+type = {other.type.value ()->clone_type ()};
+  else
+type = tl::nullopt;
 
   type_param_bounds.reserve (other.type_param_bounds.size ());
   for (const auto &e : other.type_param_bounds)
@@ -54,10 +57,10 @@ TypeParam::operator= (TypeParam const &other)
   mappings = other.mappings;
 
   // guard to prevent null pointer dereference
-  if (other.type != nullptr)
-type = other.type->clone_type ();
+  if (other.has_type ())
+type = {other.type.value ()->clone_type ()};
   else
-type = nullptr;
+type = tl::nullopt;
 
   type_param_bounds.reserve (other.type_param_bounds.size ());
   for (const auto &e : other.type_param_bounds)
@@ -69,8 +72,8 @@ TypeParam::operator= (TypeParam const &other)
 Analysis::NodeMapping
 TypeParam::get_type_mappings () const
 {
-  rust_assert (type != nullptr);
-  return type->get_mappings ();
+  rust_assert (type.has_value ());
+  return type.value ()->get_mappings ();
 }
 
 std::vector> &
diff --git a/gcc/rust/hir/tree/rust-hir-item.h 
b/gcc/rust/hir/tree/rust-hir-item.h
index bb300e9ed23..0fda1672b74 100644
--- a/gcc/rust/hir/tree/rust-hir-item.h
+++ b/gcc/rust/hir/tree/rust-hir-item.h
@@ -19,6 +19,7 @@
 #ifndef RUST_HIR_ITEM_H
 #define RUST_HIR_ITEM_H
 
+#include "optional.h"
 #include "rust-abi.h"
 #include "rust-hir-stmt.h"
 #include "rust-common.h"
@@ -102,14 +103,13 @@ class TypeParam : public GenericParam
   std::vector>
 type_param_bounds; // inlined form
 
-  // bool has_type;
-  std::unique_ptr type;
+  tl::optional> type;
 
   location_t locus;
 
 public:
   // Returns whether the type of the type param has been specified.
-  bool has_type () const { return type != nullp

[COMMITTED 119/144] gccrs: Postpone break on error after name resolution

2025-04-05 Thread arthur . cohen
From: Pierre-Emmanuel Patry 

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

gcc/rust/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry 
---
 gcc/rust/rust-session-manager.cc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

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



Re: [PATCH 3/4] combine: Optimise distribute_links search [PR116398]

2025-04-05 Thread Jeff Law




On 4/4/25 3:22 AM, Richard Sandiford wrote:

Another problem in PR101523 was that, after each successful 2->2
combination attempt, distribute_links would search further and further
for the next combinable use of the i2 destination.  Each search would
start at i2 itself, making the search quadratic in the worst case.

In a 2->2 combination, if i2 is unchanged, the search can start at i3
instead of i2.  The same thing applies to i2 when distributing i2's
links, since the only changes to earlier instructions are the deletion
of i0 and i1.

This change, combined with the previous split_i2i3 patch, gives a
34.6% speedup in combine for the testcase in PR101523.  Combine
goes from being 41% to 34% of compile time.

gcc/
PR testsuite/116398
* combine.cc (distribute_links): Take an optional start point.
(try_combine): If only i3 has changed, only distribute i3's links,
not i2's.  Start the search for the new use from i3 rather than
from the definition instruction.  Likewise start the search for
the new use from i2 when distributing i2's links.

OK
jeff



[COMMITTED 25/35] gccrs: Fix ICE when compiling path which resolves to trait constant

2025-04-05 Thread arthur . cohen
From: Philip Herron 

Fixes Rust-GCC#3552

gcc/rust/ChangeLog:

* backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): 
check for Expr trait
* hir/rust-hir-dump.cc (Dump::visit): expr is optional

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron 
---
 gcc/rust/backend/rust-compile-resolve-path.cc | 21 +++
 gcc/rust/hir/rust-hir-dump.cc |  4 +++-
 gcc/testsuite/rust/compile/issue-3552.rs  | 14 +
 3 files changed, 38 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/rust/compile/issue-3552.rs

diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc 
b/gcc/rust/backend/rust-compile-resolve-path.cc
index 2b6880c9b1a..115dd046465 100644
--- a/gcc/rust/backend/rust-compile-resolve-path.cc
+++ b/gcc/rust/backend/rust-compile-resolve-path.cc
@@ -301,6 +301,27 @@ HIRCompileBase::query_compile (HirId ref, TyTy::BaseType 
*lookup,
trait->get_mappings ().get_defid (), &trait_ref);
  rust_assert (ok);
 
+ if (trait_item.value ()->get_item_kind ()
+ == HIR::TraitItem::TraitItemKind::CONST)
+   {
+ auto &c
+   = *static_cast (trait_item.value ());
+ if (!c.has_expr ())
+   {
+ rich_location r (line_table, expr_locus);
+ r.add_range (trait->get_locus ());
+ r.add_range (c.get_locus ());
+ rust_error_at (r, "no default expression on trait constant");
+ return error_mark_node;
+   }
+
+ return CompileExpr::Compile (c.get_expr (), ctx);
+   }
+
+ if (trait_item.value ()->get_item_kind ()
+ != HIR::TraitItem::TraitItemKind::FUNC)
+   return error_mark_node;
+
  // the type resolver can only resolve type bounds to their trait
  // item so its up to us to figure out if this path should resolve
  // to an trait-impl-block-item or if it can be defaulted to the
diff --git a/gcc/rust/hir/rust-hir-dump.cc b/gcc/rust/hir/rust-hir-dump.cc
index d4958410013..0a9d617a919 100644
--- a/gcc/rust/hir/rust-hir-dump.cc
+++ b/gcc/rust/hir/rust-hir-dump.cc
@@ -1932,7 +1932,9 @@ Dump::visit (TraitItemConst &e)
 
   put_field ("name", e.get_name ().as_string ());
   visit_field ("type", e.get_type ());
-  visit_field ("expr", e.get_expr ());
+  if (e.has_expr ())
+visit_field ("expr", e.get_expr ());
+
   end ("TraitItemConst");
 }
 
diff --git a/gcc/testsuite/rust/compile/issue-3552.rs 
b/gcc/testsuite/rust/compile/issue-3552.rs
new file mode 100644
index 000..9a4451b14b8
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3552.rs
@@ -0,0 +1,14 @@
+trait Foo {
+const BAR: u32;
+}
+
+const TRAIT_REF_BAR: u32 = ::BAR;
+// { dg-error "no default expression on trait constant" "" { target *-*-* } 
.-1 }
+
+struct GlobalTraitRef;
+
+impl Foo for GlobalTraitRef {
+const BAR: u32 = TRAIT_REF_BAR;
+}
+
+fn main() {}
-- 
2.49.0



[committed] arm: add commutative alternatives to mull pattern.

2025-04-05 Thread Richard Earnshaw
Prior to Armv6, the SMULL and UMULL instructions, which have the form

 UMULL Rdlo, Rdhi, Rm, Rs

had an operand restriction such that Rdlo, Rdhi and Rm must all be
different registers.  Rs, however can overlap either of the
destination registers.  Add some register-tie alternatives to allow
the register allocator to find these forms without having to use
additional register moves.

In addition to this, the test is pretty meaningless on Thumb-1 targets
as the S/UMULL instructions do not exist in a 16-bit encoding.  So skip
the test in this case.

gcc/ChangeLog:

* config/arm/arm.md (mull): Add alternatives that allow Rs
to be tied to either Rdlo or Rdhi.

gcc/testsuite/ChangeLog:

* gcc.target/arm/pr42575.c: Skip test if thumb1.
---
 gcc/config/arm/arm.md  | 10 +-
 gcc/testsuite/gcc.target/arm/pr42575.c |  1 +
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/gcc/config/arm/arm.md b/gcc/config/arm/arm.md
index 442d86b9329..597ef6725bb 100644
--- a/gcc/config/arm/arm.md
+++ b/gcc/config/arm/arm.md
@@ -2432,11 +2432,11 @@ (define_expand "mulsidi3"
 )
 
 (define_insn "mull"
-  [(set (match_operand:SI 0 "s_register_operand" "=r,&r")
+  [(set (match_operand:SI 0 "s_register_operand" "=r,&r,&r,&r")
(mult:SI
-(match_operand:SI 2 "s_register_operand" "%r,r")
-(match_operand:SI 3 "s_register_operand" "r,r")))
-   (set (match_operand:SI 1 "s_register_operand" "=r,&r")
+(match_operand:SI 2 "s_register_operand" "%r,r,r,r")
+(match_operand:SI 3 "s_register_operand" "r,r,0,1")))
+   (set (match_operand:SI 1 "s_register_operand" "=r,&r,&r,&r")
(truncate:SI
 (lshiftrt:DI
  (mult:DI (SE:DI (match_dup 2)) (SE:DI (match_dup 3)))
@@ -2445,7 +2445,7 @@ (define_insn "mull"
   "mull%?\\t%0, %1, %2, %3"
   [(set_attr "type" "umull")
(set_attr "predicable" "yes")
-   (set_attr "arch" "v6,nov6")]
+   (set_attr "arch" "v6,nov6,nov6,nov6")]
 )
 
 (define_expand "maddsidi4"
diff --git a/gcc/testsuite/gcc.target/arm/pr42575.c 
b/gcc/testsuite/gcc.target/arm/pr42575.c
index 1998e323df1..3906c77ed56 100644
--- a/gcc/testsuite/gcc.target/arm/pr42575.c
+++ b/gcc/testsuite/gcc.target/arm/pr42575.c
@@ -1,4 +1,5 @@
 /* { dg-options "-O2" }  */
+/* { dg-skip-if "Thumb1 lacks UMULL" { arm_thumb1 } } */
 /* Make sure RA does good job allocating registers and avoids
unnecessary moves.  */
 /* { dg-final { scan-assembler-not "mov" } } */
-- 
2.34.1



[COMMITTED] Doc: #pragma pack documentation cleanup [PR114957] [PR78008] [PR60972]

2025-04-05 Thread Sandra Loosemore
This patch addresses a number of issues with the documentation of

- None of the things in this section had @cindex entries [PR114957].

- The document formatting didn't match that of other #pragma
documentation sections.

- The effect of #pragma pack(0) wasn't documented [PR78008].

- There's a long-standing bug [PR60972] reporting that #pragma pack
and the __attribute__(packed) don't get along well.  It seems worthwhile
to warn users about that since elsewhere pragmas are cross-referenced
with related or equivalent attributes.

gcc/ChangeLog
PR c/114957
PR c/78008
PR c++/60972
* doc/extend.texi (Structure-Layout Pragmas):  Add @cindex
entries and reformat the pragma descriptions to match the markup
used for other pragmas.  Document what #pragma pack(0) does.
Add cross-references to similar attributes.
---
 gcc/doc/extend.texi | 87 ++---
 1 file changed, 58 insertions(+), 29 deletions(-)

diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 109c7d26ea2..d76d333576f 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -9972,50 +9972,79 @@ always the C-language name.
 @node Structure-Layout Pragmas
 @subsection Structure-Layout Pragmas
 
-For compatibility with Microsoft Windows compilers, GCC supports a
-set of @code{#pragma} directives that change the maximum alignment of
+@cindex pragma, pack
+@cindex pack pragma
+For compatibility with Microsoft Windows compilers, GCC supports a set
+of @code{#pragma pack} directives that change the maximum alignment of
 members of structures (other than zero-width bit-fields), unions, and
-classes subsequently defined. The @var{n} value below always is required
-to be a small power of two and specifies the new alignment in bytes.
+classes subsequently defined. The @var{n} value below specifies the
+new alignment in bytes and may have the value 1, 2, 4, 8, and 16.  A
+value of 0 is also permitted and indicates the default alignment (as if
+no @code{#pragma pack} were in effect) should be used.
 
-@enumerate
-@item @code{#pragma pack(@var{n})} simply sets the new alignment.
-@item @code{#pragma pack()} sets the alignment to the one that was in
+@table @code
+@item #pragma pack(@var{n})
+Sets the new alignment according to @var{n}.
+
+@item #pragma pack()
+Sets the alignment to the one that was in
 effect when compilation started (see also command-line option
-@option{-fpack-struct[=@var{n}]} @pxref{Code Gen Options}).
-@item @code{#pragma pack(push[,@var{n}])} pushes the current alignment
+@option{-fpack-struct[=@var{n}]}.   @xref{Code Gen Options}).
+
+@item #pragma pack(push[,@var{n}])
+Pushes the current alignment
 setting on an internal stack and then optionally sets the new alignment.
-@item @code{#pragma pack(pop)} restores the alignment setting to the one
+
+@item #pragma pack(pop)
+Restores the alignment setting to the one
 saved at the top of the internal stack (and removes that stack entry).
 Note that @code{#pragma pack([@var{n}])} does not influence this internal
 stack; thus it is possible to have @code{#pragma pack(push)} followed by
-multiple @code{#pragma pack(@var{n})} instances and finalized by a single
-@code{#pragma pack(pop)}.
-@end enumerate
+multiple @code{#pragma pack(@var{n})} instances, with the original state
+restored by a single @code{#pragma pack(pop)}.
 
+@end table
+
+You can also use the @code{packed} type attribute (@pxref{Common Type
+Attributes}) to pack a structure.  However, the @code{packed}
+attribute interferes with @code{#pragma pack}, and attempting to use
+them together may cause spurious warnings or unexpected behavior.
+@c FIXME: This is PR 60972.
+
+@cindex pragma, ms_struct
+@cindex ms_struct pragma
+@cindex Microsoft struct layout
 Some targets, e.g.@: x86 and PowerPC, support the @code{#pragma ms_struct}
-directive which lays out structures and unions subsequently defined as the
-documented @code{__attribute__ ((ms_struct))}.
+directive, which causes subsequent structure and union declarations to
+be laid out in the same way as
+@code{__attribute__ ((ms_struct))}; @pxref{x86 Variable Attributes}.
 
-@enumerate
-@item @code{#pragma ms_struct on} turns on the Microsoft layout.
-@item @code{#pragma ms_struct off} turns off the Microsoft layout.
-@item @code{#pragma ms_struct reset} goes back to the default layout.
-@end enumerate
+@table @code
+@item #pragma ms_struct on
+Turns on the Microsoft layout.
+@item #pragma ms_struct off
+Turns off the Microsoft layout.
+@item #pragma ms_struct reset
+Goes back to the default layout.
+@end table
 
+@cindex pragma, scalar_storage_order
 Most targets also support the @code{#pragma scalar_storage_order} directive
-which lays out structures and unions subsequently defined as the documented
-@code{__attribute__ ((scalar_storage_order))}.
+which lays out subsequent structure and union declarations in
+in the same way as the documented
+@code{__attribute__ ((scalar_storage_orde

[pushed] c++: lambda in function template signature [PR119401]

2025-04-05 Thread Jason Merrill
Tested x86_64-pc-linux-gnu, applying to trunk.

-- 8< --

Here we instantiate the lambda three times in producing A<0>::f:
1) in tsubst_function_type, substituting the type of A<>::f
2) in tsubst_function_decl, substituting the parameters of A<>::f
3) in regenerate_decl_from_template when instantiating A<>::f

The first one gets thrown away by maybe_rebuild_function_decl_type.  Before
r15-7202, we happily built all of them and mangled the result wrongly as
lambda #3.  After r15-7202, we try to mangle #3 as #1, which breaks because
 #1 is already mangled as #1.

This patch avoids building #3 by suppressing regenerate_decl_from_template
if the template signature includes a lambda, fixing the ICE.

We now mangle the lambda as #2, which is still wrong.  Addressing that
should involve not calling tsubst_function_type from tsubst_function_decl,
and building the type from the parms types in the first place rather than
fixing it up in maybe_rebuild_function_decl_type.

PR c++/119401

gcc/cp/ChangeLog:

* pt.cc (regenerate_decl_from_template): Don't regenerate if the
signature involves a lambda.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/lambda-targ11.C: New test.
---
 gcc/cp/pt.cc   | 13 +
 gcc/testsuite/g++.dg/cpp2a/lambda-targ11.C | 13 +
 gcc/testsuite/g++.dg/cpp2a/lambda-targ12.C | 13 +
 3 files changed, 39 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/lambda-targ11.C
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/lambda-targ12.C

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 417d107d699..f7c56a10794 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -27238,6 +27238,19 @@ regenerate_decl_from_template (tree decl, tree tmpl, 
tree args)
   if (DECL_UNIQUE_FRIEND_P (decl))
goto done;
 
+  /* A template with a lambda in the signature also changes type if
+regenerated (PR119401).  */
+  walk_tree_fn find_lambda
+   = [](tree *tp, int *, void *)
+   {
+ if (TREE_CODE (*tp) == LAMBDA_EXPR)
+   return *tp;
+ return NULL_TREE;
+   };
+  if (cp_walk_tree_without_duplicates
+ (&TREE_TYPE (tmpl), find_lambda, nullptr))
+   goto done;
+
   /* Use the source location of the definition.  */
   DECL_SOURCE_LOCATION (decl) = DECL_SOURCE_LOCATION (tmpl);
 
diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-targ11.C 
b/gcc/testsuite/g++.dg/cpp2a/lambda-targ11.C
new file mode 100644
index 000..9f2f743b7eb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/lambda-targ11.C
@@ -0,0 +1,13 @@
+// PR c++/119401
+// { dg-do compile { target c++20 } }
+
+template 
+struct B {};
+template 
+struct A {
+  void f(B<[]{}>) {}
+};
+auto t = &A<0>::f;
+
+// A<0>::f(B::{lambda()#1}{}>)
+// { dg-final { scan-assembler "_ZN1AILi0EE1fE1BIXtlNS0_UlvE_" { xfail 
*-*-* } } }
diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-targ12.C 
b/gcc/testsuite/g++.dg/cpp2a/lambda-targ12.C
new file mode 100644
index 000..bb3f701967f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/lambda-targ12.C
@@ -0,0 +1,13 @@
+// PR c++/119401
+// { dg-do compile { target c++20 } }
+
+template 
+struct B {};
+template 
+struct A {
+  void f(B) {}
+};
+auto t = &A<0>::f;
+
+// A<0>::f(B::{lambda()#1}>)
+// { dg-final { scan-assembler "_ZN1AILi0EE1fE1BINS0_UlvE_EE" { xfail *-*-* } 
} }

base-commit: 95c25cb09f58810bc520c3db469945c6a751aa32
-- 
2.49.0



[COMMITTED 08/35] gccrs: lower: Handle let-else properly

2025-04-05 Thread arthur . cohen
From: Arthur Cohen 

gcc/rust/ChangeLog:

* hir/tree/rust-hir-stmt.h (class LetStmt): Add optional diverging else 
expression.
* hir/tree/rust-hir-stmt.cc: Likewise.
* hir/rust-ast-lower-stmt.cc (ASTLoweringStmt::visit): Add handling for 
lowering
diverging else.
---
 gcc/rust/hir/rust-ast-lower-stmt.cc | 14 ++
 gcc/rust/hir/tree/rust-hir-stmt.cc  | 12 +++-
 gcc/rust/hir/tree/rust-hir-stmt.h   | 16 
 3 files changed, 37 insertions(+), 5 deletions(-)

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



[PATCH 27/27] i386: Raise deprecate warning for -mavx10.1-256/512 and -mevex512 while add -mavx10.1 back with 512 bit alias

2025-04-05 Thread Haochen Jiang
When AVX10.1 options are added into GCC 14, E-core is supposed to
support up to 256 bit vector width, while P-core up to 512 bit vector
width. Therefore, we added avx10.1-256 and avx10.1-512 options into
compiler since there will be real platforms with 256 bit only support.
At the same time, for old platforms could also compile a 256 bit only
binary, we introduced -mno-evex512 to disable 512 bit vector.

However, all the future platforms will now support 512 bit vector width,
including P-core and E-core. It will result in no need for split the
option for vector width. Therefore, we will remove them in this patch.
Unlike AVX10.2 options, AVX10.1 options has been there in a major
release, so we have to raise a deprecate warning in GCC 15 and remove
them in GCC 16. At the same time, to align with avx10.2 options, we will
add just removed avx10.1 option back with warning to mention its
behavior change.

gcc/ChangeLog:

* common/config/i386/cpuinfo.h
(get_available_features): Change to FEATURE_AVX10_1.
* common/config/i386/i386-common.cc
(OPTION_MASK_ISA2_AVX10_1_512_SET): Renamed to ...
(OPTION_MASK_ISA2_AVX10_1_SET): ... this.
(OPTION_MASK_ISA2_AVX10_2_SET): Use renamed macro.
(OPTION_MASK_ISA2_AVX10_1_UNSET): Ditto.
(ix86_handle_option): Ditto.
(processor_alias_table): Use P_PROC_AVX10_1.
* common/config/i386/i386-cpuinfo.h
(enum feature_priority): Rename from AVX10_1_512 to AVX10_1.
(enum processor_features): Ditto.
* common/config/i386/i386-isas.h: Add avx10.1.
* config/i386/driver-i386.cc
(host_detect_local_cpu): Use renamed enum.
* config/i386/i386-c.cc
(ix86_target_macros_internal): Rename to avx10.1.
* config/i386/i386-isa.def (AVX10_1_512): Rename to ...
(AVX10_1): ... this.
* config/i386/i386-options.cc (isa2_opts): Rename to avx10.1.
(ix86_valid_target_attribute_inner_p): Add avx10.1.
(ix86_option_override_internal): Rename to AVX10_1.
Revise warnings to mention behavior change for option
combination in GCC 16.
* config/i386/i386.h (PTA_DIAMONDRAPIDS): Use AVX10_1.
* config/i386/i386.opt: Add avx10.1.
Add deprecate warnings for mevex512 and mavx10.1-256/512.
* config/i386/i386.opt.urls: Add avx10.1.

gcc/testsuite/ChangeLog:

* gcc.target/i386/avx10-check.h: Change to avx10.1.
* gcc.target/i386/avx10_1-1.c: Add warning check.
* gcc.target/i386/avx10_1-10.c: Ditto.
* gcc.target/i386/avx10_1-11.c: Ditto.
* gcc.target/i386/avx10_1-12.c: Ditto.
* gcc.target/i386/avx10_1-13.c: Ditto.
* gcc.target/i386/avx10_1-15.c: Ditto.
* gcc.target/i386/avx10_1-16.c: Ditto.
* gcc.target/i386/avx10_1-18.c: Ditto.
* gcc.target/i386/avx10_1-19.c: Ditto.
* gcc.target/i386/avx10_1-2.c: Ditto.
* gcc.target/i386/avx10_1-20.c: Ditto.
* gcc.target/i386/avx10_1-21.c: Ditto.
* gcc.target/i386/avx10_1-22.c: Ditto.
* gcc.target/i386/avx10_1-23.c: Ditto.
* gcc.target/i386/avx10_1-26.c: Ditto.
* gcc.target/i386/avx10_1-3.c: Ditto.
* gcc.target/i386/avx10_1-4.c: Ditto.
* gcc.target/i386/avx10_1-7.c: Ditto.
* gcc.target/i386/avx10_1-8.c: Ditto.
* gcc.target/i386/avx10_1-9.c: Ditto.
* gcc.target/i386/noevex512-1.c: Ditto.
* gcc.target/i386/noevex512-2.c: Ditto.
* gcc.target/i386/pr111068.c: Ditto.
* gcc.target/i386/pr111907.c: Ditto.
* gcc.target/i386/pr117240_avx512f.c: Ditto.
* gcc.target/i386/pr117304-1.c: Ditto.
* gcc.target/i386/pr117946.c: Ditto.
* gcc.target/i386/avx10_1-24.c: Removed.
* gcc.target/i386/avx10_1-25.c: Removed.
* gcc.target/i386/avx10_1-5.c: Removed.
* gcc.target/i386/avx10_1-6.c: Removed.
---
 gcc/common/config/i386/cpuinfo.h  |  4 +--
 gcc/common/config/i386/i386-common.cc | 20 +++---
 gcc/common/config/i386/i386-cpuinfo.h |  6 ++---
 gcc/common/config/i386/i386-isas.h|  3 ++-
 gcc/config/i386/driver-i386.cc|  2 +-
 gcc/config/i386/i386-c.cc |  9 +++
 gcc/config/i386/i386-isa.def  |  2 +-
 gcc/config/i386/i386-options.cc   | 26 ---
 gcc/config/i386/i386.h|  2 +-
 gcc/config/i386/i386.opt  | 11 +---
 gcc/config/i386/i386.opt.urls |  3 +++
 gcc/testsuite/gcc.target/i386/avx10-check.h   |  2 +-
 gcc/testsuite/gcc.target/i386/avx10_1-1.c |  3 ++-
 gcc/testsuite/gcc.target/i386/avx10_1-10.c|  4 ++-
 gcc/testsuite/gcc.target/i386/avx10_1-11.c|  3 ++-
 gcc/testsuite/gcc.target/i386/avx10_1-12.c|  1 +
 gcc/testsuite/gcc.target/i386/avx10_1-13.c|  1 +
 gcc/testsuite/gcc.target/i386/avx10_1-15.c|  3 ++-
 gcc/testsuite/gcc.target/i386/a

[COMMITTED 005/144] gccrs: ffi-polonius: Remove usage of extern types.

2025-04-05 Thread arthur . cohen
From: Arthur Cohen 

This will allow us to revert our dependency on extern types, which would
help our godbolt build as well as our various builders.

gcc/rust/ChangeLog:

* checks/errors/borrowck/ffi-polonius/src/gccrs_ffi.rs: Remove extern
type feature.
* checks/errors/borrowck/ffi-polonius/src/lib.rs: Define FFIVector
per the nomicon's recommendation
https://doc.rust-lang.org/nomicon/ffi.html#representing-opaque-structs
---
 .../errors/borrowck/ffi-polonius/src/gccrs_ffi.rs | 11 ---
 .../checks/errors/borrowck/ffi-polonius/src/lib.rs|  2 --
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/gcc/rust/checks/errors/borrowck/ffi-polonius/src/gccrs_ffi.rs 
b/gcc/rust/checks/errors/borrowck/ffi-polonius/src/gccrs_ffi.rs
index 0cb85078158..7377e3aaf85 100644
--- a/gcc/rust/checks/errors/borrowck/ffi-polonius/src/gccrs_ffi.rs
+++ b/gcc/rust/checks/errors/borrowck/ffi-polonius/src/gccrs_ffi.rs
@@ -30,11 +30,16 @@
 // ```
 include!("gccrs_ffi_generated.rs");
 
+use std::marker::{PhantomData, PhantomPinned};
+
 use crate::GccrsAtom;
 
-// Using opqaue types
-extern "C" {
-pub type FFIVector;
+// We define an opaque C type per the nomicon's recommendation:
+// https://doc.rust-lang.org/nomicon/ffi.html#representing-opaque-structs
+#[repr(C)]
+pub struct FFIVector {
+_empty: [u8; 0],
+marker: PhantomData<(*mut u8, PhantomPinned)>,
 }
 
 impl Into<(GccrsAtom, GccrsAtom)> for Pair
diff --git a/gcc/rust/checks/errors/borrowck/ffi-polonius/src/lib.rs 
b/gcc/rust/checks/errors/borrowck/ffi-polonius/src/lib.rs
index 782a63f8078..c5c0ae9756e 100644
--- a/gcc/rust/checks/errors/borrowck/ffi-polonius/src/lib.rs
+++ b/gcc/rust/checks/errors/borrowck/ffi-polonius/src/lib.rs
@@ -16,8 +16,6 @@
 // along with GCC; see the file COPYING3.  If not see
 // .
 
-#![feature(extern_types)]
-
 mod gccrs_ffi;
 
 use gccrs_ffi::FFIVector;
-- 
2.45.2



[COMMITTED 079/144] gccrs: session-manager: Fix typos in -frust-incomplete message

2025-04-05 Thread arthur . cohen
From: Arthur Cohen 

gcc/rust/ChangeLog:

* rust-session-manager.cc (Session::compile_crate): Use less repetition,
fix a typo in `reports`, fix word order.
---
 gcc/rust/rust-session-manager.cc | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

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



Re: [PATCH] combine: Allow 2->2 combos but limit insn searches [PR116398]

2025-04-05 Thread Jakub Jelinek
On Thu, Apr 03, 2025 at 02:40:43PM +0100, Richard Sandiford wrote:
> > I see.  I understood Jakub thinks my change is too aggressive since
> > it does indeed miss combine attempts from changed log-links.
> >
> > I remember that when allowing added_links_insn to override the
> > i3 return for i2_unchaged_p the bad compile-time re-surfaced.  So
> > now I wonder whether, if i2_unchanged, distribute_links (i2links)
> > does (should do?) anything?  I don't see anything that would avoid
> > adjusting links when there's still a use in newi2_patt (IIRC
> > i0 and i1 are always gone?).

Note, I'd be fine even with the earlier patch you've posted.

> --- a/gcc/combine.cc
> +++ b/gcc/combine.cc
> @@ -4208,16 +4208,7 @@ try_combine (rtx_insn *i3, rtx_insn *i2, rtx_insn *i1, 
> rtx_insn *i0,
>adjust_for_new_dest (i3);
>  }
>  
> -  /* If I2 didn't change, this is not a combination (but a simplification or
> - canonicalisation with context), which should not be done here.  Doing
> - it here explodes the algorithm.  Don't.  */
> -  if (rtx_equal_p (newi2pat, PATTERN (i2)))
> -{
> -  if (dump_file)
> - fprintf (dump_file, "i2 didn't change, not doing this\n");
> -  undo_all ();
> -  return 0;
> -}
> +  bool only_i3_changed = !i0 && !i1 && rtx_equal_p (newi2pat, PATTERN (i2));
>  
>/* We now know that we can do this combination.  Merge the insns and
>   update the status of registers and LOG_LINKS.  */
> @@ -4785,6 +4776,9 @@ try_combine (rtx_insn *i3, rtx_insn *i2, rtx_insn *i1, 
> rtx_insn *i0,
>combine_successes++;
>undo_commit ();
>  
> +  if (only_i3_changed)
> +return i3;
> +
>rtx_insn *ret = newi2pat ? i2 : i3;
>if (added_links_insn && DF_INSN_LUID (added_links_insn) < DF_INSN_LUID 
> (ret))
>  ret = added_links_insn;
> 
> so essentially your patch, I see an 11.9x improvement in combine's
> compile time in the original testcase for PR101523, going from 88%
> to 41% of total compile time.  Memory usage improves 110x, from
> 97% to 25%.  The output is unchanged.  Adding:

Though the above looks really nice.

> --- a/gcc/combine.cc
> +++ b/gcc/combine.cc
> @@ -472,7 +472,7 @@ static void move_deaths (rtx, rtx, int, rtx_insn *, rtx 
> *);
>  static bool reg_bitfield_target_p (rtx, rtx);
>  static void distribute_notes (rtx, rtx_insn *, rtx_insn *, rtx_insn *,
> rtx, rtx, rtx);
> -static void distribute_links (struct insn_link *);
> +static void distribute_links (struct insn_link *, rtx_insn * = nullptr);
>  static void mark_used_regs_combine (rtx);
>  static void record_promoted_value (rtx_insn *, rtx);
>  static bool unmentioned_reg_p (rtx, rtx);
> @@ -4209,6 +4209,8 @@ try_combine (rtx_insn *i3, rtx_insn *i2, rtx_insn *i1, 
> rtx_insn *i0,
>  }
>  
>bool only_i3_changed = !i0 && !i1 && rtx_equal_p (newi2pat, PATTERN (i2));
> +  if (only_i3_changed)
> +swap_i2i3 = false;
>  
>/* We now know that we can do this combination.  Merge the insns and
>   update the status of registers and LOG_LINKS.  */
> @@ -4584,8 +4586,8 @@ try_combine (rtx_insn *i3, rtx_insn *i2, rtx_insn *i1, 
> rtx_insn *i0,
>   NULL_RTX, NULL_RTX, NULL_RTX);
>}
>  
> -distribute_links (i3links);
> -distribute_links (i2links);
> +distribute_links (i3links, only_i3_changed ? i3 : nullptr);
> +distribute_links (i2links, !i0 && !i1 ? i2 : nullptr);
>  distribute_links (i1links);
>  distribute_links (i0links);
>  
> @@ -14978,10 +14980,13 @@ distribute_notes (rtx notes, rtx_insn *from_insn, 
> rtx_insn *i3, rtx_insn *i2,
>  
>  /* Similarly to above, distribute the LOG_LINKS that used to be present on
> I3, I2, and I1 to new locations.  This is also called to add a link
> -   pointing at I3 when I3's destination is changed.  */
> +   pointing at I3 when I3's destination is changed.
> +
> +   If START is nonnull and an insn, we know that the next location for
> +   each link is no earlier than START.  */
>  
>  static void
> -distribute_links (struct insn_link *links)
> +distribute_links (struct insn_link *links, rtx_insn *start)
>  {
>struct insn_link *link, *next_link;
>  
> @@ -15047,7 +15052,10 @@ distribute_links (struct insn_link *links)
>I3 to I2.  Also note that not much searching is typically done here
>since most links don't point very far away.  */
>  
> -  for (insn = NEXT_INSN (link->insn);
> +  insn = start;
> +  if (!insn || NOTE_P (insn))
> + insn = NEXT_INSN (link->insn);
> +  for (;
>  (insn && (this_basic_block->next_bb == EXIT_BLOCK_PTR_FOR_FN (cfun)
>|| BB_HEAD (this_basic_block->next_bb) != insn));
>  insn = NEXT_INSN (insn))
> 
> improves compile time a further 17.7%, going from 41% to 33% of
> compile time.  This still generates the same code for the testcase
> as the unpatched compiler, and I checked that a boostrap and regression
> test succeeded with the (independent rather t

[PATCH] tree-optimization/119534 - reject bogus emulated vectorized gather

2025-04-05 Thread Richard Biener
The following makes sure to reject the attempts to emulate a vector
gather when the discovered index vector type is a vector mask.

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

Richard.

PR tree-optimization/119534
* tree-vect-stmts.cc (get_load_store_type): Reject
VECTOR_BOOLEAN_TYPE_P offset vector type for emulated gathers.

* gcc.dg/vect/pr119534.c: New testcase.
---
 gcc/testsuite/gcc.dg/vect/pr119534.c | 11 +++
 gcc/tree-vect-stmts.cc   |  1 +
 2 files changed, 12 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/vect/pr119534.c

diff --git a/gcc/testsuite/gcc.dg/vect/pr119534.c 
b/gcc/testsuite/gcc.dg/vect/pr119534.c
new file mode 100644
index 000..0b4130b7cfa
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr119534.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-mavx512bw" { target { x86_64-*-* i?86-*-* } } } */
+
+void f(int w, int *out, double *d)
+{
+  for (int j = 0; j < w; j++)
+{
+  const int i = (j >= w / 2);
+  out[j] += d[i];
+}
+}
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 1361faf0cb0..f4a6bc968b3 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -2530,6 +2530,7 @@ get_load_store_type (vec_info  *vinfo, stmt_vec_info 
stmt_info,
{
  if (!TYPE_VECTOR_SUBPARTS (vectype).is_constant ()
  || !TYPE_VECTOR_SUBPARTS (gs_info->offset_vectype).is_constant ()
+ || VECTOR_BOOLEAN_TYPE_P (gs_info->offset_vectype)
  || !constant_multiple_p (TYPE_VECTOR_SUBPARTS
 (gs_info->offset_vectype),
   TYPE_VECTOR_SUBPARTS (vectype)))
-- 
2.43.0


[COMMITTED 111/144] gccrs: Move bir builder function implementation

2025-04-05 Thread arthur . cohen
From: Pierre-Emmanuel Patry 

Move function implementation to their own file.

gcc/rust/ChangeLog:

* Make-lang.in: Add new rust-bir-builder-pattern file.
* checks/errors/borrowck/rust-bir-builder-pattern.h: Remove
implementation.
* checks/errors/borrowck/rust-bir-builder-pattern.cc: New file.

Signed-off-by: Pierre-Emmanuel Patry 
---
 gcc/rust/Make-lang.in |   1 +
 .../borrowck/rust-bir-builder-pattern.cc  | 273 ++
 .../borrowck/rust-bir-builder-pattern.h   | 260 +
 3 files changed, 283 insertions(+), 251 deletions(-)
 create mode 100644 gcc/rust/checks/errors/borrowck/rust-bir-builder-pattern.cc

diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index c1a3c1fe9f3..51645be6ff6 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -172,6 +172,7 @@ GRS_OBJS = \
 rust/rust-borrow-checker.o \
 rust/rust-borrow-checker-diagnostics.o\
 rust/rust-bir-builder-expr-stmt.o \
+rust/rust-bir-builder-pattern.o \
 rust/rust-bir-dump.o \
 rust/rust-polonius.o\
 rust/rust-hir-dot-operator.o \
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-pattern.cc 
b/gcc/rust/checks/errors/borrowck/rust-bir-builder-pattern.cc
new file mode 100644
index 000..723ff7334b6
--- /dev/null
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-pattern.cc
@@ -0,0 +1,273 @@
+#include "rust-bir-builder-pattern.h"
+
+namespace Rust {
+namespace BIR {
+
+void
+PatternBindingBuilder::visit_identifier (const Analysis::NodeMapping &node,
+bool is_ref, location_t location,
+bool is_mut)
+{
+  if (is_ref)
+{
+  translated = declare_variable (
+   node,
+   new TyTy::ReferenceType (node.get_hirid (),
+TyTy::TyVar (node.get_hirid ()),
+(is_mut) ? Mutability::Mut : Mutability::Imm));
+}
+  else
+{
+  translated = declare_variable (node);
+}
+
+  if (init.has_value ())
+{
+  push_assignment (translated, init.value (), location);
+}
+}
+
+void
+PatternBindingBuilder::visit (HIR::IdentifierPattern &pattern)
+{
+  // Top-level identifiers are resolved directly to avoid useless temporary
+  // (for cleaner BIR).
+  visit_identifier (pattern.get_mappings (), pattern.get_is_ref (),
+   pattern.get_locus (), pattern.is_mut ());
+}
+
+void
+PatternBindingBuilder::visit (HIR::ReferencePattern &pattern)
+{
+  SavedState saved (this);
+
+  init = init.map ([&] (PlaceId id) {
+return ctx.place_db.lookup_or_add_path (Place::DEREF, lookup_type 
(pattern),
+   id);
+  });
+
+  type_annotation = type_annotation.map ([&] (TyTy::BaseType *ty) {
+return ty->as ()->get_base ();
+  });
+
+  pattern.get_referenced_pattern ()->accept_vis (*this);
+}
+
+void
+PatternBindingBuilder::visit (HIR::SlicePattern &pattern)
+{
+  SavedState saved (this);
+
+  // All indexes are supposed to point to the same place for borrow-checking.
+  // init = ctx.place_db.lookup_or_add_path (Place::INDEX, lookup_type
+  // (pattern), saved.init);
+  init = init.map ([&] (PlaceId id) {
+return ctx.place_db.lookup_or_add_path (Place::INDEX, lookup_type 
(pattern),
+   id);
+  });
+
+  type_annotation = type_annotation.map ([&] (TyTy::BaseType *ty) {
+return ty->as ()->get_element_type ();
+  });
+
+  // Regions are unchnaged.
+
+  for (auto &item : pattern.get_items ())
+{
+  item->accept_vis (*this);
+}
+}
+
+void
+PatternBindingBuilder::visit (HIR::AltPattern &pattern)
+{
+  rust_sorry_at (pattern.get_locus (),
+"borrow-checking of alt patterns is not yet implemented");
+}
+
+void
+PatternBindingBuilder::visit (HIR::StructPattern &pattern)
+{
+  SavedState saved (this);
+
+  auto tyty = ctx.place_db[init.value ()].tyty;
+  rust_assert (tyty->get_kind () == TyTy::ADT);
+  auto adt_ty = static_cast (tyty);
+  rust_assert (adt_ty->is_struct_struct ());
+  auto struct_ty = adt_ty->get_variants ().at (0);
+
+  for (auto &field :
+   pattern.get_struct_pattern_elems ().get_struct_pattern_fields ())
+{
+  switch (field->get_item_type ())
+   {
+ case HIR::StructPatternField::TUPLE_PAT: {
+   auto tuple
+ = static_cast (field.get ());
+
+   init = init.map ([&] (PlaceId id) {
+ return ctx.place_db.lookup_or_add_path (
+   Place::FIELD, lookup_type (*tuple->get_tuple_pattern ()), id,
+   tuple->get_index ());
+   });
+
+   type_annotation = type_annotation.map ([&] (TyTy::BaseType *ty) {
+ return ty->as ()
+   ->get_variants ()
+   .at (0)
+   ->get_fields ()
+   .at (tuple->get_index ())
+   ->get_field_type ();
+   });
+
+   tuple-

[COMMITTED 041/146] gccrs: Use default constructor for default arguments

2025-04-05 Thread arthur . cohen
From: Pierre-Emmanuel Patry 

GCC 4.8 complains about the initializer list.

gcc/rust/ChangeLog:

* typecheck/rust-tyty.h: Change initializer list to default constructor
call.

Signed-off-by: Pierre-Emmanuel Patry 
---
 gcc/rust/typecheck/rust-tyty.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h
index 94f7bce00f8..49cd00c9174 100644
--- a/gcc/rust/typecheck/rust-tyty.h
+++ b/gcc/rust/typecheck/rust-tyty.h
@@ -657,7 +657,7 @@ public:
   std::vector subst_refs,
   SubstitutionArgumentMappings generic_arguments
   = SubstitutionArgumentMappings::error (),
-  RegionConstraints region_constraints = {},
+  RegionConstraints region_constraints = RegionConstraints{},
   std::set refs = std::set ())
 : BaseType (ref, ref, TypeKind::ADT, ident, refs),
   SubstitutionRef (std::move (subst_refs), std::move (generic_arguments),
@@ -670,7 +670,7 @@ public:
   std::vector subst_refs,
   SubstitutionArgumentMappings generic_arguments
   = SubstitutionArgumentMappings::error (),
-  RegionConstraints region_constraints = {},
+  RegionConstraints region_constraints = RegionConstraints{},
   std::set refs = std::set ())
 : BaseType (ref, ty_ref, TypeKind::ADT, ident, refs),
   SubstitutionRef (std::move (subst_refs), std::move (generic_arguments),
@@ -683,7 +683,7 @@ public:
   std::vector subst_refs, ReprOptions repr,
   SubstitutionArgumentMappings generic_arguments
   = SubstitutionArgumentMappings::error (),
-  RegionConstraints region_constraints = {},
+  RegionConstraints region_constraints = RegionConstraints{},
   std::set refs = std::set ())
 : BaseType (ref, ty_ref, TypeKind::ADT, ident, refs),
   SubstitutionRef (std::move (subst_refs), std::move (generic_arguments),
-- 
2.45.2



Re: [PATCH RFA] ipa: target clone and mangling alias [PR114992]

2025-04-05 Thread Richard Biener
On Thu, 20 Mar 2025, Jason Merrill wrote:

> Tested x86_64-pc-linux-gnu.  OK for trunk and backports?
> 
> -- 8< --
> 
> Since the mangling of the second lambda changed (previously we counted all
> lambdas, now we only count lambdas with the same signature), we
> generate_mangling_alias for handler for backward compatibility.
> Since handler is COMDAT, resolve_alias puts the alias in the same comdat
> group as handler itself.  Then create_dispatcher_calls tries to add the
> alias to the same comdat group as the dispatcher, but it's already in a
> same_comdat_group, so we ICE.
> 
> It seems like we're just missing a remove_from_same_comdat_group before
> add_to_same_comdat_group.

LGTM, let's see if Honza has any comments.

Richard.

>   PR c++/114992
> 
> gcc/ChangeLog:
> 
>   * multiple_target.cc (create_dispatcher_calls):
>   remove_from_same_comdat_group before add_to_same_comdat_group.
> 
> gcc/testsuite/ChangeLog:
> 
>   * g++.target/i386/mangling-alias1.C: New test.
> ---
>  gcc/multiple_target.cc  |  6 +-
>  gcc/testsuite/g++.target/i386/mangling-alias1.C | 16 
>  2 files changed, 21 insertions(+), 1 deletion(-)
>  create mode 100644 gcc/testsuite/g++.target/i386/mangling-alias1.C
> 
> diff --git a/gcc/multiple_target.cc b/gcc/multiple_target.cc
> index d8becf4d9a9..d25277c0a93 100644
> --- a/gcc/multiple_target.cc
> +++ b/gcc/multiple_target.cc
> @@ -155,7 +155,11 @@ create_dispatcher_calls (struct cgraph_node *node)
> symtab_node *source = ref->referring;
> source->create_reference (inode, IPA_REF_ALIAS);
> if (inode->get_comdat_group ())
> - source->add_to_same_comdat_group (inode);
> + {
> +   if (source->same_comdat_group)
> + source->remove_from_same_comdat_group ();
> +   source->add_to_same_comdat_group (inode);
> + }
>   }
> else
>   gcc_unreachable ();
> diff --git a/gcc/testsuite/g++.target/i386/mangling-alias1.C 
> b/gcc/testsuite/g++.target/i386/mangling-alias1.C
> new file mode 100644
> index 000..70264e2b64e
> --- /dev/null
> +++ b/gcc/testsuite/g++.target/i386/mangling-alias1.C
> @@ -0,0 +1,16 @@
> +// PR c++/114992
> +// { dg-do compile { target { c++11 && x86_64-*-* } } }
> +// { dg-require-ifunc }
> +
> +template 
> +__attribute__((target_clones("avx2", "default")))
> +void handler(Callable) {}
> +
> +inline int func()
> +{
> +  auto l1 = [](int) {}; // different lambda signature
> +  handler([]() {}); // so this one needs a mangling alias
> +  return 42;
> +}
> +
> +int g = func();
> 
> base-commit: 56145ae79b89b823f306c2c241f6a1fe5d604816
> 

-- 
Richard Biener 
SUSE Software Solutions Germany GmbH,
Frankenstrasse 146, 90461 Nuernberg, Germany;
GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)


Re: [Patch, Fortran] C prototypes for functions returning C function pointers

2025-04-05 Thread Steve Kargl
On Mon, Mar 24, 2025 at 09:40:38PM +0100, Thomas Koenig wrote:
>
> Regression-tested.  Again no test case because I don't know
> how.  During testing, I also found that vtabs were dumped,
> this is also corrected.
> 
> OK for trunk?

Thanks for working on this, but ...

> 
>  /* This section deals with dumping the global symbol tree.  */
> diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
> index 34c8210f66a..efc059908f7 100644
> --- a/gcc/fortran/resolve.cc
> +++ b/gcc/fortran/resolve.cc
> @@ -12187,6 +12187,34 @@ caf_possible_reallocate (gfc_expr *e)
>return last_arr_ref && last_arr_ref->u.ar.type == AR_FULL;
>  }
>  
> +/*  Handle C_FUNPTR assignments, for generating C prototypes and for warning 
> if
> +pointers are assigned to procedures with different interfaces.  */
> +
> +static void
> +check_c_funptr_assign_interface (gfc_expr *lhs, gfc_expr *rhs)
> +{
> +
> +  fprintf (stderr,"%p %p\n", (void *) lhs, (void *) rhs);

This looks like a debugging printf() statement.  If it is
meant to be informative, I would expect gfc_warning( ) or
gfc_error().

-- 
Steve


[COMMITTED 075/141] gccrs: fix unconstrained generics check to handle recursive generics

2025-04-05 Thread arthur . cohen
From: Philip Herron 

Generics can be constrained within other generic types so this check needs
to be recursive.

Fixes Rust-GCC#3031

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-base.cc (walk_types_to_constrain): 
recursive walker
* typecheck/rust-tyty.cc (BaseType::get_subst_argument_mappings): new 
helper
* typecheck/rust-tyty.h: prototype

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron 
---
 .../typecheck/rust-hir-type-check-base.cc | 42 +++
 gcc/rust/typecheck/rust-tyty.cc   | 42 +++
 gcc/rust/typecheck/rust-tyty.h|  1 +
 gcc/testsuite/rust/compile/issue-3031.rs  | 15 +++
 4 files changed, 82 insertions(+), 18 deletions(-)
 create mode 100644 gcc/testsuite/rust/compile/issue-3031.rs

diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.cc 
b/gcc/rust/typecheck/rust-hir-type-check-base.cc
index 34f629c0519..8f2471d54d5 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-base.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-base.cc
@@ -31,6 +31,26 @@ TypeCheckBase::TypeCheckBase ()
 context (TypeCheckContext::get ())
 {}
 
+static void
+walk_types_to_constrain (std::set &constrained_symbols,
+const TyTy::SubstitutionArgumentMappings &constraints)
+{
+  for (const auto &c : constraints.get_mappings ())
+{
+  const TyTy::BaseType *arg = c.get_tyty ();
+  if (arg != nullptr)
+   {
+ const TyTy::BaseType *p = arg->get_root ();
+ constrained_symbols.insert (p->get_ty_ref ());
+ if (p->has_substitutions_defined ())
+   {
+ walk_types_to_constrain (constrained_symbols,
+  p->get_subst_argument_mappings ());
+   }
+   }
+}
+}
+
 bool
 TypeCheckBase::check_for_unconstrained (
   const std::vector ¶ms_to_constrain,
@@ -52,28 +72,14 @@ TypeCheckBase::check_for_unconstrained (
   HirId ref = p.get_param_ty ()->get_ref ();
   symbols_to_constrain.insert (ref);
   symbol_to_location.insert ({ref, p.get_param_locus ()});
+
+  rust_debug_loc (p.get_param_locus (), "XX constrain THIS");
 }
 
   // set up the set of constrained symbols
   std::set constrained_symbols;
-  for (const auto &c : constraint_a.get_mappings ())
-{
-  const TyTy::BaseType *arg = c.get_tyty ();
-  if (arg != nullptr)
-   {
- const TyTy::BaseType *p = arg->get_root ();
- constrained_symbols.insert (p->get_ty_ref ());
-   }
-}
-  for (const auto &c : constraint_b.get_mappings ())
-{
-  const TyTy::BaseType *arg = c.get_tyty ();
-  if (arg != nullptr)
-   {
- const TyTy::BaseType *p = arg->get_root ();
- constrained_symbols.insert (p->get_ty_ref ());
-   }
-}
+  walk_types_to_constrain (constrained_symbols, constraint_a);
+  walk_types_to_constrain (constrained_symbols, constraint_b);
 
   const auto root = reference->get_root ();
   if (root->get_kind () == TyTy::TypeKind::PARAM)
diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index 8f388120a41..fe4b8fca139 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -888,6 +888,48 @@ BaseType::needs_generic_substitutions () const
   return false;
 }
 
+const SubstitutionArgumentMappings &
+BaseType::get_subst_argument_mappings () const
+{
+  static auto empty = SubstitutionArgumentMappings::empty ();
+  const TyTy::BaseType *x = destructure ();
+  switch (x->get_kind ())
+{
+  case PROJECTION: {
+   const auto &p = *static_cast (x);
+   const auto &ref = static_cast (p);
+   return ref.get_substitution_arguments ();
+  }
+  break;
+
+  case FNDEF: {
+   const auto &fn = *static_cast (x);
+   const auto &ref = static_cast (fn);
+   return ref.get_substitution_arguments ();
+  }
+  break;
+
+  case ADT: {
+   const auto &adt = *static_cast (x);
+   const auto &ref = static_cast (adt);
+   return ref.get_substitution_arguments ();
+  }
+  break;
+
+  case CLOSURE: {
+   const auto &closure = *static_cast (x);
+   const auto &ref = static_cast (closure);
+   return ref.get_substitution_arguments ();
+  }
+  break;
+
+default:
+  return empty;
+}
+
+  return empty;
+}
+
 // InferType
 
 InferType::InferType (HirId ref, InferTypeKind infer_kind, TypeHint hint,
diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h
index 93c4a15a460..504a14e3773 100644
--- a/gcc/rust/typecheck/rust-tyty.h
+++ b/gcc/rust/typecheck/rust-tyty.h
@@ -174,6 +174,7 @@ public:
 
   bool has_substitutions_defined () const;
   bool needs_generic_substitutions () const;
+  const SubstitutionArgumentMappings &get_subst_argument_mappings () const;
 
   std::string mangle_string () const
   {
diff --git a/gcc/testsuite/rust/compile/issue-3031.rs 
b/g

Re: [PATCH][RFC] [cobol] change cbl_field_data_t::etc_t::value from _Float128 to tree

2025-04-05 Thread James K. Lowden
On Mon, 24 Mar 2025 22:55:44 +0100
Jakub Jelinek  wrote:

> > When cbl_field_t::data::value_of returned _Float128, that line
> > compared a _Float128 to its value as a size_t.  If the number was
> > negative, had a fractional component, or was too large, the test
> > failed.  
> > 
> > Now cbl_field_t::data::value_of returns a tree.  Steps: 
> > 
> > 1.  produce HOST_WIDE_INT vii from the tree
> > 2.  set REAL_VALUE_TYPE vi from vii
> > 3.  use real_identical to compare vi to the original
> > 
> > The comment for real_identical says it's a bitwise comparison.
> > That's not the same as saying the floating point value can be
> > represented exactly as a size_t.  
> 
> It isn't 100% the same, but the original doesn't make much sense as
> well, because size_t is the host size type.  E.g. if cobol1 is native
> x86_64-linux compiler, size_t will be 64-bit unsigned type, if cobol1
> is i686-linux -> x86_64-linux cross-compiler, size_t will be 32-bit
> unsigned type. We certainly don't want the two to behave differently.

I accept that cross-compilation should be supported as a matter of
policy.  You are going to a lot of effort to support
cross-compilation for the COBOL front end.  That's work we didn't know
how to do, and are grateful for,  even if it makes our lives more
complicated.  After all, generality is always more complicated.  

> But what exactly the code wants to do is unclear.

(I'm sure that's true.  In my defense, the nonterminal is named
"count", and the comment is 

// verify not floating point with nonzero fraction

but I admit that's not a lot to go on.)

Let me clarify.  :-) 

What we're dealing with here is an array subscript.   When the constant
compile-time expression is parsed, we don't know how it will be used;
we find out only when it's used as a subscript.  As an array subscript,
it can't be negative, fractional, or larger than the target's address
space.   

In fact, we shouldn't use floating point for numeric literals. We
grabbed _Float128 because it was available and served our purpose. Per
the ISO specification, though, numeric literals are not floating point.
They are fixed-point.  

Given considerations like -0.0 and infinities and NaNs, perhaps we're
better off switching to FIXED_POINT_TYPE, where they don't apply.  

If we just check for a positive integral value not too big, that should
suffice for now.  Once we switch to fixed point, it will be correct.  

How does that sound?  

--jkl



[pushed] c++: operator!= rewriting and arg-dep lookup

2025-04-05 Thread Jason Merrill
Tested x86_64-pc-linux-gnu, applying to trunk.

-- 8< --

When considering an op== as a rewrite target, we need to disqualify it if
there is a matching op!= in the same scope.  But add_candidates was assuming
that we could use the same set of op!= for all op==, which is wrong if
arg-dep lookup finds op== in multiple namespaces.

This broke 20_util/optional/relops/constrained.cc if the order of the ADL
set changed.

gcc/cp/ChangeLog:

* call.cc (add_candidates): Re-lookup ne_fns if we move into
another namespace.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/spaceship-rewrite6.C: New test.
---
 gcc/cp/call.cc| 27 +--
 .../g++.dg/cpp2a/spaceship-rewrite6.C | 33 +++
 2 files changed, 57 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/spaceship-rewrite6.C

diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
index b1469cb5a4c..7fd5d89bf3d 100644
--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -6673,6 +6673,7 @@ add_candidates (tree fns, tree first_arg, const vec *args,
   bool check_list_ctor = false;
   bool check_converting = false;
   unification_kind_t strict;
+  tree ne_context = NULL_TREE;
   tree ne_fns = NULL_TREE;
 
   if (!fns)
@@ -6719,6 +6720,7 @@ add_candidates (tree fns, tree first_arg, const vec *args,
   tree ne_name = ovl_op_identifier (false, NE_EXPR);
   if (DECL_CLASS_SCOPE_P (fn))
{
+ ne_context = DECL_CONTEXT (fn);
  ne_fns = lookup_fnfields (TREE_TYPE ((*args)[0]), ne_name,
1, tf_none);
  if (ne_fns == error_mark_node || ne_fns == NULL_TREE)
@@ -6728,8 +6730,9 @@ add_candidates (tree fns, tree first_arg, const vec *args,
}
   else
{
- tree context = decl_namespace_context (fn);
- ne_fns = lookup_qualified_name (context, ne_name, LOOK_want::NORMAL,
+ ne_context = decl_namespace_context (fn);
+ ne_fns = lookup_qualified_name (ne_context, ne_name,
+ LOOK_want::NORMAL,
  /*complain*/false);
  if (ne_fns == error_mark_node
  || !is_overloaded_fn (ne_fns))
@@ -6828,8 +6831,26 @@ add_candidates (tree fns, tree first_arg, const 
vec *args,
 
   /* When considering reversed operator==, if there's a corresponding
 operator!= in the same scope, it's not a rewrite target.  */
-  if (ne_fns)
+  if (ne_context)
{
+ if (TREE_CODE (ne_context) == NAMESPACE_DECL)
+   {
+ /* With argument-dependent lookup, fns can span multiple
+namespaces; make sure we look in the fn's namespace for a
+corresponding operator!=.  */
+ tree fn_ns = decl_namespace_context (fn);
+ if (fn_ns != ne_context)
+   {
+ ne_context = fn_ns;
+ tree ne_name = ovl_op_identifier (false, NE_EXPR);
+ ne_fns = lookup_qualified_name (ne_context, ne_name,
+ LOOK_want::NORMAL,
+ /*complain*/false);
+ if (ne_fns == error_mark_node
+ || !is_overloaded_fn (ne_fns))
+   ne_fns = NULL_TREE;
+   }
+   }
  bool found = false;
  for (lkp_iterator ne (ne_fns); !found && ne; ++ne)
if (0 && !ne.using_p ()
diff --git a/gcc/testsuite/g++.dg/cpp2a/spaceship-rewrite6.C 
b/gcc/testsuite/g++.dg/cpp2a/spaceship-rewrite6.C
new file mode 100644
index 000..0ec74e89102
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/spaceship-rewrite6.C
@@ -0,0 +1,33 @@
+// { dg-do compile { target c++20 } }
+
+// We wrongly considered D to be ne_comparable because we were looking for a
+// corresponding op!= for N::op== in ::, because ::op== happened to be the
+// first thing in the lookup set.
+
+template
+struct enable_if;
+
+template
+struct enable_if
+{ typedef _Tp type; };
+
+template  struct A { };
+
+namespace N {
+  struct X { };
+  template  auto operator== (const A&, const A&)
+-> typename enable_if::type;
+  template  auto operator!= (const A&, const A&)
+-> typename enable_if::type;
+}
+
+template
+concept ne_comparable
+= requires (const A& t, const A& u) {
+  t != u;
+};
+
+struct D { };
+int operator==(D, D);
+bool operator!=(D, D) = delete;
+static_assert( ! ne_comparable );

base-commit: 634215cdc3c569f9a9a247dcd4d9a4d6ce68ad57
-- 
2.49.0



Re: [PATCH] tailc: Don't fail musttail calls if they use or could use local arguments, instead warn [PR119376]

2025-04-05 Thread Alexander Monakov


On Tue, 25 Mar 2025, Andi Kleen wrote:

> On Tue, Mar 25, 2025 at 07:43:28PM +0300, Alexander Monakov wrote:
> > Hello,
> > 
> > FWIW I think Clang made a mistake in bending semantics in a way that is 
> > clearly
> > misaligned with the general design of C and C++, where a language-native, 
> > so to
> > speak, solution was available: introduce a scope for the local variables to
> > indicate that they cannot escape to the intended tailcall:
> > 
> > void foo(int v)
> > {
> >   {
> > int a;
> > capture(&a);
> >   }
> >   tailcall(v); // this cannot refer to 'a', even though it escaped earlier
> > }
> 
> This is not a universal fix? e.g. consider a case like
> 
> void foo(int v)
> {
>int a;
>capture(&a); 
>if (condition)
>  return tailcall(v);
>// do something with a
> }

This can be rewritten as

void foo(int v)
{
  {
int a;
capture(&a);
if (condition)
  goto tail_position;
// do something with a
  }
tail_position:
  tailcall(v);
}

or with 'do { ... if (...) break; ...} while (0)' when one prefers that to goto.

Alexander


[COMMITTED 27/35] gccrs: nr2.0: Fix test macros/mbe/macro43.rs

2025-04-05 Thread arthur . cohen
From: Owen Avery 

gcc/testsuite/ChangeLog:

* rust/compile/macros/mbe/macro43.rs: Adjust test to pass with
name resolution 2.0.
* rust/compile/nr2/exclude: Remove macros/mbe/macro43.rs.

Signed-off-by: Owen Avery 
---
 gcc/testsuite/rust/compile/macros/mbe/macro43.rs | 15 +++
 gcc/testsuite/rust/compile/nr2/exclude   |  1 -
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/gcc/testsuite/rust/compile/macros/mbe/macro43.rs 
b/gcc/testsuite/rust/compile/macros/mbe/macro43.rs
index fbc36a9d6e5..0a7f038ef36 100644
--- a/gcc/testsuite/rust/compile/macros/mbe/macro43.rs
+++ b/gcc/testsuite/rust/compile/macros/mbe/macro43.rs
@@ -1,3 +1,10 @@
+use Option::{None, Some};
+
+enum Option {
+None,
+Some(T)
+}
+
 macro_rules! nonzero_integers {
 ( $( $Ty: ident($Int: ty); )+ ) => {
 $(
@@ -14,7 +21,7 @@ macro_rules! nonzero_integers {
 // not all derive macros are implemented yet, and this test does 
not test these anyways
 // #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
 #[repr(transparent)]
-pub struct $Ty(NonZero<$Int>);
+pub struct $Ty($Int);
 
 impl $Ty {
 /// Create a non-zero without checking the value.
@@ -25,7 +32,7 @@ macro_rules! nonzero_integers {
 #[stable(feature = "nonzero", since = "1.28.0")]
 #[inline]
 pub const unsafe fn new_unchecked(n: $Int) -> Self {
-$Ty(NonZero(n))
+$Ty(n)
 }
 
 /// Create a non-zero if the given value is not zero.
@@ -33,7 +40,7 @@ macro_rules! nonzero_integers {
 #[inline]
 pub fn new(n: $Int) -> Option {
 if n != 0 {
-Some($Ty(NonZero(n)))
+Some($Ty(n))
 } else {
 None
 }
@@ -43,7 +50,7 @@ macro_rules! nonzero_integers {
 #[stable(feature = "nonzero", since = "1.28.0")]
 #[inline]
 pub fn get(self) -> $Int {
-self.0 .0
+self.0
 }
 
 }
diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index 75a0ae0ea0e..19bf6f8f609 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -5,7 +5,6 @@ issue-2043.rs
 issue-2812.rs
 issue-3315-2.rs
 lookup_err1.rs
-macros/mbe/macro43.rs
 macros/mbe/macro6.rs
 multiple_bindings1.rs
 multiple_bindings2.rs
-- 
2.49.0



[PATCH 04/10] testsuite: aarch64: restore torture options in vml[as]_float_not_used.c

2025-04-05 Thread Christophe Lyon
Remove dg-options, so that the test is executed as expected using the
options defined by advsimd-intrinsics.exp.

gcc/testsuite/
* gcc.target/aarch64/advsimd-intrinsics/vmla_float_not_fused.c:
Remove dg-options.
* gcc.target/aarch64/advsimd-intrinsics/vmls_float_not_fused.c:
Likewise.
---
 .../aarch64/advsimd-intrinsics/vmla_float_not_fused.c   | 2 --
 .../aarch64/advsimd-intrinsics/vmls_float_not_fused.c   | 2 --
 2 files changed, 4 deletions(-)

diff --git 
a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vmla_float_not_fused.c 
b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vmla_float_not_fused.c
index 18d176794f0..8f1d012230a 100644
--- a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vmla_float_not_fused.c
+++ b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vmla_float_not_fused.c
@@ -1,7 +1,5 @@
 /* { dg-do compile } */
 /* { dg-skip-if "" { arm*-*-* } } */
-/* { dg-options "-O3" } */
-
 
 #include 
 
diff --git 
a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vmls_float_not_fused.c 
b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vmls_float_not_fused.c
index 6c51d042de9..f4345644e08 100644
--- a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vmls_float_not_fused.c
+++ b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/vmls_float_not_fused.c
@@ -1,7 +1,5 @@
 /* { dg-do compile } */
 /* { dg-skip-if "" { arm*-*-* } } */
-/* { dg-options "-O3" } */
-
 
 #include 
 
-- 
2.34.1



[COMMITTED 142/146] gccrs: ast-builder: Add new methods for building structs

2025-04-05 Thread arthur . cohen
From: Arthur Cohen 

gcc/rust/ChangeLog:

* ast/rust-ast-builder.cc: Add new methods for constructing struct 
exprs.
* ast/rust-ast-builder.h: Mention how to build tuple expressions.
---
 gcc/rust/ast/rust-ast-builder.cc | 12 ++--
 gcc/rust/ast/rust-ast-builder.h  |  5 +
 2 files changed, 15 insertions(+), 2 deletions(-)

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



Re: [PATCH v2 0/4] Libsanitizer improvements

2025-04-05 Thread Aleksandar Rakic
HTEC Public

> It is mentioned in libsantizer/README.gcc :
> ```
> Both tools consist of a compiler module and a run-time library.
> The sources of the run-time library for these projects are hosted at
> https://github.com/llvm/llvm-project in the following directories:
> ```
>
> Thanks,
> Andrew

Thank you for your polite advice.

Kind regards,
Aleksandar


New Swedish PO file for 'gcc' (version 15.1-b20250316)

2025-04-05 Thread Translation Project Robot
Hello, gentle maintainer.

This is a message from the Translation Project robot.

A revised PO file for textual domain 'gcc' has been submitted
by the Swedish team of translators.  The file is available at:

https://translationproject.org/latest/gcc/sv.po

(This file, 'gcc-15.1-b20250316.sv.po', has just now been sent to you in
a separate email.)

All other PO files for your package are available in:

https://translationproject.org/latest/gcc/

Please consider including all of these in your next release, whether
official or a pretest.

Whenever you have a new distribution with a new version number ready,
containing a newer POT file, please send the URL of that distribution
tarball to the address below.  The tarball may be just a pretest or a
snapshot, it does not even have to compile.  It is just used by the
translators when they need some extra translation context.

The following HTML page has been updated:

https://translationproject.org/domain/gcc.html

If any question arises, please contact the translation coordinator.

Thank you for all your work,

The Translation Project robot, in the
name of your translation coordinator.




[COMMITTED 053/146] gccrs: allow casts from numeric types to floats

2025-04-05 Thread arthur . cohen
From: Philip Herron 

Fixes Rust-GCC#3261

gcc/rust/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron 
---
 gcc/rust/typecheck/rust-casts.cc | 10 ++
 gcc/testsuite/rust/compile/issue-3261.rs | 18 ++
 2 files changed, 28 insertions(+)
 create mode 100644 gcc/testsuite/rust/compile/issue-3261.rs

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



[PATCH] aarch64: change another CRC test

2025-04-05 Thread Sam James
Fixed the iteration number in crc-crc32-data16.c test from 8 to 16 to
match the test name, just like in r15-9038-gdf55a933cfc675.

gcc/testsuite/ChangeLog:
* gcc.target/aarch64/crc-crc32-data16.c: Fix iteration
count to match testname.
---
Do we need this as well? Untested so far.

 gcc/testsuite/gcc.target/aarch64/crc-crc32-data16.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.target/aarch64/crc-crc32-data16.c 
b/gcc/testsuite/gcc.target/aarch64/crc-crc32-data16.c
index e82cb04fcc38..7561b3ba5407 100644
--- a/gcc/testsuite/gcc.target/aarch64/crc-crc32-data16.c
+++ b/gcc/testsuite/gcc.target/aarch64/crc-crc32-data16.c
@@ -10,7 +10,7 @@ uint32_t _crc32_O0 (uint32_t crc, uint16_t data) {
   int i;
   crc = crc ^ data;
 
-  for (i = 0; i < 8; i++) {
+  for (i = 0; i < 16; i++) {
   if (crc & 1)
crc = (crc >> 1) ^ 0xEDB88320;
   else
@@ -24,7 +24,7 @@ uint32_t _crc32 (uint32_t crc, uint16_t data) {
   int i;
   crc = crc ^ data;
 
-  for (i = 0; i < 8; i++) {
+  for (i = 0; i < 16; i++) {
   if (crc & 1)
crc = (crc >> 1) ^ 0xEDB88320;
   else

base-commit: df55a933cfc675be2024b16386b96b2807464b41
-- 
2.49.0



[PATCH] libstdc++: Fix up string _M_constructor exports [PR103827]

2025-04-05 Thread Jakub Jelinek
On Thu, Mar 27, 2025 at 02:04:24PM +0100, Jan Hubicka wrote:
> > > Newline between functions please.
> > >
> > > OK with those two changes.
> > 
> > Looking back through my inbox, this one doesn't seem to have been
> > pushed. Was it superseded by something else, or is it just waiting for
> > stage 1 now?
> 
> Seems I missed the approval, sorry.  I will push it - I think it would
> be useful to have it in.
> (I have more libstdc++ work for next stage1, but solving this is IMO
> useful)

Unfortunately the exports in this patch only work on targets where size_t is
unsigned long, not e.g. on ia32 where it is unsigned int, or targets where
it is unsigned long long.

Fixed thusly, tested on x86_64-linux and i686-linux, ok for trunk?

2025-03-31  Jakub Jelinek  

PR tree-optimization/103827
PR tree-optimization/80331
PR tree-optimization/87502
* config/abi/pre/gnu.ver (GLIBCXX_3.4.34): Use [jmy] rather than m
in pattern for _M_construct(char const*, size_t).

--- libstdc++-v3/config/abi/pre/gnu.ver.jj  2025-03-31 00:01:50.579455165 
+0200
+++ libstdc++-v3/config/abi/pre/gnu.ver 2025-03-31 00:06:30.490601502 +0200
@@ -2540,9 +2540,9 @@ GLIBCXX_3.4.34 {
 
_ZNSt8__format25__locale_encoding_to_utf8ERKSt6localeSt17basic_string_viewIcSt11char_traitsIcEEPv;
 # __sso_string constructor and destructor
 _ZNSt12__sso_string[CD][12]Ev;
-# void std::__cxx11::basic_string, 
std::allocator >::_M_construct(char const*, unsigned long)
+# void std::__cxx11::basic_string, 
std::allocator >::_M_construct(char const*, size_t)
 # and wide char version
-
_ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EE12_M_constructILb[01]EEEvPK[cw]m;
+
_ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EE12_M_constructILb[01]EEEvPK[cw][jmy];
 } GLIBCXX_3.4.33;
 
 # Symbols in the support library (libsupc++) have their own tag.


Jakub



[COMMITTED 081/146] gccrs: typecheck-path: Fix typo (reciever -> receiver)

2025-04-05 Thread arthur . cohen
From: Arthur Cohen 

gcc/rust/ChangeLog:

* typecheck/rust-hir-path-probe.cc: Fix typos.
* typecheck/rust-hir-path-probe.h: Likewise.
* typecheck/rust-hir-type-check-path.cc: Likewise.
---
 gcc/rust/typecheck/rust-hir-path-probe.cc  |  4 ++--
 gcc/rust/typecheck/rust-hir-path-probe.h   |  2 +-
 gcc/rust/typecheck/rust-hir-type-check-path.cc | 10 +-
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-path-probe.cc 
b/gcc/rust/typecheck/rust-hir-path-probe.cc
index 2e9ad95dde3..1148b24b010 100644
--- a/gcc/rust/typecheck/rust-hir-path-probe.cc
+++ b/gcc/rust/typecheck/rust-hir-path-probe.cc
@@ -168,7 +168,7 @@ PathProbeType::Probe (const TyTy::BaseType *receiver,
   if (!probe_bounds)
 return probe.candidates;
 
-  if (!probe.is_reciever_generic ())
+  if (!probe.is_receiver_generic ())
 {
   std::vector> probed_bounds
= TypeBoundsProbe::Probe (receiver);
@@ -433,7 +433,7 @@ PathProbeType::union_bounds (
 }
 
 bool
-PathProbeType::is_reciever_generic () const
+PathProbeType::is_receiver_generic () const
 {
   const TyTy::BaseType *root = receiver->get_root ();
   bool receiver_is_type_param = root->get_kind () == TyTy::TypeKind::PARAM;
diff --git a/gcc/rust/typecheck/rust-hir-path-probe.h 
b/gcc/rust/typecheck/rust-hir-path-probe.h
index 09a6492596d..59ffeb114e0 100644
--- a/gcc/rust/typecheck/rust-hir-path-probe.h
+++ b/gcc/rust/typecheck/rust-hir-path-probe.h
@@ -145,7 +145,7 @@ protected:
 const std::vector> b)
 const;
 
-  bool is_reciever_generic () const;
+  bool is_receiver_generic () const;
 
   const TyTy::BaseType *receiver;
   const HIR::PathIdentSegment &search;
diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc 
b/gcc/rust/typecheck/rust-hir-type-check-path.cc
index 4746e7d730d..4c7dec1dea3 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-path.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc
@@ -354,13 +354,13 @@ TypeCheckExpr::resolve_segments (NodeId 
root_resolved_node_id,
 {
   NodeId resolved_node_id = root_resolved_node_id;
   TyTy::BaseType *prev_segment = tyseg;
-  bool reciever_is_generic = prev_segment->get_kind () == 
TyTy::TypeKind::PARAM;
-  bool reciever_is_dyn = prev_segment->get_kind () == TyTy::TypeKind::DYNAMIC;
+  bool receiver_is_generic = prev_segment->get_kind () == 
TyTy::TypeKind::PARAM;
+  bool receiver_is_dyn = prev_segment->get_kind () == TyTy::TypeKind::DYNAMIC;
 
   for (size_t i = offset; i < segments.size (); i++)
 {
   HIR::PathExprSegment &seg = segments.at (i);
-  bool probe_impls = !reciever_is_generic;
+  bool probe_impls = !receiver_is_generic;
 
   // probe the path is done in two parts one where we search impls if no
   // candidate is found then we search extensions from traits
@@ -435,7 +435,7 @@ TypeCheckExpr::resolve_segments (NodeId 
root_resolved_node_id,
}
}
 
-  if (associated_impl_block != nullptr && !reciever_is_dyn)
+  if (associated_impl_block != nullptr && !receiver_is_dyn)
{
  // associated types
  HirId impl_block_id
@@ -492,7 +492,7 @@ TypeCheckExpr::resolve_segments (NodeId 
root_resolved_node_id,
  if (tyseg->get_kind () == TyTy::TypeKind::ERROR)
return;
}
-  else if (tyseg->needs_generic_substitutions () && !reciever_is_generic)
+  else if (tyseg->needs_generic_substitutions () && !receiver_is_generic)
{
  location_t locus = seg.get_locus ();
  tyseg = SubstMapper::InferSubst (tyseg, locus);
-- 
2.45.2



[COMMITTED 029/146] gccrs: Fix bad handling for recursive type query

2025-04-05 Thread arthur . cohen
From: Philip Herron 

When resolving a type like this which is generic it causes the argument
substitution to go through bounds checking which is expected. But this
can call a type bounds probe which again calls a type query which will be
on the Impl Type on an impl block which can result in a recursive type
query which does eventually get caught and errors correctly. But this then
triggers some old error diagnositcs which are not valid error codes but old
error messages we used to catch simple errors very early on which do not
apply for this senario.

Fixes Rust-GCC#2905

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-item.cc 
(TypeCheckItem::resolve_impl_block_substitutions):
dont check for unconstrained when the self is not resolved
* typecheck/rust-hir-type-check-type.cc 
(TypeCheckType::resolve_root_path):
remove bad debug error diagnostic
* typecheck/rust-tyty-subst.cc: likewise

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron 
---
 .../typecheck/rust-hir-type-check-item.cc |   8 ++
 .../typecheck/rust-hir-type-check-type.cc |   7 +-
 gcc/rust/typecheck/rust-tyty-subst.cc |   3 -
 gcc/testsuite/rust/compile/issue-2905-1.rs|  27 
 gcc/testsuite/rust/compile/issue-2905-2.rs| 136 ++
 gcc/testsuite/rust/compile/nr2/exclude|   2 +
 6 files changed, 175 insertions(+), 8 deletions(-)
 create mode 100644 gcc/testsuite/rust/compile/issue-2905-1.rs
 create mode 100644 gcc/testsuite/rust/compile/issue-2905-2.rs

diff --git a/gcc/rust/typecheck/rust-hir-type-check-item.cc 
b/gcc/rust/typecheck/rust-hir-type-check-item.cc
index 28368d4730a..0652777c8c6 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-item.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-item.cc
@@ -724,6 +724,14 @@ TypeCheckItem::resolve_impl_block_substitutions 
(HIR::ImplBlock &impl_block,
 }
 
   TyTy::BaseType *self = TypeCheckType::Resolve (impl_block.get_type ().get 
());
+  if (self->is ())
+{
+  // we cannot check for unconstrained type arguments when the Self type is
+  // not resolved it will just add extra errors that dont help as well as
+  // the case where this could just be a recursive type query that should
+  // fail and will work later on anyway
+  return {substitutions, region_constraints};
+}
 
   // inherit the bounds
   if (!specified_bound.is_error ())
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc 
b/gcc/rust/typecheck/rust-hir-type-check-type.cc
index ee17e53eb30..0ff4ac45247 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc
@@ -426,11 +426,8 @@ TypeCheckType::resolve_root_path (HIR::TypePath &path, 
size_t *offset,
   if (!query_type (ref, &lookup))
{
  if (is_root)
-   {
- rust_error_at (seg->get_locus (),
-"failed to resolve root segment");
- return new TyTy::ErrorType (path.get_mappings ().get_hirid ());
-   }
+   return new TyTy::ErrorType (path.get_mappings ().get_hirid ());
+
  return root_tyty;
}
 
diff --git a/gcc/rust/typecheck/rust-tyty-subst.cc 
b/gcc/rust/typecheck/rust-tyty-subst.cc
index a3ebf0aa8d5..575f04a3030 100644
--- a/gcc/rust/typecheck/rust-tyty-subst.cc
+++ b/gcc/rust/typecheck/rust-tyty-subst.cc
@@ -634,8 +634,6 @@ SubstitutionRef::get_mappings_from_generic_args (
  if (resolved == nullptr
  || resolved->get_kind () == TyTy::TypeKind::ERROR)
{
- rust_error_at (binding.get_locus (),
-"failed to resolve type arguments");
  return SubstitutionArgumentMappings::error ();
}
 
@@ -701,7 +699,6 @@ SubstitutionRef::get_mappings_from_generic_args (
   BaseType *resolved = Resolver::TypeCheckType::Resolve (arg.get ());
   if (resolved == nullptr || resolved->get_kind () == 
TyTy::TypeKind::ERROR)
{
- rust_error_at (args.get_locus (), "failed to resolve type arguments");
  return SubstitutionArgumentMappings::error ();
}
 
diff --git a/gcc/testsuite/rust/compile/issue-2905-1.rs 
b/gcc/testsuite/rust/compile/issue-2905-1.rs
new file mode 100644
index 000..9b0c19da9bb
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-2905-1.rs
@@ -0,0 +1,27 @@
+#![feature(lang_items)]
+
+#[lang = "sized"]
+trait Sized {}
+
+pub struct A(T);
+
+pub trait B {
+type C;
+}
+
+// --
+// swap these two items
+
+impl B for i32 {
+type C = Weird;
+}
+
+pub struct Weird(A<(T,)>);
+
+// --
+
+trait Foo {}
+
+impl Foo for Weird {}
+
+fn main() {}
diff --git a/gcc/testsuite/rust/compile/issue-2905-2.rs 
b/gcc/testsuite/rust/compile/issue-2905-2.rs
new file mode 100644
index 0

[COMMITTED 113/146] gccrs: gcc/rust/ChangeLog:

2025-04-05 Thread arthur . cohen
From: Om Swaroop Nayak <96killera...@gmail.com>

* ast/rust-collect-lang-items.cc (get_lang_item_attr): "removed checker 
fn"
* util/rust-attributes.cc (Attributes::is_lang_item): "added fn"
* util/rust-attributes.h: "added fn"

Signed-off-by: Om Swaroop Nayak <96killera...@gmail.com>
---
 gcc/rust/ast/rust-collect-lang-items.cc | 7 +--
 gcc/rust/util/rust-attributes.cc| 8 
 gcc/rust/util/rust-attributes.h | 2 ++
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/gcc/rust/ast/rust-collect-lang-items.cc 
b/gcc/rust/ast/rust-collect-lang-items.cc
index 50d134a429f..ec6919dca14 100644
--- a/gcc/rust/ast/rust-collect-lang-items.cc
+++ b/gcc/rust/ast/rust-collect-lang-items.cc
@@ -40,12 +40,7 @@ get_lang_item_attr (const T &maybe_lang_item)
  continue;
}
 
-  bool is_lang_item = str_path == Values::Attributes::LANG
- && attr.has_attr_input ()
- && attr.get_attr_input ().get_attr_input_type ()
-  == AST::AttrInput::AttrInputType::LITERAL;
-
-  if (is_lang_item)
+  if (Analysis::Attributes::is_lang_item (str_path, attr))
{
  auto &literal
= static_cast (attr.get_attr_input ());
diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc
index 9f63234112c..0234903ba58 100644
--- a/gcc/rust/util/rust-attributes.cc
+++ b/gcc/rust/util/rust-attributes.cc
@@ -37,6 +37,14 @@ Attributes::is_known (const std::string &attribute_path)
 
   return !lookup.is_error ();
 }
+bool
+Attributes::is_lang_item (const std::string &attribute_path,
+ const AST::Attribute &attr)
+{
+  return ((attribute_path == Values::Attributes::LANG) && attr.has_attr_input 
()
+ && (attr.get_attr_input ().get_attr_input_type ()
+ == AST::AttrInput::AttrInputType::LITERAL));
+}
 
 using Attrs = Values::Attributes;
 
diff --git a/gcc/rust/util/rust-attributes.h b/gcc/rust/util/rust-attributes.h
index c928c8eb9d2..30f9eef213b 100644
--- a/gcc/rust/util/rust-attributes.h
+++ b/gcc/rust/util/rust-attributes.h
@@ -29,6 +29,8 @@ class Attributes
 {
 public:
   static bool is_known (const std::string &attribute_path);
+  static bool is_lang_item (const std::string &attribute_path,
+   const AST::Attribute &attr);
 };
 
 enum CompilerPass
-- 
2.45.2



[COMMITTED 067/146] gccrs: attributes: Add class for sharing methods on attributes.

2025-04-05 Thread arthur . cohen
From: Arthur Cohen 

gcc/rust/ChangeLog:

* util/rust-attributes.h (class Attributes): New.
* util/rust-attributes.cc: Implement Attributes::is_known().
* ast/rust-collect-lang-items.cc (is_known_attribute): Remove.
(get_lang_item_attr): Call Attributes::is_known() instead.
* hir/rust-ast-lower-base.cc 
(ASTLoweringBase::handle_outer_attributes): Likewise.
(ASTLoweringBase::is_known_attribute): Remove.
---
 gcc/rust/ast/rust-collect-lang-items.cc | 13 +
 gcc/rust/hir/rust-ast-lower-base.cc | 10 ++
 gcc/rust/util/rust-attributes.cc|  9 +
 gcc/rust/util/rust-attributes.h |  6 ++
 4 files changed, 18 insertions(+), 20 deletions(-)

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



[PATCH 2/2] GCN: Don't emit weak undefined symbols [PR119369]

2025-04-05 Thread Thomas Schwinge
This resolves all instances of PR119369
"GCN: weak undefined symbols -> execution test FAIL, 
'HSA_STATUS_ERROR_VARIABLE_UNDEFINED'";
for all affected test cases, the execution test status progresses FAIL -> PASS.

This however also causes a small number of (expected) regressions, very similar
to GCC/nvptx:

[-PASS:-]{+FAIL:+} g++.dg/abi/pure-virtual1.C  -std=c++17 (test for excess 
errors)
[-PASS:-]{+FAIL:+} g++.dg/abi/pure-virtual1.C  -std=c++26 (test for excess 
errors)
[-PASS:-]{+FAIL:+} g++.dg/abi/pure-virtual1.C  -std=c++98 (test for excess 
errors)

[-PASS:-]{+FAIL:+} g++.dg/cpp0x/pr84497.C  -std=c++11  scan-assembler 
.weak[ \t]*_?_ZTH11derived_obj
[-PASS:-]{+FAIL:+} g++.dg/cpp0x/pr84497.C  -std=c++11  scan-assembler 
.weak[ \t]*_?_ZTH13container_obj
[-PASS:-]{+FAIL:+} g++.dg/cpp0x/pr84497.C  -std=c++11  scan-assembler 
.weak[ \t]*_?_ZTH8base_obj
PASS: g++.dg/cpp0x/pr84497.C  -std=c++11 (test for excess errors)
[-PASS:-]{+FAIL:+} g++.dg/cpp0x/pr84497.C  -std=c++17  scan-assembler 
.weak[ \t]*_?_ZTH11derived_obj
[-PASS:-]{+FAIL:+} g++.dg/cpp0x/pr84497.C  -std=c++17  scan-assembler 
.weak[ \t]*_?_ZTH13container_obj
[-PASS:-]{+FAIL:+} g++.dg/cpp0x/pr84497.C  -std=c++17  scan-assembler 
.weak[ \t]*_?_ZTH8base_obj
PASS: g++.dg/cpp0x/pr84497.C  -std=c++17 (test for excess errors)
[-PASS:-]{+FAIL:+} g++.dg/cpp0x/pr84497.C  -std=c++26  scan-assembler 
.weak[ \t]*_?_ZTH11derived_obj
[-PASS:-]{+FAIL:+} g++.dg/cpp0x/pr84497.C  -std=c++26  scan-assembler 
.weak[ \t]*_?_ZTH13container_obj
[-PASS:-]{+FAIL:+} g++.dg/cpp0x/pr84497.C  -std=c++26  scan-assembler 
.weak[ \t]*_?_ZTH8base_obj
PASS: g++.dg/cpp0x/pr84497.C  -std=c++26 (test for excess errors)

[-PASS:-]{+FAIL:+} g++.dg/ext/weak2.C  -std=gnu++17  scan-assembler weak[^ 
\t]*[ \t]_?_Z3foov
PASS: g++.dg/ext/weak2.C  -std=gnu++17 (test for excess errors)
[-PASS:-]{+FAIL:+} g++.dg/ext/weak2.C  -std=gnu++26  scan-assembler weak[^ 
\t]*[ \t]_?_Z3foov
PASS: g++.dg/ext/weak2.C  -std=gnu++26 (test for excess errors)
[-PASS:-]{+FAIL:+} g++.dg/ext/weak2.C  -std=gnu++98  scan-assembler weak[^ 
\t]*[ \t]_?_Z3foov
PASS: g++.dg/ext/weak2.C  -std=gnu++98 (test for excess errors)

[-PASS:-]{+FAIL:+} gcc.dg/attr-weakref-1.c (test for excess errors)
[-FAIL:-]{+UNRESOLVED:+} gcc.dg/attr-weakref-1.c [-execution 
test-]{+compilation failed to produce executable+}

@@ -131211,25 +131211,25 @@ PASS: gcc.dg/weak/weak-1.c scan-assembler 
weak[^ \t]*[ \t]_?c
PASS: gcc.dg/weak/weak-1.c scan-assembler weak[^ \t]*[ \t]_?d
PASS: gcc.dg/weak/weak-1.c scan-assembler weak[^ \t]*[ \t]_?e
PASS: gcc.dg/weak/weak-1.c scan-assembler weak[^ \t]*[ \t]_?g
[-PASS:-]{+FAIL:+} gcc.dg/weak/weak-1.c scan-assembler weak[^ \t]*[ \t]_?j
PASS: gcc.dg/weak/weak-1.c scan-assembler-not weak[^ \t]*[ \t]_?i

PASS: gcc.dg/weak/weak-12.c (test for excess errors)
[-PASS:-]{+FAIL:+} gcc.dg/weak/weak-12.c scan-assembler weak[^ \t]*[ 
\t]_?foo

PASS: gcc.dg/weak/weak-15.c (test for excess errors)
[-PASS:-]{+FAIL:+} gcc.dg/weak/weak-15.c scan-assembler weak[^ \t]*[ \t]_?a
[-PASS:-]{+FAIL:+} gcc.dg/weak/weak-15.c scan-assembler weak[^ \t]*[ \t]_?c
[-PASS:-]{+FAIL:+} gcc.dg/weak/weak-15.c scan-assembler weak[^ \t]*[ \t]_?d
PASS: gcc.dg/weak/weak-15.c scan-assembler-not weak[^ \t]*[ \t]_?b

PASS: gcc.dg/weak/weak-16.c (test for excess errors)
[-PASS:-]{+FAIL:+} gcc.dg/weak/weak-16.c scan-assembler weak[^ \t]*[ 
\t]_?kallsyms_token_index
[-PASS:-]{+FAIL:+} gcc.dg/weak/weak-16.c scan-assembler weak[^ \t]*[ 
\t]_?kallsyms_token_table
PASS: gcc.dg/weak/weak-2.c (test for excess errors)
[-PASS:-]{+FAIL:+} gcc.dg/weak/weak-2.c scan-assembler weak[^ \t]*[ 
\t]_?ffoo1a
[-PASS:-]{+FAIL:+} gcc.dg/weak/weak-2.c scan-assembler weak[^ \t]*[ 
\t]_?ffoo1b
[-PASS:-]{+FAIL:+} gcc.dg/weak/weak-2.c scan-assembler weak[^ \t]*[ 
\t]_?ffoo1c
[-PASS:-]{+FAIL:+} gcc.dg/weak/weak-2.c scan-assembler weak[^ \t]*[ 
\t]_?ffoo1e
PASS: gcc.dg/weak/weak-2.c scan-assembler-not weak[^ \t]*[ \t]_?ffoo1d

PASS: gcc.dg/weak/weak-3.c  (test for warnings, line 58)
PASS: gcc.dg/weak/weak-3.c  (test for warnings, line 73)
PASS: gcc.dg/weak/weak-3.c (test for excess errors)
[-PASS:-]{+FAIL:+} gcc.dg/weak/weak-3.c scan-assembler weak[^ \t]*[ 
\t]_?ffoo1a
[-PASS:-]{+FAIL:+} gcc.dg/weak/weak-3.c scan-assembler weak[^ \t]*[ 
\t]_?ffoo1b
[-PASS:-]{+FAIL:+} gcc.dg/weak/weak-3.c scan-assembler weak[^ \t]*[ 
\t]_?ffoo1c
[-PASS:-]{+FAIL:+} gcc.dg/weak/weak-3.c scan-assembler weak[^ \t]*[ 
\t]_?ffoo1e
PASS: gcc.dg/weak/weak-3.c scan-assembler weak[^ \t]*[ \t]_?ffoo1f
PASS: gcc.dg/weak/weak-3.c scan-assembler weak[^ \t]*[ \t]_?ffoo1g
PASS: gcc.dg/weak/weak-3.c scan-assembler-not weak[^ \t]*[ \t]_?ffoo1d

PASS: gcc.dg/weak/weak-4.c (test for excess errors)
[-PASS:-]{+FAIL:+} gcc.dg/weak/weak-4.c scan-assembler weak[^ \t]*[ 
\t]_?vfoo1a
[-PASS:-]{

[COMMITTED 132/144] gccrs: Allow identifiers and paths to reference types during nr2.0

2025-04-05 Thread arthur . cohen
From: Owen Avery 

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Allow IdentifierExpr and PathInExpression to
reference types as well as values, remove ability for
IdentifierExpr to reference labels.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery 
---
 .../resolve/rust-late-name-resolver-2.0.cc| 35 +--
 gcc/testsuite/rust/compile/nr2/exclude|  4 ---
 2 files changed, 24 insertions(+), 15 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 c58cd967c97..daf0c871a62 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -164,16 +164,14 @@ Late::visit (AST::IdentifierExpr &expr)
   // TODO: same thing as visit(PathInExpression) here?
 
   tl::optional resolved = tl::nullopt;
-  auto label = ctx.labels.get (expr.get_ident ());
-  auto value = ctx.values.get (expr.get_ident ());
 
-  if (label)
+  if (auto value = ctx.values.get (expr.get_ident ()))
 {
-  resolved = label;
+  resolved = value;
 }
-  else if (value)
+  else if (auto type = ctx.types.get (expr.get_ident ()))
 {
-  resolved = value;
+  resolved = type;
 }
   else
 {
@@ -202,18 +200,33 @@ Late::visit (AST::PathInExpression &expr)
   // do we emit it in `get`?
 
   rust_debug ("[ARTHUR]: %s", expr.as_simple_path ().as_string ().c_str ());
-  auto value = ctx.values.resolve_path (expr.get_segments ());
-  if (!value.has_value ())
-rust_unreachable (); // Should have been resolved earlier
 
-  if (value->is_ambiguous ())
+  tl::optional resolved = tl::nullopt;
+
+  if (auto value = ctx.values.resolve_path (expr.get_segments ()))
+{
+  resolved = value;
+}
+  else if (auto type = ctx.types.resolve_path (expr.get_segments ()))
+{
+  resolved = type;
+}
+  else
+{
+  rust_error_at (expr.get_locus (),
+"could not resolve path expression: %qs",
+expr.as_simple_path ().as_string ().c_str ());
+  return;
+}
+
+  if (resolved->is_ambiguous ())
 {
   rust_error_at (expr.get_locus (), ErrorCode::E0659, "%qs is ambiguous",
 expr.as_string ().c_str ());
   return;
 }
   ctx.map_usage (Usage (expr.get_node_id ()),
-Definition (value->get_node_id ()));
+Definition (resolved->get_node_id ()));
 }
 
 void
diff --git a/gcc/testsuite/rust/compile/nr2/exclude 
b/gcc/testsuite/rust/compile/nr2/exclude
index 6c7d5041291..f91cf3132c7 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -45,7 +45,6 @@ feature_rust_attri0.rs
 feature_rust_attri1.rs
 for_lifetimes.rs
 format_args_basic_expansion.rs
-found_struct.rs
 generic-default1.rs
 generics1.rs
 generics10.rs
@@ -145,10 +144,8 @@ match2.rs
 match3.rs
 match4.rs
 match5.rs
-match8.rs
 match9.rs
 method2.rs
-missing_constructor_fields.rs
 multi_reference_type.rs
 multiple_bindings1.rs
 multiple_bindings2.rs
@@ -203,7 +200,6 @@ traits6.rs
 traits7.rs
 traits8.rs
 traits9.rs
-tuple_struct1.rs
 type-bindings1.rs
 unconstrained_type_param.rs
 undeclared_label.rs
-- 
2.45.2



[PATCH 2/2] libgomp: Add AArch64 SVE target tests to libgomp.

2025-04-05 Thread Tejas Belagod
Add AArch64 SVE target exectute tests to test various workshare constructs and
clauses with SVE types.

libgomp/ChangeLog:

* testsuite/libgomp.c-target/aarch64/aarch64.exp: Test driver.
* testsuite/libgomp.c-target/aarch64/firstprivate.c: New test.
* testsuite/libgomp.c-target/aarch64/lastprivate.c: Likewise.
* testsuite/libgomp.c-target/aarch64/private.c: Likewise.
* testsuite/libgomp.c-target/aarch64/shared.c: Likewise.
* testsuite/libgomp.c-target/aarch64/simd-aligned.c: Likewise.
* testsuite/libgomp.c-target/aarch64/simd-nontemporal.c: Likewise.
* testsuite/libgomp.c-target/aarch64/threadprivate.c: Likewise.
* testsuite/libgomp.c-target/aarch64/udr-sve.c: Likewise.
---
 .../libgomp.c-target/aarch64/aarch64.exp  |  57 
 .../libgomp.c-target/aarch64/firstprivate.c   | 128 +
 .../libgomp.c-target/aarch64/lastprivate.c| 171 +++
 .../libgomp.c-target/aarch64/private.c| 111 
 .../libgomp.c-target/aarch64/shared.c | 269 ++
 .../libgomp.c-target/aarch64/simd-aligned.c   |  52 
 .../aarch64/simd-nontemporal.c|  51 
 .../libgomp.c-target/aarch64/threadprivate.c  |  48 
 .../libgomp.c-target/aarch64/udr-sve.c| 108 +++
 9 files changed, 995 insertions(+)
 create mode 100644 libgomp/testsuite/libgomp.c-target/aarch64/aarch64.exp
 create mode 100644 libgomp/testsuite/libgomp.c-target/aarch64/firstprivate.c
 create mode 100644 libgomp/testsuite/libgomp.c-target/aarch64/lastprivate.c
 create mode 100644 libgomp/testsuite/libgomp.c-target/aarch64/private.c
 create mode 100644 libgomp/testsuite/libgomp.c-target/aarch64/shared.c
 create mode 100644 libgomp/testsuite/libgomp.c-target/aarch64/simd-aligned.c
 create mode 100644 
libgomp/testsuite/libgomp.c-target/aarch64/simd-nontemporal.c
 create mode 100644 libgomp/testsuite/libgomp.c-target/aarch64/threadprivate.c
 create mode 100644 libgomp/testsuite/libgomp.c-target/aarch64/udr-sve.c

diff --git a/libgomp/testsuite/libgomp.c-target/aarch64/aarch64.exp 
b/libgomp/testsuite/libgomp.c-target/aarch64/aarch64.exp
new file mode 100644
index 000..02d5503c48b
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c-target/aarch64/aarch64.exp
@@ -0,0 +1,57 @@
+# Copyright (C) 2006-2025 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
+# .
+
+# Load support procs.
+load_lib libgomp-dg.exp
+load_gcc_lib gcc-dg.exp
+
+# Exit immediately if this isn't an AArch64 target.
+if {![istarget aarch64*-*-*] } then {
+  return
+}
+
+lappend ALWAYS_CFLAGS "compiler=$GCC_UNDER_TEST"
+
+if { [check_effective_target_aarch64_sve] } {
+set sve_flags ""
+} else {
+set sve_flags "-march=armv8.2-a+sve"
+}
+
+# Initialize `dg'.
+dg-init
+
+#if ![check_effective_target_fopenmp] {
+#  return
+#}
+
+# Turn on OpenMP.
+lappend ALWAYS_CFLAGS "additional_flags=-fopenmp"
+
+# Gather a list of all tests.
+set tests [lsort [find $srcdir/$subdir *.c]]
+
+set ld_library_path $always_ld_library_path
+append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
+set_ld_library_path_env_vars
+
+# Main loop.
+dg-runtest $tests "" $sve_flags
+
+# All done.
+dg-finish
diff --git a/libgomp/testsuite/libgomp.c-target/aarch64/firstprivate.c 
b/libgomp/testsuite/libgomp.c-target/aarch64/firstprivate.c
new file mode 100644
index 000..4737d93e5b6
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c-target/aarch64/firstprivate.c
@@ -0,0 +1,128 @@
+/* { dg-do run { target aarch64_sve256_hw } } */
+/* { dg-options "-msve-vector-bits=256 -fopenmp -O2" } */
+
+#include 
+
+extern int omp_get_thread_num (void);
+
+static void __attribute__((noipa))
+vec_compare (svint32_t *x, svint32_t y)
+{
+  svbool_t p = svnot_b_z (svptrue_b32 (), svcmpeq_s32 (svptrue_b32 (), *x, y));
+
+  if (svptest_any (svptrue_b32 (), p))
+__builtin_abort ();
+}
+
+void  __attribute__ ((noipa))
+omp_firstprivate_sections ()
+{
+  int b[8], c[8];
+  svint32_t vb, vc;
+  int i;
+
+#pragma omp parallel for
+  for (i = 0; i < 8; i++)
+{
+  b[i] = i;
+  c[i] = i + 1;
+}
+
+  vb = svld1_s32 (svptrue_b32 (), b);
+  vc = svld1_s32 (svptrue_b32 (), c);
+
+#pragma omp parallel sections firstprivate (vb, vc)
+  {
+#pragma omp section
+vec_compare (&vb, svindex_s32 (0, 1));
+vec_compare (&vc, svindex_s32 (1, 1

[COMMITTED 086/146] gccrs: lang-item: Add Option::{None, Some}, Iterator::next, IntoIter::into_iter

2025-04-05 Thread arthur . cohen
From: Arthur Cohen 

gcc/rust/ChangeLog:

* util/rust-lang-item.h: Add new lang items.
* util/rust-lang-item.cc: Likewise.
---
 gcc/rust/util/rust-lang-item.cc | 6 ++
 gcc/rust/util/rust-lang-item.h  | 9 +
 2 files changed, 15 insertions(+)

diff --git a/gcc/rust/util/rust-lang-item.cc b/gcc/rust/util/rust-lang-item.cc
index 216202af926..c4c1d1c093a 100644
--- a/gcc/rust/util/rust-lang-item.cc
+++ b/gcc/rust/util/rust-lang-item.cc
@@ -92,6 +92,12 @@ const BiMap 
Rust::LangItem::lang_items = {{
   {"str", Kind::STR},
   {"f32_runtime", Kind::F32_RUNTIME},
   {"f64_runtime", Kind::F64_RUNTIME},
+
+  {"Some", Kind::OPTION_SOME},
+  {"None", Kind::OPTION_NONE},
+
+  {"into_iter", Kind::INTOITER_INTOITER},
+  {"next", Kind::ITERATOR_NEXT},
 }};
 
 tl::optional
diff --git a/gcc/rust/util/rust-lang-item.h b/gcc/rust/util/rust-lang-item.h
index 66d26d03907..9e432e2ccc6 100644
--- a/gcc/rust/util/rust-lang-item.h
+++ b/gcc/rust/util/rust-lang-item.h
@@ -26,6 +26,9 @@ namespace Rust {
 class LangItem
 {
 public:
+  // FIXME: We should clean up that enum to make it more inline with the list 
of
+  // lang-items in Rust 1.49
+  // 
https://github.com/rust-lang/rust/blob/1.49.0/compiler/rustc_hir/src/lang_items.rs
   enum class Kind
   {
 // 
https://github.com/rust-lang/rust/blob/master/library/core/src/ops/arith.rs
@@ -117,6 +120,12 @@ public:
 STR,
 F32_RUNTIME,
 F64_RUNTIME,
+
+OPTION_SOME,
+OPTION_NONE,
+
+INTOITER_INTOITER,
+ITERATOR_NEXT,
   };
 
   static const BiMap lang_items;
-- 
2.45.2



Re: [PATCH] gcc_release: Generate srcdir extras/infos/man pages from all FEs [PR119510]

2025-04-05 Thread Richard Biener
On Mon, 31 Mar 2025, Andreas Schwab wrote:

> On Mär 31 2025, Richard Biener wrote:
> 
> > Do we even install libffi.info?
> 
> We shouldn't.  It would conflict with the standalone libffi library, and
> we don't install anything from the target libffi library anyway (it's
> only used internally).

Indeed.

target_modules = { module= libffi; no_install=true;
   extra_configure_flags='--disable-shared --with-pic'; };

It looks like the docs are only built when makeinfo is modern:

# See if makeinfo has been installed and is modern enough
# that we can use it.
ACX_CHECK_PROG_VER([MAKEINFO], [makeinfo], [--version],
   [GNU texinfo.* \([0-9][0-9.]*\)],
   [4.[4-9]*|4.[1-9][0-9]*|[5-9]*|[1-9][0-9]*])
AM_CONDITIONAL(BUILD_DOCS, test $gcc_cv_prog_makeinfo_modern = "yes")

so without makeinfo the build might not fail w/o the generated file.

Richard.

Re: [PATCH] cobol: Make CXXFLAGS_FOR_TARGET available to the libgcobol build.

2025-04-05 Thread Richard Biener
On Fri, Mar 21, 2025 at 4:56 AM Robert Dubner  wrote:
>
> I seek benediction.  Failing that, I ask for advice.
>
> This patch makes it possible for me to set the environment variable
> 'CXXFLAGS_FOR_TARGET="-ggdb -O0"' at configure time, and end up with a
> debuggable libgcobol.so.
>
> Is this a correct way to gain that capability?

In principle the recursive make invocation should set
CXXFLAGS=$(CXXFLAGS_FOR_TARGET) already:

maybe-all-target-libgcobol:
TARGET-target-libgcobol=all
maybe-all-target-libgcobol: all-target-libgcobol
all-target-libgcobol: configure-target-libgcobol
@: $(MAKE); $(unstage)
@r=`${PWD_COMMAND}`; export r; \
s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
$(NORMAL_TARGET_EXPORTS)  \
(cd $(TARGET_SUBDIR)/libgcobol && \
  $(MAKE) $(BASE_FLAGS_TO_PASS) $(EXTRA_TARGET_FLAGS)   \
$(TARGET-target-libgcobol))

and EXTRA_TARGET_FLAGS includes

'CXXFLAGS=$$(CXXFLAGS_FOR_TARGET)' \

Some Makefile.am have sth like the following (but not libgomp for example):

# Work around what appears to be a GNU make  handling MAKEFLAGS
# values defined in terms of make variables, as is the case for CC and
# friends when we are called from the top level Makefile.
AM_MAKEFLAGS = \
"AR_FLAGS=$(AR_FLAGS)" \
"CC_FOR_BUILD=$(CC_FOR_BUILD)" \
"CC_FOR_TARGET=$(CC_FOR_TARGET)" \
"CFLAGS=$(CFLAGS)" \
"CXXFLAGS=$(CXXFLAGS)" \
"CFLAGS_FOR_BUILD=$(CFLAGS_FOR_BUILD)" \
"CFLAGS_FOR_TARGET=$(CFLAGS_FOR_TARGET)" \
"GOC_FOR_TARGET=$(GOC_FOR_TARGET)" \
"GOC=$(GOC)" \
"GOCFLAGS=$(GOCFLAGS)" \
"INSTALL=$(INSTALL)" \
"INSTALL_DATA=$(INSTALL_DATA)" \
"INSTALL_PROGRAM=$(INSTALL_PROGRAM)" \
"INSTALL_SCRIPT=$(INSTALL_SCRIPT)" \
"LDFLAGS=$(LDFLAGS)" \
"LIBCFLAGS=$(LIBCFLAGS)" \
"LIBCFLAGS_FOR_TARGET=$(LIBCFLAGS_FOR_TARGET)" \
"MAKE=$(MAKE)" \
"MAKEINFO=$(MAKEINFO) $(MAKEINFOFLAGS)" \
"PICFLAG=$(PICFLAG)" \
"PICFLAG_FOR_TARGET=$(PICFLAG_FOR_TARGET)" \
"SHELL=$(SHELL)" \
"RUNTESTFLAGS=$(RUNTESTFLAGS)" \
"exec_prefix=$(exec_prefix)" \
"infodir=$(infodir)" \
"libdir=$(libdir)" \
"includedir=$(includedir)" \
"prefix=$(prefix)" \
"tooldir=$(tooldir)" \
"gxx_include_dir=$(gxx_include_dir)" \
"AR=$(AR)" \
"AS=$(AS)" \
"LD=$(LD)" \
"RANLIB=$(RANLIB)" \
"NM=$(NM)" \
"NM_FOR_BUILD=$(NM_FOR_BUILD)" \
"NM_FOR_TARGET=$(NM_FOR_TARGET)" \
"DESTDIR=$(DESTDIR)" \
"WERROR=$(WERROR)"


> If not, then how?
>
> If so, then OK for trunk?
>
> Thanks all.
>
> From c03774e34bde193da7f80eea53b49915e311df0d Mon Sep 17 00:00:00 2001
> From: Bob Dubner mailto:rdub...@symas.com
> Date: Thu, 20 Mar 2025 23:44:12 -0400
> Subject: [PATCH] cobol: Make CXXFLAGS_FOR_TARGET available to the
> libgcobol
>  build.
>
> By setting "CXXFLAGS_FOR_TARGET=-ggdb -O0", a debuggable version
> of libgcobol.so is created.
>
> libgcobol
>
> * Makefile.am: Incorporate AM_CXXFLAGS = $(CXXFLAGS_FOR_TARGET).
> * Makefile.in: Regenerated.
> ---
>  libgcobol/Makefile.am | 2 ++
>  libgcobol/Makefile.in | 1 +
>  2 files changed, 3 insertions(+)
>
> diff --git a/libgcobol/Makefile.am b/libgcobol/Makefile.am
> index eddf209807e6..2bd634f30d4c 100644
> --- a/libgcobol/Makefile.am
> +++ b/libgcobol/Makefile.am
> @@ -52,6 +52,8 @@ libgcobol_la_LINK = $(LIBTOOL) --mode=link --tag=CXX
> $(CXX)  \
>
>  WARN_CFLAGS = -W -Wall -Wwrite-strings
>
> +AM_CXXFLAGS =$(CXXFLAGS_FOR_TARGET)
> +
>  # not defined: DEFS, MAX_ERRORS, LTLDFLAGS
>  ALL_CXXFLAGS = -I. -I$(srcdir) $(AM_CPPFLAGS) $(DEFS)  \
> $(XCFLAGS) $(AM_CXXFLAGS) $(WARN_CFLAGS) $(MAX_ERRORS)  \
> diff --git a/libgcobol/Makefile.in b/libgcobol/Makefile.in
> index a6096d2a64aa..6f3ef0750114 100644
> --- a/libgcobol/Makefile.in
> +++ b/libgcobol/Makefile.in
> @@ -425,6 +425,7 @@ libgcobol_la_LINK = $(LIBTOOL) --mode=link --tag=CXX
> $(CXX)  \
> $(LTLDFLAGS)
>
>  WARN_CFLAGS = -W -Wall -Wwrite-strings
> +AM_CXXFLAGS = $(CXXFLAGS_FOR_TARGET)
>
>  # not defined: DEFS, MAX_ERRORS, LTLDFLAGS
>  ALL_CXXFLAGS = -I. -I$(srcdir) $(AM_CPPFLAGS) $(DEFS)  \
> --
> 2.34.1
>


[PATCH 03/10] testsuite: aarch64: restore torture options in bf16_dup.c

2025-04-05 Thread Christophe Lyon
Remove dg-options, so that the test is executed as expected using the
options defined by advsimd-intrinsics.exp.
(Previously we pretend we do, but in fact all torture options are
silently overriden with -O2)

We skip it at -O0, because the tested optimizations does not take
place at this level.

gcc/testsuite/
* gcc.target/aarch64/advsimd-intrinsics/bf16_dup.c: Remove
dg-options.
---
 gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bf16_dup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bf16_dup.c 
b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bf16_dup.c
index c42c7acbbe9..da9370ba52b 100644
--- a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bf16_dup.c
+++ b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/bf16_dup.c
@@ -1,6 +1,6 @@
 /* { dg-do assemble { target { aarch64*-*-* } } } */
+/* { dg-skip-if "no optimizations" { *-*-* } { "-O0" } { "" } } */
 /* { dg-require-effective-target arm_v8_2a_bf16_neon_ok } */
-/* { dg-options "-O2" } */
 /* { dg-add-options arm_v8_2a_bf16_neon }  */
 /* { dg-additional-options "-save-temps" } */
 
-- 
2.34.1



Re: [PATCH][RFC] [cobol] change cbl_field_data_t::etc_t::value from _Float128 to tree

2025-04-05 Thread Jakub Jelinek
On Tue, Mar 25, 2025 at 01:01:59PM -0400, James K. Lowden wrote:
> (I'm sure that's true.  In my defense, the nonterminal is named
> "count", and the comment is 
> 
>   // verify not floating point with nonzero fraction
> 
> but I admit that's not a lot to go on.)
> 
> Let me clarify.  :-) 
> 
> What we're dealing with here is an array subscript.   When the constant
> compile-time expression is parsed, we don't know how it will be used;
> we find out only when it's used as a subscript.  As an array subscript,
> it can't be negative, fractional, or larger than the target's address
> space.   
> 
> In fact, we shouldn't use floating point for numeric literals. We
> grabbed _Float128 because it was available and served our purpose. Per
> the ISO specification, though, numeric literals are not floating point.
> They are fixed-point.  
> 
> Given considerations like -0.0 and infinities and NaNs, perhaps we're
> better off switching to FIXED_POINT_TYPE, where they don't apply.  
> 
> If we just check for a positive integral value not too big, that should
> suffice for now.  Once we switch to fixed point, it will be correct.  
> 
> How does that sound?  

So, if it is an array subscript, it needs to be something that fits
into the target size_t, so TYPE_PRECISION (size_type_node) is the right
precision for use there.

Plus the question is if one can actually see infinities or NaNs in the value
or if something ensures those don't appear.
E.g. if one specifies a really large constant whether it isn't turned into
infinity (and then would cause UB on the size_t(...) cast).

Jakub



[COMMITTED 24/35] gccrs: Add new test to highlight namespace for self import

2025-04-05 Thread arthur . cohen
From: Pierre-Emmanuel Patry 

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry 
---
 .../rust/compile/self_import_namespace.rs  | 14 ++
 1 file changed, 14 insertions(+)
 create mode 100644 gcc/testsuite/rust/compile/self_import_namespace.rs

diff --git a/gcc/testsuite/rust/compile/self_import_namespace.rs 
b/gcc/testsuite/rust/compile/self_import_namespace.rs
new file mode 100644
index 000..2d9b2ed8e0f
--- /dev/null
+++ b/gcc/testsuite/rust/compile/self_import_namespace.rs
@@ -0,0 +1,14 @@
+// { dg-additional-options "-frust-name-resolution-2.0" }
+
+mod bar {
+pub mod foo {}
+pub fn foo() {}
+}
+
+// This only imports the module `foo`. The function `foo` lives in
+// the value namespace and is not imported.
+use bar::foo::{self};
+
+fn main() {
+foo(); // { dg-error "expected value" }
+}
-- 
2.49.0



[COMMITTED 102/146] gccrs: add support for lang_item eq and PartialEq trait

2025-04-05 Thread arthur . cohen
From: Philip Herron 

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

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

Fixes Rust-GCC#3302

gcc/rust/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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

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

[PATCH v2 3/7] MIPSR6: Fix ICE occurred in R6 target

2025-04-05 Thread Aleksandar Rakic
From: Jaydeep Patil 

Fix ICE occurred in R6 target due to a clobber-list introduced in
MADD/MSUB during combine pass.

gcc/
* config/mips/mips.md: Define new splitters for MADD/MSUB on
the r6 target.

Cherry-picked 180f74c8ebdf13ddac806695d0333af7b924c402
from https://github.com/MIPS/gcc

Signed-off-by: Jaydeep Patil 
Signed-off-by: Faraz Shahbazker 
Signed-off-by: Aleksandar Rakic 
---
 gcc/config/mips/mips.md | 26 ++
 1 file changed, 26 insertions(+)

diff --git a/gcc/config/mips/mips.md b/gcc/config/mips/mips.md
index 21eb0ac683a..8ebd2e04b91 100644
--- a/gcc/config/mips/mips.md
+++ b/gcc/config/mips/mips.md
@@ -1820,6 +1820,19 @@
 
 ;; Split *mul_acc_si if both the source and destination accumulator
 ;; values are GPRs.
+(define_split
+  [(set (match_operand:SI 0 "d_operand")
+   (plus:SI (mult:SI (match_operand:SI 1 "d_operand")
+ (match_operand:SI 2 "d_operand"))
+(match_operand:SI 3 "d_operand")))
+   (clobber (match_operand:SI 4 "lo_operand"))
+   (clobber (match_operand:SI 5 "d_operand"))]
+  "reload_completed && ISA_HAS_R6MUL"
+  [(set (match_dup 5)
+   (mult:SI (match_dup 1) (match_dup 2)))
+   (set (match_dup 0) (plus:SI (match_dup 5) (match_dup 3)))]
+  "")
+
 (define_split
   [(set (match_operand:SI 0 "d_operand")
(plus:SI (mult:SI (match_operand:SI 1 "d_operand")
@@ -2042,6 +2055,19 @@
 
 ;; Split *mul_sub_si if both the source and destination accumulator
 ;; values are GPRs.
+(define_split
+  [(set (match_operand:SI 0 "d_operand")
+   (minus:SI (match_operand:SI 1 "d_operand")
+ (mult:SI (match_operand:SI 2 "d_operand")
+  (match_operand:SI 3 "d_operand"
+   (clobber (match_operand:SI 4 "lo_operand"))
+   (clobber (match_operand:SI 5 "d_operand"))]
+  "reload_completed && ISA_HAS_R6MUL"
+  [(set (match_dup 5)
+   (mult:SI (match_dup 2) (match_dup 3)))
+   (set (match_dup 0) (minus:SI (match_dup 1) (match_dup 5)))]
+  "")
+
 (define_split
   [(set (match_operand:SI 0 "d_operand")
 (minus:SI (match_operand:SI 1 "d_operand")
-- 
2.34.1


[COMMITTED] Doc: Improve wording of -Werror documentation [PR58973]

2025-04-05 Thread Sandra Loosemore
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 
---
 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 9400c4b94e8..b9e74cd3ac4 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 b2b9b37ca83..4c9af429ab0 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
-- 
2.34.1



[COMMITTED 022/146] gccrs: fix ICE for placeholder which is not setup

2025-04-05 Thread arthur . cohen
From: Philip Herron 

We can have a case where the placeholder is not configred and the
can_resolve check is not detecting this case which can lead to ICE.

gcc/rust/ChangeLog:

* typecheck/rust-tyty.cc (PlaceholderType::can_resolve): check for 
empty mappings

Signed-off-by: Philip Herron 
---
 gcc/rust/typecheck/rust-tyty.cc | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index 1812c618dcb..068e3902118 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -3543,7 +3543,17 @@ bool
 PlaceholderType::can_resolve () const
 {
   auto context = Resolver::TypeCheckContext::get ();
-  return context->lookup_associated_type_mapping (get_ty_ref (), nullptr);
+
+  BaseType *lookup = nullptr;
+  HirId mapping;
+
+  if (!context->lookup_associated_type_mapping (get_ty_ref (), &mapping))
+return false;
+
+  if (!context->lookup_type (mapping, &lookup))
+return false;
+
+  return lookup != nullptr;
 }
 
 BaseType *
-- 
2.45.2



[COMMITTED 045/146] gccrs: Use nr2.0 in typechecker

2025-04-05 Thread arthur . cohen
From: Owen Avery 

I probably missed a few spots, but this should cover most of the type
checker.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc: Add includes.
(TypeCheckExpr::visit): Use name resolver 2.0.
(TypeCheckExpr::resolve_operator_overload): Likewise.
(TypeCheckExpr::resolve_fn_trait_call): Likewise.
* typecheck/rust-hir-type-check-path.cc
(TypeCheckExpr::visit): Likewise.
(TypeCheckExpr::resolve_segments): Likewise.
* typecheck/rust-hir-type-check-type.cc
(TypeCheckType::resolve_segments): Likewise.
(ResolveWhereClauseItem::visit): Likewise.
(TypeCheckType::visit): Avoid usage of
Resolver::get_unit_type_node_id when handling TupleType, use
name resolver 2.0 when handling QualifiedPathInType.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery 
---
 .../typecheck/rust-hir-type-check-expr.cc |  45 ++-
 .../typecheck/rust-hir-type-check-path.cc |  27 +++-
 .../typecheck/rust-hir-type-check-type.cc | 122 +-
 gcc/testsuite/rust/compile/nr2/exclude|   4 -
 4 files changed, 155 insertions(+), 43 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc 
b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index d9f0361389f..03922bb554c 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -27,6 +27,10 @@
 #include "rust-hir-type-check-stmt.h"
 #include "rust-hir-type-check-item.h"
 #include "rust-type-util.h"
+#include "rust-immutable-name-resolution-context.h"
+
+// for flag_name_resolution_2_0
+#include "options.h"
 
 namespace Rust {
 namespace Resolver {
@@ -1238,8 +1242,17 @@ TypeCheckExpr::visit (HIR::MethodCallExpr &expr)
   // store the expected fntype
   context->insert_type (expr.get_method_name ().get_mappings (), lookup);
 
+  if (flag_name_resolution_2_0)
+{
+  auto &nr_ctx = const_cast (
+   Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());
+
+  nr_ctx.map_usage (Resolver2_0::Usage (expr.get_mappings ().get_nodeid 
()),
+   Resolver2_0::Definition (resolved_node_id));
+}
   // set up the resolved name on the path
-  if (resolver->get_name_scope ().decl_was_declared_here (resolved_node_id))
+  else if (resolver->get_name_scope ().decl_was_declared_here (
+resolved_node_id))
 {
   resolver->insert_resolved_name (expr.get_mappings ().get_nodeid (),
  resolved_node_id);
@@ -1821,8 +1834,19 @@ TypeCheckExpr::resolve_operator_overload (LangItem::Kind 
lang_item_type,
   context->insert_operator_overload (expr.get_mappings ().get_hirid (), type);
 
   // set up the resolved name on the path
-  resolver->insert_resolved_name (expr.get_mappings ().get_nodeid (),
- resolved_node_id);
+  if (flag_name_resolution_2_0)
+{
+  auto &nr_ctx = const_cast (
+   Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());
+
+  nr_ctx.map_usage (Resolver2_0::Usage (expr.get_mappings ().get_nodeid 
()),
+   Resolver2_0::Definition (resolved_node_id));
+}
+  else
+{
+  resolver->insert_resolved_name (expr.get_mappings ().get_nodeid (),
+ resolved_node_id);
+}
 
   // return the result of the function back
   infered = function_ret_tyty;
@@ -1991,8 +2015,19 @@ TypeCheckExpr::resolve_fn_trait_call (HIR::CallExpr 
&expr,
   context->insert_operator_overload (expr.get_mappings ().get_hirid (), fn);
 
   // set up the resolved name on the path
-  resolver->insert_resolved_name (expr.get_mappings ().get_nodeid (),
- resolved_node_id);
+  if (flag_name_resolution_2_0)
+{
+  auto &nr_ctx = const_cast (
+   Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());
+
+  nr_ctx.map_usage (Resolver2_0::Usage (expr.get_mappings ().get_nodeid 
()),
+   Resolver2_0::Definition (resolved_node_id));
+}
+  else
+{
+  resolver->insert_resolved_name (expr.get_mappings ().get_nodeid (),
+ resolved_node_id);
+}
 
   // return the result of the function back
   *result = function_ret_tyty;
diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc 
b/gcc/rust/typecheck/rust-hir-type-check-path.cc
index cc79e4d4995..cd0e941edd6 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-path.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc
@@ -153,8 +153,20 @@ TypeCheckExpr::visit (HIR::QualifiedPathInExpression &expr)
   bool fully_resolved = expr.get_segments ().size () <= 1;
   if (fully_resolved)
 {
-  resolver->insert_resolved_name (expr.get_mappings ().get_nodeid (),
- root_resolved_node_id);
+  if (flag_name_resolution_2_0)
+   {
+  

RE: [PATCH] change cbl_field_data_t::etc_t::value from _Float128 to tree

2025-04-05 Thread Robert Dubner
Okay!

Real progress here.  Preliminary report:

I am still seeing trouble with a PIC PP9 variable coming back .000 instead
of 0.001.

In my 679 UAT tests, the failure count is down from 23 to 4

In the NIST tests, the failure count is down from 273 to 35

It's after midnight, and my daily chores are not done, so I can't really
look into all of the failures.

Here's one, though:

IDENTIFICATION DIVISION.
PROGRAM-ID.  numeds.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 VARPP9 PIC PP9 VALUE 0.001.
01 VARP9  PIC P9  VALUE 0.01.
01 VARV9  PIC V9  VALUE 0.1.
01 VAR9   PIC 9   VALUE 1.
01 VAR9P  PIC 9P  VALUE 10.
01 VAR9PP PIC 9PP VALUE 100.
PROCEDURE DIVISION.
DISPLAY "VARPP9 should be .001 is "  VARPP9
DISPLAY "VARP9  should be .01  is "  VARP9
DISPLAY "VARV9  should be .1   is "  VARV9
DISPLAY "VAR9   should be 1is "  VAR9
DISPLAY "VAR9P  should be 10   is "  VAR9P
DISPLAY "VAR9PP should be 100  is "  VAR9PP.
END PROGRAM numeds.

What I am seeing with your patch is 

VARPP9 should be .001 is .000
VARP9  should be .01  is .01
VARV9  should be .1   is .1
VAR9   should be 1is 1
VAR9P  should be 10   is 10
VAR9PP should be 100  is 100

I am working on expanding the cobol.dg test suite.  I really am.  I am
about ready to take dg-output-file out for a spin.

> -Original Message-
> From: Jakub Jelinek 
> Sent: Saturday, March 22, 2025 03:29
> To: Richard Biener 
> Cc: Robert Dubner ; gcc-patches@gcc.gnu.org
> Subject: Re: [PATCH] change cbl_field_data_t::etc_t::value from
_Float128
> to tree
> 
> On Fri, Mar 21, 2025 at 08:25:10PM +0100, Richard Biener wrote:
> > Hmm, but I see that digits_from_float128 from
> >
> > (gdb) p debug (value)
> > 1.0e+0
> >
> > produces via real_to_integer zero:
> >
> > (gdb) s
> > real_to_integer (r=0x7fff69a0, fail=0x7fff685f, precision=128)
> > at ../../src/gcc/gcc/real.cc:1483
> > (gdb) p debug (*r)
> > 1.0e+0
> > (gdb) n
> > 1485  switch (r->cl)
> > (gdb)
> > 1502  if (r->decimal)
> > (gdb)
> > 1505  exp = REAL_EXP (r);
> > (gdb)
> > 1506  if (exp <= 0)
> > (gdb)
> > 1507goto underflow;
> > (gdb)
> > 1489  return wi::zero (precision);
> >
> > we've come from initial_from_float128 which does
> >
> >   REAL_VALUE_TYPE pow10
> > = real_powi10 (field->data.digits + field->data.rdigits);
> >   real_arithmetic (&value, MULT_EXPR, &value, &pow10);
> >
> > which produces the 1.0e+0 - do I need to process this to be "normal"?
> 
> Here is a more complete incremental patch, though just make check-cobol
> tested.  In particular, not sure if the parser_display_internal stuff
> is tested in the testsuite at all, we need to test both the 0/-0 cases
and
> values with exponents < -9, [9, -5], -4, -3, -2, -1, 0, 1, 2, 3, 4, 5,
[6,
> 9], > 9
> and in each case something that rounds up and down from the %.33E to
> %.32E.
> 
> --- gcc/cobol/parse.y.jj  2025-03-22 07:59:58.575988929 +0100
> +++ gcc/cobol/parse.y 2025-03-22 08:05:50.579195142 +0100
> @@ -4331,7 +4331,8 @@ value_clause:   VALUE all LITERAL[lit] {
>cbl_field_t *field = current_field();
>auto orig_str = original_number();
> REAL_VALUE_TYPE orig_val;
> -   real_from_string (&orig_val, orig_str);
> +   real_from_string3 (&orig_val, orig_str,
> +  TYPE_MODE (float128_type_node));
>char *initial = NULL;
> 
>if( real_identical (&orig_val, &$value) ) {
> @@ -6910,10 +6911,22 @@ num_value:  scalar // might actually
>  /*  ; */
> 
>  cce_expr:   cce_factor
> -|   cce_expr '+' cce_expr { real_arithmetic (&$$,
PLUS_EXPR,
> &$1, &$3); }
> -|   cce_expr '-' cce_expr { real_arithmetic (&$$,
MINUS_EXPR,
> &$1, &$3); }
> -|   cce_expr '*' cce_expr { real_arithmetic (&$$,
MULT_EXPR,
> &$1, &$3); }
> -|   cce_expr '/' cce_expr { real_arithmetic (&$$,
RDIV_EXPR,
> &$1, &$3); }
> +|   cce_expr '+' cce_expr {
> +  real_arithmetic (&$$, PLUS_EXPR, &$1, &$3);
> +  real_convert (&$$, TYPE_MODE (float128_type_node),
> &$$);
> +}
> +|   cce_expr '-' cce_expr {
> +  real_arithmetic (&$$, MINUS_EXPR, &$1, &$3);
> +  real_convert (&$$, TYPE_MODE (float128_type_node),
> &$$);
> +}
> +|   cce_expr '*' cce_expr {
> +  real_arithmetic (&$$, MULT_EXPR, &$1, &$3);
> +  real_convert (&$$, TYPE_MODE (float128_type_node),
> &$$);
> +}
> +|   cce_expr '/' cce_expr {
> +  real_arithmetic (&$$, RDIV_EXPR, &$1, &$3);
> +  real_convert (&$$, TYPE_MODE (float128_type_node),
> &$$);
> +

[PATCH] vect: Add assert to expand_vector_conversion [PR118616]

2025-04-05 Thread Andrew Pinski
In some cases (after inliing due to LTO and -O3), GCC cannot
figure out that the length of the converts vect is not empty
when supportable_indirect_convert_operation returns true. So
we get an extra warning because we loop through all but the last
entry and GCC decided that `converts.length () - 1` is -1. This
adds an checking only assert to avoid the warning and maybe even
produce slightly better code for this function.

Bootstrapped and tested on x86_64-linux-gnu.

PR tree-optimization/118616
gcc/ChangeLog:

* tree-vect-generic.cc (expand_vector_conversion): Add
an assert that converts vect is non empty if
supportable_indirect_convert_operation returns true.

Signed-off-by: Andrew Pinski 
---
 gcc/tree-vect-generic.cc | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/tree-vect-generic.cc b/gcc/tree-vect-generic.cc
index 173ebd9a7ba..246297ec6a9 100644
--- a/gcc/tree-vect-generic.cc
+++ b/gcc/tree-vect-generic.cc
@@ -1759,6 +1759,7 @@ expand_vector_conversion (gimple_stmt_iterator *gsi)
  converts))
 {
   new_rhs = arg;
+  gcc_checking_assert (!converts.is_empty ());
   for (unsigned int i = 0; i < converts.length () - 1; i++)
{
  new_lhs = make_ssa_name (converts[i].first);
-- 
2.43.0



[PATCH v1 0/2] Add target_version support to C frontend

2025-04-05 Thread Alfie Richards
Hi All,

This patch series relies upon my C++ frontend patch series.
I have uploaded both series to the Forgejo instance
(https://forge.sourceware.org/alfie.richards/gcc-TEST/pulls/1)
both to have a public remote branch to easily pull from and
to allow reviews on there is so desired.

This series adds support for target_version attribute in the C frontend
for the targets which set TARGET_HAS_FMV_TARGET_ATTRIBUTE to false.
(Currently Aarch64 and riscv.)

This differs from my attempt to add target_version support previously
as the ACLE rules were updated to specify the scope and signature
of the function set to be that of the default version. This simplifies
many of the edge cases previously we were dealing with and allows using
the default decl to represent the whole set. (Previously I used the
dispatched symbol creating significant complexity).

This has all been bootstrapped and regression tested on
aarch64-linux-gnu and x86_64-linux-gnu.

This is targeting GCC 16 stage 1.

Kind regards,
Alfie Richards

Alfie Richards (2):
  c: Add target_version attribute support.
  c: Improve diagnostics for C FMV declaration conflicts.

 gcc/c/c-decl.cc   | 144 +-
 gcc/testsuite/gcc.target/aarch64/mv-1.c   |  43 ++
 .../gcc.target/aarch64/mv-and-mvc-error1.c|   9 ++
 .../gcc.target/aarch64/mv-and-mvc-error2.c|   9 ++
 .../gcc.target/aarch64/mv-and-mvc-error3.c|   8 +
 .../gcc.target/aarch64/mv-and-mvc1.c  |  37 +
 .../gcc.target/aarch64/mv-and-mvc2.c  |  28 
 .../gcc.target/aarch64/mv-and-mvc3.c  |  40 +
 .../gcc.target/aarch64/mv-and-mvc4.c  |  37 +
 gcc/testsuite/gcc.target/aarch64/mv-error1.c  |  18 +++
 gcc/testsuite/gcc.target/aarch64/mv-error2.c  |   9 ++
 gcc/testsuite/gcc.target/aarch64/mv-error3.c  |  12 ++
 gcc/testsuite/gcc.target/aarch64/mv-error4.c  |   9 ++
 gcc/testsuite/gcc.target/aarch64/mv-error5.c  |   8 +
 gcc/testsuite/gcc.target/aarch64/mv-error6.c  |  20 +++
 gcc/testsuite/gcc.target/aarch64/mv-error7.c  |  11 ++
 gcc/testsuite/gcc.target/aarch64/mv-error8.c  |  12 ++
 gcc/testsuite/gcc.target/aarch64/mv-error9.c  |  12 ++
 .../gcc.target/aarch64/mv-symbols1.c  |  38 +
 .../gcc.target/aarch64/mv-symbols10.c |  42 +
 .../gcc.target/aarch64/mv-symbols11.c |  16 ++
 .../gcc.target/aarch64/mv-symbols12.c |  27 
 .../gcc.target/aarch64/mv-symbols13.c |  28 
 .../gcc.target/aarch64/mv-symbols2.c  |  28 
 .../gcc.target/aarch64/mv-symbols3.c  |  27 
 .../gcc.target/aarch64/mv-symbols4.c  |  31 
 .../gcc.target/aarch64/mv-symbols5.c  |  36 +
 .../gcc.target/aarch64/mv-symbols6.c  |  20 +++
 .../gcc.target/aarch64/mv-symbols7.c  |  47 ++
 .../gcc.target/aarch64/mv-symbols8.c  |  47 ++
 .../gcc.target/aarch64/mv-symbols9.c  |  44 ++
 gcc/testsuite/gcc.target/aarch64/mvc-error1.c |   9 ++
 gcc/testsuite/gcc.target/aarch64/mvc-error2.c |   9 ++
 .../gcc.target/aarch64/mvc-symbols1.c |  25 +++
 .../gcc.target/aarch64/mvc-symbols2.c |  15 ++
 .../gcc.target/aarch64/mvc-symbols3.c |  19 +++
 .../gcc.target/aarch64/mvc-symbols4.c |  12 ++
 .../gcc.target/aarch64/mvc-warning1.c |  13 ++
 38 files changed, 993 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/aarch64/mv-1.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/mv-and-mvc-error1.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/mv-and-mvc-error2.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/mv-and-mvc-error3.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/mv-and-mvc1.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/mv-and-mvc2.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/mv-and-mvc3.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/mv-and-mvc4.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/mv-error1.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/mv-error2.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/mv-error3.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/mv-error4.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/mv-error5.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/mv-error6.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/mv-error7.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/mv-error8.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/mv-error9.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/mv-symbols1.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/mv-symbols10.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/mv-symbols11.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/mv-symbols12.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/mv-symbols13.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/mv-symbols2.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/mv-symbols3.c
 creat

[COMMITTED 049/144] gccrs: Added counting to check for asm_construct_outputs

2025-04-05 Thread arthur . cohen
From: badumbatish 

gcc/rust/ChangeLog:

* backend/rust-compile-asm.cc (CompileAsm::asm_construct_outputs):
Set up counting to check
---
 gcc/rust/backend/rust-compile-asm.cc | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/gcc/rust/backend/rust-compile-asm.cc 
b/gcc/rust/backend/rust-compile-asm.cc
index 0dd4f672008..9305a9088bb 100644
--- a/gcc/rust/backend/rust-compile-asm.cc
+++ b/gcc/rust/backend/rust-compile-asm.cc
@@ -96,6 +96,13 @@ tree
 CompileAsm::asm_construct_outputs (HIR::InlineAsm &expr)
 {
   // TODO: Do i need to do this?
+  int count = 0;
+
+  for (auto &output : expr.get_operands ())
+{
+  if (output.register_type == AST::InlineAsmOperand::RegisterType::Out)
+   count++;
+}
   return NULL_TREE;
 }
 
-- 
2.45.2



Re: [PATCH] Libstdc++: Fix bootstrap failure for cross without tm.tm_zone [PR119550]

2025-04-05 Thread Jonathan Wakely
On Wed, 2 Apr 2025 at 07:16, Tomasz Kaminski  wrote:
>
>
>
> On Tue, Apr 1, 2025 at 2:46 PM Jonathan Wakely  wrote:
>>
>> On Tue, 1 Apr 2025 at 11:34, Tomasz Kaminski  wrote:
>> >
>> >
>> >
>> > On Mon, Mar 31, 2025 at 7:28 PM Jonathan Wakely  wrote:
>> >>
>> >> In r15-8491-g778c28c70f8573 I added a use of the Autoconf macro
>> >> AC_STRUCT_TIMEZONE, but that requires a link-test for the global tzname
>> >> object if tm.tm_zone isn't supported. That link-test isn't allowed for
>> >> cross-compilation, so bootstrap fails if tm.tm_zone isn't supported.
>> >>
>> >> Since libstdc++ only cares about tm.tm_zone and won't use tzname anyway,
>> >> we don't need the link-test. Replace AC_STRUCT_TIMEZONE with a custom
>> >> macro that only checks for tm.tm_zone. We can improve on the Autoconf
>> >> macro by checking it's a suitable type, which isn't actually checked by
>> >> AC_STRUCT_TIMEZONE.
>> >>
>> >> libstdc++-v3/ChangeLog:
>> >>
>> >> PR libstdc++/119550
>> >> * acinclude.m4 (GLIBCXX_STRUCT_TM_TM_ZONE): New macro.
>> >> * config.h.in: Regenerate.
>> >> * configure: Regenerate.
>> >> * configure.ac: Use GLIBCXX_STRUCT_TM_TM_ZONE.
>> >> * include/bits/chrono_io.h (__formatter_chrono::_M_c): Check
>> >> _GLIBCXX_USE_STRUCT_TM_TM_ZONE instead of
>> >> _GLIBCXX_HAVE_STRUCT_TM_TM_ZONE.
>> >> ---
>> >>
>> >> Testing x86_64-linux and sparc-solaris2.11, looks fine so far.
>> >>
>> >>  libstdc++-v3/acinclude.m4 |  35 
>> >>  libstdc++-v3/config.h.in  |  21 +--
>> >>  libstdc++-v3/configure| 238 --
>> >>  libstdc++-v3/configure.ac |   5 +-
>> >>  libstdc++-v3/include/bits/chrono_io.h |   2 +-
>> >>  5 files changed, 109 insertions(+), 192 deletions(-)
>> >>
>> >> diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
>> >> index e668d2dba27..02fd349e11d 100644
>> >> --- a/libstdc++-v3/acinclude.m4
>> >> +++ b/libstdc++-v3/acinclude.m4
>> >> @@ -5744,6 +5744,41 @@ AC_DEFUN([GLIBCXX_ZONEINFO_DIR], [
>> >>fi
>> >>  ])
>> >>
>> >> +dnl
>> >> +dnl Check for a tm_zone member in struct tm.
>> >> +dnl
>> >> +dnl This member is defined as const char* in Glibc, newlib, POSIX.1-2024,
>> >> +dnl and as char* in BSD (including macOS).
>> >> +dnl
>> >> +dnl Defines:
>> >> +dnl  _GLIBCXX_USE_STRUCT_TM_TM_ZONE if struct tm has a tm_zone member.
>> >> +dnl
>> >> +AC_DEFUN([GLIBCXX_STRUCT_TM_TM_ZONE], [
>> >> +
>> >> +  AC_LANG_SAVE
>> >
>> > From documentation this is deprecated in favor of AC_LANG_PUSH.
>>
>> It looks like that is supported by autoconf 2.69 and is already used
>> elsewhere in GCC. We don't currently use it in libstdc++ but it should
>> be safe to do so.
>>
>> >> +  AC_LANG_CPLUSPLUS
>> >> +  ac_save_CXXFLAGS="$CXXFLAGS"
>> >> +  CXXFLAGS="$CXXFLAGS -std=c++20"
>> >
>> > The program that is compiled does not seem to require C++20.
>> > If we change the declaration of "t" to use "= {}", we could do it in C++98.
>> > Any reason to adjust the flags at all?
>>
>> We only need to use the tm_zone member in C++20 mode, and it's
>> possible that on some platform it's not exposed for older standards
>> (very unlikely, but possible). I wanted to test for exactly what we
>> require. I don't feel strongly about it though.
>
> I would found it surprising if the layout of the structure would fiffer that 
> much,
> wouldn't this cause ABI compatibility problems for TU that memcopies struct tm
> and are compiled with different language versions?

Not if it does:

#if _USE_POSIX24
  const char* tm_zone;
#else
  const void* __tm_zone_padding;
#endif



> I have slight preference towards not overriding CXXFLAGS, as for me this 
> suggest
> that struct tm was changed in C++20 (or linked C standard), which is not the 
> case.
> But I am fine either way.

IMHO the test should be understood as "can C++20 chrono formatting use
tm_zone", and not "is tm_zone defined in C++20", which is partly why I
defined a USE macro nto a HAVE macro (but also to avoid conflicting
with the name that AC_STRUCT_TIMEZONE uses). I should have said that
in the comments above the GLIBCXX_STRUCT_TM_TM_ZONE definition though!

I'll improve that (and revisit the AC_PUSH_LANG point in stage 1).



>>
>>
>> >>
>> >> +
>> >> +  AC_CACHE_CHECK([for tm_zone member of struct tm], glibcxx_cv_tm_zone, [
>> >> +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include 
>> >> +   ],
>> >> +   [struct tm t{}; t.tm_zone = (char*)0;]
>> >> +   )],
>> >> +   [glibcxx_cv_tm_zone=yes],
>> >> +   [glibcxx_cv_tm_zone=no]
>> >> +  )
>> >> +])
>> >> +
>> >> +  if test $glibcxx_cv_tm_zone = yes; then
>> >> +AC_DEFINE(_GLIBCXX_USE_STRUCT_TM_TM_ZONE, 1,
>> >> + [Define if struct tm has a tm_zone member.])
>> >> +  fi
>> >> +
>> >> +  CXXFLAGS="$ac_save_CXXFLAGS"
>> >> +  AC_LANG_RESTORE
>> >> +])
>> >> +
>> >>  dnl
>> >>  dnl Check whether lock tables can be aligned to avoid false sharing.
>> >>  dnl

Re: [PATCH v2] RISC-V: vsetvl: skip abnormal edge on vsetvl insertion [PR119533]

2025-04-05 Thread Vineet Gupta
On 4/1/25 17:44, Jeff Law wrote:
> On 4/1/25 12:15 PM, Vineet Gupta wrote:
>> On 3/31/25 23:48, Heinrich Schuchardt wrote:
>>> On 3/30/25 01:49, Vineet Gupta wrote:
 changes since v2
- dump log sanfu

 ---
 vsetvl phase4 uses LCM guided info to insert VSETVL insns.
 It has an additional loop to insert missing vsetvls on certain edges.
 Currently it asserts/aborts on encountering EDGE_ABNORMAL.
 When enabling go frontend with V enabled, libgo build hits the assert.

 It seems to be safe to just skip the abnormal edge.
>>> Hello Vineet,
>>>
>>> Is there a test case where only following an abnormal edge between code
>>> blocks would require to call VSETVL?
>>>
>>> In the sketched code below following the exception would require VSETVL
>>> to be called while the edge from the try block to the finally block
>>> would not require this.
>>>
>>> try {
>>> for (..) {
>>> uint16_t vectorizable math
>>> if (condition)
>>> throw exception
>>> uint16_t vectorizable math
>>> }
>>> for (..) {
>>> uint8_t vectorizable math
>>> }
>>> } catch exception {
>>> } finally
>>> for (..) {
>>> uint8_t vectorizable math
>>> }
>>> }
>> Yeah we are going to run testsuite with -fnon-call-exceptions to find such 
>> cases.
>>
>> But I'd argue, there is no need to optimize vsetvl for such esoteric cases 
>> (vs.
>> code complexity trade-off).
>> After all we'd just endup with an extra VSETVL in the finally block.
> I'd look at that skeleton code as a way to potentially trip this issue 
> without needing golang.

The best I could come up with, but that won't hit the issue

#pragma riscv intrinsic "vector"
typedef long unsigned int size_t;

int foo (vfloat32m1_t op1, vfloat32m1_t op2, size_t vl, int cond, float *out)
{
  vfloat32m1_t result_1, result_2, result_3;
  try {
    result_1 = __riscv_vfadd_vv_f32m1 (op1, op2, vl);

    if (cond & 0x1)
  result_2 = __riscv_vfadd_vv_f32m1 (result_1, op2, vl);

    if (cond % 17)
  result_3 = __riscv_vfadd_vv_f32m1 (result_3, op2, vl);
    else
  result_3 = result_1;

    if (cond)
  throw 42;
  }
  catch (int i) {
  }

  result_2 = __riscv_vfadd_vv_f32m1 (result_3, op2, vl);
  *(vfloat32m1_t *)out = result_2;
 
  return 0;
}



[PATCH, V5] PR target/118541 - Do not generate unordered fp cmoves for IEEE compares on PowerPC

2025-04-05 Thread Michael Meissner
This is version 5 of the patch.

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

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

In version 3, I made the following changes:

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

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

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

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

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

extern double __ieee754_acos (double);

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

GCC currently generates the following code:

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

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

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

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

For the following code:

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

/* Verify normal > does generate xscmpgtdp.  */

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

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

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

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

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

2025-03-28  Michael Meissner  

gcc/

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

gcc/testsuite/

PR target/118541
* gcc.target/powerpc/pr118541-1.c: New test.
* gcc.target/powerpc/pr118541-2.c: Likewise.
* gcc.target/powerpc/pr118541-3.c: Likewise.
* gcc.target/powerpc/pr118541-4.c: Likewise.
---
 gcc/config/rs6000/predicates.md   | 10 +++-
 gcc/config/rs6000/rs6000-protos.h | 17 ++-
 gcc/config/rs6000/rs6000.cc   | 46 ++-
 gcc/config/rs6000/rs6000.h| 10 +++-
 gcc/config/rs6000/rs6000.md   | 25 ++
 gcc/testsuite/gcc.target/powerpc/pr118541-1.c | 28 +++
 gcc/testsuite/gcc.target/powerpc/pr118541-2.c

[COMMITTED 132/146] gccrs: lang-items: Mark Clone trait as a lang item in testsuite

2025-04-05 Thread arthur . cohen
From: Arthur Cohen 

gcc/testsuite/ChangeLog:

* rust/compile/derive_macro1.rs: Add #[lang = "clone"] to Clone trait.
* rust/compile/derive_macro3.rs: Likewise.
* rust/compile/derive_macro6.rs: Likewise.
* rust/execute/torture/derive_macro3.rs: Likewise.
---
 gcc/testsuite/rust/compile/derive_macro1.rs | 1 +
 gcc/testsuite/rust/compile/derive_macro3.rs | 1 +
 gcc/testsuite/rust/compile/derive_macro6.rs | 7 +++
 gcc/testsuite/rust/execute/torture/derive_macro3.rs | 1 +
 4 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/gcc/testsuite/rust/compile/derive_macro1.rs 
b/gcc/testsuite/rust/compile/derive_macro1.rs
index 779aad78e11..bc10d601bb8 100644
--- a/gcc/testsuite/rust/compile/derive_macro1.rs
+++ b/gcc/testsuite/rust/compile/derive_macro1.rs
@@ -1,6 +1,7 @@
 #[lang = "sized"]
 pub trait Sized {}
 
+#[lang = "clone"]
 pub trait Clone {
 fn clone(&self) -> Self;
 }
diff --git a/gcc/testsuite/rust/compile/derive_macro3.rs 
b/gcc/testsuite/rust/compile/derive_macro3.rs
index 1c7d4737bfe..ad40cae94b5 100644
--- a/gcc/testsuite/rust/compile/derive_macro3.rs
+++ b/gcc/testsuite/rust/compile/derive_macro3.rs
@@ -1,6 +1,7 @@
 #[lang = "sized"]
 pub trait Sized {}
 
+#[lang = "clone"]
 pub trait Clone {
 fn clone(&self) -> Self;
 }
diff --git a/gcc/testsuite/rust/compile/derive_macro6.rs 
b/gcc/testsuite/rust/compile/derive_macro6.rs
index b7bf7a78acd..35327c03b54 100644
--- a/gcc/testsuite/rust/compile/derive_macro6.rs
+++ b/gcc/testsuite/rust/compile/derive_macro6.rs
@@ -2,6 +2,9 @@
 pub trait Sized {}
 
 pub trait Copy {}
+
+
+#[lang = "clone"]
 pub trait Clone {
 fn clone(&self) -> Self;
 }
@@ -9,10 +12,6 @@ pub trait Clone {
 #[lang = "phantom_data"]
 pub struct PhantomData;
 
-pub struct AssertParamIsCopy {
-pub _field: PhantomData,
-}
-
 impl Copy for i32 {}
 impl Copy for i64 {}
 impl Copy for U {}
diff --git a/gcc/testsuite/rust/execute/torture/derive_macro3.rs 
b/gcc/testsuite/rust/execute/torture/derive_macro3.rs
index 7b3a089d751..4138a5bf7e4 100644
--- a/gcc/testsuite/rust/execute/torture/derive_macro3.rs
+++ b/gcc/testsuite/rust/execute/torture/derive_macro3.rs
@@ -1,6 +1,7 @@
 #[lang = "sized"]
 pub trait Sized {}
 
+#[lang = "clone"]
 pub trait Clone {
 fn clone(&self) -> Self;
 }
-- 
2.45.2



[COMMITTED 130/141] gccrs: Fix canonical path parent resolution

2025-04-05 Thread arthur . cohen
From: Pierre-Emmanuel Patry 

The algorithm was comparing using the wrong id, this lead to some
mangling errors as an erroneous parent was selected.

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.hxx: Fix the id comparison.

Signed-off-by: Pierre-Emmanuel Patry 
---
 gcc/rust/resolve/rust-forever-stack.hxx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/rust/resolve/rust-forever-stack.hxx 
b/gcc/rust/resolve/rust-forever-stack.hxx
index 59142a4094c..90e0ceb9f81 100644
--- a/gcc/rust/resolve/rust-forever-stack.hxx
+++ b/gcc/rust/resolve/rust-forever-stack.hxx
@@ -686,7 +686,7 @@ ForeverStack::to_canonical_path (NodeId id) const
  auto &link = kv.first;
  auto &child = kv.second;
 
- if (link.id == child.id)
+ if (current.id == child.id)
{
  outer_link = &link;
  break;
-- 
2.45.2



[COMMITTED 048/144] gccrs: Added new test for prep of output {}

2025-04-05 Thread arthur . cohen
From: badumbatish 

gcc/testsuite/ChangeLog:

* rust/compile/inline_asm_parse_output_operand.rs: New test.
---
 .../compile/inline_asm_parse_output_operand.rs | 18 ++
 1 file changed, 18 insertions(+)
 create mode 100644 
gcc/testsuite/rust/compile/inline_asm_parse_output_operand.rs

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



Re: [PATCH] testsuite: Remove guality xfails for aarch64*-*-*

2025-04-05 Thread Richard Sandiford
Christophe Lyon  writes:
> Since r15-7878-ge1c49f413c8, these tests appear as XPASS on aarch64,
> so we can remove the xfails introduced by r12-102-gf31ddad8ac8f11.
>
> gcc/testsuite/ChangeLog:
>
>   * gcc.dg/guality/pr90074.c: Remove xfail for aarch64.
>   * gcc.dg/guality/pr90716.c: Likewise.

OK, thanks.

Richard

> ---
>  gcc/testsuite/gcc.dg/guality/pr90074.c | 4 ++--
>  gcc/testsuite/gcc.dg/guality/pr90716.c | 2 +-
>  2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/gcc/testsuite/gcc.dg/guality/pr90074.c 
> b/gcc/testsuite/gcc.dg/guality/pr90074.c
> index 2fd884209f2..12949282516 100644
> --- a/gcc/testsuite/gcc.dg/guality/pr90074.c
> +++ b/gcc/testsuite/gcc.dg/guality/pr90074.c
> @@ -25,7 +25,7 @@ int main()
>   debug stmt for the final value of the loop during loop distribution
>   which would fix the UNSUPPORTED cases.
>   c is optimized out at -Og for no obvious reason.  */
> -  optimize_me_not(); /* { dg-final { gdb-test . "i + 1" "8" { xfail { 
> aarch64*-*-* && { any-opts "-fno-fat-lto-objects" } } } } } */
> -/* { dg-final { gdb-test .-1 "c + 1" "2" { xfail { aarch64*-*-* && { 
> any-opts "-fno-fat-lto-objects" } } } } } */
> +  optimize_me_not(); /* { dg-final { gdb-test . "i + 1" "8" } } */
> +/* { dg-final { gdb-test .-1 "c + 1" "2" } } */
>return 0;
>  }
> diff --git a/gcc/testsuite/gcc.dg/guality/pr90716.c 
> b/gcc/testsuite/gcc.dg/guality/pr90716.c
> index fe7e5567625..b2f5c9d146e 100644
> --- a/gcc/testsuite/gcc.dg/guality/pr90716.c
> +++ b/gcc/testsuite/gcc.dg/guality/pr90716.c
> @@ -20,6 +20,6 @@ int main()
>   Instead test j + 1 which will make the test UNSUPPORTED if i
>   is optimized out.  Since the test previously had wrong debug
>   with j == 0 this is acceptable.  */
> -  optimize_me_not(); /* { dg-final { gdb-test . "j + 1" "9" { xfail { 
> aarch64*-*-* && { any-opts "-fno-fat-lto-objects" } } } } } */
> +  optimize_me_not(); /* { dg-final { gdb-test . "j + 1" "9" } } */
>return 0;
>  }


  1   2   3   >