Source file test/fixedbugs/issue34723.go

     1  // errorcheck -0 -d=wb
     2  
     3  // Copyright 2019 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  // Make sure we don't introduce write barriers where we
     8  // don't need them. These cases are writing pointers to
     9  // globals to zeroed memory.
    10  
    11  package main
    12  
    13  func f1() []string {
    14  	return []string{"a"}
    15  }
    16  
    17  func f2() []string {
    18  	return []string{"a", "b"}
    19  }
    20  
    21  type T struct {
    22  	a [6]*int
    23  }
    24  
    25  func f3() *T {
    26  	t := new(T)
    27  	t.a[0] = &g
    28  	t.a[1] = &g
    29  	t.a[2] = &g
    30  	t.a[3] = &g
    31  	t.a[4] = &g
    32  	t.a[5] = &g
    33  	return t
    34  }
    35  
    36  func f4() *T {
    37  	t := new(T)
    38  	t.a[5] = &g
    39  	t.a[4] = &g
    40  	t.a[3] = &g
    41  	t.a[2] = &g
    42  	t.a[1] = &g
    43  	t.a[0] = &g
    44  	return t
    45  }
    46  
    47  func f5() *T {
    48  	t := new(T)
    49  	t.a[4] = &g
    50  	t.a[2] = &g
    51  	t.a[0] = &g
    52  	t.a[3] = &g
    53  	t.a[1] = &g
    54  	t.a[5] = &g
    55  	return t
    56  }
    57  
    58  type U struct {
    59  	a [65]*int
    60  }
    61  
    62  func f6() *U {
    63  	u := new(U)
    64  	u.a[63] = &g
    65  	// This offset is too large: we only track the first 64 pointers for zeroness.
    66  	u.a[64] = &g // ERROR "write barrier"
    67  	return u
    68  }
    69  
    70  var g int
    71  

View as plain text