Debian Codegraph @

gcc/testsuite/c-c++-common/analyzer/write-to-string-literal-5.c

raw
1 /* Verify that deduplication of -Wanalyzer-write-to-string-literal (and their
2 notes) works. */
3
4 /* { dg-additional-options "-fanalyzer-show-duplicate-count" } */
5
6 #include "../../gcc.dg/analyzer/analyzer-decls.h"
7
8 typedef __SIZE_TYPE__ size_t;
9
10 int getrandom (void *__buffer, size_t __length,
11 /* { dg-message "parameter 1 of 'getrandom' marked with attribute 'access \\(write_only, 1, 2\\)'" "" { target c } .-1 } */
12 /* { dg-message "parameter 1 of 'int getrandom\\(void\\*, size_t, unsigned int\\)' marked with attribute 'access \\(write_only, 1, 2\\)'" "" { target c++ } .-2 } */
13 unsigned int __flags)
14 __attribute__ ((access (__write_only__, 1, 2)));
15
16 #define GRND_RANDOM 0x02
17
18 void *test (int flag)
19 {
20 char *ptr;
21 if (flag)
22 ptr = (char *) __builtin_malloc (1024);
23 else
24 ptr = (char *) __builtin_alloca (1024);
25
26 __analyzer_dump_exploded_nodes (0); /* { dg-warning "2 processed enodes" } */
27
28 if (getrandom((char *)"foo", 3, GRND_RANDOM)) /* { dg-warning "write to string literal" "warning" } */
29 /* { dg-message "1 duplicate" "dup" { target *-*-* } .-1 } */
30 __builtin_printf("ok\n");
31
32 return ptr;
33 }