Debian Codegraph @

gcc/testsuite/gcc.dg/analyzer/write-to-string-literal-3.c

raw
1 typedef __SIZE_TYPE__ size_t;
2
3 void read_only (void *)
4 __attribute__ ((access (read_only, 1)));
5 void write_only (void *) /* { dg-message "parameter 1 of 'write_only' marked with attribute 'access \\(write_only, 1\\)'" } */
6 __attribute__ ((access (write_only, 1)));
7 void read_write (void *) /* { dg-message "parameter 1 of 'read_write' marked with attribute 'access \\(read_write, 1\\)'" } */
8 __attribute__ ((access (read_write, 1)));
9 void none (void *)
10 __attribute__ ((access (none, 1)));
11 void read_only_with_size (void *, size_t)
12 __attribute__ ((access (read_only, 1, 2)));
13 void write_only_with_size (void *, size_t) /* { dg-message "parameter 1 of 'write_only_with_size' marked with attribute 'access \\(write_only, 1, 2\\)'" } */
14 __attribute__ ((access (write_only, 1, 2)));
15 void read_write_with_size (void *, size_t) /* { dg-message "parameter 1 of 'read_write_with_size' marked with attribute 'access \\(read_write, 1, 2\\)'" } */
16 __attribute__ ((access (read_write, 1, 2)));
17 void none_with_size (void *, size_t)
18 __attribute__ ((access (none, 1, 2)));
19
20 void test_read_only (void)
21 {
22 const char *str = "hello world";
23 read_only ((char *)str);
24 }
25
26 void test_write_only (void)
27 {
28 const char *str = "hello world";
29 write_only ((char *)str); /* { dg-warning "write to string literal" } */
30 }
31
32 void test_read_write (void)
33 {
34 const char *str = "hello world";
35 read_write ((char *)str); /* { dg-warning "write to string literal" } */
36 }
37
38 void test_none (void)
39 {
40 const char *str = "hello world";
41 none ((char *)str);
42 }
43
44 void test_read_only_with_size (void)
45 {
46 const char *str = "hello world";
47 read_only_with_size ((char *)str, sizeof (str));
48 }
49
50 void test_write_only_with_size (void)
51 {
52 const char *str = "hello world";
53 write_only_with_size ((char *)str, sizeof (str)); /* { dg-warning "write to string literal" } */
54 }
55
56 void test_read_write_with_size (void)
57 {
58 const char *str = "hello world";
59 read_write_with_size ((char *)str, sizeof (str)); /* { dg-warning "write to string literal" } */
60 }
61
62 void test_none_with_size (void)
63 {
64 const char *str = "hello world";
65 none_with_size ((char *)str, sizeof (str));
66 }