From: Janne Blomqvist <blomqvist.janne@gmail.com>
To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org
Cc: Janne Blomqvist <blomqvist.janne@gmail.com>
Subject: [PATCH] PR 84615 Regressions due to type mismatch with character functions
Date: Wed, 21 Mar 2018 08:39:00 -0000 [thread overview]
Message-ID: <1521621546-21072-1-git-send-email-blomqvist.janne@gmail.com> (raw)
Since the kind of the hidden character length variable is not part of
the character variable definition, we must ensure that character
lengths are always of the same kind in interfaces, regardless of how
they were declared in the source. This patch ensures this when calling
a procedure.
Regtested on x86_64-pc-linux-gnu and i686-pc-linux-gnu, Ok for trunk?
gcc/fortran/ChangeLog:
2018-03-21 Janne Blomqvist <jb@gcc.gnu.org>
PR fortra/84615
* trans-expr.c (gfc_conv_procedure_call): Convert charlen to
gfc_charlen_type_node when calling procedure.
gcc/testsuite/ChangeLog:
2018-03-21 Janne Blomqvist <jb@gcc.gnu.org>
PR fortran/84615
* gfortran.dg/char_result_17.f90: New test.
---
gcc/fortran/trans-expr.c | 8 ++++++--
gcc/testsuite/gfortran.dg/char_result_17.f90 | 20 ++++++++++++++++++++
2 files changed, 26 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/gfortran.dg/char_result_17.f90
diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index 54bda1d..8bf5504 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -5973,9 +5973,13 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
gfc_add_block_to_block (&se->pre, &parmse.pre);
gfc_add_block_to_block (&se->post, &parmse.post);
tmp = parmse.expr;
+ /* TODO: It would be better to have the charlens as
+ gfc_charlen_type_node already when the interface is
+ created instead of converting it here (see PR 84615). */
tmp = fold_build2_loc (input_location, MAX_EXPR,
- TREE_TYPE (tmp), tmp,
- build_zero_cst (TREE_TYPE (tmp)));
+ gfc_charlen_type_node,
+ fold_convert (gfc_charlen_type_node, tmp),
+ build_zero_cst (gfc_charlen_type_node));
cl.backend_decl = tmp;
}
diff --git a/gcc/testsuite/gfortran.dg/char_result_17.f90 b/gcc/testsuite/gfortran.dg/char_result_17.f90
new file mode 100644
index 0000000..05ab72d
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/char_result_17.f90
@@ -0,0 +1,20 @@
+! { dg-do run }
+! PR fortran/84615
+! Charlen should always be the ABI defined character length type
+! regardless of which kind it is declared as in the source.
+program TestStringTools
+ character(len=52) :: txt
+ character(len=1), dimension(52) :: chararr = &
+ (/(char(i+64),char(i+96), i = 1,26)/)
+ txt = chararray2string(chararr)
+ if (txt .ne. "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz") &
+ STOP 1
+contains
+ function chararray2string(chararray) result(text)
+ character(len=1), dimension(:) :: chararray ! input
+ character(len=int(size(chararray, 1), kind=8)) :: text ! output
+ do i = 1,size(chararray,1)
+ text(i:i) = chararray (i)
+ end do
+ end function chararray2string
+end program TestStringTools
--
2.7.4
next reply other threads:[~2018-03-21 8:39 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-21 8:39 Janne Blomqvist [this message]
2018-03-21 17:45 ` Steve Kargl
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=1521621546-21072-1-git-send-email-blomqvist.janne@gmail.com \
--to=blomqvist.janne@gmail.com \
--cc=fortran@gcc.gnu.org \
--cc=gcc-patches@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).