return (any)&foo would not be reported as an escaping variable if foo was a pointer or slice.

This commit is contained in:
Christoffer Lerno
2025-02-06 16:33:35 +01:00
parent 3a502feb1d
commit e3851f3723
2 changed files with 5 additions and 1 deletions

View File

@@ -44,6 +44,7 @@
- Usage of @noreturn macro is type-checked as if it returns #1913.
- Bug when indexing into a constant array at compile time.
- Fixing various issues around shifts, like `z <<= { 1, 2 }`.
- `return (any)&foo` would not be reported as an escaping variable if `foo` was a pointer or slice.
### Stdlib changes
- Added '%h' and '%H' for printing out binary data in hexadecimal using the formatter.

View File

@@ -569,10 +569,12 @@ INLINE bool sema_check_not_stack_variable_escape(SemaContext *context, Expr *exp
{
Expr *outer = expr;
expr = sema_dive_into_expression(expr);
bool allow_pointer = false;
// We only want && and &
if (expr->expr_kind == EXPR_SUBSCRIPT_ADDR)
{
expr = exprptr(expr->subscript_expr.expr);
allow_pointer = true;
goto CHECK_ACCESS;
}
if (expr->expr_kind != EXPR_UNARY) return true;
@@ -598,7 +600,8 @@ CHECK_ACCESS:
case TYPE_POINTER:
case TYPE_SLICE:
// &foo[2] is fine if foo is a pointer or slice.
return true;
if (allow_pointer) return true;
break;
default:
break;
}