mojo
mojo copied to clipboard
[BUG]: Calling `__copyinit__` on `self` causes crash
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
This should be rejected by exclusivity checking, R^X checking. This is on my todo list to implement.
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)
^~