OSDN Git Service

* mklibgcc.in: Don't use \n in a line subject to
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.c-torture / execute / string-opt-12.c
1 /* Copyright (C) 2000  Free Software Foundation.
2
3    Ensure all expected transformations of builtin strcspn occur and
4    perform correctly.
5
6    Written by Kaveh R. Ghazi, 11/27/2000.  */
7
8 extern void abort (void);
9 typedef __SIZE_TYPE__ size_t;
10 extern size_t strcspn (const char *, const char *);
11 extern char *strcpy (char *, const char *);
12
13 int main ()
14 {
15   const char *const s1 = "hello world";
16   char dst[64], *d2;
17   
18   if (strcspn (s1, "hello") != 0)
19     abort();
20   if (strcspn (s1, "z") != 11)
21     abort();
22   if (strcspn (s1+4, "z") != 7)
23     abort();
24   if (strcspn (s1, "hello world") != 0)
25     abort();
26   if (strcspn (s1, "") != 11)
27     abort();
28   strcpy (dst, s1);
29   if (strcspn (dst, "") != 11)
30     abort();
31   strcpy (dst, s1); d2 = dst;
32   if (strcspn (++d2, "") != 10 || d2 != dst+1)
33     abort();
34   strcpy (dst, s1); d2 = dst;
35   if (strcspn (++d2+5, "") != 5 || d2 != dst+1)
36     abort();
37   if (strcspn ("", s1) != 0)
38     abort();
39   strcpy (dst, s1);
40   if (strcspn ("", dst) != 0)
41     abort();
42   strcpy (dst, s1); d2 = dst;
43   if (strcspn ("", ++d2) != 0 || d2 != dst+1)
44     abort();
45   strcpy (dst, s1); d2 = dst;
46   if (strcspn ("", ++d2+5) != 0 || d2 != dst+1)
47     abort();
48
49   /* Test at least one instance of the __builtin_ style.  We do this
50      to ensure that it works and that the prototype is correct.  */
51   if (__builtin_strcspn (s1, "z") != 11)
52     abort();
53
54   return 0;
55 }
56
57 #ifdef __OPTIMIZE__
58 /* When optimizing, all the above cases should be transformed into
59    something else.  So any remaining calls to the original function
60    should abort.  */
61 static size_t
62 strcspn (const char *s1, const char *s2)
63 {
64   abort();
65 }
66 #endif