OSDN Git Service

* gcc.c-torture/execute/20040208-2.c: Move ...
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.c-torture / execute / string-opt-15.c
1 /* Copyright (C) 2001  Free Software Foundation.
2
3    Ensure that short builtin memcmp are optimized and perform correctly.
4    On architectures with a cmpstrsi instruction, this test doesn't determine
5    which optimization is being performed, but it does check for correctness.
6
7    Written by Roger Sayle, 12/02/2001.  */
8
9 extern void abort (void);
10 typedef __SIZE_TYPE__ size_t;
11 extern int memcmp (const void *, const void *, size_t);
12 extern char *strcpy (char *, const char *);
13
14 int
15 main ()
16 {
17   char str[8];
18
19   strcpy (str, "3141");
20
21   if ( memcmp (str, str+2, 0) != 0 )
22     abort ();
23   if ( memcmp (str+1, str+3, 0) != 0 )
24     abort ();
25
26   if ( memcmp (str+1, str+3, 1) != 0 )
27     abort ();
28   if ( memcmp (str, str+2, 1) >= 0 )
29     abort ();
30   if ( memcmp (str+2, str, 1) <= 0 )
31     abort ();
32
33   return 0;
34 }
35
36 #ifdef __OPTIMIZE__
37 /* When optimizing, all the above cases should be transformed into
38    something else.  So any remaining calls to the original function
39    should abort.  */
40 __attribute__ ((noinline))
41 static int
42 memcmp (const void *p1, const void *p2, size_t len)
43 {
44   abort ();
45 }
46 #endif
47