blob: bf1dfb18ff187f34a09f33076cf970d52c2eaa5a [file] [log] [blame]
 // errorcheck -0 -m -l // Copyright 2015 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. // Test escape analysis with respect to field assignments. package escape var sink interface{} type X struct { p1 *int p2 *int a *int } type Y struct { x X } func field0() { i := 0 // ERROR "moved to heap: i\$" var x X x.p1 = &i sink = x.p1 } func field1() { i := 0 // ERROR "moved to heap: i\$" var x X // BAD: &i should not escape x.p1 = &i sink = x.p2 } func field3() { i := 0 // ERROR "moved to heap: i\$" var x X x.p1 = &i sink = x // ERROR "x escapes to heap" } func field4() { i := 0 // ERROR "moved to heap: i\$" var y Y y.x.p1 = &i x := y.x sink = x // ERROR "x escapes to heap" } func field5() { i := 0 // ERROR "moved to heap: i\$" var x X // BAD: &i should not escape here x.a = &i sink = x.a } // BAD: we are not leaking param x, only x.p2 func field6(x *X) { // ERROR "leaking param content: x\$" sink = x.p2 } func field6a() { i := 0 // ERROR "moved to heap: i\$" var x X // BAD: &i should not escape x.p1 = &i field6(&x) } func field7() { i := 0 var y Y y.x.p1 = &i x := y.x var y1 Y y1.x = x _ = y1.x.p1 } func field8() { i := 0 // ERROR "moved to heap: i\$" var y Y y.x.p1 = &i x := y.x var y1 Y y1.x = x sink = y1.x.p1 } func field9() { i := 0 // ERROR "moved to heap: i\$" var y Y y.x.p1 = &i x := y.x var y1 Y y1.x = x sink = y1.x // ERROR "y1\.x escapes to heap" } func field10() { i := 0 // ERROR "moved to heap: i\$" var y Y // BAD: &i should not escape y.x.p1 = &i x := y.x var y1 Y y1.x = x sink = y1.x.p2 } func field11() { i := 0 // ERROR "moved to heap: i\$" x := X{p1: &i} sink = x.p1 } func field12() { i := 0 // ERROR "moved to heap: i\$" // BAD: &i should not escape x := X{p1: &i} sink = x.p2 } func field13() { i := 0 // ERROR "moved to heap: i\$" x := &X{p1: &i} // ERROR "&X literal does not escape\$" sink = x.p1 } func field14() { i := 0 // ERROR "moved to heap: i\$" // BAD: &i should not escape x := &X{p1: &i} // ERROR "&X literal does not escape\$" sink = x.p2 } func field15() { i := 0 // ERROR "moved to heap: i\$" x := &X{p1: &i} // ERROR "&X literal escapes to heap\$" sink = x } func field16() { i := 0 // ERROR "moved to heap: i\$" var x X // BAD: &i should not escape x.p1 = &i var iface interface{} = x // ERROR "x does not escape" x1 := iface.(X) sink = x1.p2 } func field17() { i := 0 // ERROR "moved to heap: i\$" var x X x.p1 = &i var iface interface{} = x // ERROR "x does not escape" x1 := iface.(X) sink = x1.p1 } func field18() { i := 0 // ERROR "moved to heap: i\$" var x X // BAD: &i should not escape x.p1 = &i var iface interface{} = x // ERROR "x does not escape" y, _ := iface.(Y) // Put X, but extracted Y. The cast will fail, so y is zero initialized. sink = y // ERROR "y escapes to heap" }
{"ft_lang_label":"__label__en","ft_lang_prob":0.50023067,"math_prob":0.9994073,"size":2977,"snap":"2021-04-2021-17","text_gpt3_token_len":1141,"char_repetition_ratio":0.21897073,"word_repetition_ratio":0.55792683,"special_character_ratio":0.4776621,"punctuation_ratio":0.17732558,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.993363,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-04-16T03:22:15Z\",\"WARC-Record-ID\":\"<urn:uuid:f27844c4-6f09-4d9e-af7f-a20560eedc1b>\",\"Content-Length\":\"49871\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:c224ba53-62c2-4206-803e-be65ff83e90a>\",\"WARC-Concurrent-To\":\"<urn:uuid:94c5f86b-91f2-4a3a-a38b-a18dee3239fa>\",\"WARC-IP-Address\":\"74.125.192.82\",\"WARC-Target-URI\":\"https://go.googlesource.com/go/+/0e031676288ddd56fb410b6b27807a180a585db3/test/escape_field.go\",\"WARC-Payload-Digest\":\"sha1:AFCOTDU5RYIFAY47GF4CT7MD472OYK5F\",\"WARC-Block-Digest\":\"sha1:XMSQ362FWQ4F3MFICW2K7ZUDVWHHYSCL\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-17/CC-MAIN-2021-17_segments_1618038088471.40_warc_CC-MAIN-20210416012946-20210416042946-00299.warc.gz\"}"}