public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR fortran/84784 - ICEs: verify_gimple failed with -fdefault-integer-8
@ 2022-01-26 20:59 Harald Anlauf
  2022-01-27 11:48 ` Mikael Morin
  0 siblings, 1 reply; 2+ messages in thread
From: Harald Anlauf @ 2022-01-26 20:59 UTC (permalink / raw)
  To: fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 346 bytes --]

Dear Fortranners,

the use of -fdefault-integer-8 exhibits several cases where
we missed to convert the result of an intrinsic from the
declared to the effective resulting type.

The attached obvious patch fixes this for IMAGE_STATUS,
TEAM_NUMBER, and POPCNT/POPPAR.

OK for mainline if regtesting passes on x86_64-pc-linux-gnu?

Thanks,
Harald


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fortran-add-missing-conversions-for-result-of-intrin.patch --]
[-- Type: text/x-patch, Size: 3126 bytes --]

From af5cb1f0ec1cacb47acc8c2b0c0629cf3808e1af Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Wed, 26 Jan 2022 21:50:41 +0100
Subject: [PATCH] Fortran: add missing conversions for result of intrinsics to
 result type

gcc/fortran/ChangeLog:

	PR fortran/84784
	* trans-intrinsic.cc (conv_intrinsic_image_status): Convert result
	to resulting (default) integer type.
	(conv_intrinsic_team_number): Likewise.
	(gfc_conv_intrinsic_popcnt_poppar): Likewise.

gcc/testsuite/ChangeLog:

	PR fortran/84784
	* gfortran.dg/pr84784.f90: New test.
---
 gcc/fortran/trans-intrinsic.cc        | 13 +++++++------
 gcc/testsuite/gfortran.dg/pr84784.f90 | 22 ++++++++++++++++++++++
 2 files changed, 29 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/pr84784.f90

diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc
index fccf0a9b229..da854fad89d 100644
--- a/gcc/fortran/trans-intrinsic.cc
+++ b/gcc/fortran/trans-intrinsic.cc
@@ -2620,7 +2620,7 @@ conv_intrinsic_image_status (gfc_se *se, gfc_expr *expr)
   else
     gcc_unreachable ();

-  se->expr = tmp;
+  se->expr = fold_convert (gfc_get_int_type (gfc_default_integer_kind), tmp);
 }

 static void
@@ -2662,7 +2662,7 @@ conv_intrinsic_team_number (gfc_se *se, gfc_expr *expr)
   else
     gcc_unreachable ();

-  se->expr = tmp;
+  se->expr = fold_convert (gfc_get_int_type (gfc_default_integer_kind), tmp);
 }


@@ -7255,12 +7255,13 @@ gfc_conv_intrinsic_popcnt_poppar (gfc_se * se, gfc_expr *expr, int parity)

       /* Combine the results.  */
       if (parity)
-	se->expr = fold_build2_loc (input_location, BIT_XOR_EXPR, result_type,
-				    call1, call2);
+	se->expr = fold_build2_loc (input_location, BIT_XOR_EXPR,
+				    integer_type_node, call1, call2);
       else
-	se->expr = fold_build2_loc (input_location, PLUS_EXPR, result_type,
-				    call1, call2);
+	se->expr = fold_build2_loc (input_location, PLUS_EXPR,
+				    integer_type_node, call1, call2);

+      se->expr = convert (result_type, se->expr);
       return;
     }

diff --git a/gcc/testsuite/gfortran.dg/pr84784.f90 b/gcc/testsuite/gfortran.dg/pr84784.f90
new file mode 100644
index 00000000000..48dd4dd4b0a
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr84784.f90
@@ -0,0 +1,22 @@
+! { dg-do compile }
+! { dg-options "-fcoarray=lib -fdefault-integer-8" }
+! { dg-require-effective-target fortran_integer_16 }
+! PR fortran/84784 - ICEs: verify_gimple failed with -fdefault-integer-8
+
+  use iso_fortran_env, only : team_type, STAT_FAILED_IMAGE
+  implicit none
+  type(team_type) :: team
+  integer         :: new_team
+  new_team = mod(this_image(),2)+1
+  form team (new_team,team)
+    change team (team)
+    if (team_number() /= new_team) STOP 1
+  end team
+  if (image_status (1) == STAT_FAILED_IMAGE) ERROR STOP "cannot recover"
+  if (runtime_popcnt(0_16) /= 0) STOP 2
+contains
+  integer function runtime_popcnt (i)
+    integer(kind=16), intent(in) :: i
+    runtime_popcnt = popcnt(i)
+  end function
+end
--
2.31.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] PR fortran/84784 - ICEs: verify_gimple failed with -fdefault-integer-8
  2022-01-26 20:59 [PATCH] PR fortran/84784 - ICEs: verify_gimple failed with -fdefault-integer-8 Harald Anlauf
@ 2022-01-27 11:48 ` Mikael Morin
  0 siblings, 0 replies; 2+ messages in thread
From: Mikael Morin @ 2022-01-27 11:48 UTC (permalink / raw)
  To: Harald Anlauf, fortran, gcc-patches

Le 26/01/2022 à 21:59, Harald Anlauf via Fortran a écrit :
> Dear Fortranners,
> 
> the use of -fdefault-integer-8 exhibits several cases where
> we missed to convert the result of an intrinsic from the
> declared to the effective resulting type.
> 
> The attached obvious patch fixes this for IMAGE_STATUS,
> TEAM_NUMBER, and POPCNT/POPPAR.
> 
> OK for mainline if regtesting passes on x86_64-pc-linux-gnu?
> 
This is not a regression, but should be safe.
Can you add a test of POPPAR, similar to that of POPCNT?
OK with that change.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-01-27 11:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-26 20:59 [PATCH] PR fortran/84784 - ICEs: verify_gimple failed with -fdefault-integer-8 Harald Anlauf
2022-01-27 11:48 ` Mikael Morin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).