public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [gfortran,committed] Character length backend_decl could be given wrong type
@ 2007-08-11 21:44 FX Coudert
  0 siblings, 0 replies; only message in thread
From: FX Coudert @ 2007-08-11 21:44 UTC (permalink / raw)
  To: Fortran List, gcc-patches list

[-- Attachment #1: Type: text/plain, Size: 487 bytes --]

This patch fixes a case of character length backend_decl being given  
a type different than gfc_charlen_type_node, which I fixed by using  
the already existing gfc_conv_const_charlen() function. I also found  
another one, not yet exposed to my knowledge, in gfc_conv_aliased_arg 
(). I also took the liberty to change the return value of  
_gfortran_compare_string from an integer(kind=4) into a plain C int.

Committed as obvious after bootstrap and regtesting on x86_64-linux.

FX


[-- Attachment #2: foo.diff --]
[-- Type: application/octet-stream, Size: 6377 bytes --]

Index: gcc/fortran/trans-array.c
===================================================================
--- gcc/fortran/trans-array.c	(revision 127334)
+++ gcc/fortran/trans-array.c	(working copy)
@@ -4547,9 +4547,7 @@ gfc_conv_expr_descriptor (gfc_se * se, g
 	  else if (expr->ts.cl->length
 		     && expr->ts.cl->length->expr_type == EXPR_CONSTANT)
 	    {
-	      expr->ts.cl->backend_decl
-		= gfc_conv_mpz_to_tree (expr->ts.cl->length->value.integer,
-					expr->ts.cl->length->ts.kind);
+	      gfc_conv_const_charlen (expr->ts.cl);
 	      loop.temp_ss->data.temp.type
 		= gfc_typenode_for_spec (&expr->ts);
 	      loop.temp_ss->string_length
Index: gcc/fortran/trans-expr.c
===================================================================
--- gcc/fortran/trans-expr.c	(revision 127334)
+++ gcc/fortran/trans-expr.c	(working copy)
@@ -1031,8 +1031,7 @@ gfc_conv_expr_op (gfc_se * se, gfc_expr 
   enum tree_code code;
   gfc_se lse;
   gfc_se rse;
-  tree type;
-  tree tmp;
+  tree tmp, type;
   int lop;
   int checkstring;
 
@@ -1181,7 +1180,7 @@ gfc_conv_expr_op (gfc_se * se, gfc_expr 
   if (lop)
     {
       /* The result of logical ops is always boolean_type_node.  */
-      tmp = fold_build2 (code, type, lse.expr, rse.expr);
+      tmp = fold_build2 (code, boolean_type_node, lse.expr, rse.expr);
       se->expr = convert (type, tmp);
     }
   else
@@ -1275,23 +1274,20 @@ gfc_build_compare_string (tree len1, tre
 {
   tree sc1;
   tree sc2;
-  tree type;
   tree tmp;
 
   gcc_assert (POINTER_TYPE_P (TREE_TYPE (str1)));
   gcc_assert (POINTER_TYPE_P (TREE_TYPE (str2)));
 
-  type = gfc_get_int_type (gfc_default_integer_kind);
-
   sc1 = gfc_to_single_character (len1, str1);
   sc2 = gfc_to_single_character (len2, str2);
 
   /* Deal with single character specially.  */
   if (sc1 != NULL_TREE && sc2 != NULL_TREE)
     {
-      sc1 = fold_convert (type, sc1);
-      sc2 = fold_convert (type, sc2);
-      tmp = fold_build2 (MINUS_EXPR, type, sc1, sc2);
+      sc1 = fold_convert (integer_type_node, sc1);
+      sc2 = fold_convert (integer_type_node, sc2);
+      tmp = fold_build2 (MINUS_EXPR, integer_type_node, sc1, sc2);
     }
    else
      /* Build a call for the comparison.  */
@@ -1855,6 +1851,7 @@ gfc_conv_aliased_arg (gfc_se * parmse, g
 				gfc_array_index_type);
 	    tmp = fold_build2 (MINUS_EXPR, gfc_array_index_type,
 			       tmp, tmp_se.expr);
+	    tmp = fold_convert (gfc_charlen_type_node, tmp);
 	    expr->ts.cl->backend_decl = tmp;
 
 	    break;
Index: gcc/fortran/ChangeLog
===================================================================
--- gcc/fortran/ChangeLog	(revision 127362)
+++ gcc/fortran/ChangeLog	(working copy)
@@ -1,3 +1,15 @@
+2007-08-11  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
+
+	PR fortran/32937
+	* trans-array.c (gfc_conv_expr_descriptor): Use
+	gfc_conv_const_charlen to generate backend_decl of right type.
+	* trans-expr.c (gfc_conv_expr_op): Use correct return type.
+	(gfc_build_compare_string): Use int type instead of default
+	integer kind for single character comparison.
+	(gfc_conv_aliased_arg): Give backend_decl the right type.
+	* trans-decl.c (gfc_build_intrinsic_function_decls): Make
+	compare_string return an int.
+
 2007-08-11  Ian Lance Taylor  <iant@google.com>
 
 	* f95-lang.c (gfc_get_alias_set): Change return type to
Index: gcc/fortran/trans-decl.c
===================================================================
--- gcc/fortran/trans-decl.c	(revision 127334)
+++ gcc/fortran/trans-decl.c	(working copy)
@@ -1999,8 +1999,7 @@ gfc_build_intrinsic_function_decls (void
   /* String functions.  */
   gfor_fndecl_compare_string =
     gfc_build_library_function_decl (get_identifier (PREFIX("compare_string")),
-				     gfc_int4_type_node,
-				     4,
+				     integer_type_node, 4,
 				     gfc_charlen_type_node, pchar_type_node,
 				     gfc_charlen_type_node, pchar_type_node);
 
Index: gcc/testsuite/ChangeLog
===================================================================
--- gcc/testsuite/ChangeLog	(revision 127362)
+++ gcc/testsuite/ChangeLog	(working copy)
@@ -1,3 +1,8 @@
+2007-08-11  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
+
+	PR fortran/32937
+	* gfortran.dg/char_length_6.f90: New test.
+
 2007-08-10  Ollie Wild  <aaw@google.com>
 
 	* g++.dg/lookup/using18.C: New test.
Index: gcc/testsuite/gfortran.dg/char_length_6.f90
===================================================================
--- gcc/testsuite/gfortran.dg/char_length_6.f90	(revision 0)
+++ gcc/testsuite/gfortran.dg/char_length_6.f90	(revision 0)
@@ -0,0 +1,21 @@
+! { dg-do run }
+!
+program test
+  character(2_8) :: c(2)
+  logical :: l(2)
+
+  c = "aa"
+  l = c .eq. "aa"
+  if (any (.not. l)) call abort
+
+  call foo ([c(1)])
+  l = c .eq. "aa"
+  if (any (.not. l)) call abort
+
+contains
+
+  subroutine foo (c)
+    character(2) :: c(1)
+  end subroutine foo
+
+end
Index: libgfortran/libgfortran.h
===================================================================
--- libgfortran/libgfortran.h	(revision 127331)
+++ libgfortran/libgfortran.h	(working copy)
@@ -759,8 +759,8 @@ internal_proto(internal_unpack_c16);
 
 /* string_intrinsics.c */
 
-extern GFC_INTEGER_4 compare_string (GFC_INTEGER_4, const char *,
-				     GFC_INTEGER_4, const char *);
+extern int compare_string (GFC_INTEGER_4, const char *,
+			   GFC_INTEGER_4, const char *);
 iexport_proto(compare_string);
 
 /* random.c */
Index: libgfortran/ChangeLog
===================================================================
--- libgfortran/ChangeLog	(revision 127362)
+++ libgfortran/ChangeLog	(working copy)
@@ -1,3 +1,8 @@
+2007-08-11  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
+
+	* intrinsics/string_intrinsics.c (compare_string): Return an int.
+	* libgfortran.h (compare_string): Likewise.
+
 2007-08-10  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
 
 	PR fortran/31270
Index: libgfortran/intrinsics/string_intrinsics.c
===================================================================
--- libgfortran/intrinsics/string_intrinsics.c	(revision 127331)
+++ libgfortran/intrinsics/string_intrinsics.c	(working copy)
@@ -79,7 +79,7 @@ export_proto(string_minmax);
 
 /* Strings of unequal length are extended with pad characters.  */
 
-GFC_INTEGER_4
+int
 compare_string (GFC_INTEGER_4 len1, const char * s1,
 		GFC_INTEGER_4 len2, const char * s2)
 {

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2007-08-11 21:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-11 21:44 [gfortran,committed] Character length backend_decl could be given wrong type FX Coudert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).