Patchwork Cleanup fortran/convert.c

login
register
mail settings
Submitter Steven Bosscher
Date March 6, 2012, 8:41 p.m.
Message ID <CABu31nO+9AY7BEizP5=SPJqCb2vdKHorrzcZeULvJWEgw5dR5w@mail.gmail.com>
Download mbox | patch
Permalink /patch/144993/
State New
Headers show

Comments

Steven Bosscher - March 6, 2012, 8:41 p.m.
Hi,

This cleans up some remnants of the ancestors of fortran's convert.c,
which was copied from GNAT IIRC.

I would bootstrap&test this, but trunk appears to be broken for
x86_64-linux right now (ICE in patch_jump_insn). But I can post this
for review, at least.

OK for trunk, after bootstrap+test?

Ciao!
Steven


	* Make-lang.in (convert.o): Depend on convert.h.
	* convert.c: Header and comment cleanups.
	(gfc_thruthvalue_conversion): Rename static function
	to truthvalue_conversion.  Do not use 'internal_error' from here,
	use 'gcc_unreachable' instead.
	(convert): Do not use 'error' for conversions to void, use
	'gcc_unreachable' instead.  Likewise for conversions to non-scalar
	types.  Do not hanlde ENUMERAL_TYPE, the front end never creates them.
	Clean up #if 0 code.
* Make-lang.in (convert.o): Depend on convert.h.
	* convert.c: Header and comment cleanups.
	(gfc_thruthvalue_conversion): Rename static function
	to truthvalue_conversion.  Do not use 'internal_error' from here,
	use 'gcc_unreachable' instead.
	(convert): Do not use 'error' for conversions to void, use
	'gcc_unreachable' instead.  Likewise for conversions to non-scalar
	types.  Do not hanlde ENUMERAL_TYPE, the front end never creates them.
	Clean up #if 0 code.
Mikael Morin - March 8, 2012, 7:35 p.m.
On 06/03/2012 21:41, Steven Bosscher wrote:
> Hi,
> 
> This cleans up some remnants of the ancestors of fortran's convert.c,
> which was copied from GNAT IIRC.
> 
> I would bootstrap&test this, but trunk appears to be broken for
> x86_64-linux right now (ICE in patch_jump_insn). But I can post this
> for review, at least.
> 
> OK for trunk, after bootstrap+test?
> 
Yes. Thanks.

Mikael
Tobias Burnus - March 10, 2012, 10:19 a.m.
Steven Bosscher wrote:
> This cleans up some remnants of the ancestors of fortran's convert.c,
> which was copied from GNAT IIRC. I would bootstrap&test this, but trunk appears to be broken for x86_64-linux right now (ICE in patch_jump_insn). But I can post this
> for review, at least.
> OK for trunk, after bootstrap+test?

Your patch seems to have caused many Fortran regressions. At least I see 
with 185156 only one (known) failure, cf. 
http://gcc.gnu.org/ml/gcc-testresults/2012-03/msg01069.html

While starting with 185160 there are many, many gfortran failures, cf. 
http://gcc.gnu.org/ml/gcc-testresults/2012-03/msg01073.html

Tobias


> 	* Make-lang.in (convert.o): Depend on convert.h.
> 	* convert.c: Header and comment cleanups.
> 	(gfc_thruthvalue_conversion): Rename static function
> 	to truthvalue_conversion.  Do not use 'internal_error' from here,
> 	use 'gcc_unreachable' instead.
> 	(convert): Do not use 'error' for conversions to void, use
> 	'gcc_unreachable' instead.  Likewise for conversions to non-scalar
> 	types.  Do not hanlde ENUMERAL_TYPE, the front end never creates them.
> 	Clean up #if 0 code.
Thomas Koenig - March 10, 2012, 5:22 p.m.
Am 10.03.2012 11:19, schrieb Tobias Burnus:
> Steven Bosscher wrote:
>> This cleans up some remnants of the ancestors of fortran's convert.c,
>> which was copied from GNAT IIRC. I would bootstrap&test this, but
>> trunk appears to be broken for x86_64-linux right now (ICE in
>> patch_jump_insn). But I can post this
>> for review, at least.
>> OK for trunk, after bootstrap+test?
>
> Your patch seems to have caused many Fortran regressions. At least I see
> with 185156 only one (known) failure, cf.
> http://gcc.gnu.org/ml/gcc-testresults/2012-03/msg01069.html
>
> While starting with 185160 there are many, many gfortran failures, cf.
> http://gcc.gnu.org/ml/gcc-testresults/2012-03/msg01073.html

