* [PATCH,fortran/32942] Give EXPONENT the correct return type
@ 2007-07-31 20:52 Steve Kargl
2007-07-31 21:25 ` FX Coudert
0 siblings, 1 reply; 2+ messages in thread
From: Steve Kargl @ 2007-07-31 20:52 UTC (permalink / raw)
To: fortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 502 bytes --]
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
[-- Attachment #2: pr32942.diff --]
[-- Type: text/x-diff, Size: 1421 bytes --]
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. */
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH,fortran/32942] Give EXPONENT the correct return type
2007-07-31 20:52 [PATCH,fortran/32942] Give EXPONENT the correct return type Steve Kargl
@ 2007-07-31 21:25 ` FX Coudert
0 siblings, 0 replies; 2+ messages in thread
From: FX Coudert @ 2007-07-31 21:25 UTC (permalink / raw)
To: Steve Kargl; +Cc: fortran, gcc-patches
> 2007-07-31 Steven G. Kargl <kargl@gcc.gnu.org>
>
> PR fortran/32942
> *trans-intrinsic.c (gfc_conv_intrinsic_exponent): Convert to correct
> type.
OK to commit.
It looks like many of the -fdefault-integer-8 bugs will allow us to
catch occurences of these problems. I'm currently regtesting the
following fix for PR 32938, which I'll commit as obvious as soon as
regtest is finished (along with ChangeLog entry and testcase, of
course).
Index: trans-stmt.c
===================================================================
--- trans-stmt.c (revision 127059)
+++ trans-stmt.c (working copy)
@@ -447,7 +447,8 @@ gfc_trans_return (gfc_code * code ATTRIB
gfc_conv_expr (&se, code->expr);
- tmp = build2 (MODIFY_EXPR, TREE_TYPE (result), result, se.expr);
+ tmp = build2 (MODIFY_EXPR, TREE_TYPE (result), result,
+ fold_convert (TREE_TYPE (result), se.expr));
gfc_add_expr_to_block (&se.pre, tmp);
tmp = build1_v (GOTO_EXPR, gfc_get_return_label ());
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-07-31 20:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-31 20:52 [PATCH,fortran/32942] Give EXPONENT the correct return type Steve Kargl
2007-07-31 21:25 ` 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).