This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH,fortran/32942] Give EXPONENT the correct return type
- From: Steve Kargl <sgk at troutmask dot apl dot washington dot edu>
- To: fortran at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Tue, 31 Jul 2007 13:31:57 -0700
- Subject: [PATCH,fortran/32942] Give EXPONENT the correct return type
The library routines for EXPONENT return a INTEGER(4) value.
When -fdefault-integer-8 is used, the result needs to be
convert to the correct type. The attach patch, regression
tested on amd64-*-freebsd, does the trick.
OK for trunk?
2007-07-31 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/32942
* gfortran.dg/exponent_2.f90: New test.
2007-07-31 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/32942
*trans-intrinsic.c (gfc_conv_intrinsic_exponent): Convert to correct
type.
--
Steve
Index: testsuite/gfortran.dg/exponent_2.f90
===================================================================
--- testsuite/gfortran.dg/exponent_2.f90 (revision 0)
+++ testsuite/gfortran.dg/exponent_2.f90 (revision 0)
@@ -0,0 +1,11 @@
+! { dg-do run }
+! { dg-options "-fdefault-integer-8" }
+! PR fortran/32942
+! Testcase contributed by Dominique d'Humieres <dominiq@lps.ens.fr>.
+integer i
+real x
+x = 3.0
+if (2 /= exponent(x)) call abort
+i = exponent (x)
+if (i /= 2) call abort
+end
Index: fortran/trans-intrinsic.c
===================================================================
--- fortran/trans-intrinsic.c (revision 127065)
+++ fortran/trans-intrinsic.c (working copy)
@@ -718,9 +718,9 @@ gfc_conv_intrinsic_lib_function (gfc_se
/* Generate code for EXPONENT(X) intrinsic function. */
static void
-gfc_conv_intrinsic_exponent (gfc_se * se, gfc_expr * expr)
+gfc_conv_intrinsic_exponent (gfc_se *se, gfc_expr *expr)
{
- tree arg, fndecl;
+ tree arg, fndecl, type;
gfc_expr *a1;
gfc_conv_intrinsic_function_args (se, expr, &arg, 1);
@@ -744,7 +744,9 @@ gfc_conv_intrinsic_exponent (gfc_se * se
gcc_unreachable ();
}
- se->expr = build_call_expr (fndecl, 1, arg);
+ /* Convert it to the required type. */
+ type = gfc_typenode_for_spec (&expr->ts);
+ se->expr = fold_convert (type, build_call_expr (fndecl, 1, arg));
}
/* Evaluate a single upper or lower bound. */