Commit 611b1df4 by Kaveh R. Ghazi Committed by Kaveh Ghazi

builtins.c (expand_builtin_strspn, [...]): Handle another transformation.

	* builtins.c (expand_builtin_strspn, expand_builtin_strcspn):
	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.

From-SVN: r37986
parent 55deb046
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.
......
......@@ -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')
{
......
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.
......
......@@ -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;
}
......
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment