Bug 27958 - assignments to and from zero-sized string selections not handled
Summary: assignments to and from zero-sized string selections not handled
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.2.0
: P3 normal
Target Milestone: 4.1.2
Assignee: Francois-Xavier Coudert
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: patch, wrong-code
Depends on:
Blocks:
 
Reported: 2006-06-08 13:28 UTC by Francois-Xavier Coudert
Modified: 2006-06-20 06:12 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 4.2.0 4.1.2
Known to fail:
Last reconfirmed: 2006-06-08 13:28:30


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Francois-Xavier Coudert 2006-06-08 13:28:06 UTC
The following code is legal, but segfaults at runtime when compiled with gfortran:

$ cat a.f90 
  character(len=10) :: s
  s = "abcdefghij"
  s(6:5) = s(7:5)
  print *, s
  end
$ ifort a.f90 -check all && ./a.out
 abcdefghij
$ gfortran a.f90 && ./a.out   
zsh: segmentation fault  ./a.out
Comment 1 Francois-Xavier Coudert 2006-06-08 21:48:46 UTC
Subject: Bug 27958

Author: fxcoudert
Date: Thu Jun  8 21:48:05 2006
New Revision: 114496

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=114496
Log:
	PR fortran/27958

	* trans-expr.c (gfc_conv_substring): If the substring start is
	greater than its end, the length of the substring is zero, and
	not negative.
	(gfc_trans_string_copy): Don't generate a call to
	_gfortran_copy_string when destination length is zero.

	* gcc/testsuite/gfortran.dg/substr_2.f: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/substr_2.f
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/testsuite/ChangeLog

Comment 2 Francois-Xavier Coudert 2006-06-20 06:04:30 UTC
Subject: Bug 27958

Author: fxcoudert
Date: Tue Jun 20 06:04:14 2006
New Revision: 114803

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=114803
Log:
2006-06-20  Francois-Xavier Coudert  <coudert@clipper.ens.fr>

	PR fortran/27958
	* trans-expr.c (gfc_conv_substring): If the substring start is
	greater than its end, the length of the substring is zero, and
	not negative.
	(gfc_trans_string_copy): Don't generate a call to
	_gfortran_copy_string when destination length is zero.

2006-06-20  Francois-Xavier Coudert  <coudert@clipper.ens.fr>

	PR libfortran/27895
	* resolve.c (compute_last_value_for_triplet): New function.
	(check_dimension): Correctly handle zero-sized array sections.
	Add checking on last element of array sections.

2006-06-20  Francois-Xavier Coudert  <coudert@clipper.ens.fr>

	* trans.c (gfc_msg_bounds, gfc_msg_fault, gfc_msg_wrong_return):
	Add strings for common runtime error messages.
	(gfc_trans_runtime_check): Add a locus argument, use a string
	and not a string tree for the message.
	* trans.h (gfc_trans_runtime_check): Change prototype accordingly.
	(gfc_msg_bounds, gfc_msg_fault, gfc_msg_wrong_return): Add proto.
	* trans-const.c (gfc_strconst_bounds, gfc_strconst_fault,
	gfc_strconst_wrong_return, gfc_strconst_current_filename): Remove.
	(gfc_init_constants): Likewise.
	* trans-const.h: Likewise.
	* trans-decl.c (gfc_build_builtin_function_decls): Call to
	_gfortran_runtime_error has only one argument, the message string.
	* trans-array.h (gfc_conv_array_ref): Add a symbol argument and a
	locus.
	* trans-array.c (gfc_trans_array_bound_check): Build precise
	error messages.
	(gfc_conv_array_ref): Use the new symbol argument and the locus
	to build more precise error messages.
	(gfc_conv_ss_startstride): More precise error messages.
	* trans-expr.c (gfc_conv_variable): Give symbol reference and
	locus to gfc_conv_array_ref.
	(gfc_conv_function_call): Use the new prototype for
	gfc_trans_runtime_check.
	* trans-stmt.c (gfc_trans_goto): Build more precise error message.
	* trans-io.c (set_string): Likewise.
	* trans-intrinsic.c (gfc_conv_intrinsic_bound): Use new prototype
	for gfc_trans_runtime_check.

2006-06-20  Thomas Koenig  <Thomas.Koenig@online.de>

	PR fortran/27715
	* arith.c:  Cast the characters from the strings to unsigned
	char to avoid values less than 0 for extended ASCII.

2006-06-20  Thomas Koenig  <Thomas.Koenig@online.de>

	PR libfortran/27784
	* intrinsics/string_intrinsics.c (compare_string):
	Use memcmp instead of strncmp to avoid tripping over
	CHAR(0) in a string.

2006-06-20  Francois-Xavier Coudert  <coudert@clipper.ens.fr>

	PR fortran/27958
	* gcc/testsuite/gfortran.dg/substr_2.f: New test.

2006-06-20  Francois-Xavier Coudert  <coudert@clipper.ens.fr>

	PR libfortran/27895
	* gfortran.dg/bounds_check_3.f90: New test.

2006-06-20  Thomas Koenig  <Thomas.Koenig@online.de>

	PR fortran/27715
	* gfortran.dg/extended_char_comparison_1.f:  New test.

2006-06-20  Thomas Koenig  <Thomas.Koenig@online.de>

	PR fortran/27784
	* gfortran.dg/string_null_compare_1.f:  New test case.

Added:
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/bounds_check_3.f90
      - copied unchanged from r114414, trunk/gcc/testsuite/gfortran.dg/bounds_check_3.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/extended_char_comparison_1.f
      - copied unchanged from r114317, trunk/gcc/testsuite/gfortran.dg/extended_char_comparison_1.f
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/string_null_compare_1.f
      - copied unchanged from r114175, trunk/gcc/testsuite/gfortran.dg/string_null_compare_1.f
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/substr_2.f
      - copied unchanged from r114496, trunk/gcc/testsuite/gfortran.dg/substr_2.f
Modified:
    branches/gcc-4_1-branch/gcc/fortran/ChangeLog
    branches/gcc-4_1-branch/gcc/fortran/arith.c
    branches/gcc-4_1-branch/gcc/fortran/resolve.c
    branches/gcc-4_1-branch/gcc/fortran/trans-array.c
    branches/gcc-4_1-branch/gcc/fortran/trans-array.h
    branches/gcc-4_1-branch/gcc/fortran/trans-const.c
    branches/gcc-4_1-branch/gcc/fortran/trans-const.h
    branches/gcc-4_1-branch/gcc/fortran/trans-decl.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-io.c
    branches/gcc-4_1-branch/gcc/fortran/trans-stmt.c
    branches/gcc-4_1-branch/gcc/fortran/trans.c
    branches/gcc-4_1-branch/gcc/fortran/trans.h
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_1-branch/libgfortran/ChangeLog
    branches/gcc-4_1-branch/libgfortran/intrinsics/string_intrinsics.c

Comment 3 Francois-Xavier Coudert 2006-06-20 06:12:53 UTC
Fixed.