aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/analyzer/setjmp-9.c
blob: c2b00e3b95c5bb1a70f73a11776da2d22cb94add (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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* { dg-additional-options "-fdiagnostics-show-line-numbers -fdiagnostics-path-format=inline-events -fdiagnostics-show-caret" } */
/* { dg-enable-nn-line-numbers "" } */
/* { dg-require-effective-target indirect_jumps } */

#include "test-setjmp.h"
#include <stddef.h>
#include "analyzer-decls.h"

extern int foo (int) __attribute__ ((__pure__));

static jmp_buf env;

extern int unknown_val;

static void inner (void)
{
  /* Pass value that might be 0 to longjmp. */
  longjmp (env, unknown_val);
}

void outer (void)
{
  int i;

  foo (0);

  i = SETJMP(env);

  if (i != 0)
    {
      foo (2);
      __analyzer_dump_path (); /* { dg-message "path" } */
    }
  else
    {
      foo (1);
      inner ();
    }
  foo (3);
}

/* { dg-begin-multiline-output "" }
   NN |       __analyzer_dump_path ();
      |       ^~~~~~~~~~~~~~~~~~~~~~~
  'outer': event 1
    |
    |   NN | void outer (void)
    |      |      ^~~~~
    |      |      |
    |      |      (1) entry to 'outer'
    |
  'outer': event 2
    |
    |   NN |   i = SETJMP(env);
    |      |       ^~~~~~
    |      |       |
    |      |       (2) 'setjmp' called here
    |
  'outer': events 3-5
    |
    |   NN |   if (i != 0)
    |      |      ^
    |      |      |
    |      |      (3) following 'false' branch (when 'i == 0')...
    |......
    |   NN |       foo (1);
    |      |       ~~~~~~~
    |      |       |
    |      |       (4) ...to here
    |   NN |       inner ();
    |      |       ~~~~~~~~
    |      |       |
    |      |       (5) calling 'inner' from 'outer'
    |
    +--> 'inner': events 6-7
           |
           |   NN | static void inner (void)
           |      |             ^~~~~
           |      |             |
           |      |             (6) entry to 'inner'
           |......
           |   NN |   longjmp (env, unknown_val);
           |      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~
           |      |   |
           |      |   (7) rewinding from 'longjmp' in 'inner'...
           |
    <------+
    |
  'outer': event 8
    |
    |   NN |   i = SETJMP(env);
    |      |       ^~~~~~
    |      |       |
    |      |       (8) ...to 'setjmp' in 'outer' (saved at (2))
    |
  'outer': events 9-11
    |
    |   NN |   if (i != 0)
    |      |      ^
    |      |      |
    |      |      (9) following 'true' branch (when 'i != 0')...
    |   NN |     {
    |   NN |       foo (2);
    |      |       ~~~~~~~
    |      |       |
    |      |       (10) ...to here
    |   NN |       __analyzer_dump_path ();
    |      |       ~~~~~~~~~~~~~~~~~~~~~~~
    |      |       |
    |      |       (11) here
    |
    { dg-end-multiline-output "" } */