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] Fix PR37976, wrong types from folding strspn


PRE these days nicely detects wrong types in the IL ... both
folding strspn and strcspn wrongly return integer typed zero while
they should return size typed zeros.  Fixed thusly.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.

Richard.

2008-11-01  Richard Guenther  <rguenther@suse.de>

	PR middle-end/37976
	* builtins.c (fold_builtin_strspn): Return a size_t.
	(fold_builtin_strcspn): Likewise.

	* gcc.c-torture/compile/pr37976.c: New testcase.

Index: gcc/builtins.c
===================================================================
*** gcc/builtins.c	(revision 141511)
--- gcc/builtins.c	(working copy)
*************** fold_builtin_strspn (tree s1, tree s2)
*** 11398,11404 ****
        if ((p1 && *p1 == '\0') || (p2 && *p2 == '\0'))
  	/* Evaluate and ignore both arguments in case either one has
  	   side-effects.  */
! 	return omit_two_operands (integer_type_node, integer_zero_node,
  				  s1, s2);
        return NULL_TREE;
      }
--- 11398,11404 ----
        if ((p1 && *p1 == '\0') || (p2 && *p2 == '\0'))
  	/* Evaluate and ignore both arguments in case either one has
  	   side-effects.  */
! 	return omit_two_operands (size_type_node, size_zero_node,
  				  s1, s2);
        return NULL_TREE;
      }
*************** fold_builtin_strcspn (tree s1, tree s2)
*** 11444,11451 ****
  	{
  	  /* Evaluate and ignore argument s2 in case it has
  	     side-effects.  */
! 	  return omit_one_operand (integer_type_node,
! 				   integer_zero_node, s2);
  	}
  
        /* If the second argument is "", return __builtin_strlen(s1).  */
--- 11444,11451 ----
  	{
  	  /* Evaluate and ignore argument s2 in case it has
  	     side-effects.  */
! 	  return omit_one_operand (size_type_node,
! 				   size_zero_node, s2);
  	}
  
        /* If the second argument is "", return __builtin_strlen(s1).  */
Index: gcc/testsuite/gcc.c-torture/compile/pr37976.c
===================================================================
*** gcc/testsuite/gcc.c-torture/compile/pr37976.c	(revision 0)
--- gcc/testsuite/gcc.c-torture/compile/pr37976.c	(revision 0)
***************
*** 0 ****
--- 1,6 ----
+ void percent_x(int ch, char *p, char* ok_chars)                                 
+ { 
+   char *cp = ch == 'a' ? p : "";                                                
+   for (;*(cp += __builtin_strspn (cp, ok_chars));)
+     ;                                                                           
+ }


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