This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [gfortran] Minor cleanup to trans-intrinsic.c


Paul Brook wrote:
>>>2004-12-20  Tobias Schlueter  <tobias.schlueter@physik.uni-muenchen.de>
>>>
>>>      * trans-intrinsic.c (build_fix_expr): Change 'op' argument
>>>      to correct enum type.
>>>      (gfc_conv_intrinsic_aint): Likewise.  Also correct comment in
>>>      front of function.  Add default case to switch.

...

> No. I think this is a latent bug.
> I suggest add the gcc_unreachable, and do s/FLOOR/TRUNC/

I finally got around to finding out why this is not as simple as you suggested
:-) I didn't commit this, as I'm not completely sure this is complete (even
though it passes testing):  I'm not sure if the comment in the beginning of
the hunk in gfc_init_builtin_functions means that I have to change some other
place as well.  I also verified that the behavior of AINT (truncates) and
ANINT (rounds) is indeed correct.

Bubblestrapped and tested on i686-pc-linux.

- Tobi

2006-02-07  Tobias Schl"uter  <tobias.schlueter@physik.uni-muenchen.de>

	* f95-lang.c (gfc_init_builtin_functions): Define BUILT_IN_TRUNC
	and BUILT_IN_TRUNCF instead of BUILT_IN_FLOOR and BUILT_IN_FLOORF.
	* trans-intrinsic.c (build_fix_expr): Change 'op' argument
	to correct enum type.
	(gfc_conv_intrinsic_aint): Likewise.  Clarify comment in front of
	function.  Add default case to switch, deal with FIX_TRUNC_EXPR
	instead of FIX_FLOOR_EXPR.

Index: f95-lang.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/f95-lang.c,v
retrieving revision 1.30
diff -u -p -r1.30 f95-lang.c
--- f95-lang.c  23 Jan 2005 14:36:25 -0000      1.30
+++ f95-lang.c  7 Feb 2005 14:34:53 -0000
@@ -781,14 +781,14 @@ gfc_init_builtin_functions (void)

   /* We define these separately as the fortran versions have different
      semantics (they return an integer type) */
-  gfc_define_builtin ("__builtin_floor", mfunc_double[0],
-                     BUILT_IN_FLOOR, "floor", true);
-  gfc_define_builtin ("__builtin_floorf", mfunc_float[0],
-                     BUILT_IN_FLOORF, "floorf", true);
   gfc_define_builtin ("__builtin_round", mfunc_double[0],
                      BUILT_IN_ROUND, "round", true);
   gfc_define_builtin ("__builtin_roundf", mfunc_float[0],
                      BUILT_IN_ROUNDF, "roundf", true);
+  gfc_define_builtin ("__builtin_trunc", mfunc_double[0],
+                     BUILT_IN_TRUNC, "trunc", true);
+  gfc_define_builtin ("__builtin_truncf", mfunc_float[0],
+                     BUILT_IN_TRUNCF, "truncf", true);

   gfc_define_builtin ("__builtin_cabs", func_cdouble_double,
                      BUILT_IN_CABS, "cabs", true);
Index: trans-intrinsic.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/trans-intrinsic.c,v
retrieving revision 1.43
diff -u -p -r1.43 trans-intrinsic.c
--- trans-intrinsic.c   23 Jan 2005 14:36:25 -0000      1.43
+++ trans-intrinsic.c   7 Feb 2005 14:34:54 -0000
@@ -277,7 +277,8 @@ build_round_expr (stmtblock_t * pblock,
    however the RTL expander only actually supports FIX_TRUNC_EXPR.  */

 static tree
-build_fix_expr (stmtblock_t * pblock, tree arg, tree type, int op)
+build_fix_expr (stmtblock_t * pblock, tree arg, tree type,
+               enum tree_code op)
 {
   switch (op)
     {
@@ -300,14 +301,14 @@ build_fix_expr (stmtblock_t * pblock, tr

 /* Round a real value using the specified rounding mode.
    We use a temporary integer of that same kind size as the result.
-   Values larger than can be represented by this kind are unchanged, as
-   will not be accurate enough to represent the rounding.
+   Values larger than those that can be represented by this kind are
+   unchanged, as will not be accurate enough to represent the rounding.
     huge = HUGE (KIND (a))
     aint (a) = ((a > huge) || (a < -huge)) ? a : (real)(int)a
    */

 static void
-gfc_conv_intrinsic_aint (gfc_se * se, gfc_expr * expr, int op)
+gfc_conv_intrinsic_aint (gfc_se * se, gfc_expr * expr, enum tree_code op)
 {
   tree type;
   tree itype;
@@ -337,17 +338,21 @@ gfc_conv_intrinsic_aint (gfc_se * se, gf
        }
       break;

-    case FIX_FLOOR_EXPR:
+    case FIX_TRUNC_EXPR:
       switch (kind)
        {
        case 4:
-         n = BUILT_IN_FLOORF;
+         n = BUILT_IN_TRUNCF;
          break;

        case 8:
-         n = BUILT_IN_FLOOR;
+         n = BUILT_IN_TRUNC;
          break;
        }
+      break;
+
+    default:
+      gcc_unreachable ();
     }

   /* Evaluate the argument.  */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]