forked from facebook/hermes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
load_store_capture_vars.js
153 lines (142 loc) · 4.56 KB
/
load_store_capture_vars.js
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// RUN: %hermes -hermes-parser -dump-ir %s -O -fno-inline | %FileCheck %s --match-full-lines
//CHECK-LABEL:function store_x_not_captured() : number
//CHECK-NEXT:frame = [y : number]
//CHECK-NEXT:%BB0:
//CHECK-NEXT: %0 = StoreFrameInst 3 : number, [y] : number
//CHECK-NEXT: %1 = CreateFunctionInst %foo() : undefined
//CHECK-NEXT: %2 = CallInst %1 : closure, undefined : undefined
//CHECK-NEXT: %3 = ReturnInst 9 : number
//CHECK-NEXT:function_end
function store_x_not_captured() {
var y = 3;
var x = 4;
var k = function foo() { y = 12; }
k();
x = 9;
return x;
}
//CHECK-LABEL:function store_x_is_captured() : number
//CHECK-NEXT:frame = [y : number, x : number]
//CHECK-NEXT:%BB0:
//CHECK-NEXT: %0 = StoreFrameInst 3 : number, [y] : number
//CHECK-NEXT: %1 = StoreFrameInst 4 : number, [x] : number
//CHECK-NEXT: %2 = CreateFunctionInst %"foo 1#"() : undefined
//CHECK-NEXT: %3 = CallInst %2 : closure, undefined : undefined
//CHECK-NEXT: %4 = StoreFrameInst 9 : number, [x] : number
//CHECK-NEXT: %5 = ReturnInst 9 : number
//CHECK-NEXT:function_end
function store_x_is_captured() {
var y = 3;
var x = 4;
var k = function foo() { y = x; }
k();
x = 9;
return x;
}
//CHECK-LABEL:function load_x_not_captured() : number
//CHECK-NEXT:frame = [y : number]
//CHECK-NEXT:%BB0:
//CHECK-NEXT: %0 = StoreFrameInst 3 : number, [y] : number
//CHECK-NEXT: %1 = CreateFunctionInst %"foo 2#"() : undefined
//CHECK-NEXT: %2 = CallInst %1 : closure, undefined : undefined
//CHECK-NEXT: %3 = ReturnInst 4 : number
//CHECK-NEXT:function_end
function load_x_not_captured() {
var y = 3;
var x = 4;
var k = function foo() { y = 12; }
k();
return x;
}
//CHECK-LABEL:function load_x_is_captured() : number
//CHECK-NEXT:frame = [x : number]
//CHECK-NEXT:%BB0:
//CHECK-NEXT: %0 = StoreFrameInst 4 : number, [x] : number
//CHECK-NEXT: %1 = CreateFunctionInst %"foo 3#"() : undefined
//CHECK-NEXT: %2 = CallInst %1 : closure, undefined : undefined
//CHECK-NEXT: %3 = LoadFrameInst [x] : number
//CHECK-NEXT: %4 = ReturnInst %3 : number
//CHECK-NEXT:function_end
function load_x_is_captured() {
var y = 3;
var x = 4;
var k = function foo() { x = 12; }
k();
return x;
}
//CHECK-LABEL:function load_x_captured_as_load() : number
//CHECK-NEXT:frame = []
//CHECK-NEXT:%BB0:
//CHECK-NEXT: %0 = CreateFunctionInst %"foo 4#"() : undefined
//CHECK-NEXT: %1 = CallInst %0 : closure, undefined : undefined
//CHECK-NEXT: %2 = ReturnInst 4 : number
//CHECK-NEXT:function_end
function load_x_captured_as_load() {
var y = 3;
var x = 4;
var k = function foo() { print(x); }
k();
return x;
}
function abort() {
throw 42;
}
//CHECK-LABEL:function "foo 5#"(x)
//CHECK-NEXT:frame = []
//CHECK-NEXT:%BB0:
//CHECK-NEXT: %0 = AllocStackInst $a
//CHECK-NEXT: %1 = StoreStackInst %x, %0
//CHECK-NEXT: %2 = TryStartInst %BB1, %BB2
//CHECK-NEXT:%BB1:
//CHECK-NEXT: %3 = CatchInst
//CHECK-NEXT: %4 = LoadStackInst %0
//CHECK-NEXT: %5 = BinaryOperatorInst '+', %4, 100 : number
//CHECK-NEXT: %6 = StoreStackInst %5 : string|number, %0
//CHECK-NEXT: %7 = BranchInst %BB3
//CHECK-NEXT:%BB3:
//CHECK-NEXT: %8 = LoadStackInst %0
//CHECK-NEXT: %9 = ReturnInst %8
//CHECK-NEXT:%BB2:
//CHECK-NEXT: %10 = LoadStackInst %0
//CHECK-NEXT: %11 = BinaryOperatorInst '+', %10, 1 : number
//CHECK-NEXT: %12 = StoreStackInst %11 : string|number, %0
//CHECK-NEXT: %13 = LoadPropertyInst globalObject : object, "abort" : string
//CHECK-NEXT: %14 = CallInst %13, undefined : undefined
//CHECK-NEXT: %15 = BinaryOperatorInst '+', %11 : string|number, 2 : number
//CHECK-NEXT: %16 = StoreStackInst %15 : string|number, %0
//CHECK-NEXT: %17 = BranchInst %BB4
//CHECK-NEXT:%BB4:
//CHECK-NEXT: %18 = TryEndInst
//CHECK-NEXT: %19 = BranchInst %BB3
//CHECK-NEXT:function_end
function foo(x) {
var a = x;
try {
a += 1;
abort();
a += 2;
} catch (e) {
a += 100;
}
return a;
}
//CHECK-LABEL:function postponed_store_in_use_block(x) : undefined
//CHECK-NEXT: frame = [x]
//CHECK-NEXT: %BB0:
//CHECK-NEXT: %0 = StoreFrameInst %x, [x]
//CHECK-NEXT: %1 = CreateFunctionInst %""()
//CHECK-NEXT: %2 = BinaryOperatorInst '+', 0 : number, %1 : closure
//CHECK-NEXT: %3 = ReturnInst undefined : undefined
//CHECK-NEXT: function_end
function postponed_store_in_use_block(x) {
switch (0) {
// This caused a crash because StackPromotion inserted an invalid load.
case 0: 0 + function() { return x; }
}
}