2 // { dg-options "-O2" }
6 extern "C" int warn_open_missing_mode (void);
7 extern "C" int warn_open_too_many_arguments (void);
8 extern "C" void abort (void);
12 __attribute__((noinline)) int
13 myopen2 (const char *path, int oflag)
15 if (expected_char++ != path[0] || path[1] != '\0')
26 // In real __open_2 this would terminate the program:
27 // open with O_CREAT without third argument.
35 __attribute__((noinline)) int
36 myopenva (const char *path, int oflag, ...)
40 if ((oflag & 0x40) != 0)
43 mode = va_arg (ap, int);
46 if (expected_char++ != path[0] || path[1] != '\0')
51 if (oflag != 0x43 || mode != 0644)
63 if (oflag != 0x43 || mode != 0600)
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 ());
104 if (myopen ("a", 0x43, 0644))
106 if (myopen ("b", 0x3, 0755))
108 if (myopen ("c", 0x2))
110 if (myopen ("d", l0 + 0x43, 0600))
112 if (myopen ("e", l0 + 0x3, 0700))
114 if (myopen ("f", l0 + 0x2))
116 // Invalid use of myopen, but only detectable at runtime.
117 if (myopen ("g", l0 + 0x43) != -6)