mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-01-11 20:15:29 +08:00
builtins.c (expand_builtin_strcpy): Don't evaluate side-effects in src twice.
* builtins.c (expand_builtin_strcpy): Don't evaluate side-effects in src twice. * gcc.c-torture/execute/string-opt-17.c: New test. From-SVN: r68431
This commit is contained in:
parent
6d1cb95f3f
commit
946137a0d6
@ -1,3 +1,8 @@
|
||||
2003-06-24 Jakub Jelinek <jakub@redhat.com>
|
||||
|
||||
* builtins.c (expand_builtin_strcpy): Don't evaluate side-effects in
|
||||
src twice.
|
||||
|
||||
2003-06-24 J"orn Rennecke <joern.rennecke@superh.com>
|
||||
|
||||
Back out these patches:
|
||||
|
@ -2788,7 +2788,7 @@ expand_builtin_strcpy (tree arglist, rtx target, enum machine_mode mode)
|
||||
|
||||
src = TREE_VALUE (TREE_CHAIN (arglist));
|
||||
len = c_strlen (src);
|
||||
if (len == 0)
|
||||
if (len == 0 || TREE_SIDE_EFFECTS (len))
|
||||
return 0;
|
||||
|
||||
dst = TREE_VALUE (arglist);
|
||||
|
@ -1,3 +1,7 @@
|
||||
2003-06-24 Jakub Jelinek <jakub@redhat.com>
|
||||
|
||||
* gcc.c-torture/execute/string-opt-17.c: New test.
|
||||
|
||||
2003-06-24 Mark Mitchell <mark@codesourcery.com>
|
||||
|
||||
PR c++/5754
|
||||
|
45
gcc/testsuite/gcc.c-torture/execute/string-opt-17.c
Normal file
45
gcc/testsuite/gcc.c-torture/execute/string-opt-17.c
Normal file
@ -0,0 +1,45 @@
|
||||
/* Copyright (C) 2003 Free Software Foundation.
|
||||
|
||||
Test strcpy optimizations don't evaluate side-effects twice.
|
||||
|
||||
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);
|
||||
|
||||
size_t
|
||||
test1 (char *s, size_t i)
|
||||
{
|
||||
strcpy (s, "foobarbaz" + i++);
|
||||
return i;
|
||||
}
|
||||
|
||||
size_t
|
||||
check2 (void)
|
||||
{
|
||||
static size_t r = 5;
|
||||
if (r != 5)
|
||||
abort ();
|
||||
return ++r;
|
||||
}
|
||||
|
||||
void
|
||||
test2 (char *s)
|
||||
{
|
||||
strcpy (s, "foobarbaz" + check2 ());
|
||||
}
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
char buf[10];
|
||||
if (test1 (buf, 7) != 8 || memcmp (buf, "az", 3))
|
||||
abort ();
|
||||
test2 (buf);
|
||||
if (memcmp (buf, "baz", 4))
|
||||
abort ();
|
||||
exit (0);
|
||||
}
|
Loading…
Reference in New Issue
Block a user