Add some basic escape analysis errors for return &x

This commit is contained in:
gingerBill
2024-03-23 14:58:10 +00:00
parent eb61cf6043
commit 624b870f28
3 changed files with 68 additions and 51 deletions

View File

@@ -229,6 +229,7 @@ struct Entity {
CommentGroup *comment;
bool is_foreign;
bool is_export;
bool is_global;
} Variable;
struct {
Type * type_parameter_specialization;
@@ -480,3 +481,25 @@ gb_internal Entity *strip_entity_wrapping(Ast *expr) {
Entity *e = entity_from_expr(expr);
return strip_entity_wrapping(e);
}
gb_internal bool is_entity_local_variable(Entity *e) {
if (e == nullptr) {
return false;
}
if (e->kind != Entity_Variable) {
return false;
}
if (e->Variable.is_global) {
return false;
}
if (e->scope == nullptr) {
return true;
}
if (e->flags & (EntityFlag_ForValue|EntityFlag_SwitchValue)) {
return false;
}
return ((e->scope->flags &~ ScopeFlag_ContextDefined) == 0) ||
(e->scope->flags & ScopeFlag_Proc) != 0;
}