This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH, fortran] Convert returned types to correct 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: Thu, 2 Aug 2007 13:16:57 -0700
- Subject: [PATCH, fortran] Convert returned types to correct type.
:ADDPATCH:
Here's is another patch that fixes a problem exposed by
-fdefault-integer-8. The return type of the selected_*_kind
function was int4 but needs to be converted to int8.
I've tested the patch on both i386 and amd64-*-freebsd.
2007-08-02 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/32968
* gfortran.dg/selected_kind_1.f90: New test.
2007-08-02 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/32968
* trans-intrinsic.c(gfc_conv_intrinsic_si_kind,
gfc_conv_intrinsic_sr_kind): Convert to the correct type.
--
Steve
Index: gcc/testsuite/gfortran.dg/selected_kind_1.f90
===================================================================
--- gcc/testsuite/gfortran.dg/selected_kind_1.f90 (revision 0)
+++ gcc/testsuite/gfortran.dg/selected_kind_1.f90 (revision 0)
@@ -0,0 +1,16 @@
+! { dg-do run }
+! { dg-options "-fdefault-integer-8" }
+! PR fortran/32968
+program selected
+
+ if (selected_int_kind (1) /= 1) call abort
+ if (selected_int_kind (3) /= 2) call abort
+ if (selected_int_kind (5) /= 4) call abort
+ if (selected_int_kind (10) /= 8) call abort
+ if (selected_real_kind (1) /= 4) call abort
+ if (selected_real_kind (2) /= 4) call abort
+ if (selected_real_kind (9) /= 8) call abort
+ if (selected_real_kind (10) /= 8) call abort
+
+end program selected
+
Index: gcc/fortran/trans-intrinsic.c
===================================================================
--- gcc/fortran/trans-intrinsic.c (revision 127167)
+++ gcc/fortran/trans-intrinsic.c (working copy)
@@ -3467,11 +3467,15 @@ gfc_conv_intrinsic_verify (gfc_se * se,
static void
gfc_conv_intrinsic_si_kind (gfc_se * se, gfc_expr * expr)
{
- tree arg;
+ tree arg, type;
gfc_conv_intrinsic_function_args (se, expr, &arg, 1);
arg = build_fold_addr_expr (arg);
+
+ /* Convert it to the required type. */
+ type = gfc_typenode_for_spec (&expr->ts);
se->expr = build_call_expr (gfor_fndecl_si_kind, 1, arg);
+ se->expr = fold_convert (type, se->expr);
}
/* Generate code for SELECTED_REAL_KIND (P, R) intrinsic function. */
@@ -3480,7 +3484,7 @@ static void
gfc_conv_intrinsic_sr_kind (gfc_se * se, gfc_expr * expr)
{
gfc_actual_arglist *actual;
- tree args;
+ tree args, type;
gfc_se argse;
args = NULL_TREE;
@@ -3498,7 +3502,11 @@ gfc_conv_intrinsic_sr_kind (gfc_se * se,
gfc_add_block_to_block (&se->post, &argse.post);
args = gfc_chainon_list (args, argse.expr);
}
+
+ /* Convert it to the required type. */
+ type = gfc_typenode_for_spec (&expr->ts);
se->expr = build_function_call_expr (gfor_fndecl_sr_kind, args);
+ se->expr = fold_convert (type, se->expr);
}