[PATCH] c++: Don't treat lambda typedef as lambda declaration [PR106221]

2024-12-21 Thread Nathaniel Shead
Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk?

-- >8 --

I noticed that in a couple of places we sometimes treat any TYPE_DECL of
lambda type as defining a lambda, which isn't always true since C++20:
in `using T = decltype([]{})`, T is not a lambda-declaration.

PR c++/106221
PR c++/110680

gcc/cp/ChangeLog:

* pt.cc (check_default_tmpl_args): Check this is actually a
lambda declaration and not just a typedef.
(push_template_decl): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/lambda-uneval19.C: New test.

Signed-off-by: Nathaniel Shead 
---
 gcc/cp/pt.cc |  8 
 gcc/testsuite/g++.dg/cpp2a/lambda-uneval19.C | 20 
 2 files changed, 24 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/lambda-uneval19.C

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 7fa286698ef..0ffa0b53e26 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -5637,8 +5637,7 @@ check_default_tmpl_args (tree decl, tree parms, bool 
is_primary,
local scope.  */
 return true;
 
-  if ((TREE_CODE (decl) == TYPE_DECL
-   && TREE_TYPE (decl)
+  if ((DECL_IMPLICIT_TYPEDEF_P (decl)
&& LAMBDA_TYPE_P (TREE_TYPE (decl)))
   || (TREE_CODE (decl) == FUNCTION_DECL
  && LAMBDA_FUNCTION_P (decl)))
@@ -5924,7 +5923,7 @@ push_template_decl (tree decl, bool is_friend)
  template  friend void A::f();
is not primary.  */
 ;
-  else if (TREE_CODE (decl) == TYPE_DECL && LAMBDA_TYPE_P (TREE_TYPE (decl)))
+  else if (DECL_IMPLICIT_TYPEDEF_P (decl) && LAMBDA_TYPE_P (TREE_TYPE (decl)))
 /* Lambdas are not primary.  */
 ;
   else
@@ -6077,7 +6076,8 @@ push_template_decl (tree decl, bool is_friend)
   else if (!ctx
   || TREE_CODE (ctx) == FUNCTION_DECL
   || (CLASS_TYPE_P (ctx) && TYPE_BEING_DEFINED (ctx))
-  || (TREE_CODE (decl) == TYPE_DECL && LAMBDA_TYPE_P (TREE_TYPE 
(decl)))
+  || (DECL_IMPLICIT_TYPEDEF_P (decl)
+  && LAMBDA_TYPE_P (TREE_TYPE (decl)))
   || (is_friend && !(DECL_LANG_SPECIFIC (decl)
  && DECL_TEMPLATE_INFO (decl
 {
diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-uneval19.C 
b/gcc/testsuite/g++.dg/cpp2a/lambda-uneval19.C
new file mode 100644
index 000..a9682cce6e6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/lambda-uneval19.C
@@ -0,0 +1,20 @@
+// { dg-do compile { target c++20 } }
+
+// PR c++/106221
+using T = decltype([](){});
+
+template
+using foo = T;
+
+using bar = foo;
+
+// PR c++/110680
+template 
+struct S {
+  auto f() { return X; }
+};
+
+template 
+using C = decltype(S().f());
+
+using D = C;
-- 
2.47.0



Re: [2nd PING, Fortran, Patch, PR107635, Part 1] Rework handling of allocatable components in derived type coarrays.

2024-12-21 Thread Jerry D

On 12/20/24 9:09 AM, Andre Vehreschild wrote:

Thank you very much Jerry.

The delta between the two patches is really minor. In resolve.c I have 
removed some attr.pointer setting and in caf/single.c the handling for 
those as well as treating non-descriptor arrays differently.


Most changes in the diff of v2 to v3 are about lines having moved due to 
other patches.


And I will be around for fixing occurring issues. Btw, in the 
OpenCoarrays GitHub repo the branch for 774 implements this new way of 
accessing data for mpi.


Thanks again for looking and regards,
Andre

Andre Vehreschild


Please go ahead and Push. We have had some off list discussions and this 
is the best path forward.


Best regards to all,

Jerry


[PATCH] c++: Suppress note linked to error suppressed by -Wno-template-body [PR118163]

2024-12-21 Thread Simon Martin
When erroring out due to an incomplete type, we add a contextual note
about the type. However, when the error is suppressed by
-Wno-template-body, the note remains, making the compiler output quite
puzzling.

This patch makes sure the note is suppressed if we're processing a
template declaration body with -Wno-template-body.

Successfully tested on x86_64-pc-linux-gnu.

PR c++/118163

gcc/cp/ChangeLog:

* cp-tree.h (get_current_template): Declare.
* error.cc (get_current_template): Make non static.
* typeck2.cc (cxx_incomplete_type_inform): Suppress note when
parsing a template declaration with -Wno-template-body.

gcc/testsuite/ChangeLog:

* g++.dg/diagnostic/incomplete-type-2.C: New test.
* g++.dg/diagnostic/incomplete-type-2a.C: New test.

---
 gcc/cp/cp-tree.h|  1 +
 gcc/cp/error.cc |  2 +-
 gcc/cp/typeck2.cc   |  6 ++
 gcc/testsuite/g++.dg/diagnostic/incomplete-type-2.C |  7 +++
 .../g++.dg/diagnostic/incomplete-type-2a.C  | 13 +
 5 files changed, 28 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/diagnostic/incomplete-type-2.C
 create mode 100644 gcc/testsuite/g++.dg/diagnostic/incomplete-type-2a.C

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 6de8f64b5ee..52f954b63d9 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -7297,6 +7297,7 @@ struct decl_location_traits
 typedef hash_map erroneous_templates_t;
 extern GTY((cache)) erroneous_templates_t *erroneous_templates;
 
+extern tree get_current_template ();
 extern bool cp_seen_error ();
 #define seen_error() cp_seen_error ()
 
diff --git a/gcc/cp/error.cc b/gcc/cp/error.cc
index 8c0644fba7e..7fd03dd6d12 100644
--- a/gcc/cp/error.cc
+++ b/gcc/cp/error.cc
@@ -197,7 +197,7 @@ class cxx_format_postprocessor : public format_postprocessor
 /* Return the in-scope template that's currently being parsed, or
NULL_TREE otherwise.  */
 
-static tree
+tree
 get_current_template ()
 {
   if (scope_chain && in_template_context && !current_instantiation ())
diff --git a/gcc/cp/typeck2.cc b/gcc/cp/typeck2.cc
index fce687e83b3..505c143dae7 100644
--- a/gcc/cp/typeck2.cc
+++ b/gcc/cp/typeck2.cc
@@ -273,6 +273,12 @@ cxx_incomplete_type_inform (const_tree type)
   if (!TYPE_MAIN_DECL (type))
 return;
 
+  /* When processing a template declaration body, the error generated by the
+ caller (if any) might have been suppressed by -Wno-template-body. If that
+ is the case, suppress the inform as well.  */
+  if (!warn_template_body && get_current_template ())
+return;
+
   location_t loc = DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type));
   tree ptype = strip_top_quals (CONST_CAST_TREE (type));
 
diff --git a/gcc/testsuite/g++.dg/diagnostic/incomplete-type-2.C 
b/gcc/testsuite/g++.dg/diagnostic/incomplete-type-2.C
new file mode 100644
index 000..e2fb20a4ae8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/diagnostic/incomplete-type-2.C
@@ -0,0 +1,7 @@
+// PR c++/118163
+// { dg-do "compile" }
+
+template
+struct S {  // { dg-note "until the closing brace" }
+  S s; // { dg-error "has incomplete type" }
+};
diff --git a/gcc/testsuite/g++.dg/diagnostic/incomplete-type-2a.C 
b/gcc/testsuite/g++.dg/diagnostic/incomplete-type-2a.C
new file mode 100644
index 000..d13021d0b68
--- /dev/null
+++ b/gcc/testsuite/g++.dg/diagnostic/incomplete-type-2a.C
@@ -0,0 +1,13 @@
+// PR c++/118163
+// { dg-do "compile" }
+// { dg-additional-options "-Wno-template-body" }
+
+template
+struct S {  // { dg-bogus "until the closing brace" }
+  S s; // { dg-bogus "has incomplete type" }
+};
+
+// Check that we don't suppress errors outside of the body.
+struct forward_decl;   // { dg-note "forward declaration" }
+template
+void foo (forward_decl) {}  // { dg-error "has incomplete type" }
-- 
2.44.0



Re: [PING] [PATCH, part4] Fortran: fix passing of NULL() to assumed-rank, derived type dummy [PR104819]

2024-12-21 Thread Andre Vehreschild
Hi Harald,

the patch looks ok to me.

Thanks for the patch,
Andre


On Fri, 20 Dec 2024 19:00:05 +0100
Harald Anlauf  wrote:

> Ping!
>
> Am 14.12.24 um 20:56 schrieb Harald Anlauf:
> > Dear all,
> >
> > this patch is the 4th part of a series on the passing of NULL() to
> > assumed-rank dummies.  This one handles the case of a derived type
> > dummy and is mostly straightforward.
> >
> > There was one particular problem I encountered: passing NULL() to
> > an allocatable dummy with no intent given.  This lead to an ICE
> > I could not resolve other than treating this the same as if an
> > intent(in) were given.  If someone has a better idea, I'd love
> > to learn about it...
> >
> > Testcase cross-checked with Intel's ifx.
> >
> > Regtested on x86_64-pc-linux-gnu.  OK for mainline?
> >
> > Thanks,
> > Harald
> >
> > P.S.: if someone would like to assist with the case of class
> > dummies, please let me know.
> >
>
>


--
Andre Vehreschild * Email: vehre ad gmx dot de


Re: [PATCH v1] Match: Refactor the signed SAT_ADD match patterns [NFC]

2024-12-21 Thread Richard Biener
On Tue, Dec 10, 2024 at 7:30 AM  wrote:
>
> From: Pan Li 
>
> This patch would like to refactor the all signed SAT_ADD patterns,
> aka:
> * Extract type check outside.
> * Re-arrange the related match pattern forms together.

OK

> The below test suites are passed for this patch.
> * The rv64gcv fully regression test.
> * The x86 bootstrap test.
> * The x86 fully regression test.
>
> gcc/ChangeLog:
>
> * match.pd: Refactor sorts of signed SAT_ADD match patterns.
>
> Signed-off-by: Pan Li 
> ---
>  gcc/match.pd | 140 +--
>  1 file changed, 58 insertions(+), 82 deletions(-)
>
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 55617b21139..dd5302015c7 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -3314,90 +3314,66 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>  }
>  (if (wi::eq_p (trunc_max, int_cst_1) && wi::eq_p (max, int_cst_2)))
>
> -/* Signed saturation add, case 1:
> -   T sum = (T)((UT)X + (UT)Y)
> -   SAT_S_ADD = (X ^ sum) & !(X ^ Y) < 0 ? (-(T)(X < 0) ^ MAX) : sum;
> -
> -   The T and UT are type pair like T=int8_t, UT=uint8_t.  */
> -(match (signed_integer_sat_add @0 @1)
> - (cond^ (lt (bit_and:c (bit_xor:c @0 (nop_convert@2 (plus (nop_convert @0)
> - (nop_convert @1
> -  (bit_not (bit_xor:c @0 @1)))
> -   integer_zerop)
> -   (bit_xor:c (negate (convert (lt @0 integer_zerop))) max_value)
> -   @2)
> - (if (INTEGRAL_TYPE_P (type) && !TYPE_UNSIGNED (type
> -
> -/* Signed saturation add, case 2:
> -   T sum = (T)((UT)X + (UT)Y)
> -   SAT_S_ADD = (X ^ sum) & !(X ^ Y) >= 0 ? sum : (-(T)(X < 0) ^ MAX);
> -
> -   The T and UT are type pair like T=int8_t, UT=uint8_t.  */
> -(match (signed_integer_sat_add @0 @1)
> - (cond^ (ge (bit_and:c (bit_xor @0 (nop_convert@2 (plus (nop_convert @0)
> -   (nop_convert @1
> -  (bit_not (bit_xor:c @0 @1)))
> -   integer_zerop)
> -   @2
> -   (bit_xor:c (negate (convert (lt @0 integer_zerop))) max_value))
> - (if (INTEGRAL_TYPE_P (type) && !TYPE_UNSIGNED (type
> -
> -/* Signed saturation add, case 3:
> -   T sum = (T)((UT)X + (UT)Y)
> -   SAT_S_ADD = (X ^ Y) < 0 && (X ^ sum) >= 0 ? (-(T)(X < 0) ^ MAX) : sum;
> -
> -   The T and UT are type pair like T=int8_t, UT=uint8_t.  */
> -(match (signed_integer_sat_add @0 @1)
> - (cond^ (bit_and:c (lt (bit_xor @0 (nop_convert@2 (plus (nop_convert @0)
> -   (nop_convert @1
> -  integer_zerop)
> -  (ge (bit_xor:c @0 @1) integer_zerop))
> -   (bit_xor:c (nop_convert (negate (nop_convert (convert
> - (lt @0 
> integer_zerop)
> -  max_value)
> -   @2)
> - (if (INTEGRAL_TYPE_P (type) && !TYPE_UNSIGNED (type
> -
> -/* Signed saturation add, case 4:
> -   Z = .ADD_OVERFLOW (X, Y)
> -   SAT_S_ADD = IMAGPART_EXPR (Z) != 0 ? (-(T)(X < 0) ^ MAX) : sum;  */
> -(match (signed_integer_sat_add @0 @1)
> - (cond^ (ne (imagpart (IFN_ADD_OVERFLOW:c@2 @0 @1)) integer_zerop)
> -   (bit_xor:c (nop_convert?
> -   (negate (nop_convert? (convert (lt @0 integer_zerop)
> -  max_value)
> -   (realpart @2))
> - (if (INTEGRAL_TYPE_P (type) && !TYPE_UNSIGNED (type)
> -  && types_match (type, @0, @1
> -
> -/* Signed saturation add, case 5:
> -   T sum = (T)((UT)X + (UT)Y);
> -   SAT_S_ADD = (X ^ sum) < 0 & ~((X ^ Y) < 0) ? (-(T)(X < 0) ^ MAX) : sum;
> -
> -   The T and UT are type pair like T=int8_t, UT=uint8_t.  */
> -(match (signed_integer_sat_add @0 @1)
> - (cond^ (bit_and:c (lt (bit_xor @0 (nop_convert@2 (plus (nop_convert @0)
> +(if (INTEGRAL_TYPE_P (type) && !TYPE_UNSIGNED (type))
> + (match (signed_integer_sat_add @0 @1)
> +  /* T SUM = (T)((UT)X + (UT)Y)
> + SAT_S_ADD = (X ^ SUM) & !(X ^ Y) < 0 ? (-(T)(X < 0) ^ MAX) : SUM  */
> +  (cond^ (lt (bit_and:c (bit_xor:c @0 (nop_convert@2 (plus (nop_convert @0)
> +  (nop_convert @1
> +   (bit_not (bit_xor:c @0 @1)))
> +integer_zerop)
> +(bit_xor:c (negate (convert (lt @0 integer_zerop))) max_value)
> +@2))
> + (match (signed_integer_sat_add @0 @1)
> +  /* T SUM = (T)((UT)X + (UT)Y)
> + SAT_S_ADD = (X ^ SUM) & !(X ^ Y) >= 0 ? SUM : (-(T)(X < 0) ^ MAX)  */
> +  (cond^ (ge (bit_and:c (bit_xor @0 (nop_convert@2 (plus (nop_convert @0)
>  (nop_convert @1
> -  integer_zerop)
> -  (bit_not (lt (bit_xor:c @0 @1) integer_zerop)))
> -   (bit_xor:c (nop_convert (negate (nop_convert (convert
> +   (bit_not (bit_xor:c @0 @1)))
> +integer_zerop)
> +@2
> +(bit_xor:c (negate (convert (lt 

Re: [Fortran, Patch, PR107635, Part 1] Rework handling of allocatable components in derived type coarrays.

2024-12-21 Thread Damian Rouson
On Tue, Dec 17, 2024 at 20:05 Steve Kargl 
wrote:

> On Mon, Dec 16, 2024 at 04:53:42AM -0800,
Or, perhaps, you care to qualify your generalization?

Thanks for asking.  When I tried using kind type parameters on derived
types with gfortran a few months ago, I gave up because the issues appeared
to be so fundamental that I couldn’t even find workarounds that would allow
me to use the feature at all while awaiting patches.  I corresponded with
Paul, who did the initial implementation of parameterized derives.  I hope
Paul is ok with me quoting his description of the overall situation about 2
months ago.  Paul’s assessment is below.  Also,  I believe Andre is
planning to work on PDT support sometime next year.

Damian


— snip —

The most significant change that is required comes about from PR82649.
While kludges exist, the best approach is to completely change the PDT
representation,
which is generated in decl.cc(gfc_get_pdt_instance). My plan was to
represent a PDT instance by a container:

type(pdt_instance)
   type(pdt_data), dimension(gfc_max_dimensions), pointer :: data
   integer, kind :: param1
...
  integer, len :: paramN
...
end type

Of course, this change will result in a huge amount of downstream fallout
in resolve.cc and trans*.cc. Grepping "attr.pdt" will reveal the affected
files.

The present representation for *each element* is:
type(pdt_instance)
   integer, kind :: param1
...
  integer, len :: paramN
...
  data_components
end type

A possible alternative approach would be to add a "hidden" field,
_allocated and to leave a single element with the parameter fields
retaining their values after deallocation.


[PATCH 2/2] Ada: Fix GNU/Hurd maximum priority

2024-12-21 Thread Samuel Thibault
gcc/ada/ChangeLog:

* libgnat/system-gnu.ads: Set Max_Priority to 60.

Signed-off-by: Samuel Thibault 
---
 gcc/ada/libgnat/system-gnu.ads | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/ada/libgnat/system-gnu.ads b/gcc/ada/libgnat/system-gnu.ads
index f46b32359f2..5049ab88856 100644
--- a/gcc/ada/libgnat/system-gnu.ads
+++ b/gcc/ada/libgnat/system-gnu.ads
@@ -95,7 +95,7 @@ package System is
 
--  Priority-related Declarations (RM D.1)
 
-   Max_Priority   : constant Positive := 0;
+   Max_Priority   : constant Positive := 60;
Max_Interrupt_Priority : constant Positive := 63;
 
subtype Any_Priority   is Integer  range  0 .. 63;
-- 
2.43.0



[PATCH 1/2] Ada: Add GNU/Hurd glibc api bits

2024-12-21 Thread Samuel Thibault
They are mostly shared with Linux

gcc/ada/ChangeLog:

* s-oscons-tmplt.c [__GNU__] (_XOPEN_SOURCE, _BSD_SOURCE): Define.
[__GNU__]: Include  and 
[__GNU__]: Set MSG_Forced_Flags to "MSG_NOSIGNAL".
[__GNU__]: Define SIZEOF_sigset.
[__GNU__]: Define PTHREAD_*SIZE

Signed-off-by: Samuel Thibault 
---
 gcc/ada/s-oscons-tmplt.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/gcc/ada/s-oscons-tmplt.c b/gcc/ada/s-oscons-tmplt.c
index 96eb99dfdac..4e1f6fbdd2b 100644
--- a/gcc/ada/s-oscons-tmplt.c
+++ b/gcc/ada/s-oscons-tmplt.c
@@ -86,7 +86,7 @@ pragma Style_Checks ("N");
  ** a number of non-POSIX but useful/required features.
  **/
 
-#if defined (__linux__) || defined (__ANDROID__)
+#if defined (__linux__) || defined (__ANDROID__) || defined (__GNU__)
 
 /* Define _XOPEN_SOURCE to get IOV_MAX */
 # if !defined (_XOPEN_SOURCE)
@@ -96,7 +96,7 @@ pragma Style_Checks ("N");
 /* Define _BSD_SOURCE to get CRTSCTS */
 # define _BSD_SOURCE
 
-#endif /* defined (__linux__) || defined (__ANDROID__) */
+#endif /* defined (__linux__) || defined (__ANDROID__) || defined (__GNU__) */
 
 /* Include gsocket.h before any system header so it can redefine FD_SETSIZE */
 
@@ -160,7 +160,7 @@ pragma Style_Checks ("N");
 #endif
 
 #if defined (__linux__) || defined (__ANDROID__) || defined (__QNX__) \
-  || defined (__rtems__)
+  || defined (__rtems__) || defined (__GNU__)
 # include 
 # include 
 #endif
@@ -1469,7 +1469,7 @@ CND(MSG_WAITALL, "Wait for full reception")
 #endif
 CND(MSG_NOSIGNAL, "No SIGPIPE on send")
 
-#if defined (__linux__) || defined (__ANDROID__) || defined (__QNX__)
+#if defined (__linux__) || defined (__ANDROID__) || defined (__QNX__) || 
defined (__GNU__)
 # define MSG_Forced_Flags "MSG_NOSIGNAL"
 #else
 # define MSG_Forced_Flags "0"
@@ -1938,7 +1938,7 @@ CST(Poll_Linkname, "")
 
 #endif /* HAVE_SOCKETS */
 
-#if defined (__linux__) || defined (__ANDROID__) || defined (__QNX__)
+#if defined (__linux__) || defined (__ANDROID__) || defined (__QNX__) || 
defined (__GNU__)
 #define SIZEOF_sigset (sizeof (sigset_t))
 CND(SIZEOF_sigset, "sigset")
 #endif
@@ -1999,7 +1999,7 @@ CNS(CLOCK_RT_Ada, "")
 
 #if defined (__APPLE__) || defined (__ANDROID__) || defined (DUMMY) \
   || defined (__FreeBSD__) || defined (__linux__) \
-  || defined (__QNX__) || defined (__rtems__)
+  || defined (__QNX__) || defined (__rtems__) || defined (__GNU__)
 
 /*
 
@@ -2044,7 +2044,7 @@ CND(PTHREAD_RWLOCK_SIZE, "pthread_rwlock_t")
 CND(PTHREAD_ONCE_SIZE,   "pthread_once_t")
 
 #endif /* __APPLE__ || __ANDROID__ || __FreeBSD ||__linux__
-  || __QNX__|| __rtems__ */
+  || __QNX__|| __rtems__ || __GNU__ */
 
 /*
 
-- 
2.43.0



[PATCH] Add OPTION_GLIBC_P and OPTION_GLIBC

2024-12-21 Thread Samuel Thibault
From: Svante Signell 

GNU/Hurd uses glibc just like GNU/Linux.

This is needed for gcc to notice that glibc supports split stack in
finish_options.

gcc/ChangeLog:
* gcc/config/gnu.h (OPTION_GLIBC_P, OPTION_GLIBC): Define.

Patch from Svante Signell for PR go/104290.
---
 gcc/config/gnu.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gcc/config/gnu.h b/gcc/config/gnu.h
index e2a33baf040..d082816aaa3 100644
--- a/gcc/config/gnu.h
+++ b/gcc/config/gnu.h
@@ -19,6 +19,9 @@ You should have received a copy of the GNU General Public 
License
 along with GCC.  If not, see .
 */
 
+#define OPTION_GLIBC_P(opts)   (DEFAULT_LIBC == LIBC_GLIBC)
+#define OPTION_GLIBC   OPTION_GLIBC_P (&global_options)
+
 #undef GNU_USER_TARGET_OS_CPP_BUILTINS
 #define GNU_USER_TARGET_OS_CPP_BUILTINS()  \
 do {   \
-- 
2.43.0



Re: [PING] [PATCH, part4] Fortran: fix passing of NULL() to assumed-rank, derived type dummy [PR104819]

2024-12-21 Thread Harald Anlauf

Hi Andre,

Am 21.12.24 um 17:41 schrieb Andre Vehreschild:

Hi Harald,

the patch looks ok to me.


thanks for taking a look!

Pushed as r15-6408.

Harald


Thanks for the patch,
Andre


On Fri, 20 Dec 2024 19:00:05 +0100
Harald Anlauf  wrote:


Ping!

Am 14.12.24 um 20:56 schrieb Harald Anlauf:

Dear all,

this patch is the 4th part of a series on the passing of NULL() to
assumed-rank dummies.  This one handles the case of a derived type
dummy and is mostly straightforward.

There was one particular problem I encountered: passing NULL() to
an allocatable dummy with no intent given.  This lead to an ICE
I could not resolve other than treating this the same as if an
intent(in) were given.  If someone has a better idea, I'd love
to learn about it...

Testcase cross-checked with Intel's ifx.

Regtested on x86_64-pc-linux-gnu.  OK for mainline?

Thanks,
Harald

P.S.: if someone would like to assist with the case of class
dummies, please let me know.







--
Andre Vehreschild * Email: vehre ad gmx dot de






Re: [PATCH v3] libstdc++: fix a dangling reference crash in ranges::is_permutation

2024-12-21 Thread Giuseppe D'Angelo

Hello,

On 20/12/2024 22:20, Patrick Palka wrote:

The attached patch fixes it. I've tested on Linux x86-64. Adding a
negative test for this is somehow challenging (how do you test you're
not using a dangling reference?), but running the modified test under
ASAN shows the fix in place.


I'd expect a constexpr version of the test to reliably fail as soon as
it encounters the UB.


Good idea! added.






Do you need me to create a report on bugzilla and cross-reference it
from the patch?


That'd be good since we'll probably want to backport the fix to the
release branches and the PR could reflect that.


Done, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118160



Makes sense, but it might be preferable for sake of QoI to fix this
without introducing extra dereferences or projection applications
if possible.

auto&& is supposed to perform lifetime extension, but that only happens
for an outermost temporary and not any temporaries within a
subexpression IIUC.  So how about if we use a second auto&& for the
*__scan subexpression so that lifetime extension occurs there?



libstdc++-v3/ChangeLog:

* include/bits/ranges_algo.h (__is_permutation_fn): Do not cache
the projection result in a local variable, as that may create
dangling references.
* testsuite/25_algorithms/is_permutation/constrained.cc: Add a
test with a range returning prvalues.

Signed-off-by: Giuseppe D'Angelo 
---
  libstdc++-v3/include/bits/ranges_algo.h   |  3 +--
  .../25_algorithms/is_permutation/constrained.cc   | 11 +++
  2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/bits/ranges_algo.h 
b/libstdc++-v3/include/bits/ranges_algo.h
index 772bf4dd997..4d3c4325e2c 100644
--- a/libstdc++-v3/include/bits/ranges_algo.h
+++ b/libstdc++-v3/include/bits/ranges_algo.h
@@ -567,9 +567,8 @@ namespace ranges
  
  	for (auto __scan = __first1; __scan != __last1; ++__scan)

  {
-   auto&& __proj_scan = std::__invoke(__proj1, *__scan);
auto __comp_scan = [&]  (_Tp&& __arg) -> bool {
- return std::__invoke(__pred, __proj_scan,


If we go with the second auto&& approach then we should perfect forward
__proj_scan here as you alluded to.  That might seem unsafe at first
glance (if say the project returns an rvalue) but since the predicate is
regular_invocable it mustn't modify its arguments IIUC.


Just to reiterate: if the projection returns an rvalue, it would be 
wrong for the predicate to actually move from it, as it would violate 
the equality-preserving semantic requirements of regular_invocable? I'll 
add the missing forward then.


New patch attached.

Thanks,
--
Giuseppe D'Angelo

From 61b84e56c2034ae0f93f8d46ff0a1ca7bebf21e2 Mon Sep 17 00:00:00 2001
From: Giuseppe D'Angelo 
Date: Fri, 20 Dec 2024 12:55:01 +0100
Subject: [PATCH] libstdc++: fix a dangling reference crash in
 ranges::is_permutation [PR118160]

The code was caching the result of `invoke(proj, *it)` in a local
`auto &&` variable. The problem is that this may create dangling
references, for instance in case `proj` is `std::identity` (the common
case) and `*it` produces a prvalue: lifetime extension does not
apply here due to the expressions involved.

Instead, store (and lifetime-extend) the result of `*it` in a separate
variable, then project that variable. While at it, also forward the
result of the projection to the predicate, so that the predicate can
act on the proper value category.

libstdc++-v3/ChangeLog:

	PR libstdc++/118160
	* include/bits/ranges_algo.h (__is_permutation_fn): Avoid a
	dangling reference by storing the result of the iterator
	dereference and the result of the projection in two distinct
	variables, in order to lifetime-extend each one.
	Forward the projected value to the predicate.
	* testsuite/25_algorithms/is_permutation/constrained.cc: Add a
	test with a range returning prvalues. Test it in a constexpr
	context, in order to rely on the compiler to catch UB.

Signed-off-by: Giuseppe D'Angelo 
---
 libstdc++-v3/include/bits/ranges_algo.h |  7 +--
 .../25_algorithms/is_permutation/constrained.cc | 13 +
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/bits/ranges_algo.h b/libstdc++-v3/include/bits/ranges_algo.h
index 772bf4dd997..80d8123443f 100644
--- a/libstdc++-v3/include/bits/ranges_algo.h
+++ b/libstdc++-v3/include/bits/ranges_algo.h
@@ -567,9 +567,12 @@ namespace ranges
 
 	for (auto __scan = __first1; __scan != __last1; ++__scan)
 	  {
-	auto&& __proj_scan = std::__invoke(__proj1, *__scan);
+	auto&& __scan_deref = *__scan;
+	auto&& __proj_scan =
+	  std::__invoke(__proj1, std::forward(__scan_deref));
 	auto __comp_scan = [&]  (_Tp&& __arg) -> bool {
-	  return std::__invoke(__pred, __proj_scan,
+	  return std::__invoke(__pred,
+   std::forward(__proj_scan),
    std::forward<_Tp>(__arg));
 	};
 	if (__scan 

Re: [PATCH] vect: Do not use partial vectors when emulating vectors [PR116351].

2024-12-21 Thread Richard Biener
On Thu, 19 Dec 2024, Robin Dapp wrote:

> > I wonder if LOOP_VINFO_LENS is really empty here?  If not, who recorded
> > the len and why did that not disable partial vectors?
> 
> It's not empty.  vectorizable_operation fills it for a vectype of vector short
> (4).  Before (in vector_type_mode), we determined that a vector long (1) has 
> an
> integer mode with the same size so it is not discarded.

I don't quite understand - you are checking loop_vinfo->vector_mode, but
how can you be sure no chosen vector uses a !VECTOR_MODE_P?  It seems
fragile to rely on (it might work in this case), instead when any
!VECTOR_MODE_P needs a 'len' we should reject it - so why does this
not happen here?

Richard.


Re: [PATCH] testsuite: generalize ifcombine field-merge tests [PR118025]

2024-12-21 Thread Richard Biener



> Am 21.12.2024 um 06:29 schrieb Alexandre Oliva :
> 
> On Dec 20, 2024, Jakub Jelinek  wrote:
> 
>>> On Wed, Dec 18, 2024 at 12:59:11AM -0300, Alexandre Oliva wrote:
>>> * gcc.dg/field-merge-16.c: New.
> 
>> Note the test FAILs on i686-linux or on x86_64-linux with -m32.
> 
> Also fixed herein.
> 
> 
> A number of tests that check for specific ifcombine transformations
> fail on AVR and PRU targets, whose type sizes and alignments aren't
> conducive of the expected transformations.  Adjust the expectations.
> 
> Most execution tests should run successfully regardless of the
> transformations, but a few that could conceivably fail if short and
> char have the same bit width now check for that and bypass the tests
> that would fail.
> 
> Conversely, one test that had such a runtime test, but that would work
> regardless, no longer has that runtime test, and its types are
> narrowed so that the transformations on 32-bit targets are more likely
> to be the same as those that used to take place on 64-bit targets.
> This latter change is somewhat obviated by a separate patch, but I've
> left it in place anyway.
> 
> Regstrapped on x86_64-linux-gnu.  I'd appreciate if someone who can test
> AVR and PRU would confirm that it fixes all field-merge-* failures.  Ok
> to install?

Ok

Richard 

> 
> for  gcc/testsuite/ChangeLog
> 
>PR testsuite/118025
>* field-merge-1.c: Skip BIT_FIELD_REF counting on AVR and PRU.
>* field-merge-3.c: Bypass the test if short doesn't have the
>expected size.
>* field-merge-8.c: Likewise.
>* field-merge-9.c: Likewise.  Skip optimization counting on
>AVR and PRU.
>* field-merge-14.c: Skip optimization counting on AVR and PRU.
>* field-merge-15.c: Likewise.
>* field-merge-17.c: Likewise.
>* field-merge-16.c: Likewise.  Drop runtime bypass.  Use
>smaller types.
> ---
> gcc/testsuite/gcc.dg/field-merge-1.c  |2 +-
> gcc/testsuite/gcc.dg/field-merge-13.c |2 +-
> gcc/testsuite/gcc.dg/field-merge-14.c |3 ++-
> gcc/testsuite/gcc.dg/field-merge-15.c |2 +-
> gcc/testsuite/gcc.dg/field-merge-16.c |   17 +++--
> gcc/testsuite/gcc.dg/field-merge-17.c |2 +-
> gcc/testsuite/gcc.dg/field-merge-3.c  |2 ++
> gcc/testsuite/gcc.dg/field-merge-8.c  |2 ++
> gcc/testsuite/gcc.dg/field-merge-9.c  |4 +++-
> 9 files changed, 20 insertions(+), 16 deletions(-)
> 
> diff --git a/gcc/testsuite/gcc.dg/field-merge-1.c 
> b/gcc/testsuite/gcc.dg/field-merge-1.c
> index 1818e104437e1..4405d40ee79d8 100644
> --- a/gcc/testsuite/gcc.dg/field-merge-1.c
> +++ b/gcc/testsuite/gcc.dg/field-merge-1.c
> @@ -58,7 +58,7 @@ int main () {
>   return 0;
> }
> 
> -/* { dg-final { scan-tree-dump-times "BIT_FIELD_REF" 8 "optimized" } } */
> +/* { dg-final { scan-tree-dump-times "BIT_FIELD_REF" 8 "optimized" { target 
> { ! { avr-*-* pru-*-* } } } } } */
> /* { dg-final { scan-assembler-not "cmpb" { target { i*86-*-* || x86_64-*-* } 
> } } } */
> /* { dg-final { scan-assembler-times "cmpl" 8 { target { i*86-*-* || 
> x86_64-*-* } } } } */
> /* { dg-final { scan-assembler-times "cmpw" 8 { target { powerpc*-*-* || 
> rs6000-*-* } } } } */
> diff --git a/gcc/testsuite/gcc.dg/field-merge-13.c 
> b/gcc/testsuite/gcc.dg/field-merge-13.c
> index 7e4f4c499347f..eeef73338f8e5 100644
> --- a/gcc/testsuite/gcc.dg/field-merge-13.c
> +++ b/gcc/testsuite/gcc.dg/field-merge-13.c
> @@ -90,4 +90,4 @@ int main () {
>   return 0;
> }
> 
> -/* { dg-final { scan-tree-dump-times "optimizing" 9 "ifcombine" } } */
> +/* { dg-final { scan-tree-dump-times "optimizing" 9 "ifcombine" { target { ! 
> { avr-*-* pru-*-* } } } } } */
> diff --git a/gcc/testsuite/gcc.dg/field-merge-14.c 
> b/gcc/testsuite/gcc.dg/field-merge-14.c
> index 91d84cfebf196..73259e0936e4e 100644
> --- a/gcc/testsuite/gcc.dg/field-merge-14.c
> +++ b/gcc/testsuite/gcc.dg/field-merge-14.c
> @@ -1,7 +1,8 @@
> /* { dg-do run } */
> /* { dg-options "-O -fdump-tree-ifcombine-details" } */
> 
> -/* Check that we don't get confused by multiple conversions.  */
> +/* Check that we don't get confused by multiple conversions.  Conceivably, we
> +   could combine both tests using b, but the current logic won't do that.  */
> 
> __attribute__((noipa))
> int f(int *a,int *d)
> diff --git a/gcc/testsuite/gcc.dg/field-merge-15.c 
> b/gcc/testsuite/gcc.dg/field-merge-15.c
> index 34641e893c92f..fc38464527161 100644
> --- a/gcc/testsuite/gcc.dg/field-merge-15.c
> +++ b/gcc/testsuite/gcc.dg/field-merge-15.c
> @@ -33,4 +33,4 @@ int main () {
>   return 0;
> }
> 
> -/* { dg-final { scan-tree-dump-times "optimizing" 6 "ifcombine" } } */
> +/* { dg-final { scan-tree-dump-times "optimizing" 6 "ifcombine" { target { ! 
> { avr-*-* pru-*-* } } } } } */
> diff --git a/gcc/testsuite/gcc.dg/field-merge-16.c 
> b/gcc/testsuite/gcc.dg/field-merge-16.c
> index 2ca23ea663a45..afdaf45b6a949 100644
> --- a/gcc/testsuite/gcc.dg/field-merge-16.c
> +++ b/gcc/testsuite/gcc.dg/field-merge-16.c
> @@ -4,17 +4,17 @@
> /* Check that tests for