One error from the log is

/home/tkoenig/trunk/gcc/testsuite/gfortran.dg/gnu_logical_1.F:4:0: 
error: type mismatch in binary expression
logical(kind=8)

logical(kind=8)

logical(kind=4)

D.2303 = k8 & l1.26;

	Thomas

Patch

Index: Make-lang.in
===================================================================
--- Make-lang.in	(revision 185013)
+++ Make-lang.in	(working copy)
@@ -346,7 +347,7 @@  fortran/f95-lang.o: $(GFORTRAN_TRANS_DEP
   $(TM_H) debug.h langhooks.h $(FLAGS_H) $(EXPR_H) $(LANGHOOKS_DEF_H) \
   libfuncs.h expr.h $(DIAGNOSTIC_H)
 fortran/scanner.o: toplev.h fortran/cpp.h
-fortran/convert.o: $(GFORTRAN_TRANS_DEPS)
+fortran/convert.o: $(GFORTRAN_TRANS_DEPS) convert.h
 fortran/frontend-passes.o: $(GFORTRAN_TRANS_DEPS)
 fortran/trans.o: $(GFORTRAN_TRANS_DEPS) tree-iterator.h
 fortran/trans-decl.o: $(GFORTRAN_TRANS_DEPS) gt-fortran-trans-decl.h \
Index: convert.c
===================================================================
--- convert.c	(revision 185015)
+++ convert.c	(working copy)
@@ -1,5 +1,5 @@ 
-/* Language-level data type conversion for GNU C.
-   Copyright (C) 1987, 1988, 1991, 1998, 2002, 2007, 2008, 2010
+/* Data type conversion
+   Copyright (C) 1987, 1988, 1991, 1998, 2002, 2007, 2008, 2010, 2012
    Free Software Foundation, Inc.
 
 This file is part of GCC.
@@ -19,62 +19,23 @@  along with GCC; see the file COPYING3.  
 <http://www.gnu.org/licenses/>.  */
 
 
-/* This file contains the functions for converting C expressions
-   to different data types.  The only entry point is `convert'.
-   Every language front end must have a `convert' function
-   but what kind of conversions it does will depend on the language.  */
-
-/* copied from the f77 frontend I think */
-
-/* copied from c-convert.c without significant modification*/
-/* Change of width--truncation and extension of integers or reals--
-   is represented with NOP_EXPR.  Proper functioning of many things
-   assumes that no other conversions can be NOP_EXPRs.
-*/
-
-/* I've added support for WITH_RECORD_EXPR.  */
+/* This file contains the functions for converting expressions to
+   different data types for the translation of the gfortran internal
+   representation to GIMPLE.  The only entry point is `convert'.  */
 
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
 #include "tree.h"
-#include "flags.h"
 #include "convert.h"
-#include "diagnostic-core.h"	/* For error.  */
-#include "gfortran.h"
-#include "trans.h"
-
-/*
-   Conversion between integer and pointer is represented with CONVERT_EXPR.
-   Converting integer to real uses FLOAT_EXPR
-   and real to integer uses FIX_TRUNC_EXPR.
-
-   Here is a list of all the functions that assume that widening and
-   narrowing is always done with a NOP_EXPR:
-     In convert.c, convert_to_integer.
-     In c-typeck.c, build_binary_op (boolean ops), and
-	c_common_truthvalue_conversion.
-     In expr.c: expand_expr, for operands of a MULT_EXPR.
-     In fold-const.c: fold.
-     In tree.c: get_narrower and get_unwidened.  */
-
-/* Subroutines of `convert'.  */
 
 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
-   or validate its data type for an `if' or `while' statement or ?..: exp.
+   or validate its data type for a GIMPLE `if' or `while' statement.
 
-   This preparation consists of taking the ordinary
-   representation of an expression expr and producing a valid tree
-   boolean expression describing whether expr is nonzero.  We could
-   simply always do build_binary_op (NE_EXPR, expr, boolean_false_node, 1),
-   but we optimize comparisons, &&, ||, and !.
-
-   The resulting type should always be `boolean_type_node'.
-   This is much simpler than the corresponding C version because we have a
-   distinct boolean type.  */
+   The resulting type should always be `boolean_type_node'.  */
 
 static tree
-gfc_truthvalue_conversion (tree expr)
+truthvalue_conversion (tree expr)
 {
   switch (TREE_CODE (TREE_TYPE (expr)))
     {
@@ -101,7 +62,7 @@  gfc_truthvalue_conversion (tree expr)
 				expr, build_int_cst (TREE_TYPE (expr), 0));
 
     default:
-      internal_error ("Unexpected type in truthvalue_conversion");
+      gcc_unreachable ();
     }
 }
 
