mips.h (ISA_HAS_DSP, [...]): New macros.
[official-gcc.git] / gcc / testsuite / gcc.dg / va-arg-pack-len-1.c
blob7df638006882741fb04413b3fbe599a12e9a1e39
1 /* { dg-do run } */
2 /* { dg-options "-O2" } */
4 #include <stdarg.h>
6 extern int warn_open_missing_mode (void);
7 extern int warn_open_too_many_arguments (void);
8 extern void abort (void);
10 char expected_char;
12 __attribute__((noinline)) int
13 myopen2 (const char *path, int oflag)
15 if (expected_char++ != path[0] || path[1] != '\0')
16 abort ();
17 switch (path[0])
19 case 'f':
20 if (oflag != 0x2)
21 abort ();
22 break;
23 case 'g':
24 if (oflag != 0x43)
25 abort ();
26 /* In real __open_2 this would terminate the program:
27 open with O_CREAT without third argument. */
28 return -6;
29 default:
30 abort ();
32 return 0;
35 __attribute__((noinline)) int
36 myopenva (const char *path, int oflag, ...)
38 int mode = 0;
39 va_list ap;
40 if ((oflag & 0x40) != 0)
42 va_start (ap, oflag);
43 mode = va_arg (ap, int);
44 va_end (ap);
46 if (expected_char++ != path[0] || path[1] != '\0')
47 abort ();
48 switch (path[0])
50 case 'a':
51 if (oflag != 0x43 || mode != 0644)
52 abort ();
53 break;
54 case 'b':
55 if (oflag != 0x3)
56 abort ();
57 break;
58 case 'c':
59 if (oflag != 0x2)
60 abort ();
61 break;
62 case 'd':
63 if (oflag != 0x43 || mode != 0600)
64 abort ();
65 break;
66 case 'e':
67 if (oflag != 0x3)
68 abort ();
69 break;
70 default:
71 abort ();
73 return 0;
76 extern inline __attribute__((always_inline, gnu_inline)) int
77 myopen (const char *path, int oflag, ...)
79 if (__builtin_va_arg_pack_len () > 1)
80 warn_open_too_many_arguments ();
82 if (__builtin_constant_p (oflag))
84 if ((oflag & 0x40) != 0 && __builtin_va_arg_pack_len () < 1)
86 warn_open_missing_mode ();
87 return myopen2 (path, oflag);
89 return myopenva (path, oflag, __builtin_va_arg_pack ());
92 if (__builtin_va_arg_pack_len () < 1)
93 return myopen2 (path, oflag);
95 return myopenva (path, oflag, __builtin_va_arg_pack ());
98 volatile int l0;
101 main (void)
103 expected_char = 'a';
104 if (myopen ("a", 0x43, 0644))
105 abort ();
106 if (myopen ("b", 0x3, 0755))
107 abort ();
108 if (myopen ("c", 0x2))
109 abort ();
110 if (myopen ("d", l0 + 0x43, 0600))
111 abort ();
112 if (myopen ("e", l0 + 0x3, 0700))
113 abort ();
114 if (myopen ("f", l0 + 0x2))
115 abort ();
116 /* Invalid use of myopen, but only detectable at runtime. */
117 if (myopen ("g", l0 + 0x43) != -6)
118 abort ();
119 return 0;