[PATCH] Fix PR30147, fold_read_from_constant_string ICEing on aggregate return type

Richard Guenther rguenther@suse.de
Tue Dec 12 12:13:00 GMT 2006


This fixes PR30147 where we try to fold

  *(charD.21[1:1] *) "K"

to 'K' of type (charD.21[1:1] *).  On fold-converting to that type we
ICE.

Fixed by only folding a read if the return type is integer.

Bootstrapped and tested on x86_64-unknown-linux-gnu.

Applied to mainline and 4.2 branch.

Richard.

2006-12-12  Richard Guenther  <rguenther@suse.de>

	PR middle-end/30147
	* fold-const.c (fold_read_from_constant_string): Only fold read
	from constant string if the result type is integer.

	* gfortran.fortran-torture/compile/pr30147.f90: New testcase.

Index: testsuite/gfortran.fortran-torture/compile/pr30147.f90
===================================================================
*** testsuite/gfortran.fortran-torture/compile/pr30147.f90	(revision 0)
--- testsuite/gfortran.fortran-torture/compile/pr30147.f90	(revision 0)
***************
*** 0 ****
--- 1,13 ----
+ MODULE input_cp2k_motion
+   IMPLICIT NONE
+   interface
+     SUBROUTINE keyword_create(variants)
+       CHARACTER(len=*), DIMENSION(:), &
+       INTENT(in)                   :: variants
+     end subroutine
+   end interface
+ CONTAINS
+   SUBROUTINE create_neb_section()
+     CALL keyword_create(variants=(/"K"/))
+   END SUBROUTINE create_neb_section
+ END MODULE input_cp2k_motion
Index: fold-const.c
===================================================================
*** fold-const.c	(revision 119733)
--- fold-const.c	(working copy)
*************** fold_unary_to_constant (enum tree_code c
*** 12726,12732 ****
  tree
  fold_read_from_constant_string (tree exp)
  {
!   if (TREE_CODE (exp) == INDIRECT_REF || TREE_CODE (exp) == ARRAY_REF)
      {
        tree exp1 = TREE_OPERAND (exp, 0);
        tree index;
--- 12817,12825 ----
  tree
  fold_read_from_constant_string (tree exp)
  {
!   if ((TREE_CODE (exp) == INDIRECT_REF
!        || TREE_CODE (exp) == ARRAY_REF)
!       && TREE_CODE (TREE_TYPE (exp)) == INTEGER_TYPE)
      {
        tree exp1 = TREE_OPERAND (exp, 0);
        tree index;



More information about the Gcc-patches mailing list