Commit 2dee4af1 by Jakub Jelinek Committed by Jakub Jelinek

builtins.c (c_strlen): Use TREE_STRING_LENGTH - 1 for max.

	* builtins.c (c_strlen): Use TREE_STRING_LENGTH - 1 for max.
	(c_getstr): New function.
	(expand_builtin_strstr): Do nothing if -fcheck-memory-usage.
	If both arguments are constant string, optimize out.
	(expand_builtin_strchr, expand_builtin_strrchr): New functions.
	(expand_builtin_strpbrk): Use c_getstr, do nothing if
	-fcheck-memory-usage.
	(expand_builtin_fputs): Likewise.
	(expand_builtin_strcmp): Add MODE argument.
	Use even if !HAVE_cmpstrsi.
	Optimize the case when both arguments are constant strings.
	(expand_builtin): Adjust expand_builtin_strcmp caller.
	Call expand_builtin_strchr and expand_builtin_strrchr.
	* c-common.c (c_common_nodes_and_builtins): Add strchr and strrchr
	builtins.
	* builtins.def (BUILT_IN_STRRCHR): Add.

	* gcc.c-torture/execute/string-opt-1.c: Add test for strstr
	with both arguments constant strings.
	* gcc.c-torture/execute/string-opt-3.c: New test.
	* gcc.c-torture/execute/string-opt-4.c: New test.
	* gcc.c-torture/execute/string-opt-5.c: New test.