@@ -110,50 +71,33 @@  gfc_truthvalue_conversion (tree expr)
    is always TYPE.  This function implements all reasonable
    conversions; callers should filter out those that are
    not permitted by the language being compiled.  */
-/* We are assuming that given a SIMPLE val, the result will be a SIMPLE rhs.
-   If this is not the case, we will abort with an internal error.  */
+
 tree
 convert (tree type, tree expr)
 {
   tree e = expr;
-  enum tree_code code = TREE_CODE (type);
+  enum tree_code code;
+
+  if (type == TREE_TYPE (expr))
+    return expr;
 
-  if (type == TREE_TYPE (expr)
+  if (TREE_CODE (type) == ERROR_MARK
       || TREE_CODE (expr) == ERROR_MARK
-      || code == ERROR_MARK || TREE_CODE (TREE_TYPE (expr)) == ERROR_MARK)
+      || TREE_CODE (TREE_TYPE (expr)) == ERROR_MARK)
     return expr;
 
+  gcc_checking_assert (TREE_CODE (TREE_TYPE (expr)) != VOID_TYPE);
+
   if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (TREE_TYPE (expr)))
     return fold_build1_loc (input_location, NOP_EXPR, type, expr);
-  if (TREE_CODE (TREE_TYPE (expr)) == ERROR_MARK)
-    return error_mark_node;
-  if (TREE_CODE (TREE_TYPE (expr)) == VOID_TYPE)
-    {
-      error ("void value not ignored as it ought to be");
-      return error_mark_node;
-    }
+
+  code = TREE_CODE (type);
   if (code == VOID_TYPE)
     return fold_build1_loc (input_location, CONVERT_EXPR, type, e);
-#if 0
-  /* This is incorrect.  A truncation can't be stripped this way.
-     Extensions will be stripped by the use of get_unwidened.  */
-  if (TREE_CODE (expr) == NOP_EXPR)
-    return convert (type, TREE_OPERAND (expr, 0));
-#endif
-  if (code == INTEGER_TYPE || code == ENUMERAL_TYPE)
-    return fold (convert_to_integer (type, e));
   if (code == BOOLEAN_TYPE)
-    {
-      e = gfc_truthvalue_conversion (e);
-
-      /* If we have a NOP_EXPR, we must fold it here to avoid
-	 infinite recursion between fold () and convert ().  */
-      if (TREE_CODE (e) == NOP_EXPR)
-	return fold_build1_loc (input_location, NOP_EXPR, type,
-				TREE_OPERAND (e, 0));
-      else
-	return fold_build1_loc (input_location, NOP_EXPR, type, e);
-    }
+    return truthvalue_conversion (e);
+  if (code == INTEGER_TYPE)
+    return fold (convert_to_integer (type, e));
   if (code == POINTER_TYPE || code == REFERENCE_TYPE)
     return fold (convert_to_pointer (type, e));
   if (code == REAL_TYPE)
@@ -163,6 +107,6 @@  convert (tree type, tree expr)
   if (code == VECTOR_TYPE)
     return fold (convert_to_vector (type, e));
 
-  error ("conversion to non-scalar type requested");
-  return error_mark_node;
+  gcc_unreachable ();
 }
+