* [patch, fortran] Fix PR 83316
@ 2017-12-08 18:42 Thomas Koenig
2017-12-08 19:17 ` Steve Kargl
0 siblings, 1 reply; 2+ messages in thread
From: Thomas Koenig @ 2017-12-08 18:42 UTC (permalink / raw)
To: fortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 560 bytes --]
Hello world,
the attached patch fixes a case where simplification wasn't done
correctly for maxval and minval with character variables.
Regression-tested. OK for trunk?
Regards
Thomas
2017-12-08 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/83316
* arith.c (gfc_character2character): New function.
* arith.h: Add prototype.
* simplify.c (gfc_convert_constant): Handle character type.
2017-12-08 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/83316
* gfortran.dg/minval_char_5.f90: New test.
[-- Attachment #2: p1.diff --]
[-- Type: text/x-patch, Size: 1587 bytes --]
Index: arith.c
===================================================================
--- arith.c (Revision 255181)
+++ arith.c (Arbeitskopie)
@@ -2514,7 +2514,19 @@ gfc_int2log (gfc_expr *src, int kind)
return result;
}
+/* Convert character to character. We only use wide strings internally,
+ so we only set the kind. */
+gfc_expr *
+gfc_character2character (gfc_expr *src, int kind)
+{
+ gfc_expr *result;
+ result = gfc_copy_expr (src);
+ result->ts.kind = kind;
+
+ return result;
+}
+
/* Helper function to set the representation in a Hollerith conversion.
This assumes that the ts.type and ts.kind of the result have already
been set. */
Index: arith.h
===================================================================
--- arith.h (Revision 255181)
+++ arith.h (Arbeitskopie)
@@ -82,6 +82,7 @@ gfc_expr *gfc_hollerith2real (gfc_expr *, int);
gfc_expr *gfc_hollerith2complex (gfc_expr *, int);
gfc_expr *gfc_hollerith2character (gfc_expr *, int);
gfc_expr *gfc_hollerith2logical (gfc_expr *, int);
+gfc_expr *gfc_character2character (gfc_expr *, int);
#endif /* GFC_ARITH_H */
Index: simplify.c
===================================================================
--- simplify.c (Revision 255181)
+++ simplify.c (Arbeitskopie)
@@ -7130,6 +7130,13 @@ gfc_convert_constant (gfc_expr *e, bt type, int ki
}
break;
+ case BT_CHARACTER:
+ if (type == BT_CHARACTER)
+ f = gfc_character2character;
+ else
+ goto oops;
+ break;
+
default:
oops:
gfc_internal_error ("gfc_convert_constant(): Unexpected type");
[-- Attachment #3: minval_char_5.f90 --]
[-- Type: text/x-fortran, Size: 361 bytes --]
! { dg-do run }
! PR fortran/83316 - this used to ICE
program tminmaxval
implicit none
character(len=*), parameter :: b = "a"
character(len=*), parameter :: e = "c"
character(len=*), parameter :: s(3) = (/"a", "b", "c"/)
if (minval(s) /= b) then
call abort
end if
if (maxval(s) /= e) then
call abort
end if
end program tminmaxval
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [patch, fortran] Fix PR 83316
2017-12-08 18:42 [patch, fortran] Fix PR 83316 Thomas Koenig
@ 2017-12-08 19:17 ` Steve Kargl
0 siblings, 0 replies; 2+ messages in thread
From: Steve Kargl @ 2017-12-08 19:17 UTC (permalink / raw)
To: Thomas Koenig; +Cc: fortran, gcc-patches
On Fri, Dec 08, 2017 at 07:42:21PM +0100, Thomas Koenig wrote:
>
> the attached patch fixes a case where simplification wasn't done
> correctly for maxval and minval with character variables.
>
> Regression-tested. OK for trunk?
>
OK.
--
Steve
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-12-08 19:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-08 18:42 [patch, fortran] Fix PR 83316 Thomas Koenig
2017-12-08 19:17 ` Steve Kargl
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).