summaryrefslogtreecommitdiff
path: root/support/regression/tests/gcc-torture-execute-string-opt-17.c
blob: 71ad0b44987303764cd0f40fe3caef666bf63a25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
   string-opt-17.c from the execute part of the gcc torture tests.
 */

#include <testfwk.h>

#ifdef __SDCC
#pragma std_c99
#endif

/* Copyright (C) 2003  Free Software Foundation.

   Test strcpy optimizations don't evaluate side-effects twice.
      
   Written by Jakub Jelinek, June 23, 2003.  */

#include <string.h>

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)
    ASSERT (0);
  return ++r;
}

void
test2 (char *s)
{
  strcpy (s, "foobarbaz" + check2 ());
}

void
testTortureExecute (void)
{
  char buf[10];
  if (test1 (buf, 7) != 8 || memcmp (buf, "az", 3))
    ASSERT (0);
  test2 (buf);
  if (memcmp (buf, "baz", 4))
    ASSERT (0);
  return;
}