public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Harald Anlauf <anlauf@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-6900] Fortran: add missing conversions for result of intrinsics to result type
Date: Thu, 27 Jan 2022 19:23:49 +0000 (GMT)	[thread overview]
Message-ID: <20220127192350.02A3D3858430@sourceware.org> (raw)

https://gcc.gnu.org/g:7eb61a45a171d4f8f5bf4d4f469d42e657c69a6a

commit r12-6900-g7eb61a45a171d4f8f5bf4d4f469d42e657c69a6a
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Thu Jan 27 20:23:00 2022 +0100

    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.

Diff:
---
 gcc/fortran/trans-intrinsic.cc        | 13 +++++++------
 gcc/testsuite/gfortran.dg/pr84784.f90 | 27 +++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 6 deletions(-)

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..3129b927687
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr84784.f90
@@ -0,0 +1,27 @@
+! { 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
+  if (runtime_poppar(1_16) /= 1) STOP 3
+contains
+  integer function runtime_popcnt (i)
+    integer(kind=16), intent(in) :: i
+    runtime_popcnt = popcnt(i)
+  end function
+  integer function runtime_poppar (i)
+    integer(kind=16), intent(in) :: i
+    runtime_poppar = poppar(i)
+  end function
+end


                 reply	other threads:[~2022-01-27 19:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220127192350.02A3D3858430@sourceware.org \
    --to=anlauf@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).