diff options
author | Jakub Jelinek <jakub@redhat.com> | 2003-06-28 14:19:27 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2003-06-28 14:19:27 +0200 |
commit | ae808627c355ab7fd2a703b379af52ac76f3be73 (patch) | |
tree | 7fc785a0955781bbb3aa4a98aab0dd79c676a433 /gcc/testsuite | |
parent | a487649ce8e6ab118a384e9f4aece4a406fecb42 (diff) | |
download | gcc-ae808627c355ab7fd2a703b379af52ac76f3be73.zip gcc-ae808627c355ab7fd2a703b379af52ac76f3be73.tar.gz gcc-ae808627c355ab7fd2a703b379af52ac76f3be73.tar.bz2 |
builtins.c (c_strlen): Add only_value argument.
* builtins.c (c_strlen): Add only_value argument.
Handle COND_EXPR and COMPOUND_EXPR.
(expand_builtin_strlen): Optimize also strlen (i++ ? "foo" : "bar").
Adjust c_strlen callers.
(expand_builtin_strcpy, expand_builtin_strncpy,
expand_builtin_strcmp, expand_builtin_strncmp,
expand_builtin_fputs, expand_builtin_sprintf,
fold_builtin): Adjust c_strlen callers.
* gcc.c-torture/execute/builtins/string-8.c: New test.
* gcc.c-torture/execute/builtins/string-8-lib.c: New.
* gcc.c-torture/execute/stdio-opt-1.c (main): Add new tests.
* gcc.c-torture/execute/string-opt-7.c (main): Add new test.
From-SVN: r68634
Diffstat (limited to 'gcc/testsuite')
-rw-r--r-- | gcc/testsuite/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/testsuite/gcc.c-torture/execute/builtins/string-8-lib.c | 1 | ||||
-rw-r--r-- | gcc/testsuite/gcc.c-torture/execute/builtins/string-8.c | 41 | ||||
-rw-r--r-- | gcc/testsuite/gcc.c-torture/execute/stdio-opt-1.c | 11 | ||||
-rw-r--r-- | gcc/testsuite/gcc.c-torture/execute/string-opt-7.c | 8 |
5 files changed, 68 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e551aae..bc2058a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2003-06-28 Jakub Jelinek <jakub@redhat.com> + + * gcc.c-torture/execute/builtins/string-8.c: New test. + * gcc.c-torture/execute/builtins/string-8-lib.c: New. + * gcc.c-torture/execute/stdio-opt-1.c (main): Add new tests. + * gcc.c-torture/execute/string-opt-7.c (main): Add new test. + 2003-06-27 Mark Mitchell <mark@codesourcery.com> PR c++/10468 diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/string-8-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/string-8-lib.c new file mode 100644 index 0000000..9753c24 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/string-8-lib.c @@ -0,0 +1 @@ +#include "lib/strlen.c" diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/string-8.c b/gcc/testsuite/gcc.c-torture/execute/builtins/string-8.c new file mode 100644 index 0000000..220b6ed --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/string-8.c @@ -0,0 +1,41 @@ +/* Copyright (C) 2003 Free Software Foundation. + + Test strlen optimizations on conditional expressions. + + Written by Jakub Jelinek, June 23, 2003. */ + +typedef __SIZE_TYPE__ size_t; +extern char *strcpy (char *, const char *); +extern int memcmp (const void *, const void *, size_t); +extern void abort (void); +extern void exit (int); +extern int inside_main; + +size_t g, h, i, j, k, l; + +size_t +foo (void) +{ + if (l) + abort (); + return ++l; +} + +void +main_test (void) +{ + if (strlen (i ? "foo" + 1 : j ? "bar" + 1 : "baz" + 1) != 2) + abort (); + if (strlen (g++ ? "foo" : "bar") != 3 || g != 1) + abort (); + if (strlen (h++ ? "xfoo" + 1 : "bar") != 3 || h != 1) + abort (); + if (strlen ((i++, "baz")) != 3 || i != 1) + abort (); + /* The following calls might not optimize strlen call away. */ + inside_main = 0; + if (strlen (j ? "foo" + k++ : "bar" + k++) != 3 || k != 1) + abort (); + if (strlen (foo () ? "foo" : "bar") != 3 || l != 1) + abort (); +} diff --git a/gcc/testsuite/gcc.c-torture/execute/stdio-opt-1.c b/gcc/testsuite/gcc.c-torture/execute/stdio-opt-1.c index fc43c57..8cfb4eb 100644 --- a/gcc/testsuite/gcc.c-torture/execute/stdio-opt-1.c +++ b/gcc/testsuite/gcc.c-torture/execute/stdio-opt-1.c @@ -12,6 +12,8 @@ extern void abort(void); If stdio.h provides one, that is okay. */ extern int fputs(); +int i; + int main() { FILE *s_array[] = {stdout, NULL}, **s_ptr = s_array; @@ -51,6 +53,15 @@ int main() __builtin_fputc ('\n', *s_ptr); __builtin_fwrite ("hello\n", 1, 6, *s_ptr); + /* Check side-effects in conditional expression. */ + s_ptr = s_array; + fputs (i++ ? "f" : "x", *s_ptr++); + if (s_ptr != s_array+1 || *s_ptr != 0 || i != 1) + abort(); + fputs (--i ? "\n" : "\n", *--s_ptr); + if (s_ptr != s_array || i != 0) + abort(); + return 0; } diff --git a/gcc/testsuite/gcc.c-torture/execute/string-opt-7.c b/gcc/testsuite/gcc.c-torture/execute/string-opt-7.c index ed1b2a4..5b915d7 100644 --- a/gcc/testsuite/gcc.c-torture/execute/string-opt-7.c +++ b/gcc/testsuite/gcc.c-torture/execute/string-opt-7.c @@ -12,6 +12,8 @@ extern int strcmp (const char *, const char *); extern int strncmp (const char *, const char *, size_t); extern void *memset (void *, int, size_t); +int i; + int main () { const char *const src = "hello world"; @@ -62,6 +64,12 @@ int main () if (__builtin_strncpy (dst, src, 4) != dst || strncmp (dst, src, 4)) abort(); + memset (dst, 0, sizeof (dst)); + if (strncpy (dst, i++ ? "xfoo" + 1 : "bar", 4) != dst + || strcmp (dst, "bar") + || i != 1) + abort (); + return 0; } |