Debian Codegraph @

gcc/testsuite/c-c++-common/analyzer/stdarg-pr111289-int.c

raw
1 #include <stdarg.h>
2 #include <stdint.h>
3
4 typedef unsigned int mode_t;
5
6 extern void openat (int, const char *, int, mode_t);
7
8 /* Signed vs unsigned of same integral type. */
9
10 static void
11 test_1 (char const *name, ...)
12 {
13 va_list arg;
14 va_start (arg, name);
15
16 mode_t mode = va_arg (arg, mode_t); /* { dg-bogus "-Wanalyzer-va-arg-type-mismatch" } */
17
18 va_end (arg);
19 openat (-42, name, 0, mode);
20 }
21
22 void
23 call_test_1 ()
24 {
25 test_1 ("nonexist.ent/", 0600);
26 }
27
28 /* Not the same size: small enough for int promotion. */
29
30 int16_t global_2;
31
32 static void
33 test_2 (char const *name, ...)
34 {
35 va_list arg;
36 va_start (arg, name);
37
38 global_2 = va_arg (arg, int16_t); /* { dg-warning "promoted to 'int'" } */
39
40 va_end (arg);
41 }
42
43 void
44 call_test_2 ()
45 {
46 test_2 ("nonexist.ent/", 42);
47 }
48
49 /* Not the same size: too big for int promotion. */
50
51 long long global_3;
52
53 static void
54 test_3 (char const *name, ...)
55 {
56 va_list arg;
57 va_start (arg, name);
58
59 global_3 = va_arg (arg, long long); /* { dg-warning "'va_arg' expected 'long long int' but received 'int' for variadic argument 1 of 'arg'" } */
60
61 va_end (arg);
62 }
63
64 void
65 call_test_3 ()
66 {
67 test_3 ("nonexist.ent/", 42);
68 }