aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/analyzer/signal-exit.c
blob: 41a819b838c88bc4432462782c4c2d62b4def77e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/* Example of a bad call within a signal handler with replacement
   alternative.  'handler' calls 'exit', and 'exit' is not allowed
   from a signal handler.  But '_exit' is allowed.  */
/* { dg-require-effective-target signal } */

#include <signal.h>
#include <stdlib.h>

extern void body_of_program(void);

static void handler(int signum)
{
  exit(1); /* { dg-warning "call to 'exit' from within signal handler" "warning" } */
  /* { dg-message "note: '_exit' is a possible signal-safe alternative for 'exit'" "replacement note" { target *-*-* } .-1 } */
}

int main(int argc, const char *argv)
{
  signal(SIGINT, handler); /* { dg-message "registering 'handler' as signal handler" } */

  body_of_program();

  return 0;
}