From-SVN: r37338
parent 54d87db8
2000-11-09 Jakub Jelinek <jakub@redhat.com>
* builtins.c (c_strlen): Use TREE_STRING_LENGTH - 1 for max.
(c_getstr): New function.
(expand_builtin_strstr): Do nothing if -fcheck-memory-usage.
If both arguments are constant string, optimize out.
(expand_builtin_strchr, expand_builtin_strrchr): New functions.
(expand_builtin_strpbrk): Use c_getstr, do nothing if
-fcheck-memory-usage.
(expand_builtin_fputs): Likewise.
(expand_builtin_strcmp): Add MODE argument.
Use even if !HAVE_cmpstrsi.
Optimize the case when both arguments are constant strings.
(expand_builtin): Adjust expand_builtin_strcmp caller.
Call expand_builtin_strchr and expand_builtin_strrchr.
* c-common.c (c_common_nodes_and_builtins): Add strchr and strrchr
builtins.
* builtins.def (BUILT_IN_STRRCHR): Add.
2000-11-08 Gerald Pfeifer <pfeifer@dbai.tuwien.ac.at> 2000-11-08 Gerald Pfeifer <pfeifer@dbai.tuwien.ac.at>
* fixinc/gnu-regex.c: Rename EGCS LOCAL markers to GCC LOCAL. * fixinc/gnu-regex.c: Rename EGCS LOCAL markers to GCC LOCAL.
......
...@@ -42,6 +42,7 @@ DEF_BUILTIN(BUILT_IN_STRLEN) ...@@ -42,6 +42,7 @@ DEF_BUILTIN(BUILT_IN_STRLEN)
DEF_BUILTIN(BUILT_IN_STRSTR) DEF_BUILTIN(BUILT_IN_STRSTR)
DEF_BUILTIN(BUILT_IN_STRPBRK) DEF_BUILTIN(BUILT_IN_STRPBRK)
DEF_BUILTIN(BUILT_IN_STRCHR) DEF_BUILTIN(BUILT_IN_STRCHR)
DEF_BUILTIN(BUILT_IN_STRRCHR)
DEF_BUILTIN(BUILT_IN_FSQRT) DEF_BUILTIN(BUILT_IN_FSQRT)
DEF_BUILTIN(BUILT_IN_SIN) DEF_BUILTIN(BUILT_IN_SIN)
DEF_BUILTIN(BUILT_IN_COS) DEF_BUILTIN(BUILT_IN_COS)
......
...@@ -5179,6 +5179,8 @@ c_common_nodes_and_builtins () ...@@ -5179,6 +5179,8 @@ c_common_nodes_and_builtins ()
built_in_decls[BUILT_IN_STRCHR] = built_in_decls[BUILT_IN_STRCHR] =
builtin_function ("__builtin_strchr", string_ftype_string_int, builtin_function ("__builtin_strchr", string_ftype_string_int,
BUILT_IN_STRCHR, BUILT_IN_NORMAL, "strchr"); BUILT_IN_STRCHR, BUILT_IN_NORMAL, "strchr");
builtin_function ("__builtin_strrchr", string_ftype_string_int,
BUILT_IN_STRRCHR, BUILT_IN_NORMAL, "strrchr");
builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr, builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr,
BUILT_IN_STRCPY, BUILT_IN_NORMAL, "strcpy"); BUILT_IN_STRCPY, BUILT_IN_NORMAL, "strcpy");
builtin_function ("__builtin_strlen", strlen_ftype, builtin_function ("__builtin_strlen", strlen_ftype,
...@@ -5249,6 +5251,10 @@ c_common_nodes_and_builtins () ...@@ -5249,6 +5251,10 @@ c_common_nodes_and_builtins ()
BUILT_IN_NORMAL, NULL_PTR); BUILT_IN_NORMAL, NULL_PTR);
builtin_function ("strstr", string_ftype_string_string, BUILT_IN_STRSTR, builtin_function ("strstr", string_ftype_string_string, BUILT_IN_STRSTR,
BUILT_IN_NORMAL, NULL_PTR); BUILT_IN_NORMAL, NULL_PTR);
builtin_function ("strchr", string_ftype_string_int, BUILT_IN_STRCHR,
BUILT_IN_NORMAL, NULL_PTR);
builtin_function ("strrchr", string_ftype_string_int, BUILT_IN_STRRCHR,
BUILT_IN_NORMAL, NULL_PTR);
builtin_function ("strpbrk", string_ftype_string_string, BUILT_IN_STRPBRK, builtin_function ("strpbrk", string_ftype_string_string, BUILT_IN_STRPBRK,
BUILT_IN_NORMAL, NULL_PTR); BUILT_IN_NORMAL, NULL_PTR);
builtin_function ("strcpy", string_ftype_ptr_ptr, BUILT_IN_STRCPY, builtin_function ("strcpy", string_ftype_ptr_ptr, BUILT_IN_STRCPY,
......
2000-11-09 Jakub Jelinek <jakub@redhat.com>
* gcc.c-torture/execute/string-opt-1.c: Add test for strstr
with both arguments constant strings.
* gcc.c-torture/execute/string-opt-3.c: New test.
* gcc.c-torture/execute/string-opt-4.c: New test.
* gcc.c-torture/execute/string-opt-5.c: New test.
2000-11-08 Nick Clifton <nickc@redhat.com> 2000-11-08 Nick Clifton <nickc@redhat.com>
* gcc.c-torture/execute/20001108-1.c: New test case. Checks * gcc.c-torture/execute/20001108-1.c: New test case. Checks
......
...@@ -22,7 +22,9 @@ int main() ...@@ -22,7 +22,9 @@ int main()
abort(); abort();
if (strstr (foo + 6, "o") != foo + 7) if (strstr (foo + 6, "o") != foo + 7)
abort(); abort();
if (strstr (foo + 1, "world") != foo + 6)
abort();
return 0; return 0;
} }
......
/* Copyright (C) 2000 Free Software Foundation.
Ensure all expected transformations of builtin strlen, strcmp and strrchr
occur and perform correctly.
Written by Jakub Jelinek, 11/7/2000. */
extern void abort (void);
extern __SIZE_TYPE__ strlen (const char *);
extern int strcmp (const char *, const char *);
extern char *strrchr (const char *, int);
int x = 6;
char *bar = "hi world";
int main()
{
const char *const foo = "hello world";
if (strlen (foo) != 11)
abort ();
if (strlen (foo + 4) != 7)
abort ();
if (strlen (foo + (x++ & 7)) != 5)
abort ();
if (x != 7)
abort ();
if (strcmp (foo, "hello") <= 0)
abort ();
if (strcmp (foo + 2, "llo") <= 0)
abort ();
if (strcmp (foo, foo) != 0)
abort ();
if (strcmp (foo, "hello world ") >= 0)
abort ();
if (strcmp (foo + 10, "dx") >= 0)
abort ();
if (strcmp (10 + foo, "dx") >= 0)
abort ();
if (strrchr (foo, 'x'))
abort ();
if (strrchr (foo, 'o') != foo + 7)
abort ();
if (strrchr (foo, 'e') != foo + 1)
abort ();
if (strrchr (foo + 3, 'e'))
abort ();
if (strrchr (foo, '\0') != foo + 11)
abort ();
if (strrchr (bar, '\0') != bar + 8)
abort ();
if (strrchr (bar + 4, '\0') != bar + 8)
abort ();
if (strrchr (bar + (x++ & 3), '\0') != bar + 8)
abort ();
if (x != 8)
abort ();
return 0;
}
#ifdef __OPTIMIZE__
/* When optimizing, all the above cases should be transformed into
something else. So any remaining calls to the original function
should abort. */
__SIZE_TYPE__
strlen (const char *s)
{
abort ();
}
int
strcmp (const char *s1, const char *s2)
{
abort ();
}
char *
strrchr (const char *s, int c)
{
abort ();
}
#endif
/* Copyright (C) 2000 Free Software Foundation.
Ensure all expected transformations of builtin strchr occur and
perform correctly.
Written by Jakub Jelinek, 11/7/2000. */
extern void abort (void);
extern char *strchr (const char *, int);
int main()
{
const char *const foo = "hello world";
if (strchr (foo, 'x'))
abort ();
if (strchr (foo, 'o') != foo + 4)
abort ();
if (strchr (foo + 5, 'o') != foo + 7)
abort ();
if (strchr (foo, '\0') != foo + 11)
abort ();
return 0;
}
#ifdef __OPTIMIZE__
/* When optimizing, all the above cases should be transformed into
something else. So any remaining calls to the original function
should abort. */
char *
strchr (const char *s, int c)
{
abort ();
}
#endif
/* Copyright (C) 2000 Free Software Foundation.
Ensure builtin strlen, strcmp, strchr and strrchr perform correctly.
Written by Jakub Jelinek, 11/7/2000. */
extern void abort (void);
extern __SIZE_TYPE__ strlen (const char *);
extern int strcmp (const char *, const char *);
extern char *strchr (const char *, int);
extern char *strrchr (const char *, int);
int x = 6;
char *bar = "hi world";
int main()
{
const char *const foo = "hello world";
if (strlen (bar) != 8)
abort ();
if (strlen (bar + (++x & 2)) != 6)
abort ();
if (x != 7)
abort ();
if (strlen (foo + (x++, 6)) != 5)
abort ();
if (x != 8)
abort ();
if (strlen (foo + (++x & 1)) != 10)
abort ();
if (x != 9)
abort ();
if (strcmp (foo + (x -= 6), "lo world"))
abort ();
if (x != 3)
abort ();
if (strcmp (foo, bar) >= 0)
abort ();
if (strcmp (foo, bar + (x++ & 1)) >= 0)
abort ();
if (x != 4)
abort ();
if (strchr (foo + (x++ & 7), 'l') != foo + 9)
abort ();
if (x != 5)
abort ();
if (strchr (bar, 'o') != bar + 4)
abort ();
if (strchr (bar, '\0') != bar + 8)
abort ();
if (strrchr (bar, 'x'))
abort ();
if (strrchr (bar, 'o') != bar + 4)
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