Bug 29392

Summary: Segfault on data character initialization
Product: gcc Reporter: Francois-Xavier Coudert <fxcoudert>
Component: fortranAssignee: Paul Thomas <pault>
Status: RESOLVED FIXED    
Severity: normal CC: gcc-bugs
Priority: P3 Keywords: ice-on-valid-code
Version: 4.2.0   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2006-10-08 21:17:00
Attachments: Simple fix, testcase and ChangeLog entries.

Description Francois-Xavier Coudert 2006-10-08 21:16:53 UTC
$ cat a9.f90 
  character(LEN=2) :: a(2) 
  data ((a(I)(k:k),I=1,2),k=1,2) /4*'a'/ 
  IF (ANY(a.NE."aa")) CALL ABORT() 
  END 
$ gfortran a9.f90
 In file a9.f90:2

  data ((a(I)(k:k),I=1,2),k=1,2) /4*'a'/ 
                                   1
Warning: initialization string truncated to match variable at (1)
a9.f90:0: internal compiler error: Segmentation fault


The segfault happens at:

    at ../../trunk/gcc/fortran/data.c:194
194       memcpy (&dest[start], rvalue->value.character.string, len);

#0  create_character_intializer (init=0xce48e0, ts=Variable "ts" is not available.
)
    at ../../trunk/gcc/fortran/data.c:194
#1  0x000000000040e511 in gfc_assign_data_value (lvalue=0xce3240, 
    rvalue=0xce3e80, index=0x7fbfffeaa0) at ../../trunk/gcc/fortran/data.c:323
#2  0x0000000000448482 in traverse_data_var (var=0xcb1470, where=0xcb0f50)
    at ../../trunk/gcc/fortran/resolve.c:6094
#3  0x0000000000448293 in traverse_data_var (var=0xcb11b0, where=0xcb0f50)
    at ../../trunk/gcc/fortran/resolve.c:6146
#4  0x0000000000448293 in traverse_data_var (var=0xcb09f0, where=0xcb0f50)
    at ../../trunk/gcc/fortran/resolve.c:6146
#5  0x0000000000448e1f in resolve_types (ns=0xce2330)
    at ../../trunk/gcc/fortran/resolve.c:6240
#6  0x000000000044b75d in gfc_resolve (ns=0xce2330)
    at ../../trunk/gcc/fortran/resolve.c:6918
#7  0x0000000000440a68 in gfc_parse_file ()
    at ../../trunk/gcc/fortran/parse.c:3212

There, we have:

(gdb) p rvalue->value.character.string
$4 = 0xcb0b30 "a"
(gdb) p len
$5 = -13513439
(gdb) p dest
$6 = 0xcb0450 "  "
(gdb) p start
$7 = 13513439
Comment 1 Paul Thomas 2006-10-16 14:05:58 UTC
Created attachment 12445 [details]
Simple fix, testcase and ChangeLog entries.

I'll submit this tonight.

Paul
Comment 2 patchapp@dberlin.org 2006-10-16 15:25:21 UTC
Subject: Bug number PR29392

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2006-10/msg00804.html
Comment 3 Paul Thomas 2006-10-16 22:29:58 UTC
Subject: Bug 29392

Author: pault
Date: Mon Oct 16 22:29:46 2006
New Revision: 117797

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=117797
Log:
2006-10-17  Paul Thomas <pault@gcc.gnu.org>

	PR fortran/20541
	* trans-array.c (gfc_trans_array_bounds): Test for and set
	negative stride of a non-constant bound array to zero.

	PR fortran/29392
	* data.c (create_character_intializer): Copy and simplify
	the expressions for the start and end of a sub-string
	reference.

2006-10-17  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/29392
	* gfortran.dg/data_char_3.f90: New test.

	PR fortran/20541
	* gfortran.dg/negative_automatic_size.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/data_char_3.f90
    trunk/gcc/testsuite/gfortran.dg/negative_automatic_size.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/data.c
    trunk/gcc/fortran/trans-array.c
    trunk/gcc/testsuite/ChangeLog

Comment 4 Paul Thomas 2006-10-17 11:30:53 UTC
Fixed on trunk

Paul
Comment 5 Paul Thomas 2006-11-10 21:52:38 UTC
Subject: Bug 29392

Author: pault
Date: Fri Nov 10 21:52:00 2006
New Revision: 118666

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=118666
Log:
2006-11-10 Paul Thomas <pault@gcc.gnu.org>

	Backport from mainline.

	PR fortran/29371
	* trans-expr.c (gfc_trans_pointer_assignment): Add the expression
	for the assignment of null to the data field to se->pre, rather
	than block.

	PR fortran/29392
	* data.c (create_character_intializer): Copy and simplify
	the expressions for the start and end of a sub-string
	reference.

	PR fortran/29216
	PR fortran/29314
	* gfortran.h : Add EXEC_INIT_ASSIGN.
	* dump-parse-tree.c (gfc_show_code_node): The same.
	* trans-expr.c (gfc_trans_init_assign): New function.
	* trans-stmt.h : Add prototype for gfc_trans_init_assign.
	* trans.c (gfc_trans_code): Implement EXEC_INIT_ASSIGN.
	* resolve.c (resolve_allocate_exp): Replace EXEC_ASSIGN by
	EXEC_INIT_ASSIGN.
	(resolve_code): EXEC_INIT_ASSIGN does not need resolution.
	(apply_default_init): New function.
	(resolve_symbol): Call it for derived types that become
	defined but which do not already have an initialization
	expression..
	* st.c (gfc_free_statement): Include EXEC_INIT_ASSIGN.
	
	PR fortran/29387
	* trans-intrinsic.c (gfc_conv_intrinsic_len): Rearrange to have
	a specific case for EXPR_VARIABLE and, in default, build an ss
	to call gfc_conv_expr_descriptor for array expressions..

	PR fortran/29490
	* trans-expr.c (gfc_set_interface_mapping_bounds): In the case
	that GFC_TYPE_ARRAY_LBOUND is not available, use descriptor
	values for it and GFC_TYPE_ARRAY_UBOUND.

	PR fortran/29641
	* trans-types.c (gfc_get_derived_type): If the derived type
	namespace has neither a parent nor a proc_name, set NULL for
	the search namespace.

	PR fortran/24518
	* trans-intrinsic.c (gfc_conv_intrinsic_mod): Use built_in fmod
	for both MOD and MODULO, if it is available.

	PR fortran/29565
	* trans-expr.c (gfc_conv_aliased_arg): For an INTENT(OUT), save
	the declarations from the unused loops by merging the block
	scope for each; this ensures that the temporary is declared.

2006-11-10 Paul Thomas <pault@gcc.gnu.org>

	PR fortran/29371
	* gfortran.dg/nullify_3.f90: New test.

	PR fortran/29392
	* gfortran.dg/data_char_3.f90: New test.

	PR fortran/29216
	* gfortran.dg/result_default_init_1.f90: New test.

	PR fortran/29314
	* gfortran.dg/automatic_default_init_1.f90: New test.

	PR fortran/29387
	* trans-intrinsic.c (gfc_conv_intrinsic_len): Rearrange to have
	a specific case for EXPR_VARIABLE and, in default, build an ss
	to call gfc_conv_expr_descriptor for array expressions..

	PR fortran/29490
	* trans-expr.c (gfc_set_interface_mapping_bounds): In the case
	that GFC_TYPE_ARRAY_LBOUND is not available, use descriptor
	values for it and GFC_TYPE_ARRAY_UBOUND.

	PR fortran/29641
	* trans-types.c (gfc_get_derived_type): If the derived type
	namespace has neither a parent nor a proc_name, set NULL for
	the search namespace.

	PR fortran/29565
	* gfortran.dg/gfortran.dg/aliasing_dummy_3.f90: New test.


Added:
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/actual_array_interface_1.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/aliasing_dummy_3.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/automatic_default_init_1.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/data_char_3.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/intrinsic_actual_2.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/nullify_3.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/result_default_init_1.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/used_types_11.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/used_types_12.f90
Modified:
    branches/gcc-4_1-branch/gcc/fortran/ChangeLog
    branches/gcc-4_1-branch/gcc/fortran/data.c
    branches/gcc-4_1-branch/gcc/fortran/dump-parse-tree.c
    branches/gcc-4_1-branch/gcc/fortran/f95-lang.c
    branches/gcc-4_1-branch/gcc/fortran/gfortran.h
    branches/gcc-4_1-branch/gcc/fortran/resolve.c
    branches/gcc-4_1-branch/gcc/fortran/st.c
    branches/gcc-4_1-branch/gcc/fortran/trans-expr.c
    branches/gcc-4_1-branch/gcc/fortran/trans-intrinsic.c
    branches/gcc-4_1-branch/gcc/fortran/trans-stmt.h
    branches/gcc-4_1-branch/gcc/fortran/trans-types.c
    branches/gcc-4_1-branch/gcc/fortran/trans.c
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog