public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/104128] New: ICE in gfc_widechar_to_char, at fortran/scanner.c:199
@ 2022-01-19 18:51 gscfq@t-online.de
  2022-01-19 19:29 ` [Bug fortran/104128] " anlauf at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: gscfq@t-online.de @ 2022-01-19 18:51 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104128

            Bug ID: 104128
           Summary: ICE in gfc_widechar_to_char, at fortran/scanner.c:199
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gscfq@t-online.de
  Target Milestone: ---

Affects versions down to at least r5 :
(follow-up of pr83079)


$ cat z1.f90
program p
   character(3), parameter :: a = 'abc'
   print *, transfer(a , 4_'xy', size=2)
end


$ cat z2.f90
program p
   character(len=3, kind=4), parameter :: a = 'abc'
   print *, transfer('xyz', [a], size=2)
end


$ gfortran-12-20220116 -c z1.f90
f951: internal compiler error: in gfc_widechar_to_char, at
fortran/scanner.c:199
0x7737d6 gfc_widechar_to_char(unsigned int const*, int)
        ../../gcc/fortran/scanner.c:199
0x792e22 gfc_target_interpret_expr(unsigned char*, unsigned long, gfc_expr*,
bool)
        ../../gcc/fortran/target-memory.c:639
0x792dec interpret_array
        ../../gcc/fortran/target-memory.c:392
0x792dec gfc_target_interpret_expr(unsigned char*, unsigned long, gfc_expr*,
bool)
        ../../gcc/fortran/target-memory.c:583
0x786f9d gfc_simplify_transfer(gfc_expr*, gfc_expr*, gfc_expr*)
        ../../gcc/fortran/simplify.c:8188
0x701c3a do_simplify
        ../../gcc/fortran/intrinsic.c:4676
0x70cb1a gfc_intrinsic_func_interface(gfc_expr*, int)
        ../../gcc/fortran/intrinsic.c:5055
0x760e98 resolve_unknown_f
        ../../gcc/fortran/resolve.c:2972
0x760e98 resolve_function
        ../../gcc/fortran/resolve.c:3329
0x760e98 gfc_resolve_expr(gfc_expr*)
        ../../gcc/fortran/resolve.c:7169
0x767284 gfc_resolve_expr(gfc_expr*)
        ../../gcc/fortran/resolve.c:7136
0x767284 gfc_resolve_code(gfc_code*, gfc_namespace*)
        ../../gcc/fortran/resolve.c:11928
0x765c3f gfc_resolve_blocks(gfc_code*, gfc_namespace*)
        ../../gcc/fortran/resolve.c:10944
0x765f98 gfc_resolve_code(gfc_code*, gfc_namespace*)
        ../../gcc/fortran/resolve.c:11918
0x7688d7 resolve_codes
        ../../gcc/fortran/resolve.c:17537
0x76899e gfc_resolve(gfc_namespace*)
        ../../gcc/fortran/resolve.c:17572
0x750cc4 resolve_all_program_units
        ../../gcc/fortran/parse.c:6586
0x750cc4 gfc_parse_file()
        ../../gcc/fortran/parse.c:6842
0x79e33f gfc_be_parse_file
        ../../gcc/fortran/f95-lang.c:216

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/104128] ICE in gfc_widechar_to_char, at fortran/scanner.c:199
  2022-01-19 18:51 [Bug fortran/104128] New: ICE in gfc_widechar_to_char, at fortran/scanner.c:199 gscfq@t-online.de
@ 2022-01-19 19:29 ` anlauf at gcc dot gnu.org
  2022-01-19 21:24 ` anlauf at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: anlauf at gcc dot gnu.org @ 2022-01-19 19:29 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104128

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
                 CC|                            |anlauf at gcc dot gnu.org
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2022-01-19

--- Comment #1 from anlauf at gcc dot gnu.org ---
Confirmed.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/104128] ICE in gfc_widechar_to_char, at fortran/scanner.c:199
  2022-01-19 18:51 [Bug fortran/104128] New: ICE in gfc_widechar_to_char, at fortran/scanner.c:199 gscfq@t-online.de
  2022-01-19 19:29 ` [Bug fortran/104128] " anlauf at gcc dot gnu.org
@ 2022-01-19 21:24 ` anlauf at gcc dot gnu.org
  2022-01-21 20:48 ` anlauf at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: anlauf at gcc dot gnu.org @ 2022-01-19 21:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104128

--- Comment #2 from anlauf at gcc dot gnu.org ---
Tentative, semi-obvious patch:

