[Bug fortran/68155] ICE on initializing character array in type (len_lhs <> len_rhs)

2023-09-24 Thread pault at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68155

Paul Thomas  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |FIXED

--- Comment #15 from Paul Thomas  ---
Fixed on 13-branch and mainline.

Thanks for the report and sorry that it has taken a little while to fix.

Regards

Paul

[Bug fortran/68155] ICE on initializing character array in type (len_lhs <> len_rhs)

2023-09-24 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68155

--- Comment #14 from CVS Commits  ---
The releases/gcc-13 branch has been updated by Paul Thomas :

https://gcc.gnu.org/g:8c1925ece0193058120e94614e99360e9600777e

commit r13-7833-g8c1925ece0193058120e94614e99360e9600777e
Author: Paul Thomas 
Date:   Sun Sep 24 15:26:01 2023 +0100

Fortran: Pad mismatched charlens in component initializers [PR68155]

2023-09-24  Paul Thomas  

gcc/fortran
PR fortran/68155
* decl.cc (fix_initializer_charlen): New function broken out of
add_init_expr_to_sym.
(add_init_expr_to_sym, build_struct): Call the new function.

gcc/testsuite/
PR fortran/68155
* gfortran.dg/pr68155.f90: New test.

[Bug fortran/68155] ICE on initializing character array in type (len_lhs <> len_rhs)

2023-09-24 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68155

--- Comment #13 from CVS Commits  ---
The master branch has been updated by Paul Thomas :

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

commit r14-4242-gc23ce23e9ce162c49bca8900c8a20079b49501c9
Author: Paul Thomas 
Date:   Sun Sep 24 09:00:52 2023 +0100

Fortran: Pad mismatched charlens in component initializers [PR68155]

2023-09-24  Paul Thomas  

gcc/fortran
PR fortran/68155
* decl.cc (fix_initializer_charlen): New function broken out of
add_init_expr_to_sym.
(add_init_expr_to_sym, build_struct): Call the new function.

PR fortran/111271
* trans-expr.cc (gfc_conv_intrinsic_to_class): Remove repeated
condition.

gcc/testsuite/
PR fortran/68155
* gfortran.dg/pr68155.f90: New test.

[Bug fortran/68155] ICE on initializing character array in type (len_lhs <> len_rhs)

2023-09-19 Thread pault at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68155

Paul Thomas  changed:

   What|Removed |Added

 CC||pault at gcc dot gnu.org
   Assignee|unassigned at gcc dot gnu.org  |pault at gcc dot gnu.org

--- Comment #12 from Paul Thomas  ---
Created attachment 55938
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55938=edit
Fix for the test in comment #11

This patch needs checking against all the other comments and a suitable
dejagnu-ified testcase developing. It does regtest cleanly.

Paul

[Bug fortran/68155] ICE on initializing character array in type (len_lhs <> len_rhs)

2020-01-10 Thread markeggleston at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68155

markeggleston at gcc dot gnu.org changed:

   What|Removed |Added

 CC||markeggleston at gcc dot 
gnu.org

--- Comment #11 from markeggleston at gcc dot gnu.org ---
program p
  implicit none
  type t
character(3) :: c2(2) = ['b', 'c'] // 'a'   ! not padded
character(3) :: c3(2) = ['b', 'c'] // 'ax'  ! OK
character(3) :: c4(2) = ['b', 'c'] // 'axy' ! OK
  end type
  type(t)  :: z
  character(3) :: c
  c = z%c2(1) ! OK
  print *, "'", c, "'"
  c = z%c2(2) ! OK
  print *, c
  c = z%c3(1) ! OK
  print *, c
  c = z%c3(2) ! OK
  print *, c
  c = z%c4(1) ! OK
  print *, c
  c = z%c4(2) ! truncated
  print *, c
end

produces:

 'ba'
 'ca'
 'bax'
 'cax'
 'bax'
 'cax'

