OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [go.test/] [test/] [goto.go] - Blame information for rev 700

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 700 jeremybenn
// errchk $G -e $D/$F.go
2
 
3
// Copyright 2011 The Go Authors.  All rights reserved.
4
// Use of this source code is governed by a BSD-style
5
// license that can be found in the LICENSE file.
6
 
7
// Each test is in a separate function just so that if the
8
// compiler stops processing after one error, we don't
9
// lose other ones.
10
 
11
package main
12
 
13
var (
14
        i, n int
15
        x    []int
16
        c    chan int
17
        m    map[int]int
18
        s    string
19
)
20
 
21
// goto after declaration okay
22
func _() {
23
        x := 1
24
        goto L
25
L:
26
        _ = x
27
}
28
 
29
// goto before declaration okay
30
func _() {
31
        goto L
32
L:
33
        x := 1
34
        _ = x
35
}
36
 
37
// goto across declaration not okay
38
func _() {
39
        goto L // ERROR "goto L jumps over declaration of x at LINE+1|goto jumps over declaration"
40
        x := 1  // GCCGO_ERROR "defined here"
41
        _ = x
42
L:
43
}
44
 
45
// goto across declaration in inner scope okay
46
func _() {
47
        goto L
48
        {
49
                x := 1
50
                _ = x
51
        }
52
L:
53
}
54
 
55
// goto across declaration after inner scope not okay
56
func _() {
57
        goto L // ERROR "goto L jumps over declaration of x at LINE+5|goto jumps over declaration"
58
        {
59
                x := 1
60
                _ = x
61
        }
62
        x := 1  // GCCGO_ERROR "defined here"
63
        _ = x
64
L:
65
}
66
 
67
// goto across declaration in reverse okay
68
func _() {
69
L:
70
        x := 1
71
        _ = x
72
        goto L
73
}
74
 
75
// error shows first offending variable
76
func _() {
77
        goto L // ERROR "goto L jumps over declaration of x at LINE+1|goto jumps over declaration"
78
        x := 1  // GCCGO_ERROR "defined here"
79
        _ = x
80
        y := 1
81
        _ = y
82
L:
83
}
84
 
85
// goto not okay even if code path is dead
86
func _() {
87
        goto L // ERROR "goto L jumps over declaration of x at LINE+1|goto jumps over declaration"
88
        x := 1  // GCCGO_ERROR "defined here"
89
        _ = x
90
        y := 1
91
        _ = y
92
        return
93
L:
94
}
95
 
96
// goto into outer block okay
97
func _() {
98
        {
99
                goto L
100
        }
101
L:
102
}
103
 
104
// goto backward into outer block okay
105
func _() {
106
L:
107
        {
108
                goto L
109
        }
110
}
111
 
112
// goto into inner block not okay
113
func _() {
114
        goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
115
        {       // GCCGO_ERROR "block starts here"
116
        L:
117
        }
118
}
119
 
120
// goto backward into inner block still not okay
121
func _() {
122
        {       // GCCGO_ERROR "block starts here"
123
        L:
124
        }
125
        goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"
126
}
127
 
128
// error shows first (outermost) offending block
129
func _() {
130
        goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
131
        {
132
                {
133
                        {       // GCCGO_ERROR "block starts here"
134
                        L:
135
                        }
136
                }
137
        }
138
}
139
 
140
// error prefers block diagnostic over declaration diagnostic
141
func _() {
142
        goto L // ERROR "goto L jumps into block starting at LINE+3|goto jumps into block"
143
        x := 1
144
        _ = x
145
        {       // GCCGO_ERROR "block starts here"
146
        L:
147
        }
148
}
149
 
150
// many kinds of blocks, all invalid to jump into or among,
151
// but valid to jump out of
152
 
153
// if
154
 
155
func _() {
156
L:
157
        if true {
158
                goto L
159
        }
160
}
161
 
162
func _() {
163
L:
164
        if true {
165
                goto L
166
        } else {
167
        }
168
}
169
 
170
func _() {
171
L:
172
        if false {
173
        } else {
174
                goto L
175
        }
176
}
177
 
178
func _() {
179
        goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
180
        if true {       // GCCGO_ERROR "block starts here"
181
        L:
182
        }
183
}
184
 
185
func _() {
186
        goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
187
        if true {       // GCCGO_ERROR "block starts here"
188
        L:
189
        } else {
190
        }
191
}
192
 
193
func _() {
194
        goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
195
        if true {
196
        } else {        // GCCGO_ERROR "block starts here"
197
        L:
198
        }
199
}
200
 
201
func _() {
202
        if false {      // GCCGO_ERROR "block starts here"
203
        L:
204
        } else {
205
                goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"
206
        }
207
}
208
 
209
func _() {
210
        if true {
211
                goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
212
        } else {        // GCCGO_ERROR "block starts here"
213
        L:
214
        }
215
}
216
 
217
func _() {
218
        if true {
219
                goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
220
        } else if false {       // GCCGO_ERROR "block starts here"
221
        L:
222
        }
223
}
224
 
225
func _() {
226
        if true {
227
                goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
228
        } else if false {       // GCCGO_ERROR "block starts here"
229
        L:
230
        } else {
231
        }
232
}
233
 
234
func _() {
235
        // This one is tricky.  There is an implicit scope
236
        // starting at the second if statement, and it contains
237
        // the final else, so the outermost offending scope
238
        // really is LINE+1 (like in the previous test),
239
        // even though it looks like it might be LINE+3 instead.
240
        if true {
241
                goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
242
        } else if false {
243
        } else {        // GCCGO_ERROR "block starts here"
244
        L:
245
        }
246
}
247
 
