mojo icon indicating copy to clipboard operation
mojo copied to clipboard

[BUG]: Calling `__copyinit__` on `self` causes crash

Open soraros opened this issue 1 year ago • 1 comments

Bug description

As title. I'm not sure what should happen though. If f is marked always_inline, the code diverges.

Steps to reproduce

# @always_inline
fn f(n: Int) -> Tensor[DType.int64]:
  var v = Tensor[DType.int64](n)
  v.__copyinit__(v)
  return v

fn main():
  var v = f(10)
  print(v[0])

System information

Mojo 0.7.0 on Docker, Intel Mac

soraros avatar Feb 05 '24 20:02 soraros

This should be rejected by exclusivity checking, R^X checking. This is on my todo list to implement.

lattner avatar Jul 29 '24 00:07 lattner

This is fixed, we now diagnose exclusivity violations like this (currently as a warning, will upgrade to an error over time):

t4.mojo:6:19: warning: call argument allows writing a memory location previously writable through another aliased argument
    a.__copyinit__(a)
    ~             ^~
t4.mojo:6:19: note: 'a' value is passed through aliasing 'borrowed' argument
    a.__copyinit__(a)
                  ^~

lattner avatar Aug 18 '24 16:08 lattner