Skip to content
Snippets Groups Projects
  • Keith Randall's avatar
    61bc17f0
    cmd/compile: don't assume pointer of a slice is non-nil · 61bc17f0
    Keith Randall authored
    unsafe.SliceData can return pointers which are nil. That function gets
    lowered to the SSA OpSlicePtr, which the compiler assumes is non-nil.
    This used to be the case as OpSlicePtr was only used in situations
    where the bounds check already passed. But with unsafe.SliceData that
    is no longer the case.
    
    There are situations where we know it is nil. Use Bounded() to
    indicate that.
    
    I looked through all the uses of OSPTR and added SetBounded where it
    made sense. Most OSPTR results are passed directly to runtime calls
    (e.g. memmove), so even if we know they are non-nil that info isn't
    helpful.
    
    Fixes #59293
    
    Change-Id: I437a15330db48e0082acfb1f89caf8c56723fc51
    Reviewed-on: https://go-review.googlesource.com/c/go/+/479896
    
    
    Reviewed-by: default avatarMatthew Dempsky <mdempsky@google.com>
    Reviewed-by: default avatarKeith Randall <khr@google.com>
    TryBot-Result: Gopher Robot <gobot@golang.org>
    Run-TryBot: Keith Randall <khr@golang.org>
    61bc17f0
    History
    cmd/compile: don't assume pointer of a slice is non-nil
    Keith Randall authored
    unsafe.SliceData can return pointers which are nil. That function gets
    lowered to the SSA OpSlicePtr, which the compiler assumes is non-nil.
    This used to be the case as OpSlicePtr was only used in situations
    where the bounds check already passed. But with unsafe.SliceData that
    is no longer the case.
    
    There are situations where we know it is nil. Use Bounded() to
    indicate that.
    
    I looked through all the uses of OSPTR and added SetBounded where it
    made sense. Most OSPTR results are passed directly to runtime calls
    (e.g. memmove), so even if we know they are non-nil that info isn't
    helpful.
    
    Fixes #59293
    
    Change-Id: I437a15330db48e0082acfb1f89caf8c56723fc51
    Reviewed-on: https://go-review.googlesource.com/c/go/+/479896
    
    
    Reviewed-by: default avatarMatthew Dempsky <mdempsky@google.com>
    Reviewed-by: default avatarKeith Randall <khr@google.com>
    TryBot-Result: Gopher Robot <gobot@golang.org>
    Run-TryBot: Keith Randall <khr@golang.org>
Code owners
Assign users and groups as approvers for specific file changes. Learn more.