@@ -45,7 +45,7 @@ def test_swift_move_function(self):
45
45
self .process = self .target .LaunchSimple (None , None , os .getcwd ())
46
46
threads = lldbutil .get_threads_stopped_at_breakpoint (
47
47
self .process , self .breakpoints [0 ])
48
- self .assertTrue (len (threads ) == 1 )
48
+ self .assertEqual (len (threads ), 1 )
49
49
self .thread = threads [0 ]
50
50
51
51
self .do_check_copyable_value_test ()
@@ -55,6 +55,10 @@ def test_swift_move_function(self):
55
55
# ccf is conditional control flow
56
56
self .do_check_copyable_value_ccf_true ()
57
57
self .do_check_copyable_value_ccf_false ()
58
+ self .do_check_copyable_var_ccf_true_reinit_out_block ()
59
+ self .do_check_copyable_var_ccf_true_reinit_in_block ()
60
+ self .do_check_copyable_var_ccf_false_reinit_out_block ()
61
+ self .do_check_copyable_var_ccf_false_reinit_in_block ()
58
62
59
63
def setUp (self ):
60
64
TestBase .setUp (self )
@@ -68,9 +72,14 @@ def add_breakpoints(self, name, num_breakpoints):
68
72
pat = pattern .format (name , i + 1 )
69
73
brk = self .target .BreakpointCreateBySourceRegex (
70
74
pat , self .main_source_spec )
71
- self .assertTrue (brk .GetNumLocations () > 0 , VALID_BREAKPOINT )
75
+ self .assertGreater (brk .GetNumLocations (), 0 , VALID_BREAKPOINT )
72
76
yield brk
73
77
78
+ def get_var (self , name ):
79
+ frame = self .thread .frames [0 ]
80
+ self .assertTrue (frame .IsValid (), "Couldn't get a frame." )
81
+ return frame .FindVariable (name )
82
+
74
83
def do_setup_breakpoints (self ):
75
84
self .breakpoints = []
76
85
@@ -88,126 +97,255 @@ def do_setup_breakpoints(self):
88
97
self .breakpoints .extend (
89
98
self .add_breakpoints ('copyableValueCCFFalseTest' ,
90
99
3 ))
100
+ self .breakpoints .extend (
101
+ self .add_breakpoints ('copyableVarTestCCFlowTrueReinitOutOfBlockTest' ,
102
+ 5 ))
103
+ self .breakpoints .extend (
104
+ self .add_breakpoints ('copyableVarTestCCFlowTrueReinitInBlockTest' ,
105
+ 5 ))
106
+ self .breakpoints .extend (
107
+ self .add_breakpoints ('copyableVarTestCCFlowFalseReinitOutOfBlockTest' ,
108
+ 4 ))
109
+ self .breakpoints .extend (
110
+ self .add_breakpoints ('copyableVarTestCCFlowFalseReinitInBlockTest' , 3 ))
91
111
92
112
def do_check_copyable_value_test (self ):
93
- frame = self .thread .frames [0 ]
94
- self .assertTrue (frame .IsValid (), "Couldn't get a frame." )
95
-
96
113
# We haven't defined varK yet.
97
- varK = frame . FindVariable ('k' )
114
+ varK = self . get_var ('k' )
98
115
99
- self .assertTrue (varK .value == None , "varK initialized too early?!" )
116
+ self .assertIsNone (varK .value , "varK initialized too early?!" )
100
117
101
118
# Go to break point 2. k should be valid.
102
119
self .runCmd ('continue' )
103
- self .assertTrue (varK .unsigned > 0 , "varK not initialized?!" )
120
+ self .assertGreater (varK .unsigned , 0 , "varK not initialized?!" )
104
121
105
122
# Go to breakpoint 3. k should no longer be valid.
106
123
self .runCmd ('continue' )
107
- self .assertTrue (varK .value == None , "K is live but was moved?!" )
124
+ self .assertIsNone (varK .value , "K is live but was moved?!" )
108
125
109
126
# Run so we hit the next breakpoint to jump to the next test's
110
127
# breakpoint.
111
128
self .runCmd ('continue' )
112
129
113
130
def do_check_copyable_var_test (self ):
114
- frame = self .thread .frames [0 ]
115
- self .assertTrue (frame .IsValid (), "Couldn't get a frame." )
116
-
117
131
# We haven't defined varK yet.
118
- varK = frame . FindVariable ('k' )
119
- self .assertTrue (varK .value == None , "varK initialized too early?!" )
132
+ varK = self . get_var ('k' )
133
+ self .assertIsNone (varK .value , "varK initialized too early?!" )
120
134
121
135
# Go to break point 2. k should be valid.
122
136
self .runCmd ('continue' )
123
- self .assertTrue (varK .unsigned > 0 , "varK not initialized?!" )
137
+ self .assertGreater (varK .unsigned , 0 , "varK not initialized?!" )
124
138
125
139
# Go to breakpoint 3. We invalidated k
126
140
self .runCmd ('continue' )
127
- self .assertTrue (varK .value == None , "K is live but was moved?!" )
141
+ self .assertIsNone (varK .value , "K is live but was moved?!" )
128
142
129
143
# Go to the last breakpoint and make sure that k is reinitialized
130
144
# properly.
131
145
self .runCmd ('continue' )
132
- self .assertTrue (varK .unsigned > 0 , "varK not initialized" )
146
+ self .assertGreater (varK .unsigned , 0 , "varK not initialized" )
133
147
134
148
# Run so we hit the next breakpoint to go to the next test.
135
149
self .runCmd ('continue' )
136
150
137
151
def do_check_addressonly_value_test (self ):
138
- frame = self .thread .frames [0 ]
139
- self .assertTrue (frame .IsValid (), "Couldn't get a frame." )
140
-
141
- # We haven't defined varK or varM yet... so we shouldn't have a summary.
142
- varK = frame .FindVariable ('k' )
152
+ # We haven't defined varK yet.
153
+ varK = self .get_var ('k' )
143
154
144
155
# Go to break point 2. k should be valid and m should not be. Since M is
145
156
# a dbg.declare it is hard to test robustly that it is not initialized
146
157
# so we don't do so. We have an additional llvm.dbg.addr test where we
147
158
# move the other variable and show the correct behavior with
148
159
# llvm.dbg.declare.
149
160
self .runCmd ('continue' )
150
-
151
- self .assertTrue (varK .unsigned > 0 , "var not initialized?!" )
161
+ self .assertGreater (varK .unsigned , 0 , "var not initialized?!" )
152
162
153
163
# Go to breakpoint 3.
154
164
self .runCmd ('continue' )
155
- self .assertTrue (varK .unsigned == 0 ,
165
+ self .assertEqual (varK .unsigned , 0 ,
156
166
"dbg thinks varK is live despite move?!" )
157
167
158
168
# Run so we hit the next breakpoint as part of the next test.
159
169
self .runCmd ('continue' )
160
170
161
171
def do_check_addressonly_var_test (self ):
162
- frame = self .thread .frames [0 ]
163
- self .assertTrue (frame .IsValid (), "Couldn't get a frame." )
164
-
165
- varK = frame .FindVariable ('k' )
172
+ varK = self .get_var ('k' )
166
173
167
174
# Go to break point 2. k should be valid.
168
175
self .runCmd ('continue' )
169
- self .assertTrue (varK .unsigned > 0 , "varK not initialized?!" )
176
+ self .assertGreater (varK .unsigned , 0 , "varK not initialized?!" )
170
177
171
178
# Go to breakpoint 3. K was invalidated.
172
179
self .runCmd ('continue' )
173
- self .assertTrue (varK .value == None , "K is live but was moved?!" )
180
+ self .assertIsNone (varK .value , "K is live but was moved?!" )
174
181
175
182
# Go to the last breakpoint and make sure that k is reinitialized
176
183
# properly.
177
184
self .runCmd ('continue' )
178
- self .assertTrue (varK .unsigned > 0 , "varK not initialized" )
185
+ self .assertGreater (varK .unsigned , 0 , "varK not initialized" )
179
186
180
187
# Run so we hit the next breakpoint as part of the next test.
181
188
self .runCmd ('continue' )
182
189
183
190
def do_check_copyable_value_ccf_true (self ):
184
- frame = self .thread .frames [0 ]
185
- self .assertTrue (frame .IsValid (), "Couldn't get a frame." )
186
- varK = frame .FindVariable ('k' )
191
+ varK = self .get_var ('k' )
187
192
188
193
# Check at our start point that we do not have any state for varK and
189
194
# then continue to our next breakpoint.
190
- self .assertTrue (varK .value == None , "varK should not have a value?!" )
195
+ self .assertIsNone (varK .value , "varK should not have a value?!" )
191
196
self .runCmd ('continue' )
192
197
193
198
# At this breakpoint, k should be defined since we are going to do
194
199
# something with it.
195
- self .assertTrue (varK .value != None , "varK should have a value?!" )
200
+ self .assertIsNotNone (varK .value , "varK should have a value?!" )
196
201
self .runCmd ('continue' )
197
202
198
203
# At this breakpoint, we are now in the conditional control flow part of
199
204
# the loop. Make sure that we can see k still.
200
- self .assertTrue (varK .value != None , "varK should have a value?!" )
205
+ self .assertIsNotNone (varK .value , "varK should have a value?!" )
201
206
self .runCmd ('continue' )
202
207
203
208
# Ok, we just performed the move. k should not be no longer initialized.
204
- self .runCmd ('fr v' )
205
- self .assertTrue (varK .value == None , "varK should not have a value?!" )
209
+ self .assertIsNone (varK .value , "varK should not have a value?!" )
206
210
self .runCmd ('continue' )
207
211
208
212
# Finally we left the conditional control flow part of the function. k
209
213
# should still be None.
210
- self .assertTrue (varK .value == None , "varK should not have a value!" )
214
+ self .assertIsNone (varK .value , "varK should not have a value!" )
215
+
216
+ # Run again so we go and run to the next test.
217
+ self .runCmd ('continue' )
211
218
212
219
def do_check_copyable_value_ccf_false (self ):
213
- pass
220
+ varK = self .get_var ('k' )
221
+
222
+ # Check at our start point that we do not have any state for varK and
223
+ # then continue to our next breakpoint.
224
+ self .assertIsNone (varK .value , "varK should not have a value?!" )
225
+ self .runCmd ('continue' )
226
+
227
+ # At this breakpoint, k should be defined since we are going to do
228
+ # something with it.
229
+ self .assertIsNotNone (varK .value , "varK should have a value?!" )
230
+ self .runCmd ('continue' )
231
+
232
+ # At this breakpoint, we are now past the end of the conditional
233
+ # statement. We know due to the move checking that k can not have any
234
+ # uses that are reachable from the move. So it is safe to always not
235
+ # provide the value here.
236
+ self .assertIsNone (varK .value , "varK should have a value?!" )
237
+
238
+ # Run again so we go and run to the next test.
239
+ self .runCmd ('continue' )
240
+
241
+ def do_check_copyable_var_ccf_true_reinit_out_block (self ):
242
+ varK = self .get_var ('k' )
243
+
244
+ # At first we should not have a value for k.
245
+ self .assertEqual (varK .unsigned , 0 , "varK should be nullptr!" )
246
+ self .runCmd ('continue' )
247
+
248
+ # Now we are in the conditional true block. K should be defined since we
249
+ # are on the move itself.
250
+ self .assertGreater (varK .unsigned , 0 , "varK should not be nullptr!" )
251
+ self .runCmd ('continue' )
252
+
253
+ # Now we have executed the move and we are about to run code using
254
+ # m. Make sure that K is not available!
255
+ self .assertEqual (varK .unsigned , 0 ,
256
+ "varK was already moved! Should be nullptr" )
257
+ self .runCmd ('continue' )
258
+
259
+ # We are now out of the conditional lexical block on the line of code
260
+ # that redefines k. k should still be not available.
261
+ self .assertEqual (varK .unsigned , 0 ,
262
+ "varK was already moved! Should be nullptr" )
263
+ self .runCmd ('continue' )
264
+
265
+ # Ok, we have now reinit k and are about to call a method on it. We
266
+ # should be valid now.
267
+ self .assertGreater (varK .unsigned , 0 ,
268
+ "varK should have be reinitialized?!" )
269
+
270
+ # Run again so we go and run to the next test.
271
+ self .runCmd ('continue' )
272
+
273
+ def do_check_copyable_var_ccf_true_reinit_in_block (self ):
274
+ varK = self .get_var ('k' )
275
+
276
+ # At first we should not have a value for k.
277
+ self .assertEqual (varK .unsigned , 0 , "varK should be nullptr!" )
278
+ self .runCmd ('continue' )
279
+
280
+ # Now we are in the conditional true block. K should be defined since we
281
+ # are on the move itself.
282
+ self .assertGreater (varK .unsigned , 0 , "varK should not be nullptr!" )
283
+ self .runCmd ('continue' )
284
+
285
+ # Now we have executed the move and we are about to reinit k but have
286
+ # not yet. Make sure we are not available!
287
+ self .assertEqual (varK .unsigned , 0 ,
288
+ "varK was already moved! Should be nullptr" )
289
+ self .runCmd ('continue' )
290
+
291
+ # We are now still inside the conditional part of the code, but have
292
+ # reinitialized varK.
293
+ self .assertGreater (varK .unsigned , 0 ,
294
+ "varK was reinit! Should be valid value!" )
295
+ self .runCmd ('continue' )
296
+
297
+ # We now have left the conditional part of the function. k should still
298
+ # be available.
299
+ self .assertGreater (varK .unsigned , 0 ,
300
+ "varK should have be reinitialized?!" )
301
+
302
+ # Run again so we go and run to the next test.
303
+ self .runCmd ('continue' )
304
+
305
+ def do_check_copyable_var_ccf_false_reinit_out_block (self ):
306
+ varK = self .get_var ('k' )
307
+
308
+ # At first we should not have a value for k.
309
+ self .assertEqual (varK .unsigned , 0 , "varK should be nullptr!" )
310
+ self .runCmd ('continue' )
311
+
312
+ # Now we are right above the beginning of the false check. varK should
313
+ # still be valid.
314
+ self .assertGreater (varK .unsigned , 0 , "varK should not be nullptr!" )
315
+ self .runCmd ('continue' )
316
+
317
+ # Now we are after the conditional part of the code on the reinit
318
+ # line. Since this is reachable from the move and we haven't reinit yet,
319
+ # k should not be available.
320
+ self .assertEqual (varK .unsigned , 0 ,
321
+ "varK was already moved! Should be nullptr" )
322
+ self .runCmd ('continue' )
323
+
324
+ # Ok, we have now reinit k and are about to call a method on it. We
325
+ # should be valid now.
326
+ self .assertGreater (varK .unsigned , 0 ,
327
+ "varK should have be reinitialized?!" )
328
+
329
+ # Run again so we go and run to the next test.
330
+ self .runCmd ('continue' )
331
+
332
+ def do_check_copyable_var_ccf_false_reinit_in_block (self ):
333
+ varK = self .get_var ('k' )
334
+
335
+ # At first we should not have a value for k.
336
+ self .assertEqual (varK .unsigned , 0 , "varK should be nullptr!" )
337
+ self .runCmd ('continue' )
338
+
339
+ # Now we are on the doSomething above the false check. So varK should be
340
+ # valid.
341
+ self .assertGreater (varK .unsigned , 0 , "varK should not be nullptr!" )
342
+ self .runCmd ('continue' )
343
+
344
+ # Now we are after the conditional scope. Since k was reinitialized in
345
+ # the conditional scope, along all paths we are valid so varK should
346
+ # still be available.
347
+ self .assertGreater (varK .unsigned , 0 ,
348
+ "varK should not be nullptr?!" )
349
+
350
+ # Run again so we go and run to the next test.
351
+ self .runCmd ('continue' )
0 commit comments