Skip several analyzer socket tests on hppa*-*-hpux*
[official-gcc.git] / gcc / testsuite / c-c++-common / analyzer / signal-4a.c
blobb5c6012ec2ec853fbc920c891604175edaebad31
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 void test (void)
26 void *ptr = malloc (1024);
27 signal(SIGINT, int_handler);
28 body_of_program();
29 free (ptr);
32 /* "call to 'fprintf' from within signal handler [CWE-479]". */
33 /* { dg-begin-multiline-output "" }
34 NN | fprintf(stderr, "LOG: %s", msg);
35 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
36 'test': events 1-2
38 | NN | void test (void)
39 | | ^~~~
40 | | |
41 | | (1) entry to 'test'
42 |......
43 | NN | signal(SIGINT, int_handler);
44 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
45 | | |
46 | | (2) registering 'int_handler' as signal handler
48 event 3
50 |cc1:
51 | (3): later on, when the signal is delivered to the process
53 +--> 'int_handler': events 4-5
55 | NN | static void int_handler(int signum)
56 | | ^~~~~~~~~~~
57 | | |
58 | | (4) entry to 'int_handler'
59 | NN | {
60 | NN | custom_logger("got signal");
61 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
62 | | |
63 | | (5) calling 'custom_logger' from 'int_handler'
65 +--> 'custom_logger': events 6-7
67 | NN | void custom_logger(const char *msg)
68 | | ^~~~~~~~~~~~~
69 | | |
70 | | (6) entry to 'custom_logger'
71 | NN | {
72 | NN | fprintf(stderr, "LOG: %s", msg);
73 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
74 | | |
75 | | (7) call to 'fprintf' from within signal handler
77 { dg-end-multiline-output "" { target c } } */
78 /* { dg-begin-multiline-output "" }
79 NN | fprintf(stderr, "LOG: %s", msg);
80 | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
81 'void test()': events 1-2
83 | NN | void test (void)
84 | | ^~~~
85 | | |
86 | | (1) entry to 'test'
87 |......
88 | NN | signal(SIGINT, int_handler);
89 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
90 | | |
91 | | (2) registering 'void int_handler(int)' as signal handler
93 event 3
95 |cc1plus:
96 | (3): later on, when the signal is delivered to the process
98 +--> 'void int_handler(int)': events 4-5
100 | NN | static void int_handler(int signum)
101 | | ^~~~~~~~~~~
102 | | |
103 | | (4) entry to 'int_handler'
104 | NN | {
105 | NN | custom_logger("got signal");
106 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
107 | | |
108 | | (5) calling 'custom_logger' from 'int_handler'
110 +--> 'void custom_logger(const char*)': events 6-7
112 | NN | void custom_logger(const char *msg)
113 | | ^~~~~~~~~~~~~
114 | | |
115 | | (6) entry to 'custom_logger'
116 | NN | {
117 | NN | fprintf(stderr, "LOG: %s", msg);
118 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
119 | | |
120 | | (7) call to 'int fprintf(FILE*, const char*, ...)' from within signal handler
122 { dg-end-multiline-output "" { target c++ } } */