]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: Fix character-kind=4 substring resolution (PR95837)
authorKwok Cheung Yeung <kcy@codesourcery.com>
Tue, 18 Aug 2020 11:35:43 +0000 (04:35 -0700)
committerKwok Cheung Yeung <kcy@codesourcery.com>
Tue, 18 Aug 2020 11:35:43 +0000 (04:35 -0700)
This is a backport from master of commit
f48bffe70cba310461ec19ffcd07c573a6b86575.

Testing showed that it is always set and its value matches
always ts->kind (if available) or otherwise, if it is a variable,
the sym->ts.kind.

gcc/fortran/ChangeLog:

PR fortran/95837
* resolve.c (gfc_resolve_substring_charlen): Remove
bogus ts.kind setting for the expression.

gcc/testsuite/ChangeLog:

PR fortran/95837
* gfortran.dg/char4-subscript.f90: New test.

gcc/fortran/ChangeLog.omp
gcc/fortran/resolve.c
gcc/testsuite/ChangeLog.omp
gcc/testsuite/gfortran.dg/char4-subscript.f90 [new file with mode: 0644]

index 00c6be0588f66319ab1da5c645445cffa29ff88e..a6b7452ecd596a896b42343248515dc574704111 100644 (file)
@@ -1,3 +1,12 @@
+2020-08-18  Kwok Cheung Yeung  <kcy@codesourcery.com>
+
+       Backport from mainline
+       2020-06-25  Tobias Burnus  <tobias@codesourcery.com>
+
+       PR fortran/95837
+       * resolve.c (gfc_resolve_substring_charlen): Remove
+       bogus ts.kind setting for the expression.
+
 2020-08-14  Kwok Cheung Yeung  <kcy@codesourcery.com>
 
        Backport from mainline
index 3166cc3afc49b4efcc583c62c42ccd617e47566c..c05be550700cf5b5ab3d9e69dab926d8618d3b33 100644 (file)
@@ -5140,9 +5140,6 @@ gfc_resolve_substring_charlen (gfc_expr *e)
        return;
     }
 
-  e->ts.type = BT_CHARACTER;
-  e->ts.kind = gfc_default_character_kind;
-
   if (!e->ts.u.cl)
     e->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL);
 
index 8f652f46a0802365385d1edab8f28211c2b0303c..e9d589fc98f831502d2c06e6fe67154f8060c77e 100644 (file)
@@ -1,3 +1,11 @@
+2020-08-18  Kwok Cheung Yeung  <kcy@codesourcery.com>
+
+       Backport from mainline
+       2020-06-25  Tobias Burnus  <tobias@codesourcery.com>
+
+       PR fortran/95837
+       * gfortran.dg/char4-subscript.f90: New test.
+
 2020-08-14  Kwok Cheung Yeung  <kcy@codesourcery.com>
 
        Backport from mainline
diff --git a/gcc/testsuite/gfortran.dg/char4-subscript.f90 b/gcc/testsuite/gfortran.dg/char4-subscript.f90
new file mode 100644 (file)
index 0000000..f1f915c
--- /dev/null
@@ -0,0 +1,30 @@
+! { dg-do run }
+! { dg-additional-options "-fdump-tree-original" }
+!
+! PR fortran/95837
+!
+type t
+  character(len=:, kind=4), pointer :: str2
+end type t
+type(t) :: var
+
+allocate(character(len=5, kind=4) :: var%str2)
+
+var%str2(1:1) = 4_"d"
+var%str2(2:3) = 4_"ef"
+var%str2(4:4) = achar(int(Z'1F600'), kind=4)
+var%str2(5:5) = achar(int(Z'1F608'), kind=4)
+
+if (var%str2(1:3) /= 4_"def") stop 1
+if (ichar(var%str2(4:4)) /= int(Z'1F600')) stop 2
+if (ichar(var%str2(5:5)) /= int(Z'1F608')) stop 2
+
+deallocate(var%str2)
+end
+
+! Note: the last '\x00' is regarded as string terminator, hence, the tailing \0 byte is not in the dump
+
+! { dg-final { scan-tree-dump "  \\(\\*var\\.str2\\)\\\[1\\\]{lb: 1 sz: 4} = .d\\\\x00\\\\x00.\\\[1\\\]{lb: 1 sz: 4};" "original" } }
+! { dg-final { scan-tree-dump "  __builtin_memmove \\(\\(void \\*\\) &\\(\\*var.str2\\)\\\[2\\\]{lb: 1 sz: 4}, \\(void \\*\\) &.e\\\\x00\\\\x00\\\\x00f\\\\x00\\\\x00.\\\[1\\\]{lb: 1 sz: 4}, 8\\);" "original" } }
+! { dg-final { scan-tree-dump "  \\(\\*var.str2\\)\\\[4\\\]{lb: 1 sz: 4} = .\\\\x00\\\\xf6\\\\x01.\\\[1\\\]{lb: 1 sz: 4};" "original" } }
+! { dg-final { scan-tree-dump "  \\(\\*var.str2\\)\\\[5\\\]{lb: 1 sz: 4} = .\\\\b\\\\xf6\\\\x01.\\\[1\\\]{lb: 1 sz: 4};" "original" } }