Debian Codegraph @

gcc/testsuite/gcc.dg/analyzer/pr103892.c

raw
1 /* { dg-additional-options "-O2 -Wno-analyzer-too-complex -Wno-analyzer-symbol-too-complex" } */
2
3 /* C only: C++ FE optimizes argstr_get_word completely away
4 and therefore the number of SN diminishes compared to C,
5 making the analysis bails out early. */
6
7 extern void free (void *__ptr) __attribute__ ((__nothrow__ , __leaf__));
8
9 enum pipecmd_tag
10 {
11 PIPECMD_PROCESS,
12 PIPECMD_SEQUENCE
13 };
14
15 struct pipecmd {
16 enum pipecmd_tag tag;
17 union pipecmd_union_t {
18 struct pipecmd_process {
19 int argc;
20 int argv_max;
21 char **argv;
22 } process;
23 struct pipecmd_sequence {
24 int ncommands;
25 int commands_max;
26 struct pipecmd **commands;
27 } sequence;
28 } u;
29 };
30
31 #ifdef __cplusplus
32 typedef pipecmd::pipecmd_union_t::pipecmd_process pipecmd_process_t;
33 typedef pipecmd::pipecmd_union_t::pipecmd_sequence pipecmd_sequence_t;
34 #else
35 typedef struct pipecmd_process pipecmd_process_t;
36 typedef struct pipecmd_sequence pipecmd_sequence_t;
37 #endif
38
39 static char *argstr_get_word (const char **argstr)
40 {
41 while (**argstr) { /* { dg-warning "infinite loop" } */
42 switch (**argstr) {
43 case ' ':
44 case '\t':
45 return (char *) ((void *) 0);
46 }
47 }
48 return (char *) ((void *) 0);
49 }
50
51 struct pipecmd *pipecmd_new_argstr (const char *argstr)
52 {
53 argstr_get_word (&argstr);
54 return (struct pipecmd *) ((void *) 0);
55 }
56
57 void pipecmd_free (struct pipecmd *cmd)
58 {
59 int i;
60
61 if (!cmd)
62 return;
63
64 switch (cmd->tag) {
65 case PIPECMD_PROCESS: {
66 pipecmd_process_t *cmdp = &cmd->u.process;
67
68 for (i = 0; i < cmdp->argc; ++i)
69 free (cmdp->argv[i]);
70 free (cmdp->argv);
71
72 break;
73 }
74
75 case PIPECMD_SEQUENCE: {
76 pipecmd_sequence_t *cmds = &cmd->u.sequence;
77
78 for (i = 0; i < cmds->ncommands; ++i)
79 pipecmd_free (cmds->commands[i]);
80 free (cmds->commands);
81
82 break;
83 }
84 }
85
86 free (cmd);
87 }