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]

[Patch,Fortran] PR43040 - Wrong code with LTO and GAMMA


Hi all,

when the Fortran GAMMA intrinsic was added, the tgamma built in was
supposed to be called. The way (t)gamma was added in mathbuiltins.def
was not fully correct, but it worked as the middle end had no closer
look. Well, with LTO the middle end now is stricter - and the result is
that GAMMA returns the wrong numbers.

The fix is easy: Consistently call it TGAMMA for the middle end and only
call it "gamma" for the compiler user. That's what this patch does.

Build on x86-64-linux. Regtesting is currently running, but I do not
expect any problem. I tested "gamma_5.f90" with -flto and it succeeds:
    gfortran -g -flto gfortran.dg/gamma_5.f90 && ./a.out
If it is deemed to be useful, I can also add a -flto test case.

OK for the trunk, when regtesting succeeds?

Tobias

PS: I have not looked at the (l)round(f,l) issue mentioned in the PR -
nor at other builtins.
2010-02-12  Tobias Burnus  <burnus@net-b.de>

	PR fortran/43040
	* gfortran.h (gfc_isym_id): Rename GFS_ISYM_GAMMA to GFS_ISYM_TGAMMA.
	* intrinsic.c (add_functions): Ditto.
	* iresolve.c (gfc_resolve_gamma): Call tgamma instead of gamma.
	* mathbuiltins.def: Use TGAMMA instead of GAMMA with "tgamma".

Index: gcc/fortran/intrinsic.c
===================================================================
--- gcc/fortran/intrinsic.c	(revision 156732)
+++ gcc/fortran/intrinsic.c	(working copy)
@@ -1665,15 +1665,15 @@ add_functions (void)
 
   make_generic ("fput", GFC_ISYM_FPUT, GFC_STD_GNU);
 
-  add_sym_1 ("gamma", GFC_ISYM_GAMMA, CLASS_ELEMENTAL, ACTUAL_NO, BT_REAL, dr,
+  add_sym_1 ("gamma", GFC_ISYM_TGAMMA, CLASS_ELEMENTAL, ACTUAL_NO, BT_REAL, dr,
 	     GFC_STD_F2008, gfc_check_fn_r, gfc_simplify_gamma,
 	     gfc_resolve_gamma, x, BT_REAL, dr, REQUIRED);
 
-  add_sym_1 ("dgamma", GFC_ISYM_GAMMA, CLASS_ELEMENTAL, ACTUAL_NO, BT_REAL, dr, GFC_STD_GNU,
+  add_sym_1 ("dgamma", GFC_ISYM_TGAMMA, CLASS_ELEMENTAL, ACTUAL_NO, BT_REAL, dr, GFC_STD_GNU,
 	     gfc_check_fn_d, gfc_simplify_gamma, gfc_resolve_gamma,
 	     x, BT_REAL, dr, REQUIRED);
 
-  make_generic ("gamma", GFC_ISYM_GAMMA, GFC_STD_F2008);
+  make_generic ("gamma", GFC_ISYM_TGAMMA, GFC_STD_F2008);
 
   /* Unix IDs (g77 compatibility)  */
   add_sym_1 ("getcwd", GFC_ISYM_GETCWD, NO_CLASS, ACTUAL_NO, BT_INTEGER, di,  GFC_STD_GNU,
Index: gcc/fortran/mathbuiltins.def
===================================================================
--- gcc/fortran/mathbuiltins.def	(revision 156732)
+++ gcc/fortran/mathbuiltins.def	(working copy)
@@ -48,6 +48,6 @@ DEFINE_MATH_BUILTIN   (Y1,    "y1",
 DEFINE_MATH_BUILTIN   (YN,    "yn",     2)
 DEFINE_MATH_BUILTIN   (ERF,   "erf",    0)
 DEFINE_MATH_BUILTIN   (ERFC,  "erfc",   0)
-DEFINE_MATH_BUILTIN   (GAMMA, "tgamma", 0)
+DEFINE_MATH_BUILTIN   (TGAMMA,"tgamma", 0)
 DEFINE_MATH_BUILTIN   (LGAMMA,"lgamma", 0)
 DEFINE_MATH_BUILTIN   (HYPOT, "hypot",  1)
Index: gcc/fortran/gfortran.h
===================================================================
--- gcc/fortran/gfortran.h	(revision 156732)
+++ gcc/fortran/gfortran.h	(working copy)
@@ -377,7 +377,7 @@ enum gfc_isym_id
   GFC_ISYM_FSEEK,
   GFC_ISYM_FSTAT,
   GFC_ISYM_FTELL,
-  GFC_ISYM_GAMMA,
+  GFC_ISYM_TGAMMA,
   GFC_ISYM_GERROR,
   GFC_ISYM_GETARG,
   GFC_ISYM_GET_COMMAND,
Index: gcc/fortran/iresolve.c
===================================================================
--- gcc/fortran/iresolve.c	(revision 156732)
+++ gcc/fortran/iresolve.c	(working copy)
@@ -912,7 +912,7 @@ gfc_resolve_gamma (gfc_expr *f, gfc_expr
 {
   f->ts = x->ts;
   f->value.function.name
-    = gfc_get_string ("__gamma_%d", x->ts.kind);
+    = gfc_get_string ("__tgamma_%d", x->ts.kind);
 }
 
 

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