aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2024-07-22 22:52:10 +0100
committergingerBill <bill@gingerbill.org>2024-07-22 22:52:10 +0100
commit6eb28aeafc177ae91ae704c3e4f2c75b9f27b092 (patch)
treeb469d783437081f0ceb3df35a2d57b692eb98f90 /src
parent12b971746cd18a55e637b63d02ccf23e85c86e40 (diff)
Check to see if people are return a slice of a local fixed array from a procedure
Diffstat (limited to 'src')
-rw-r--r--src/check_stmt.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp
index 6c3570cc8..76b6d3f40 100644
--- a/src/check_stmt.cpp
+++ b/src/check_stmt.cpp
@@ -2517,7 +2517,7 @@ gb_internal void check_return_stmt(CheckerContext *ctx, Ast *node) {
Entity *e = entity_of_node(x);
if (is_entity_local_variable(e)) {
unsafe_return_error(o, "the address of a local variable");
- } else if(x->kind == Ast_CompoundLit) {
+ } else if (x->kind == Ast_CompoundLit) {
unsafe_return_error(o, "the address of a compound literal");
} else if (x->kind == Ast_IndexExpr) {
Entity *f = entity_of_node(x->IndexExpr.expr);
@@ -2532,6 +2532,14 @@ gb_internal void check_return_stmt(CheckerContext *ctx, Ast *node) {
unsafe_return_error(o, "the address of an indexed variable", f->type);
}
}
+ } else if (expr->kind == Ast_SliceExpr) {
+ Ast *x = unparen_expr(expr->SliceExpr.expr);
+ Entity *e = entity_of_node(x);
+ if (is_entity_local_variable(e) && is_type_array(e->type)) {
+ unsafe_return_error(o, "a slice of a local variable");
+ } else if (x->kind == Ast_CompoundLit) {
+ unsafe_return_error(o, "a slice of a compound literal");
+ }
} else if (o.mode == Addressing_Constant && is_type_slice(o.type)) {
ERROR_BLOCK();
unsafe_return_error(o, "a compound literal of a slice");