PR 84615 Regressions due to type mismatch with character functions
authorJanne Blomqvist <jb@gcc.gnu.org>
Wed, 21 Mar 2018 18:46:44 +0000 (20:46 +0200)
committerJanne Blomqvist <jb@gcc.gnu.org>
Wed, 21 Mar 2018 18:46:44 +0000 (20:46 +0200)
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.

gcc/fortran/ChangeLog:

2018-03-21  Janne Blomqvist  <jb@gcc.gnu.org>

PR fortran/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.

From-SVN: r258736

gcc/fortran/ChangeLog
gcc/fortran/trans-expr.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/char_result_17.f90 [new file with mode: 0644]

index 8bcaabbf6259645a10f26cf73085ba24abc4ee90..b69b559cae7fb7cb77e9de60e23ff6b682c1878c 100644 (file)
@@ -1,8 +1,14 @@
+2018-03-21  Janne Blomqvist  <jb@gcc.gnu.org>
+
+       PR fortran/84615
+       * trans-expr.c (gfc_conv_procedure_call): Convert charlen to
+       gfc_charlen_type_node when calling procedure.
+
 2018-03-20  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        PR fortran/85001
        * interface.c (symbol_rank): Remove bogus null pointer check that
-       crept in when translating a ternary operator into an if-else 
+       crept in when translating a ternary operator into an if-else
        constructor.
 
 2018-03-19  Thomas Koenig  <tkoenig@gcc.gnu.org>
index 54bda1d019b7ec4fe97748e3f88939634808e221..8bf550445cc19739804e20314b0570b4bf142911 100644 (file)
@@ -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;
        }
 
index 5d25d56226a76a0d8cb0b8a954998b422894e975..43122bb71b49f89889086430d35d25219b35f96c 100644 (file)
@@ -1,3 +1,8 @@
+2018-03-21  Janne Blomqvist  <jb@gcc.gnu.org>
+
+       PR fortran/84615
+       * gfortran.dg/char_result_17.f90: New test.
+
 2018-03-21  David Malcolm  <dmalcolm@redhat.com>
 
        PR c++/84994
diff --git a/gcc/testsuite/gfortran.dg/char_result_17.f90 b/gcc/testsuite/gfortran.dg/char_result_17.f90
new file mode 100644 (file)
index 0000000..05ab72d
--- /dev/null
@@ -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