From a2ef63f5b636eda66905a2130add336b54b8f9b1 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Thu, 21 Aug 2025 00:33:56 +0200 Subject: [PATCH] Error if a stack allocated variable is too big (configurable with `--max-stack-object-size`). --- releasenotes.md | 1 + src/build/build.h | 2 ++ src/build/build_options.c | 10 ++++++++++ src/build/builder.c | 2 ++ src/compiler/parse_expr.c | 11 +++++++---- src/compiler/parse_global.c | 3 ++- src/compiler/sema_casts.c | 14 +++++--------- src/compiler/sema_decls.c | 10 ++++++++++ src/compiler/sema_internal.h | 2 +- src/compiler/sema_stmts.c | 17 ++++++----------- src/utils/common.h | 2 ++ test/test_suite/statements/big_locals.c3 | 6 ++++++ 12 files changed, 54 insertions(+), 26 deletions(-) create mode 100644 test/test_suite/statements/big_locals.c3 diff --git a/releasenotes.md b/releasenotes.md index a7e15e1f4..e58c39bd7 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -17,6 +17,7 @@ - Fix max module name to 31 chars and the entire module path to 63 characters. - Improve error message for missing `$endif`. - `foo[x][y] = b` now interpreted as `(*&foo[x])[y] = b` which allows overloads to do chained [] accesses. +- Error if a stack allocated variable is too big (configurable with `--max-stack-object-size`). ### Fixes - List.remove_at would incorrectly trigger ASAN. diff --git a/src/build/build.h b/src/build/build.h index 89707b3ff..eefb63961 100644 --- a/src/build/build.h +++ b/src/build/build.h @@ -585,6 +585,7 @@ typedef struct BuildOptions_ MemoryEnvironment memory_environment; SanitizeMode sanitize_mode; uint32_t max_vector_size; + uint32_t max_stack_object_size; bool print_keywords; bool print_attributes; bool print_builtins; @@ -725,6 +726,7 @@ typedef struct LinkerType linker_type; uint32_t symtab_size; uint32_t max_vector_size; + uint32_t max_stack_object_size; uint32_t switchrange_max_size; uint32_t switchjump_max_size; const char **args; diff --git a/src/build/build_options.c b/src/build/build_options.c index 0e0ca32da..02314d09c 100644 --- a/src/build/build_options.c +++ b/src/build/build_options.c @@ -177,6 +177,7 @@ static void usage(bool full) print_opt("--win64-simd=