diff --git a/gcc/fortran/target-memory.cc b/gcc/fortran/target-memory.cc
index 361907b0e51..7ce7d736629 100644
--- a/gcc/fortran/target-memory.cc
+++ b/gcc/fortran/target-memory.cc
@@ -365,7 +365,8 @@ gfc_target_encode_expr (gfc_expr *source, unsigned char
*buffer,


 static size_t
-interpret_array (unsigned char *buffer, size_t buffer_size, gfc_expr *result)
+interpret_array (unsigned char *buffer, size_t buffer_size, gfc_expr *result,
+                bool convert_widechar)
 {
   gfc_constructor_base base = NULL;
   size_t array_size = 1;
@@ -390,7 +391,7 @@ interpret_array (unsigned char *buffer, size_t buffer_size,
gfc_expr *result)
       gfc_constructor_append_expr (&base, e, &result->where);

       ptr += gfc_target_interpret_expr (&buffer[ptr], buffer_size - ptr, e,
-                                       true);
+                                       convert_widechar);
     }

   result->value.constructor = base;
@@ -580,7 +581,7 @@ gfc_target_interpret_expr (unsigned char *buffer, size_t
buffer_size,
                           gfc_expr *result, bool convert_widechar)
 {
   if (result->expr_type == EXPR_ARRAY)
-    return interpret_array (buffer, buffer_size, result);
+    return interpret_array (buffer, buffer_size, result, convert_widechar);

   switch (result->ts.type)
     {

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/104128] ICE in gfc_widechar_to_char, at fortran/scanner.c:199
  2022-01-19 18:51 [Bug fortran/104128] New: ICE in gfc_widechar_to_char, at fortran/scanner.c:199 gscfq@t-online.de
  2022-01-19 19:29 ` [Bug fortran/104128] " anlauf at gcc dot gnu.org
  2022-01-19 21:24 ` anlauf at gcc dot gnu.org
@ 2022-01-21 20:48 ` anlauf at gcc dot gnu.org
  2022-01-21 20:49 ` anlauf at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: anlauf at gcc dot gnu.org @ 2022-01-21 20:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104128

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P4
           Keywords|                            |wrong-code

--- Comment #3 from anlauf at gcc dot gnu.org ---
The patch in comment#2 fixes the ICE in comment#0, but uncovers a few issues
with TRANSFER between different integer kinds.  E.g.

program p
  implicit none
  character(kind=4,len=2), parameter :: z    = 4_"FG"
  character(kind=1,len=*), parameter :: x    = transfer (z, 'abcdefgh')
  character(kind=4,len=*), parameter :: v    = transfer (x, z)
  print *, z
  print *, v
  if (v /= z) stop 3
end

shows that we do not get a clean round-trip.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/104128] ICE in gfc_widechar_to_char, at fortran/scanner.c:199
  2022-01-19 18:51 [Bug fortran/104128] New: ICE in gfc_widechar_to_char, at fortran/scanner.c:199 gscfq@t-online.de
                   ` (2 preceding siblings ...)
  2022-01-21 20:48 ` anlauf at gcc dot gnu.org
@ 2022-01-21 20:49 ` anlauf at gcc dot gnu.org
  2022-01-21 22:06 ` anlauf at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: anlauf at gcc dot gnu.org @ 2022-01-21 20:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104128

--- Comment #4 from anlauf at gcc dot gnu.org ---
(In reply to anlauf from comment #3)
> with TRANSFER between different integer kinds.  E.g.
oops, that should read: character kinds

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/104128] ICE in gfc_widechar_to_char, at fortran/scanner.c:199
  2022-01-19 18:51 [Bug fortran/104128] New: ICE in gfc_widechar_to_char, at fortran/scanner.c:199 gscfq@t-online.de
                   ` (3 preceding siblings ...)
  2022-01-21 20:49 ` anlauf at gcc dot gnu.org
@ 2022-01-21 22:06 ` anlauf at gcc dot gnu.org
  2022-01-23 20:07 ` anlauf at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: anlauf at gcc dot gnu.org @ 2022-01-21 22:06 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104128

--- Comment #5 from anlauf at gcc dot gnu.org ---
The issue in comment#3 is likely unrelated to TRANSFER:

program p
  implicit none
! integer, parameter :: k = 1
  integer, parameter :: k = 4
  character(kind=k,len=2), parameter :: z = k_"FG"
  character(kind=1,len=*), parameter :: x = transfer (z, 'abcdefgh')
  character(kind=k,len=2)            :: u = transfer (x, z) ! always OK
  character(kind=k,len=2), parameter :: v = transfer (x, z) ! OK (kind=1)
  logical, parameter                 :: l = (z == v)
  print *, "z == v:", l
  print *, z
  print *, u
  if (u /= z) stop 4
  print *, v
  if (v /= z) stop 3  ! stops here for kind=4
end

This works for k=1 (z==v), but fails for k=4 (z/=v, but should be same).

(NAG confirms my expectations.)

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/104128] ICE in gfc_widechar_to_char, at fortran/scanner.c:199
  2022-01-19 18:51 [Bug fortran/104128] New: ICE in gfc_widechar_to_char, at fortran/scanner.c:199 gscfq@t-online.de
                   ` (4 preceding siblings ...)
  2022-01-21 22:06 ` anlauf at gcc dot gnu.org