ICE is gone, however, the first two items are not padded.

trunk (10.0 at r280100).

[Bug fortran/68155] ICE on initializing character array in type (len_lhs <> len_rhs)

2018-03-28 Thread anlauf at gmx dot de
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68155

--- Comment #10 from Harald Anlauf  ---
The structure constructor seems to lose the character length, which
can be best seen from the tree dump.

program p
  implicit none
  type t
!   character(3) :: c1(2) = [ 'b', 'c']   ! OK
!   character(3) :: c2(2) = [ character(1) :: 'b', 'c'] // "" ! OK
!   character(3) :: c3(2) = [ 'b', 'c'] // "" ! ICE
character(3) :: c4(2) = [ '' , '' ] // "" ! wrong output
  end type t
  type(t)  :: z
! print *, "'", z%c1(2), "'" ! OK
! print *, "'", z%c2(2), "'" ! OK
! print *, "'", z%c3(2), "'" ! ICE
  print *, "'", z%c4(2), "'" ! wrong output: '^@^@^@'
end

% grep c4 pr68155-zz4b.f90.003t.original
  static struct t z = {.c4={"", ""}};  <--- length 0!
_gfortran_transfer_character_write (_parm.0, [1], 3);

[Bug fortran/68155] ICE on initializing character array in type (len_lhs <> len_rhs)

2018-03-27 Thread anlauf at gmx dot de
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68155

Harald Anlauf  changed:

   What|Removed |Added

 CC||anlauf at gmx dot de

--- Comment #9 from Harald Anlauf  ---
Playing around with the code in comment #6, with default initialization
within the type:

program p
  implicit none
  type t
!character(3) :: c2(2) = ['b', 'c'] // 'a'   ! lacks padding? / ICE
 character(3) :: c3(2) = ['b', 'c'] // 'ax'  ! OK
 character(3) :: c4(2) = ['b', 'c'] // 'axy' ! only partially OK
   end type
   type(t)  :: z
   character(3) :: c
   c = z%c3(1) ! OK
   print *, c
   c = z%c3(2) ! OK
   print *, c
   c = z%c4(1) ! OK
   print *, c
   c = z%c4(2) ! truncated
   print *, c
end

This prints:

 bax
 cax
 bax
 ca

The dump tree starts with:

