mirror of
				https://github.com/golang/go.git
				synced 2025-11-04 02:30:57 +00:00 
			
		
		
		
	cmd/compile: add write barrier to type switch
Type switches need write barriers if the written-to variable is heap allocated. For the added needwritebarrier call, the right arg doesn't really matter, I just pass something that will never disqualify the write barrier. The left arg is the one that matters. Fixes #14306 Change-Id: Ic2754167cce062064ea2eeac2944ea4f77cc9c3b Reviewed-on: https://go-review.googlesource.com/19481 Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
		
							parent
							
								
									c93193aec0
								
							
						
					
					
						commit
						e3033fc535
					
				
					 2 changed files with 15 additions and 1 deletions
				
			
		| 
						 | 
					@ -836,7 +836,7 @@ func gen(n *Node) {
 | 
				
			||||||
		Cgen_as_wb(n.Left, n.Right, true)
 | 
							Cgen_as_wb(n.Left, n.Right, true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	case OAS2DOTTYPE:
 | 
						case OAS2DOTTYPE:
 | 
				
			||||||
		cgen_dottype(n.Rlist.N, n.List.N, n.List.Next.N, false)
 | 
							cgen_dottype(n.Rlist.N, n.List.N, n.List.Next.N, needwritebarrier(n.List.N, n.Rlist.N))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	case OCALLMETH:
 | 
						case OCALLMETH:
 | 
				
			||||||
		cgen_callmeth(n, 0)
 | 
							cgen_callmeth(n, 0)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -144,3 +144,17 @@ type T8 struct {
 | 
				
			||||||
func f16(x []T8, y T8) []T8 {
 | 
					func f16(x []T8, y T8) []T8 {
 | 
				
			||||||
	return append(x, y) // ERROR "write barrier"
 | 
						return append(x, y) // ERROR "write barrier"
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func t1(i interface{}) **int {
 | 
				
			||||||
 | 
						// From issue 14306, make sure we have write barriers in a type switch
 | 
				
			||||||
 | 
						// where the assigned variable escapes.
 | 
				
			||||||
 | 
						switch x := i.(type) { // ERROR "write barrier"
 | 
				
			||||||
 | 
						case *int:
 | 
				
			||||||
 | 
							return &x
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						switch y := i.(type) { // no write barrier here
 | 
				
			||||||
 | 
						case **int:
 | 
				
			||||||
 | 
							return y
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue