URL
https://opencores.org/ocsvn/openrisc/openrisc/trunk
Subversion Repositories openrisc
[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [go.test/] [test/] [goto.go] - Rev 700
Compare with Previous | Blame | View Log
// errchk $G -e $D/$F.go// Copyright 2011 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.// Each test is in a separate function just so that if the// compiler stops processing after one error, we don't// lose other ones.package mainvar (i, n intx []intc chan intm map[int]ints string)// goto after declaration okayfunc _() {x := 1goto LL:_ = x}// goto before declaration okayfunc _() {goto LL:x := 1_ = x}// goto across declaration not okayfunc _() {goto L // ERROR "goto L jumps over declaration of x at LINE+1|goto jumps over declaration"x := 1 // GCCGO_ERROR "defined here"_ = xL:}// goto across declaration in inner scope okayfunc _() {goto L{x := 1_ = x}L:}// goto across declaration after inner scope not okayfunc _() {goto L // ERROR "goto L jumps over declaration of x at LINE+5|goto jumps over declaration"{x := 1_ = x}x := 1 // GCCGO_ERROR "defined here"_ = xL:}// goto across declaration in reverse okayfunc _() {L:x := 1_ = xgoto L}// error shows first offending variablefunc _() {goto L // ERROR "goto L jumps over declaration of x at LINE+1|goto jumps over declaration"x := 1 // GCCGO_ERROR "defined here"_ = xy := 1_ = yL:}// goto not okay even if code path is deadfunc _() {goto L // ERROR "goto L jumps over declaration of x at LINE+1|goto jumps over declaration"x := 1 // GCCGO_ERROR "defined here"_ = xy := 1_ = yreturnL:}// goto into outer block okayfunc _() {{goto L}L:}// goto backward into outer block okayfunc _() {L:{goto L}}// goto into inner block not okayfunc _() {goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"{ // GCCGO_ERROR "block starts here"L:}}// goto backward into inner block still not okayfunc _() {{ // GCCGO_ERROR "block starts here"L:}goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"}// error shows first (outermost) offending blockfunc _() {goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"{{{ // GCCGO_ERROR "block starts here"L:}}}}// error prefers block diagnostic over declaration diagnosticfunc _() {goto L // ERROR "goto L jumps into block starting at LINE+3|goto jumps into block"x := 1_ = x{ // GCCGO_ERROR "block starts here"L:}}// many kinds of blocks, all invalid to jump into or among,// but valid to jump out of// iffunc _() {L:if true {goto L}}func _() {L:if true {goto L} else {}}func _() {L:if false {} else {goto L}}func _() {goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"if true { // GCCGO_ERROR "block starts here"L:}}func _() {goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"if true { // GCCGO_ERROR "block starts here"L:} else {}}func _() {goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"if true {} else { // GCCGO_ERROR "block starts here"L:}}func _() {if false { // GCCGO_ERROR "block starts here"L:} else {goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"}}func _() {if true {goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"} else { // GCCGO_ERROR "block starts here"L:}}func _() {if true {goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"} else if false { // GCCGO_ERROR "block starts here"L:}}func _() {if true {goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"} else if false { // GCCGO_ERROR "block starts here"L:} else {}}func _() {// This one is tricky. There is an implicit scope// starting at the second if statement, and it contains// the final else, so the outermost offending scope// really is LINE+1 (like in the previous test),// even though it looks like it might be LINE+3 instead.if true {goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"} else if false {} else { // GCCGO_ERROR "block starts here"L:}}/* Want to enable these tests but gofmt mangles them. Issue 1972.func _() {// This one is okay, because the else is in the// implicit whole-if block and has no inner block// (no { }) around it.if true {goto L} elseL:}func _() {// Still not okay.if true { //// GCCGO_ERROR "block starts here"L:} elsegoto L //// ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"}*/// forfunc _() {for {goto L}L:}func _() {for {goto LL:}}func _() {for { // GCCGO_ERROR "block starts here"L:}goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"}func _() {for { // GCCGO_ERROR "block starts here"goto LL1:}L:goto L1 // ERROR "goto L1 jumps into block starting at LINE-5|goto jumps into block"}func _() {for i < n { // GCCGO_ERROR "block starts here"L:}goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"}func _() {for i = 0; i < n; i++ { // GCCGO_ERROR "block starts here"L:}goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"}func _() {for i = range x { // GCCGO_ERROR "block starts here"L:}goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"}func _() {for i = range c { // GCCGO_ERROR "block starts here"L:}goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"}func _() {for i = range m { // GCCGO_ERROR "block starts here"L:}goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"}func _() {for i = range s { // GCCGO_ERROR "block starts here"L:}goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"}// switchfunc _() {L:switch i {case 0:goto L}}func _() {L:switch i {case 0:default:goto L}}func _() {switch i {case 0:default:L:goto L}}func _() {switch i {case 0:default:goto LL:}}func _() {switch i {case 0:goto LL:;default:}}func _() {goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"switch i {case 0:L: // GCCGO_ERROR "block starts here"}}func _() {goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"switch i {case 0:L: // GCCGO_ERROR "block starts here";default:}}func _() {goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"switch i {case 0:default:L: // GCCGO_ERROR "block starts here"}}func _() {switch i {default:goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"case 0:L: // GCCGO_ERROR "block starts here"}}func _() {switch i {case 0:L: // GCCGO_ERROR "block starts here";default:goto L // ERROR "goto L jumps into block starting at LINE-4|goto jumps into block"}}// select// different from switch. the statement has no implicit block around it.func _() {L:select {case <-c:goto L}}func _() {L:select {case c <- 1:default:goto L}}func _() {select {case <-c:default:L:goto L}}func _() {select {case c <- 1:default:goto LL:}}func _() {select {case <-c:goto LL:;default:}}func _() {goto L // ERROR "goto L jumps into block starting at LINE+2|goto jumps into block"select {case c <- 1:L: // GCCGO_ERROR "block starts here"}}func _() {goto L // ERROR "goto L jumps into block starting at LINE+2|goto jumps into block"select {case c <- 1:L: // GCCGO_ERROR "block starts here";default:}}func _() {goto L // ERROR "goto L jumps into block starting at LINE+3|goto jumps into block"select {case <-c:default:L: // GCCGO_ERROR "block starts here"}}func _() {select {default:goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"case <-c:L: // GCCGO_ERROR "block starts here"}}func _() {select {case <-c:L: // GCCGO_ERROR "block starts here";default:goto L // ERROR "goto L jumps into block starting at LINE-4|goto jumps into block"}}