p ()
{
  character(kind=1) c[1:3];
  static struct t z = {.c3={"bax", "cax"}, .c4={"bax ", "cax "}};

  __builtin_memmove ((void *) , (void *) [0], 3);
[...]
  __builtin_memmove ((void *) , (void *) [1], 3);
[...]

I do not see from the dump tree what could be wrong with the character
lengths, but somehow the truncation in the last print needs to be
understood.

Enabling the line with c2 and adding a line

   c = z%c2(1)

to the main produces in the dump

  static struct t z = {.c2={"ba", "ca"}, .c3={"bax", "cax"}, .c4={"bax ", "cax
"}};

  __builtin_memmove ((void *) , (void *) [0], 3);

which should not happen.

[Bug fortran/68155] ICE on initializing character array in type (len_lhs <> len_rhs)

2018-03-20 Thread kargl at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68155

kargl at gcc dot gnu.org changed:

   What|Removed |Added

 CC||kargl at gcc dot gnu.org

--- Comment #8 from kargl at gcc dot gnu.org ---
The code in the original comment compiles and gives

 gfcx -o z a.f90 && ./z
 y


The code in comment #2 gives

 gfcx -o z a.f90 && ./z
 ab

The code without type gives in comment #6 gives

 gfcx -o z a.f90 && ./z
   2   3 b  c  
   2   3 ab ac 
   2   3 axbaxc
   2   3 axyaxy

when wrapped in TYPE, I get

 gfcx -o z a.f90 && ./z
a.f90:13:0:

 end

internal compiler error: in output_constructor_regular_field, at varasm.c:5125
0x6cd37a output_constructor_regular_field
../../gcc/gcc/varasm.c:5125
0x6cd37a output_constructor
../../gcc/gcc/varasm.c:5433
0xfd4190 output_constant
../../gcc/gcc/varasm.c:4807
0xfd4190 output_constructor_regular_field
../../gcc/gcc/varasm.c:5163
0xfd4190 output_constructor
../../gcc/gcc/varasm.c:5433
0xfd56b1 output_constant
../../gcc/gcc/varasm.c:4807
0xfd56b1 assemble_variable_contents
../../gcc/gcc/varasm.c:2126
0xfdb41f assemble_variable(tree_node*, int, int, int)
../../gcc/gcc/varasm.c:2305
0xfdff99 varpool_node::assemble_decl()
../../gcc/gcc/varpool.c:590
0x934f1c output_in_order
../../gcc/gcc/cgraphunit.c:2385
0x934f1c symbol_table::compile()
../../gcc/gcc/cgraphunit.c:2623
0x937059 symbol_table::compile()
../../gcc/gcc/cgraphunit.c:2537
0x937059 symbol_table::finalize_compilation_unit()
../../gcc/gcc/cgraphunit.c:2717

So some of this PR is fixed.

[Bug fortran/68155] ICE on initializing character array in type (len_lhs <> len_rhs)

2016-12-05 Thread gerhard.steinmetz.fort...@t-online.de
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68155

--- Comment #7 from Gerhard Steinmetz  
---
Sequence changed, still ok :

$ cat zz3.f90
program p
   character(3) :: c1(2) = ['b', 'c'] // ''
   character(3) :: c2(2) = ['b', 'c'] // 'a'
   character(3) :: c3(2) = ['b', 'c'] // 'ax'
   character(3) :: c4(2) = ['b', 'c'] // 'axy'
   print *, size(c1), len(c1), c1
   print *, size(c2), len(c2), c2
   print *, size(c3), len(c3), c3
   print *, size(c4), len(c4), c4
end

$ gfortran-7-20161204 zz3.f90
$ a.out
   2   3 b  c
   2   3 ba ca
   2   3 baxcax
   2   3 baxcax

---


Similar, embedded :

$ cat zz4.f90
program p
   type t
  character(3) :: c1(2) = ['b', 'c'] // ''
  character(3) :: c2(2) = ['b', 'c'] // 'a'
  character(3) :: c3(2) = ['b', 'c'] // 'ax'
  character(3) :: c4(2) = ['b', 'c'] // 'axy'
   end type
   type(t) :: z
   print *, size(z%c1), len(z%c1), z%c1
   print *, size(z%c2), len(z%c2), z%c2
   print *, size(z%c3), len(z%c3), z%c3
   print *, size(z%c4), len(z%c4), z%c4
end

$ gfortran-7-20161204 zz4.f90
zz4.f90:13:0:

 end

internal compiler error: in output_constructor_regular_field, at varasm.c:5017
0xf3fcc4 output_constructor_regular_field
../../gcc/varasm.c:5017
0xf3fcc4 output_constructor
../../gcc/varasm.c:5325
0xf3e7c1 output_constant
../../gcc/varasm.c:4702
0xf3e7c1 output_constructor_regular_field
../../gcc/varasm.c:5055
0xf3e7c1 output_constructor
../../gcc/varasm.c:5325
0xf40064 output_constant
../../gcc/varasm.c:4702
0xf40064 assemble_variable_contents
../../gcc/varasm.c:2083
0xf479c9 assemble_variable(tree_node*, int, int, int)
../../gcc/varasm.c:2259
0xf4d1e8 varpool_node::assemble_decl()
../../gcc/varpool.c:588
0xf4de75 varpool_node::assemble_decl()
../../gcc/cgraph.h:2631
0xf4de75 symbol_table::output_variables()
../../gcc/varpool.c:754
0x855a77 symbol_table::compile()
../../gcc/cgraphunit.c:2495
0x857ea2 symbol_table::compile()
../../gcc/cgraphunit.c:2558
0x857ea2 symbol_table::finalize_compilation_unit()
../../gcc/cgraphunit.c:2584

[Bug fortran/68155] ICE on initializing character array in type (len_lhs <> len_rhs)

2016-12-05 Thread gerhard.steinmetz.fort...@t-online.de
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68155

Gerhard Steinmetz  changed:

   What|Removed |Added

Version|5.2.1   |7.0

--- Comment #6 from Gerhard Steinmetz  
---
Valid code :

$ cat zz1.f90
program p
   character(3) :: c1(2) = '' // ['b', 'c']
   character(3) :: c2(2) = 'a' // ['b', 'c']
   character(3) :: c3(2) = 'ax' // ['b', 'c']
   character(3) :: c4(2) = 'axy' // ['b', 'c']
   print *, size(c1), len(c1), c1
   print *, size(c2), len(c2), c2
   print *, size(c3), len(c3), c3
   print *, size(c4), len(c4), c4
end

$ gfortran-7-20161204 zz1.f90
$ a.out
   2   3 b  c
   2   3 ab ac
   2   3 axbaxc
   2   3 axyaxy

---


Similar, embedded in a type :

$ cat zz2.f90
program p
   type t
  character(3) :: c1(2) = '' // ['b', 'c']
  character(3) :: c2(2) = 'a' // ['b', 'c']
  character(3) :: c3(2) = 'ax' // ['b', 'c']
  character(3) :: c4(2) = 'axy' // ['b', 'c']
   end type
   type(t) :: z
   print *, size(z%c1), len(z%c1), z%c1
   print *, size(z%c2), len(z%c2), z%c2
   print *, size(z%c3), len(z%c3), z%c3
   print *, size(z%c4), len(z%c4), z%c4
end

$ gfortran-7-20161204 zz2.f90
zz2.f90:13:0:

 end

internal compiler error: in output_constructor_regular_field, at varasm.c:5017
0xf3fcc4 output_constructor_regular_field
../../gcc/varasm.c:5017
0xf3fcc4 output_constructor
../../gcc/varasm.c:5325
0xf3e7c1 output_constant
../../gcc/varasm.c:4702
0xf3e7c1 output_constructor_regular_field
../../gcc/varasm.c:5055
0xf3e7c1 output_constructor
../../gcc/varasm.c:5325
0xf40064 output_constant
../../gcc/varasm.c:4702
0xf40064 assemble_variable_contents
../../gcc/varasm.c:2083
0xf479c9 assemble_variable(tree_node*, int, int, int)
../../gcc/varasm.c:2259
0xf4d1e8 varpool_node::assemble_decl()
../../gcc/varpool.c:588
0x85501b output_in_order
../../gcc/cgraphunit.c:2248
0x8553ed symbol_table::compile()
../../gcc/cgraphunit.c:2488
0x857ea2 symbol_table::compile()
../../gcc/cgraphunit.c:2558
0x857ea2 symbol_table::finalize_compilation_unit()
../../gcc/cgraphunit.c:2584

[Bug fortran/68155] ICE on initializing character array in type (len_lhs <> len_rhs)

2016-12-05 Thread gerhard.steinmetz.fort...@t-online.de
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68155

--- Comment #5 from Gerhard Steinmetz  
---
*** Bug 78570 has been marked as a duplicate of this bug. ***

[Bug fortran/68155] ICE on initializing character array in type (len_lhs <> len_rhs)

2016-12-05 Thread gerhard.steinmetz.fort...@t-online.de
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68155

--- Comment #4 from Gerhard Steinmetz  
---
Update, new backtrace :


$ gfortran-7-20161127 z1t.f90
z1t.f90:3:28:

   character(2) :: z(1) = '' // ['y']
1
Warning: CHARACTER expression at (1) is being truncated (2/1)
[-Wcharacter-truncation]
f951: internal compiler error: free_expr0(): Bad expr type
0x68ea6f gfc_internal_error(char const*, ...)
../../gcc/fortran/error.c:1327
0x68f7cb free_expr0
../../gcc/fortran/expr.c:494
0x68f81d gfc_free_expr(gfc_expr*)
../../gcc/fortran/expr.c:513
0x71b273 gfc_free_charlen(gfc_charlen*, gfc_charlen*)
../../gcc/fortran/symbol.c:3840
0x71b349 gfc_free_namespace(gfc_namespace*)
../../gcc/fortran/symbol.c:3890
0x71b89c gfc_symbol_done_2()
../../gcc/fortran/symbol.c:3926
0x6c33d8 gfc_done_2()
../../gcc/fortran/misc.c:264
0x6e61f6 translate_all_program_units
../../gcc/fortran/parse.c:6057
0x6e61f6 gfc_parse_file()
../../gcc/fortran/parse.c:6238
0x729ee2 gfc_be_parse_file
../../gcc/fortran/f95-lang.c:202

---


Different ICEs using LANG=de_DE.UTF-8, for example :

$ gfortran-7-20161204 -O2 -fcheck=all z1t.f90
f951: internal compiler error: Speicherzugriffsfehler
0xc4940f crash_signal
../../gcc/toplev.c:333
0x856200 process_function_and_variable_attributes
../../gcc/cgraphunit.c:726
0x856200 analyze_functions
../../gcc/cgraphunit.c:1029
0x857e28 symbol_table::finalize_compilation_unit()
../../gcc/cgraphunit.c:2562

[Bug fortran/68155] ICE on initializing character array in type (len_lhs <> len_rhs)

2015-10-29 Thread gerhard.steinmetz.fort...@t-online.de
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68155

--- Comment #2 from Gerhard Steinmetz  
---
Fails (again len_lhs <> len_rhs) :

$ cat z3t.f90
program p
   type t
  character(2) :: z(1) = 'ab' // ['y']
   end type
   type(t) :: z
   print *, z
end

$ gfortran -g -O0 -Wall -fcheck=all z3t.f90
z3t.f90:3:28:

   character(2) :: z(1) = 'ab' // ['y']
1
Warning: CHARACTER expression at (1) is being truncated (3/2)
[-Wcharacter-truncation]
f951: internal compiler error: Segmentation fault

---

Again, works without type :

$ cat z3c.f90
program p
   character(2) :: z(1) = 'ab' // ['y']
   print *, z
end

$ gfortran -g -O0 -Wall -fcheck=all z3c.f90
z3c.f90:2:25:

character(2) :: z(1) = 'ab' // ['y']
 1
Warning: CHARACTER expression at (1) is being truncated (3/2)
[-Wcharacter-truncation]

$ a.out
 ab

---

Eventually one of the recent patches cures this one too.


[Bug fortran/68155] ICE on initializing character array in type (len_lhs <> len_rhs)

2015-10-29 Thread gerhard.steinmetz.fort...@t-online.de
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68155

--- Comment #1 from Gerhard Steinmetz  
---
Works with len_lhs == len_rhs :

$ cat z2t.f90
program p
   type t
  character(2) :: z(1) = 'a' // ['y']
   end type
   type(t) :: z
   print *, z
end

$ gfortran -g -O0 -Wall -fcheck=all z2t.f90
$ a.out
 ay


[Bug fortran/68155] ICE on initializing character array in type (len_lhs <> len_rhs)

2015-10-29 Thread dominiq at lps dot ens.fr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68155

Dominique d'Humieres  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2015-10-29
 Ever confirmed|0   |1

--- Comment #3 from Dominique d'Humieres  ---
Confirmed from 4.8 up to trunk (6.0).