From b5ddc36d7f9c6d96ad1239977293631dbb487bec Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Fri, 23 May 2025 21:40:14 +0200 Subject: [PATCH] Limit vector max size, default is 4096 bits, but may be increased using --max-vector-size. --- lib/std/core/env.c3 | 1 + releasenotes.md | 1 + src/build/build.h | 3 +++ src/build/build_options.c | 18 +++++++++++++++++- src/build/builder.c | 3 +++ src/build/project.c | 16 +++++++++++++++- src/compiler/compiler.c | 1 + src/compiler/sema_types.c | 13 +++++++++++-- src/utils/common.h | 1 + test/test_suite/vector/vector_limit.c3 | 5 +++++ test/unit/stdlib/core/builtintests.c3 | 16 ++++++++-------- test/unit/stdlib/os/subprocess.c3 | 3 ++- 12 files changed, 68 insertions(+), 13 deletions(-) create mode 100644 test/test_suite/vector/vector_limit.c3 diff --git a/lib/std/core/env.c3 b/lib/std/core/env.c3 index 0c9f7c3a8..81217f7c0 100644 --- a/lib/std/core/env.c3 +++ b/lib/std/core/env.c3 @@ -120,6 +120,7 @@ const String COMPILER_BUILD_HASH = $$BUILD_HASH; const String COMPILER_BUILD_DATE = $$BUILD_DATE; const OsType OS_TYPE = OsType.from_ordinal($$OS_TYPE); const ArchType ARCH_TYPE = ArchType.from_ordinal($$ARCH_TYPE); +const usz MAX_VECTOR_SIZE = $$MAX_VECTOR_SIZE; const bool ARCH_32_BIT = $$REGISTER_SIZE == 32; const bool ARCH_64_BIT = $$REGISTER_SIZE == 64; const bool LIBC = $$COMPILER_LIBC_AVAILABLE; diff --git a/releasenotes.md b/releasenotes.md index fe506259e..0feb304bf 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -14,6 +14,7 @@ - Deprecate `MyEnum.elements`. - Deprecate `SomeFn.params`. - Improve error message when encountering recursively defined structs. #2146 +- Limit vector max size, default is 4096 bits, but may be increased using --max-vector-size. ### Fixes - Assert triggered when casting from `int[2]` to `uint[2]` #2115 diff --git a/src/build/build.h b/src/build/build.h index 416e4a0dd..a3bea7866 100644 --- a/src/build/build.h +++ b/src/build/build.h @@ -7,6 +7,7 @@ #include "../version.h" #include +#define MAX_SYMTAB_SIZE (1024 * 1024) #define MAX_BUILD_LIB_DIRS 1024 #define MAX_COMMAND_LINE_FILES 4096 #define MAX_COMMAND_LINE_RUN_ARGS 2048 @@ -578,6 +579,7 @@ typedef struct BuildOptions_ RiscvFloatCapability riscv_float_capability; MemoryEnvironment memory_environment; SanitizeMode sanitize_mode; + uint32_t max_vector_size; bool print_keywords; bool print_attributes; bool print_builtins; @@ -702,6 +704,7 @@ typedef struct CompilerBackend backend; LinkerType linker_type; uint32_t symtab_size; + uint32_t max_vector_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 f0e70dde4..502d3be82 100644 --- a/src/build/build_options.c +++ b/src/build/build_options.c @@ -168,6 +168,7 @@ static void usage(bool full) print_opt("--fp-math=