OSDN Git Service

* builtins.c (expand_builtin_strspn, expand_builtin_strcspn):
authorghazi <ghazi@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 4 Dec 2000 01:07:47 +0000 (01:07 +0000)
committerghazi <ghazi@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 4 Dec 2000 01:07:47 +0000 (01:07 +0000)
Handle another transformation.

testsuite:
* gcc.c-torture/execute/string-opt-11.c: Add more strspn checks.
* gcc.c-torture/execute/string-opt-12.c: Add more strcspn checks.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@37986 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/builtins.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/string-opt-11.c
gcc/testsuite/gcc.c-torture/execute/string-opt-12.c

index c74983a..d38d2d9 100644 (file)
@@ -1,3 +1,8 @@
+2000-12-03  Kaveh R. Ghazi  <ghazi@teal.rutgers.edu>
+
+       * builtins.c (expand_builtin_strspn, expand_builtin_strcspn):
+       Handle another transformation.
+
 2000-12-03  Nick Clifton  <nickc@redhat.com>
 
        * config.gcc: Add support for StrongARM targets.
index 1d8e5e2..d6fa5bb 100644 (file)
@@ -2594,12 +2594,13 @@ expand_builtin_strspn (arglist, target, mode)
          return expand_expr (size_int (r), target, mode, EXPAND_NORMAL);
        }
       
-      /* If the second argument is "", return 0.  */
-      if (p2 && *p2 == '\0')
+      /* If either argument is "", return 0.  */
+      if ((p1 && *p1 == '\0') || (p2 && *p2 == '\0'))
         {
-         /* Evaluate and ignore argument s1 in case it has
+         /* Evaluate and ignore both arguments in case either one has
             side-effects.  */
          expand_expr (s1, const0_rtx, VOIDmode, EXPAND_NORMAL);
+         expand_expr (s2, const0_rtx, VOIDmode, EXPAND_NORMAL);
          return const0_rtx;
        }
       return 0;
@@ -2638,6 +2639,15 @@ expand_builtin_strcspn (arglist, target, mode)
          return expand_expr (size_int (r), target, mode, EXPAND_NORMAL);
        }
       
+      /* If the first argument is "", return 0.  */
+      if (p1 && *p1 == '\0')
+        {
+         /* Evaluate and ignore argument s2 in case it has
+            side-effects.  */
+         expand_expr (s2, const0_rtx, VOIDmode, EXPAND_NORMAL);
+         return const0_rtx;
+       }
+
       /* If the second argument is "", return __builtin_strlen(s1).  */
       if (p2 && *p2 == '\0')
         {
index 754f9fa..4ec9d5a 100644 (file)
@@ -1,3 +1,8 @@
+2000-12-03  Kaveh R. Ghazi  <ghazi@teal.rutgers.edu>
+
+       * gcc.c-torture/execute/string-opt-11.c: Add more strspn checks.
+       * gcc.c-torture/execute/string-opt-12.c: Add more strcspn checks.
+
 2000-12-03  Joseph S. Myers  <jsm28@cam.ac.uk>
 
        * gcc.c-torture/execute/20001203-1.c: New test.
index 9d043c9..b17e4c1 100644 (file)
@@ -34,6 +34,17 @@ int main ()
   strcpy (dst, s1); d2 = dst;
   if (strspn (++d2+5, "") != 0 || d2 != dst+1)
     abort();
+  if (strspn ("", s1) != 0)
+    abort();
+  strcpy (dst, s1);
+  if (strspn ("", dst) != 0)
+    abort();
+  strcpy (dst, s1); d2 = dst;
+  if (strspn ("", ++d2) != 0 || d2 != dst+1)
+    abort();
+  strcpy (dst, s1); d2 = dst;
+  if (strspn ("", ++d2+5) != 0 || d2 != dst+1)
+    abort();
 
   return 0;
 }
index 0126b85..ebe47e5 100644 (file)
@@ -34,6 +34,17 @@ int main ()
   strcpy (dst, s1); d2 = dst;
   if (strcspn (++d2+5, "") != 5 || d2 != dst+1)
     abort();
+  if (strcspn ("", s1) != 0)
+    abort();
+  strcpy (dst, s1);
+  if (strcspn ("", dst) != 0)
+    abort();
+  strcpy (dst, s1); d2 = dst;
+  if (strcspn ("", ++d2) != 0 || d2 != dst+1)
+    abort();
+  strcpy (dst, s1); d2 = dst;
+  if (strcspn ("", ++d2+5) != 0 || d2 != dst+1)
+    abort();
 
   return 0;
 }