public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Martin Liska <marxin@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/marxin/heads/martin-hook-test-v4)] PR fortran/97272 - Wrong answer from MAXLOC with character argXZXX Date: Fri, 6 Nov 2020 13:06:33 +0000 (GMT) [thread overview] Message-ID: <20201106130633.656413857806@sourceware.org> (raw) https://gcc.gnu.org/g:323a43e556749c93dd0e10e6db37b02c5a763eac commit 323a43e556749c93dd0e10e6db37b02c5a763eac Author: Harald Anlauf <anlauf@gmx.de> Date: Sun Oct 4 20:24:29 2020 +0200 PR fortran/97272 - Wrong answer from MAXLOC with character argXZXX The optional KIND argument to the MINLOC/MAXLOC intrinsic must not be passed to the library function, as the kind conversion of the result is treated explicitly elsewhere. gcc/fortran/ChangeLog: PR fortran/97272 * trans-intrinsic.c (strip_kind_from_actual): Helper function for removal of KIND argument. (gfc_conv_intrinsic_minmaxloc): Ignore KIND argument here, as it is treated elsewhere. gcc/testsuite/ChangeLog: PR fortran/97272 * gfortran.dg/pr97272.f90: New test. Diff: --- gcc/fortran/trans-intrinsic.c | 19 +++++++++++++++++++ gcc/testsuite/gfortran.dg/pr97272.f90 | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c index 3b3bd8629cd..8729bc12152 100644 --- a/gcc/fortran/trans-intrinsic.c +++ b/gcc/fortran/trans-intrinsic.c @@ -5073,6 +5073,24 @@ gfc_conv_intrinsic_dot_product (gfc_se * se, gfc_expr * expr) } +/* Remove unneeded kind= argument from actual argument list when the + result conversion is dealt with in a different place. */ + +static void +strip_kind_from_actual (gfc_actual_arglist * actual) +{ + for (gfc_actual_arglist *a = actual; a; a = a->next) + { + gfc_actual_arglist *b = a->next; + if (b && b->name && strcmp (b->name, "kind") == 0) + { + a->next = b->next; + b->next = NULL; + gfc_free_actual_arglist (b); + } + } +} + /* Emit code for minloc or maxloc intrinsic. There are many different cases we need to handle. For performance reasons we sometimes create two loops instead of one, where the second one is much simpler. @@ -5208,6 +5226,7 @@ gfc_conv_intrinsic_minmaxloc (gfc_se * se, gfc_expr * expr, enum tree_code op) { gfc_actual_arglist *a, *b; a = actual; + strip_kind_from_actual (a); while (a->next) { b = a->next; diff --git a/gcc/testsuite/gfortran.dg/pr97272.f90 b/gcc/testsuite/gfortran.dg/pr97272.f90 new file mode 100644 index 00000000000..e81903860ea --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr97272.f90 @@ -0,0 +1,19 @@ +! { dg-do run } +! PR fortran/97272 - Wrong answer from MAXLOC with character arg + +program test + implicit none + integer :: i, j, k, l = 10 + character, allocatable :: a(:) + allocate (a(l)) + a(:) = 'a' + l = l - 1 + a(l) = 'b' + i = maxloc (a, dim=1) + j = maxloc (a, dim=1, kind=2) + k = maxloc (a, dim=1, kind=8, back=.true.) +! print *, 'i = ', i, 'a(i) = ', a(i) +! print *, 'j = ', j, 'a(j) = ', a(j) +! print *, 'k = ', k, 'a(k) = ', a(k) + if (i /= l .or. j /= l .or. k /= l) stop 1 +end
reply other threads:[~2020-11-06 13:06 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=20201106130633.656413857806@sourceware.org \ --to=marxin@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: linkBe 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).