From 5702d601df059ba4465dad572f6e70f578335549 Mon Sep 17 00:00:00 2001 From: David Gonzalez Martin Date: Fri, 13 Jun 2025 18:15:26 -0600 Subject: [PATCH] Pass 'va_end' --- CMakeLists.txt | 3 +++ src/compiler.bbb | 6 ++++++ src/emitter.cpp | 3 ++- src/parser.cpp | 3 ++- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ae44d6b..2e57d33 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,3 +51,6 @@ target_link_libraries(bb PUBLIC llvm_bindings) add_compile_options(-Wall -Wextra -pedantic -Wpedantic -Werror -Wno-c99-extensions -Wno-unused-function -Wno-missing-designated-field-initializers -fno-signed-char -fwrapv -fno-strict-aliasing) add_compile_definitions(CMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}") add_compile_definitions(BB_CI=${BB_CI}) + +# add_compile_options(-fsanitize=address) +# add_link_options(-fsanitize=address) diff --git a/src/compiler.bbb b/src/compiler.bbb index 77217d8..c280c1e 100644 --- a/src/compiler.bbb +++ b/src/compiler.bbb @@ -8510,6 +8510,7 @@ analyze_type = fn (module: &Module, value: &Value, expected_type: &Type, analysi // TODO: this is the default case .ampersand, .exclamation, + .va_end, => { >is_boolean = unary_is_boolean(unary_id); @@ -11120,6 +11121,10 @@ emit_value = fn (module: &Module, value: &Value, type_kind: TypeKind, expect_con { llvm_value = llvm_unary_value; }, + .va_end => + { + llvm_value = emit_intrinsic_call(module, ."llvm.va_end", [ module.llvm.pointer_type ][..], [ llvm_unary_value ][..]); + }, else => { #trap(); }, } }, @@ -13717,6 +13722,7 @@ names: [_][]u8 = "struct_varargs", "struct_zero", "unreachable", + "varargs", ]; [export] main = fn [cc(c)] (argument_count: u32, argv: &&u8, envp: &&u8) s32 diff --git a/src/emitter.cpp b/src/emitter.cpp index b5601c6..ff5b292 100644 --- a/src/emitter.cpp +++ b/src/emitter.cpp @@ -7065,7 +7065,8 @@ fn void analyze_block(Module* module, Block* block) fn LLVMValueRef emit_constant_array(Module* module, Slice elements, Type* element_type) { - LLVMValueRef value_buffer[64]; + LLVMValueRef value_buffer[128]; + assert(elements.length <= array_length(value_buffer)); resolve_type_in_place(module, element_type); diff --git a/src/parser.cpp b/src/parser.cpp index e42590e..a8655b8 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -1937,7 +1937,7 @@ fn Value* parse_left(Module* module, Scope* scope, ValueBuilder builder) case TokenId::left_bracket: { u64 element_count = 0; - Value* value_buffer[64]; + Value* value_buffer[128]; skip_space(module); @@ -1976,6 +1976,7 @@ fn Value* parse_left(Module* module, Scope* scope, ValueBuilder builder) } auto value = parse_value(module, scope, {}); + assert(element_count < array_length(value_buffer)); value_buffer[element_count] = value; element_count += 1;