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 . +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. */