Source file test/fixedbugs/issue59638.go

     1  // build -gcflags=-l=4
     2  
     3  // Copyright 2023 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  package p
     8  
     9  type Interface interface {
    10  	MonitoredResource() (resType string, labels map[string]string)
    11  	Done()
    12  }
    13  
    14  func Autodetect(x int) Interface {
    15  	return func() Interface {
    16  		func() Interface {
    17  			x++
    18  			Do(func() {
    19  				var ad, gd Interface
    20  
    21  				go func() {
    22  					defer gd.Done()
    23  					ad = aad()
    24  				}()
    25  				go func() {
    26  					defer ad.Done()
    27  					gd = aad()
    28  					defer func() { recover() }()
    29  				}()
    30  
    31  				autoDetected = ad
    32  				if gd != nil {
    33  					autoDetected = gd
    34  				}
    35  			})
    36  			return autoDetected
    37  		}()
    38  		return nil
    39  	}()
    40  }
    41  
    42  var autoDetected Interface
    43  var G int
    44  
    45  type If int
    46  
    47  func (x If) MonitoredResource() (resType string, labels map[string]string) {
    48  	return "", nil
    49  }
    50  
    51  //go:noinline
    52  func (x If) Done() {
    53  	G++
    54  }
    55  
    56  //go:noinline
    57  func Do(fn func()) {
    58  	fn()
    59  }
    60  
    61  //go:noinline
    62  func aad() Interface {
    63  	var x If
    64  	return x
    65  }
    66  

View as plain text