[PATCH][committed] Fix PR32140, miscompile at -O1

Richard Guenther rguenther@suse.de
Wed Jun 20 14:46:00 GMT 2007


This patch from Andrew fixes PR32140.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to mainline
after approval in the PR audit trail.

Richard.

2007-06-20  Andrew Pinski  <andrew_pinski@playstation.sony.com>
	Richard Guenther  <rguenther@suse.de>

	PR fortran/32140
	* trans.c (gfc_build_addr_expr): Use the correct types.

	* gfortran.fortran-torture/execute/pr32140.f90: New testcase.

Index: fortran/trans.c
===================================================================
*** fortran/trans.c	(revision 125848)
--- fortran/trans.c	(working copy)
*************** gfc_build_addr_expr (tree type, tree t)
*** 266,272 ****
        && TREE_CODE (base_type) == ARRAY_TYPE
        && TYPE_MAIN_VARIANT (TREE_TYPE (type))
  	 == TYPE_MAIN_VARIANT (TREE_TYPE (base_type)))
!     natural_type = type;
    else
      natural_type = build_pointer_type (base_type);
  
--- 266,280 ----
        && TREE_CODE (base_type) == ARRAY_TYPE
        && TYPE_MAIN_VARIANT (TREE_TYPE (type))
  	 == TYPE_MAIN_VARIANT (TREE_TYPE (base_type)))
!     {
!       tree min_val = size_zero_node;
!       tree type_domain = TYPE_DOMAIN (base_type);
!       if (type_domain && TYPE_MIN_VALUE (type_domain))
!         min_val = TYPE_MIN_VALUE (type_domain);
!       t = build4 (ARRAY_REF, TREE_TYPE (type), t, min_val,
! 		  NULL_TREE, NULL_TREE);
!       natural_type = type;
!     }
    else
      natural_type = build_pointer_type (base_type);
  
Index: testsuite/gfortran.fortran-torture/execute/pr32140.f90
===================================================================
*** testsuite/gfortran.fortran-torture/execute/pr32140.f90	(revision 0)
--- testsuite/gfortran.fortran-torture/execute/pr32140.f90	(revision 0)
***************
*** 0 ****
--- 1,16 ----
+ MODULE TEST
+ CONTAINS
+ PURE FUNCTION s2a_3(s1,s2,s3) RESULT(a)
+     CHARACTER(LEN=*), INTENT(IN)             :: s1, s2, s3
+     CHARACTER(LEN=4), DIMENSION(3)        :: a
+ 
+   a(1)=s1; a(2)=s2; a(3)=s3
+ END FUNCTION
+ END MODULE
+ 
+ USE TEST
+ character(len=12) :: line
+ write(line,'(3A4)') s2a_3("a","bb","ccc")
+ IF (line.NE."a   bb  ccc") CALL ABORT()
+ END
+ 



More information about the Fortran mailing list