Debian Codegraph @

doc/SystemTap_Beginners_Guide/testsuite/systemtap.base/optim_voidstmt.stp

raw
1 /*
2 * optim_voidstmt.stp
3 *
4 * Verify statement optimizations in void contexts.
5 */
6
7 /* The printfs here force it not to be pure. */
8 function goodL() { printf(""); return 1 }
9 function goodS() { printf(""); return "1" }
10
11 /* These two functions lie about being pure, so they should be optimized out.
12 * If they get called, you get an error, and the test fails.
13 */
14 function badL:long() %{ /* pure */ CONTEXT->last_error = "NOSEE"; %}
15 function badS:string() %{ /* pure */ CONTEXT->last_error = "NOSEE"; %}
16
17 function fn1(x) { return x }
18 function fn2(x, y) { return x * y }
19
20 probe begin {
21 println("systemtap starting probe")
22 }
23
24 probe end {
25 println("systemtap ending probe")
26
27 // most of these wouldn't have been optimized before, because part of the
28 // expression has an apparant side-effect in the good* calls
29
30 // unary numeric operators
31 (+(goodL() + badL()))
32 (-(goodL() + badL()))
33 (!(goodL() + badL()))
34 (~(goodL() + badL()))
35
36 // binary numeric operators
37 goodL() * badL()
38 goodL() / badL()
39 goodL() % badL()
40 goodL() + badL()
41 goodL() - badL()
42 goodL() >> badL()
43 goodL() << badL()
44 goodL() & badL()
45 goodL() ^ badL()
46 goodL() | badL()
47 goodL() < badL()
48 goodL() > badL()
49 goodL() <= badL()
50 goodL() >= badL()
51 goodL() == badL()
52 goodL() != badL()
53
54 // logical operators
55 goodL() && badL()
56 badL() && badL()
57 goodL() || badL()
58 badL() || badL()
59
60 // ternary operator
61 goodL() ? badL() : goodL()
62 goodL() ? goodL() : badL()
63 badL() ? badL() : badL()
64
65 // binary string operators
66 goodS() . badS()
67 goodS() < badS()
68 goodS() > badS()
69 goodS() <= badS()
70 goodS() >= badS()
71 goodS() == badS()
72 goodS() != badS()
73
74 // string-printing
75 sprintf("%d\n", goodL() + badL())
76 sprintf("%d %d %s %s\n", goodL(), badL(), goodS(), badS())
77
78 // function calls
79 fn1(badL() + goodL())
80 fn2(badL(), goodL())
81
82 // something complex, but harmless enough that only
83 // the good* calls should survive
84 fn1(fn2(goodL() - strlen(badL() + badL() * badL() / strlen(goodS()) ?
85 badS() . badS() . sprint(badL())
86 : sprint(badL(), badS())),
87 badL() < badL() || badS() == badS()) +
88 goodL() % strlen(goodS()))
89
90 println("systemtap test success")
91 }
92
93 probe never {
94 print(goodL(), badL(), goodS(), badS(), fn1(1), fn2(1, 1))
95 }