@ 2022-01-23 20:07 ` anlauf at gcc dot gnu.org
  2022-01-23 21:09 ` anlauf at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: anlauf at gcc dot gnu.org @ 2022-01-23 20:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104128

--- Comment #6 from anlauf at gcc dot gnu.org ---
The remaining issues in this PR seem to be related to inconsistencies
between expr->representation.string and expr->value.character.string
that occur for non-default character kind that are created in gfc_copy_expr.

Hackish fix to avoid converting the (bytewise) representation.string for
non-default character kind:

diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc
index 279d9b30991..ed82a94022f 100644
--- a/gcc/fortran/expr.cc
+++ b/gcc/fortran/expr.cc
@@ -312,7 +312,8 @@ gfc_copy_expr (gfc_expr *p)
          break;

        case BT_CHARACTER:
-         if (p->representation.string)
+         if (p->representation.string
+             && p->ts.kind == gfc_default_character_kind)
            q->value.character.string
              = gfc_char_to_widechar (q->representation.string);
          else

Needs regtesting.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/104128] ICE in gfc_widechar_to_char, at fortran/scanner.c:199
  2022-01-19 18:51 [Bug fortran/104128] New: ICE in gfc_widechar_to_char, at fortran/scanner.c:199 gscfq@t-online.de
                   ` (5 preceding siblings ...)
  2022-01-23 20:07 ` anlauf at gcc dot gnu.org
@ 2022-01-23 21:09 ` anlauf at gcc dot gnu.org
  2022-01-27 19:39 ` cvs-commit at gcc dot gnu.org
  2022-01-27 19:40 ` anlauf at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: anlauf at gcc dot gnu.org @ 2022-01-23 21:09 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104128

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |anlauf at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

--- Comment #7 from anlauf at gcc dot gnu.org ---
Submitted: https://gcc.gnu.org/pipermail/fortran/2022-January/057437.html

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/104128] ICE in gfc_widechar_to_char, at fortran/scanner.c:199
  2022-01-19 18:51 [Bug fortran/104128] New: ICE in gfc_widechar_to_char, at fortran/scanner.c:199 gscfq@t-online.de
                   ` (6 preceding siblings ...)
  2022-01-23 21:09 ` anlauf at gcc dot gnu.org
@ 2022-01-27 19:39 ` cvs-commit at gcc dot gnu.org
  2022-01-27 19:40 ` anlauf at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-01-27 19:39 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104128

--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:b51fb28ed294cdf19087ca9d9ad107c9c52bec42

commit r12-6902-gb51fb28ed294cdf19087ca9d9ad107c9c52bec42
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Sun Jan 23 21:55:33 2022 +0100

    Fortran: fix issues with internal conversion between default and wide char

    gcc/fortran/ChangeLog:

            PR fortran/104128
            * expr.cc (gfc_copy_expr): Convert internal representation of
            string to wide char in value only for default character kind.
            * target-memory.cc (interpret_array): Pass flag for conversion of
            wide chars.
            (gfc_target_interpret_expr): Likewise.

    gcc/testsuite/ChangeLog:

            PR fortran/104128
            * gfortran.dg/transfer_simplify_14.f90: New test.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/104128] ICE in gfc_widechar_to_char, at fortran/scanner.c:199
  2022-01-19 18:51 [Bug fortran/104128] New: ICE in gfc_widechar_to_char, at fortran/scanner.c:199 gscfq@t-online.de
                   ` (7 preceding siblings ...)
  2022-01-27 19:39 ` cvs-commit at gcc dot gnu.org
@ 2022-01-27 19:40 ` anlauf at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: anlauf at gcc dot gnu.org @ 2022-01-27 19:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104128

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED
   Target Milestone|---                         |12.0

--- Comment #9 from anlauf at gcc dot gnu.org ---
Fixed for gcc-12.  Closing.

Thanks for the report!

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-01-27 19:40 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-19 18:51 [Bug fortran/104128] New: ICE in gfc_widechar_to_char, at fortran/scanner.c:199 gscfq@t-online.de
2022-01-19 19:29 ` [Bug fortran/104128] " anlauf at gcc dot gnu.org
2022-01-19 21:24 ` anlauf at gcc dot gnu.org
2022-01-21 20:48 ` anlauf at gcc dot gnu.org
2022-01-21 20:49 ` anlauf at gcc dot gnu.org
2022-01-21 22:06 ` anlauf at gcc dot gnu.org
2022-01-23 20:07 ` anlauf at gcc dot gnu.org
2022-01-23 21:09 ` anlauf at gcc dot gnu.org
2022-01-27 19:39 ` cvs-commit at gcc dot gnu.org
2022-01-27 19:40 ` anlauf at gcc dot gnu.org

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).