diff options
| author | gingerBill <bill@gingerbill.org> | 2024-03-23 14:58:10 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2024-03-23 14:58:10 +0000 |
| commit | 624b870f2827b330c0e5c8aa887c61cfe3c7b33f (patch) | |
| tree | 429fb084778ef7cc1e21050b8d3822cebf0c87f3 /src/entity.cpp | |
| parent | eb61cf6043b85278a2b90392361a6d0d1269f16e (diff) | |
Add some basic escape analysis errors for `return &x`
Diffstat (limited to 'src/entity.cpp')
| -rw-r--r-- | src/entity.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/entity.cpp b/src/entity.cpp index a160313b4..6cea0930f 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -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; +}
\ No newline at end of file |