testsuite: Skip analyzer tests on AIX.
[official-gcc.git] / gcc / testsuite / c-c++-common / analyzer / signal-4b.c
blobd2b5db7b2760ef5db69bf2ca1e69ac637d2b9240
1 /* Verify how paths are printed for signal-handler diagnostics. */
3 /* { dg-options "-fanalyzer -fdiagnostics-show-line-numbers -fdiagnostics-path-format=inline-events -fdiagnostics-show-caret" } */
4 /* { dg-enable-nn-line-numbers "" } */
5 /* { dg-require-effective-target signal } */
7 #include <stdio.h>
8 #include <signal.h>
9 #include <stdlib.h>
11 extern void body_of_program(void);
13 void custom_logger(const char *msg)
15 fprintf(stderr, "LOG: %s", msg); /* { dg-warning "call to 'fprintf' from within signal handler" "" { target c } } */
16 /* { dg-warning "call to 'int fprintf\\(FILE\\*, const char\\*, ...\\)' from within signal handler" "" { target c++ } .-1 } */
19 static void int_handler(int signum)
21 custom_logger("got signal");
24 static void __analyzer_register_handler ()
26 signal(SIGINT, int_handler);
29 void test (void)
31 __analyzer_register_handler ();
32 body_of_program();
35 /* "call to 'fprintf' from within signal handler [CWE-479]". */
36 /* { dg-begin-multiline-output "" }
37 NN | fprintf(stderr, "LOG: %s", msg);
38 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
39 'test': events 1-2
41 | NN | void test (void)
42 | | ^~~~
43 | | |
44 | | (1) entry to 'test'
45 | NN | {
46 | NN | __analyzer_register_handler ();
47 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
48 | | |
49 | | (2) calling '__analyzer_register_handler' from 'test'
51 +--> '__analyzer_register_handler': events 3-4
53 | NN | static void __analyzer_register_handler ()
54 | | ^~~~~~~~~~~~~~~~~~~~~~~~~~~
55 | | |
56 | | (3) entry to '__analyzer_register_handler'
57 | NN | {
58 | NN | signal(SIGINT, int_handler);
59 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
60 | | |
61 | | (4) registering 'int_handler' as signal handler
63 event 5
65 |cc1:
66 | (5): later on, when the signal is delivered to the process
68 +--> 'int_handler': events 6-7
70 | NN | static void int_handler(int signum)
71 | | ^~~~~~~~~~~
72 | | |
73 | | (6) entry to 'int_handler'
74 | NN | {
75 | NN | custom_logger("got signal");
76 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
77 | | |
78 | | (7) calling 'custom_logger' from 'int_handler'
80 +--> 'custom_logger': events 8-9
82 | NN | void custom_logger(const char *msg)
83 | | ^~~~~~~~~~~~~
84 | | |
85 | | (8) entry to 'custom_logger'
86 | NN | {
87 | NN | fprintf(stderr, "LOG: %s", msg);
88 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
89 | | |
90 | | (9) call to 'fprintf' from within signal handler
92 { dg-end-multiline-output "" { target c } } */
93 /* { dg-begin-multiline-output "" }
94 NN | fprintf(stderr, "LOG: %s", msg);
95 | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
96 'void test()': events 1-2
98 | NN | void test (void)
99 | | ^~~~
100 | | |
101 | | (1) entry to 'test'
102 | NN | {
103 | NN | __analyzer_register_handler ();
104 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
105 | | |
106 | | (2) calling '__analyzer_register_handler' from 'test'
108 +--> 'void __analyzer_register_handler()': events 3-4
110 | NN | static void __analyzer_register_handler ()
111 | | ^~~~~~~~~~~~~~~~~~~~~~~~~~~
112 | | |
113 | | (3) entry to '__analyzer_register_handler'
114 | NN | {
115 | NN | signal(SIGINT, int_handler);
116 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
117 | | |
118 | | (4) registering 'void int_handler(int)' as signal handler
120 event 5
122 |cc1plus:
123 | (5): later on, when the signal is delivered to the process
125 +--> 'void int_handler(int)': events 6-7
127 | NN | static void int_handler(int signum)
128 | | ^~~~~~~~~~~
129 | | |
130 | | (6) entry to 'int_handler'
131 | NN | {
132 | NN | custom_logger("got signal");
133 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
134 | | |
135 | | (7) calling 'custom_logger' from 'int_handler'
137 +--> 'void custom_logger(const char*)': events 8-9
139 | NN | void custom_logger(const char *msg)
140 | | ^~~~~~~~~~~~~
141 | | |
142 | | (8) entry to 'custom_logger'
143 | NN | {
144 | NN | fprintf(stderr, "LOG: %s", msg);
145 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
146 | | |
147 | | (9) call to 'int fprintf(FILE*, const char*, ...)' from within signal handler
149 { dg-end-multiline-output "" { target c++ } } */