public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch, fortran] Fix PR 88658, wrong type for MAX1 and friends type when simplifying
@ 2019-01-02 14:32 Thomas Koenig
  2019-01-06 10:54 ` *ping* " Thomas Koenig
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Koenig @ 2019-01-02 14:32 UTC (permalink / raw)
  To: fortran, gcc-patches

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

Hello world,

the attached patch fixes the PR, a regression introduced by r265649,
by special-casing those intrinsics of the min/max family which
need to be special-cased.

This is actually something that had been fixed before (PR 14377),
but at the time, no test case had been committed.

Regression-tested. OK for trunk?

Regards

	Thomas

2019-01-02  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/88658
	* gfortran.h: Add macro gfc_real_4_kind
	* simplify.c (simplify_min_max): Special case for the types of
	AMAX0, AMIN0, MAX1 and MIN1, which actually change the types of
	their arguments.

2019-01-02  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/88658
	* gfortran.dg/min_max_type_2.f90: New test.

[-- Attachment #2: p1.diff --]
[-- Type: text/x-patch, Size: 1623 bytes --]

Index: gfortran.h
===================================================================
--- gfortran.h	(Revision 267335)
+++ gfortran.h	(Arbeitskopie)
@@ -2967,6 +2967,7 @@ extern int gfc_character_storage_size;
 
 #define gfc_logical_4_kind 4
 #define gfc_integer_4_kind 4
+#define gfc_real_4_kind 4
 
 /* symbol.c */
 void gfc_clear_new_implicit (void);
Index: simplify.c
===================================================================
--- simplify.c	(Revision 267335)
+++ simplify.c	(Arbeitskopie)
@@ -4963,6 +4963,8 @@ static gfc_expr *
 simplify_min_max (gfc_expr *expr, int sign)
 {
   gfc_actual_arglist *arg, *last, *extremum;
+  gfc_expr *tmp, *ret;
+  const char *fname;
 
   last = NULL;
   extremum = NULL;
@@ -4995,7 +4997,27 @@ simplify_min_max (gfc_expr *expr, int sign)
   if (expr->value.function.actual->next != NULL)
     return NULL;
 
-  return gfc_copy_expr (expr->value.function.actual->expr);
+  /* Handle special cases of specific functions (min|max)1 and
+     a(min|max)0.  */
+
+  tmp = expr->value.function.actual->expr;
+  fname = expr->value.function.isym->name;
+
+  if ((tmp->ts.type != BT_INTEGER || tmp->ts.kind != gfc_integer_4_kind)
+      && (strcmp (fname, "min1") == 0 || strcmp (fname, "max1") == 0))
+    {
+      ret = gfc_convert_constant (tmp, BT_INTEGER, gfc_integer_4_kind);
+    }
+  else if ((tmp->ts.type != BT_REAL || tmp->ts.kind != gfc_real_4_kind)
+	   && (strcmp (fname, "amin0") == 0 || strcmp (fname, "amax0") == 0))
+    {
+      ret = gfc_convert_constant (tmp, BT_REAL, gfc_real_4_kind);
+    }
+  else
+    ret = gfc_copy_expr (tmp);
+
+  return ret;
+
 }
 
 

[-- Attachment #3: min_max_type_2.f90 --]
[-- Type: text/x-fortran, Size: 506 bytes --]

! { dg-do  run }
! PR 88658 - make sure the types for min1, max1, amax0 and amin0 are
! correct when simplified

program main
  real :: RVCOMP
  character (len=12) :: line
  integer :: n

  RVCOMP = MAX1(2.3, 3.1, 4.4) / 5 
  if (rvcomp /= 0.) stop 1
  rvcomp = min1(2.3, 3.1, 5.1) / 5
  if (rvcomp /= 0.) stop 2
  write (unit=line, fmt='(F12.5)') amax0(42, 21, 7)
  if (line /= '    42.00000') stop 3
  write (unit=line, fmt='(F12.5)') amin0(42,21,7)
  if (line /= '     7.00000') stop 4
end program main

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

* *ping* [patch, fortran] Fix PR 88658, wrong type for MAX1 and friends type when simplifying
  2019-01-02 14:32 [patch, fortran] Fix PR 88658, wrong type for MAX1 and friends type when simplifying Thomas Koenig
@ 2019-01-06 10:54 ` Thomas Koenig
  2019-01-06 11:48   ` Janne Blomqvist
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Koenig @ 2019-01-06 10:54 UTC (permalink / raw)
  To: fortran, gcc-patches

Am 02.01.19 um 15:31 schrieb Thomas Koenig:
> Hello world,
> 
> the attached patch fixes the PR, a regression introduced by r265649,
> by special-casing those intrinsics of the min/max family which
> need to be special-cased.
> 
> This is actually something that had been fixed before (PR 14377),
> but at the time, no test case had been committed.
> 
> Regression-tested. OK for trunk?
> 
> Regards
> 
>      Thomas

Ping?

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

* Re: *ping* [patch, fortran] Fix PR 88658, wrong type for MAX1 and friends type when simplifying
  2019-01-06 10:54 ` *ping* " Thomas Koenig
@ 2019-01-06 11:48   ` Janne Blomqvist
  0 siblings, 0 replies; 3+ messages in thread
From: Janne Blomqvist @ 2019-01-06 11:48 UTC (permalink / raw)
  To: Thomas Koenig; +Cc: fortran, gcc-patches

On Sun, Jan 6, 2019 at 12:54 PM Thomas Koenig <tkoenig@netcologne.de> wrote:

> Am 02.01.19 um 15:31 schrieb Thomas Koenig:
> > Hello world,
> >
> > the attached patch fixes the PR, a regression introduced by r265649,
> > by special-casing those intrinsics of the min/max family which
> > need to be special-cased.
> >
> > This is actually something that had been fixed before (PR 14377),
> > but at the time, no test case had been committed.
> >
> > Regression-tested. OK for trunk?
> >
> > Regards
> >
> >      Thomas
>
> Ping?
>

Ok, thanks.

-- 
Janne Blomqvist

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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-02 14:32 [patch, fortran] Fix PR 88658, wrong type for MAX1 and friends type when simplifying Thomas Koenig
2019-01-06 10:54 ` *ping* " Thomas Koenig
2019-01-06 11:48   ` Janne Blomqvist

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).