blob: d6e2b4954c202d795948a8f391aad7e11e146d00 (
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
|
#include <setjmp.h>
#include <time.h>
/* just try trick the compiler into not optimizing stuff by
making it "uncertain" which path to take. */
int always_true(void)
{
time_t t = time(NULL);
if (t == time(NULL))
return 1;
if (t != time(NULL))
return 1;
if (t == time(NULL))
return 1;
if (t != time(NULL))
return 1;
return 0;
}
jmp_buf g_JmpBuf;
int onelevel(void)
{
if (always_true())
longjmp(g_JmpBuf, 1);
return 0;
}
int twolevels_inner(void)
{
if (always_true())
longjmp(g_JmpBuf, 1);
return 0;
}
int twolevels_outer(void)
{
int rc;
always_true();
rc = twolevels_inner();
always_true();
return rc;
}
int main()
{
int rc = 1;
/* first */
if (!setjmp(g_JmpBuf))
rc = onelevel();
/* second */
if (!setjmp(g_JmpBuf))
rc = twolevels_outer();
return rc != 1;
}
|