...

Source file src/cmd/compile/internal/loopvar/testdata/for_esc_address.go

Documentation: cmd/compile/internal/loopvar/testdata

     1  // Copyright 2023 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"fmt"
     9  	"os"
    10  )
    11  
    12  func main() {
    13  	sum := 0
    14  	var is []*int
    15  	for i := 0; i < 10; i++ {
    16  		for j := 0; j < 10; j++ {
    17  			if i == j { // 10 skips
    18  				continue
    19  			}
    20  			sum++
    21  		}
    22  		if i&1 == 0 {
    23  			is = append(is, &i)
    24  		}
    25  	}
    26  
    27  	bug := false
    28  	if sum != 100-10 {
    29  		fmt.Printf("wrong sum, expected %d, saw %d\n", 90, sum)
    30  		bug = true
    31  	}
    32  	sum = 0
    33  	for _, pi := range is {
    34  		sum += *pi
    35  	}
    36  	if sum != 2+4+6+8 {
    37  		fmt.Printf("wrong sum, expected %d, saw %d\n", 20, sum)
    38  		bug = true
    39  	}
    40  	if !bug {
    41  		fmt.Printf("PASS\n")
    42  	} else {
    43  		os.Exit(11)
    44  	}
    45  }
    46  

View as plain text