Esc

returned_local_address

Finds return *x; with x a local, a pointer into a stack frame that is gone.

Category correctness, deny by default.

Example
#import "Basic";

Point :: struct {
    x, y: int;
}

origin :: () -> *Point {
    p: Point;
    return *p;
}

main :: () {
    p := origin();
    print("%\n", p.x);
}
Diagnostic
error[returned_local_address]: this returns the address of the local `p`, which is gone once the procedure returns
  --> example.jai:9:12
   |
 9 |     return *p;
   |            ^^
   |            -- stack storage borrowed here
   |
   = help: return the value itself, take the memory from an allocator (`New`, `alloc`), or have the caller pass the place to fill
   = note: `returned_local_address` is `deny` by default
Fixed
#import "Basic";

Point :: struct {
    x, y: int;
}

origin :: () -> *Point {
    p := New(Point);
    return p;
}

main :: () {
    p := origin();
    print("%\n", p.x);
    free(p);
}

Covers locals, by-value parameters (the copy is the callee's), for variables and views of local fixed arrays, through copies, fields and Any. Literals the compiler keeps alive are fine.