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, middle-end, commited]: Fix PR21282


Hello!

This patch fixes a thinko in (int)ceil(float) and (int)floor(float) conversion on !TARGET_C99_FUNCTIONS targets. As shown in PR report, this testcase can still produce a call to floorf():

extern double floor (double);

long foo (float f)
{
 return (long) floor (f);
}

The obvoius fix is to disable all (int)ceil(float) and (int)floor(float) conversions for !TARGET_C99_FUNCTIONS targets.

Patch was commited to mainline under obvious rule (as it is the same fix as for floorf and floorl) after it passed
bootstrap on i686-pc-linux-gnu. Patch was regtested on sparc-sun-solaris2.8 for c and on i686-pc-linux-gnu for c and c++.
A testcase from PR was added to the testsuite.

2005-05-03 Uros Bizjak <uros@kss-loka.si>

	PR middle-end/21282
	* convert.c (convert_to_integer): Convert ceil and floor in
	c99 mode only.

testsuite:

	PR middle-end/21282
	* gcc.dg/pr21282.c: New.


Uros.


Index: convert.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/convert.c,v
retrieving revision 1.61
diff -u -p -r1.61 convert.c
--- convert.c	15 Apr 2005 05:43:46 -0000	1.61
+++ convert.c	3 May 2005 08:00:55 -0000
@@ -349,26 +349,20 @@ convert_to_integer (tree type, tree expr
       
       switch (fcode)
         {
-	case BUILT_IN_CEILF:
-	case BUILT_IN_CEILL:
+	case BUILT_IN_CEIL: case BUILT_IN_CEILF: case BUILT_IN_CEILL:
 	  /* Only convert in ISO C99 mode.  */
 	  if (!TARGET_C99_FUNCTIONS)
 	    break;
-	  /* ... Fall through ...  */
-	case BUILT_IN_CEIL:
 	  if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (long_long_integer_type_node))
 	    fn = mathfn_built_in (s_intype, BUILT_IN_LLCEIL);
 	  else
 	    fn = mathfn_built_in (s_intype, BUILT_IN_LCEIL);
 	  break;
 
-	case BUILT_IN_FLOORF:
-	case BUILT_IN_FLOORL:
+	case BUILT_IN_FLOOR: case BUILT_IN_FLOORF: case BUILT_IN_FLOORL:
 	  /* Only convert in ISO C99 mode.  */
 	  if (!TARGET_C99_FUNCTIONS)
 	    break;
-	  /* ... Fall through ...  */
-	case BUILT_IN_FLOOR:
 	  if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (long_long_integer_type_node))
 	    fn = mathfn_built_in (s_intype, BUILT_IN_LLFLOOR);
 	  else
/* { dg-do compile } */
/* { dg-options "-O1" } */

extern double floor (double);

long foo (float f)
{
	  return (long) floor (f);
}

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