mirror of
https://github.com/odin-lang/Odin.git
synced 2026-02-16 08:04:07 +00:00
Add some basic escape analysis errors for return &x
This commit is contained in:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user