248
/* Want to enable these tests but gofmt mangles them.  Issue 1972.
249
 
250
func _() {
251
        // This one is okay, because the else is in the
252
        // implicit whole-if block and has no inner block
253
        // (no { }) around it.
254
        if true {
255
                goto L
256
        } else
257
                L:
258
}
259
 
260
func _() {
261
        // Still not okay.
262
        if true {       //// GCCGO_ERROR "block starts here"
263
        L:
264
        } else
265
                goto L //// ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"
266
}
267
 
268
*/
269
 
270
// for
271
 
272
func _() {
273
        for {
274
                goto L
275
        }
276
L:
277
}
278
 
279
func _() {
280
        for {
281
                goto L
282
        L:
283
        }
284
}
285
 
286
func _() {
287
        for {   // GCCGO_ERROR "block starts here"
288
        L:
289
        }
290
        goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"
291
}
292
 
293
func _() {
294
        for {   // GCCGO_ERROR "block starts here"
295
                goto L
296
        L1:
297
        }
298
L:
299
        goto L1 // ERROR "goto L1 jumps into block starting at LINE-5|goto jumps into block"
300
}
301
 
302
func _() {
303
        for i < n {     // GCCGO_ERROR "block starts here"
304
        L:
305
        }
306
        goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"
307
}
308
 
309
func _() {
310
        for i = 0; i < n; i++ { // GCCGO_ERROR "block starts here"
311
        L:
312
        }
313
        goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"
314
}
315
 
316
func _() {
317
        for i = range x {       // GCCGO_ERROR "block starts here"
318
        L:
319
        }
320
        goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"
321
}
322
 
323
func _() {
324
        for i = range c {       // GCCGO_ERROR "block starts here"
325
        L:
326
        }
327
        goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"
328
}
329
 
330
func _() {
331
        for i = range m {       // GCCGO_ERROR "block starts here"
332
        L:
333
        }
334
        goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"
335
}
336
 
337
func _() {
338
        for i = range s {       // GCCGO_ERROR "block starts here"
339
        L:
340
        }
341
        goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"
342
}
343
 
344
// switch
345
 
346
func _() {
347
L:
348
        switch i {
349
        case 0:
350
                goto L
351
        }
352
}
353
 
354
func _() {
355
L:
356
        switch i {
357
        case 0:
358
 
359
        default:
360
                goto L
361
        }
362
}
363
 
364
func _() {
365
        switch i {
366
        case 0:
367
 
368
        default:
369
        L:
370
                goto L
371
        }
372
}
373
 
374
func _() {
375
        switch i {
376
        case 0:
377
 
378
        default:
379
                goto L
380
        L:
381
        }
382
}
383
 
384
func _() {
385
        switch i {
386
        case 0:
387
                goto L
388
        L:
389
                ;
390
        default:
391
        }
392
}
393
 
394
func _() {
395
        goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
396
        switch i {
397
        case 0:
398
        L:      // GCCGO_ERROR "block starts here"
399
        }
400
}
401
 
402
func _() {
403
        goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
404
        switch i {
405
        case 0:
406
        L:      // GCCGO_ERROR "block starts here"
407
                ;
408
        default:
409
        }
410
}
411
 
412
func _() {
413
        goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
414
        switch i {
415
        case 0:
416
        default:
417
        L:      // GCCGO_ERROR "block starts here"
418
        }
419
}
420
 
421
func _() {
422
        switch i {
423
        default:
424
                goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
425
        case 0:
426
        L:      // GCCGO_ERROR "block starts here"
427
        }
428
}
429
 
430
func _() {
431
        switch i {
432
        case 0:
433
        L:      // GCCGO_ERROR "block starts here"
434
                ;
435
        default:
436
                goto L // ERROR "goto L jumps into block starting at LINE-4|goto jumps into block"
437
        }
438
}
439
 
440
// select
441
// different from switch.  the statement has no implicit block around it.
442
 
443
func _() {
444
L:
445
        select {
446
        case <-c:
447
                goto L
448
        }
449
}
450
 
451
func _() {
452
L:
453
        select {
454
        case c <- 1:
455
 
456
        default:
457
                goto L
458
        }
459
}
460
 
461
func _() {
462
        select {
463
        case <-c:
464
 
465
        default:
466
        L:
467
                goto L
468
        }
469
}
470
 
471
func _() {
472
        select {
473
        case c <- 1:
474
 
475
        default:
476
                goto L
477
        L:
478
        }
479
}
480
 
481
func _() {
482
        select {
483
        case <-c:
484
                goto L
485
        L:
486
                ;
487
        default:
488
        }
489
}
490
 
491
func _() {
492
        goto L // ERROR "goto L jumps into block starting at LINE+2|goto jumps into block"
493
        select {
494
        case c <- 1:
495
        L:      // GCCGO_ERROR "block starts here"
496
        }
497
}
498
 
499
func _() {
500
        goto L // ERROR "goto L jumps into block starting at LINE+2|goto jumps into block"
501
        select {
502
        case c <- 1:
503
        L:      // GCCGO_ERROR "block starts here"
504
                ;
505
        default:
506
        }
507
}
508
 
509
func _() {
510
        goto L // ERROR "goto L jumps into block starting at LINE+3|goto jumps into block"
511
        select {
512
        case <-c:
513
        default:
514
        L:      // GCCGO_ERROR "block starts here"
515
        }
516
}
517
 
518
func _() {
519
        select {
520
        default:
521
                goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
522
        case <-c:
523
        L:      // GCCGO_ERROR "block starts here"
524
        }
525
}
526
 
527
func _() {
528
        select {
529
        case <-c:
530
        L:      // GCCGO_ERROR "block starts here"
531
                ;
532
        default:
533
                goto L // ERROR "goto L jumps into block starting at LINE-4|goto jumps into block"
534
        }
535
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.