diff --git a/lib/std/core/builtin.c3 b/lib/std/core/builtin.c3 index 7bbe2dac7..76eb92da0 100644 --- a/lib/std/core/builtin.c3 +++ b/lib/std/core/builtin.c3 @@ -68,25 +68,6 @@ macro anycast(any* v, $Type) @builtin return ($Type*)v.ptr; } -enum CallLocation : int(String name) -{ - UNKNOWN("???"), - FUNCTION("function"), - METHOD("method"), - MACRO("macro"), - LAMBDA("lambda"), - TEST("test"), -} - -struct CallstackElement -{ - CallstackElement* prev; - String function; - String file; - CallLocation location; - uint line; -} - fn bool print_backtrace(String message, int backtraces_to_ignore) @if(env::NATIVE_STACKTRACE) { @pool() @@ -132,27 +113,10 @@ fn void default_panic(String message, String file, String function, uint line) @ } fn void default_panic(String message, String file, String function, uint line) @if(!env::NATIVE_STACKTRACE) { - CallstackElement* stack = $$stacktrace(); $if $defined(io::stderr): - if (stack) stack = stack.prev; - if (stack) - { - io::eprint("\nERROR: '"); - io::eprint(message); - io::eprintn("'"); - } - else - { - io::eprint("\nERROR: '"); - io::eprint(message); - io::eprintfn("', in %s (%s:%d)", function, file, line); - } - while (stack) - { - io::eprintfn(" in %s %s (%s:%d)", stack.location.name, stack.function, stack.file, stack.line); - if (stack == stack.prev) break; - stack = stack.prev; - } + io::eprint("\nERROR: '"); + io::eprint(message); + io::eprintfn("', in %s (%s:%d)", function, file, line); $endif $$trap(); } diff --git a/lib/std/core/runtime.c3 b/lib/std/core/runtime.c3 index f75285415..f45836bf0 100644 --- a/lib/std/core/runtime.c3 +++ b/lib/std/core/runtime.c3 @@ -4,14 +4,6 @@ module std::core::runtime; import libc; -struct StackTrace -{ - StackTrace* prev; - String file; - String function; - uint line; -} - struct AnyStruct { void* ptr; @@ -223,8 +215,6 @@ fn bool run_tests(TestUnit[] tests) name.appendf("Testing %s ", unit.name); name.append_repeat('.', max_name - unit.name.len + 2); io::printf("%s ", name.str_view()); - CallstackElement* stack = $$stacktrace(); - if (stack) stack.prev = null; if (libc::setjmp(&context.buf) == 0) { if (catch err = unit.func()) diff --git a/src/compiler/enums.h b/src/compiler/enums.h index 533210651..3e2c347aa 100644 --- a/src/compiler/enums.h +++ b/src/compiler/enums.h @@ -932,7 +932,6 @@ typedef enum BUILTIN_SWIZZLE2, BUILTIN_SIN, BUILTIN_SQRT, - BUILTIN_STACKTRACE, BUILTIN_SYSCALL, BUILTIN_SYSCLOCK, BUILTIN_TRAP, diff --git a/src/compiler/llvm_codegen.c b/src/compiler/llvm_codegen.c index a6e645ccf..950745cc4 100644 --- a/src/compiler/llvm_codegen.c +++ b/src/compiler/llvm_codegen.c @@ -1521,27 +1521,27 @@ static GenContext *llvm_gen_module(Module *module, LLVMContextRef shared_context if (decl->func_decl.body) { has_elements = true; - llvm_emit_function_body(gen_context, decl, decl->func_decl.attr_test ? ST_TEST : decl->func_decl.attr_benchmark ? ST_BENCHMARK : ST_FUNCTION); + llvm_emit_function_body(gen_context, decl); } FOREACH_END(); FOREACH_BEGIN(Decl *func, unit->lambdas) if (only_used && !func->is_live) continue; has_elements = true; - llvm_emit_function_body(gen_context, func, ST_LAMBDA); + llvm_emit_function_body(gen_context, func); FOREACH_END(); if (active_target.type != TARGET_TYPE_TEST && active_target.type != TARGET_TYPE_BENCHMARK && unit->main_function && unit->main_function->is_synthetic) { has_elements = true; - llvm_emit_function_body(gen_context, unit->main_function, ST_FUNCTION); + llvm_emit_function_body(gen_context, unit->main_function); } FOREACH_BEGIN(Decl *decl, unit->methods) if (only_used && !decl->is_live) continue; if (!decl->func_decl.body) continue; has_elements = true; - llvm_emit_function_body(gen_context, decl, ST_METHOD); + llvm_emit_function_body(gen_context, decl); FOREACH_END(); gencontext_end_file_emit(gen_context, unit); diff --git a/src/compiler/llvm_codegen_builtins.c b/src/compiler/llvm_codegen_builtins.c index 2324fc8e2..936e69ed5 100644 --- a/src/compiler/llvm_codegen_builtins.c +++ b/src/compiler/llvm_codegen_builtins.c @@ -136,16 +136,6 @@ INLINE void llvm_emit_unreachable_stmt(GenContext *c, BEValue *result_value, Exp llvm_emit_block(c, after_unreachable); } -INLINE void llvm_emit_stacktrace(GenContext *c, BEValue *result_value, Expr *expr) -{ - if (!c->debug.emulated_stacktrace) - { - llvm_value_set(result_value, llvm_get_zero(c, type_voidptr), type_voidptr); - return; - } - llvm_value_set(result_value, c->debug.stacktrace.ref, type_voidptr); -} - INLINE void llvm_emit_volatile_store(GenContext *c, BEValue *result_value, Expr *expr) { BEValue value; @@ -825,9 +815,6 @@ void llvm_emit_builtin_call(GenContext *c, BEValue *result_value, Expr *expr) case BUILTIN_REVERSE: llvm_emit_reverse(c, result_value, expr); return; - case BUILTIN_STACKTRACE: - llvm_emit_stacktrace(c, result_value, expr); - return; case BUILTIN_VOLATILE_STORE: llvm_emit_volatile_store(c, result_value, expr); return; diff --git a/src/compiler/llvm_codegen_expr.c b/src/compiler/llvm_codegen_expr.c index 63846a033..cc45d3aa6 100644 --- a/src/compiler/llvm_codegen_expr.c +++ b/src/compiler/llvm_codegen_expr.c @@ -27,7 +27,7 @@ static inline void llvm_emit_initializer_list_expr(GenContext *c, BEValue *value static inline void llvm_emit_macro_block(GenContext *c, BEValue *be_value, Expr *expr); static inline void llvm_emit_post_inc_dec(GenContext *c, BEValue *value, Expr *expr, int diff); static inline void llvm_emit_pre_inc_dec(GenContext *c, BEValue *value, Expr *expr, int diff); -static inline void llvm_emit_return_block(GenContext *c, BEValue *be_value, Type *type, AstId current, BlockExit **block_exit, Stacktrace *old_stack_trace); +static inline void llvm_emit_return_block(GenContext *c, BEValue *be_value, Type *type, AstId current, BlockExit **block_exit); static inline void llvm_emit_subscript_addr_with_base(GenContext *c, BEValue *result, BEValue *parent, BEValue *index, SourceSpan loc); static inline void llvm_emit_try_unwrap(GenContext *c, BEValue *value, Expr *expr); static inline void llvm_emit_vector_initializer_list(GenContext *c, BEValue *value, Expr *expr); @@ -5398,9 +5398,6 @@ void llvm_emit_raw_call(GenContext *c, BEValue *result_value, FunctionPrototype { BEValue no_err; - // Emit the current stack into the thread local or things will get messed up. - llvm_emit_pop_stacktrace(c, NULL); - // 17a. If we used the error var as the indirect recipient, then that will hold the error. // otherwise it's whatever value in be_value. BEValue error_holder = *result_value; @@ -5435,9 +5432,6 @@ void llvm_emit_raw_call(GenContext *c, BEValue *result_value, FunctionPrototype return; } - // Emit the current stack into the thread local or things will get messed up. - llvm_emit_pop_stacktrace(c, NULL); - // 17i. The simple case here is where there is a normal return. // In this case be_value already holds the result } @@ -5727,9 +5721,6 @@ INLINE void llvm_emit_call_invocation(GenContext *c, BEValue *result_value, llvm_emit_raw_call(c, result_value, prototype, func_type, func, arg_values, arg_count, inline_flag, error_var, sret_return, &synthetic_return_param); - // Emit the current stack into the thread local or things will get messed up. - llvm_emit_pop_stacktrace(c, NULL); - // 17i. The simple case here is where there is a normal return. // In this case be_value already holds the result } @@ -5793,8 +5784,6 @@ static void llvm_emit_call_expr(GenContext *c, BEValue *result_value, Expr *expr return; } - llvm_emit_update_stack_row(c, expr->span.row); - LLVMTypeRef func_type; LLVMValueRef func; @@ -5983,7 +5972,7 @@ static inline void llvm_emit_expression_list_expr(GenContext *c, BEValue *be_val } } -static inline void llvm_emit_return_block(GenContext *c, BEValue *be_value, Type *type, AstId current, BlockExit **block_exit, Stacktrace *old_stack_trace) +static inline void llvm_emit_return_block(GenContext *c, BEValue *be_value, Type *type, AstId current, BlockExit **block_exit) { Type *type_lowered = type_lowering(type); @@ -6009,7 +5998,6 @@ static inline void llvm_emit_return_block(GenContext *c, BEValue *be_value, Type if (!type_is_optional(type)) { llvm_emit_expr(c, be_value, expr); - if (old_stack_trace) llvm_emit_pop_stacktrace(c, old_stack_trace); return; } } @@ -6020,12 +6008,6 @@ static inline void llvm_emit_return_block(GenContext *c, BEValue *be_value, Type LLVMValueRef return_out = NULL; LLVMBasicBlockRef expr_block = llvm_basic_block_new(c, "expr_block.exit"); LLVMBasicBlockRef cleanup_error_block = error_block; - bool error_env_restore = false; - if (old_stack_trace && error_block) - { - cleanup_error_block = llvm_basic_block_new(c, "restore_env_block"); - error_env_restore = true; - } BlockExit exit = { .block_return_exit = expr_block, .block_optional_exit = cleanup_error_block, @@ -6053,7 +6035,7 @@ static inline void llvm_emit_return_block(GenContext *c, BEValue *be_value, Type { // Do we have more than one exit? // Then follow the normal path. - if (!llvm_basic_block_is_unused(expr_block) || error_env_restore) break; + if (!llvm_basic_block_is_unused(expr_block)) break; // Do we have a void function? That's the only // possible case if the last statement isn't return. @@ -6084,7 +6066,6 @@ static inline void llvm_emit_return_block(GenContext *c, BEValue *be_value, Type // Output directly to a value llvm_emit_expr(c, be_value, ret_expr); - if (old_stack_trace) llvm_emit_pop_stacktrace(c, old_stack_trace); return; } while (0); @@ -6093,7 +6074,7 @@ static inline void llvm_emit_return_block(GenContext *c, BEValue *be_value, Type llvm_emit_stmt(c, value); // In the case of a void with no return, then this may be true. - if (llvm_basic_block_is_unused(expr_block) && !error_env_restore) + if (llvm_basic_block_is_unused(expr_block)) { // Skip the expr block. llvm_value_set(be_value, llvm_get_undef(c, type_lowered), type_lowered); @@ -6102,12 +6083,6 @@ static inline void llvm_emit_return_block(GenContext *c, BEValue *be_value, Type llvm_emit_br(c, expr_block); - if (error_env_restore) - { - llvm_emit_block(c, cleanup_error_block); - llvm_emit_pop_stacktrace(c, old_stack_trace); - llvm_emit_br(c, error_block); - } // Emit the exit block. llvm_emit_block(c, expr_block); @@ -6121,7 +6096,6 @@ static inline void llvm_emit_return_block(GenContext *c, BEValue *be_value, Type } DONE: - if (old_stack_trace) llvm_emit_pop_stacktrace(c, old_stack_trace); c->return_out = old_ret_out; c->catch_block = error_block; @@ -6131,8 +6105,7 @@ DONE: static inline void llvm_emit_expr_block(GenContext *context, BEValue *be_value, Expr *expr) { - llvm_emit_return_block(context, be_value, expr->type, expr->expr_block.first_stmt, expr->expr_block.block_exit_ref, - NULL); + llvm_emit_return_block(context, be_value, expr->type, expr->expr_block.first_stmt, expr->expr_block.block_exit_ref); } static inline void llvm_emit_macro_block(GenContext *c, BEValue *be_value, Expr *expr) @@ -6177,22 +6150,11 @@ static inline void llvm_emit_macro_block(GenContext *c, BEValue *be_value, Expr val->backend_value = value.value; FOREACH_END(); - bool restore_at_exit = false; - Stacktrace old_stack_trace; if (llvm_use_debug(c)) { llvm_debug_push_lexical_scope(c, astptr(expr->macro_block.first_stmt)->span); - if (c->debug.emulated_stacktrace) - { - restore_at_exit = true; - llvm_emit_update_stack_row(c, expr->span.row); - Decl *macro = expr->macro_block.macro; - old_stack_trace = c->debug.stacktrace; - llvm_emit_push_emulated_stacktrace(c, macro, macro->name, ST_MACRO); - } } - llvm_emit_return_block(c, be_value, expr->type, expr->macro_block.first_stmt, expr->macro_block.block_exit, restore_at_exit ? &old_stack_trace : NULL); - if (restore_at_exit) c->debug.stacktrace = old_stack_trace; + llvm_emit_return_block(c, be_value, expr->type, expr->macro_block.first_stmt, expr->macro_block.block_exit); bool is_unreachable = expr->macro_block.is_noreturn && c->current_block && c->current_block_is_target; if (is_unreachable) { diff --git a/src/compiler/llvm_codegen_function.c b/src/compiler/llvm_codegen_function.c index 02a0084ac..f98c4e8a3 100644 --- a/src/compiler/llvm_codegen_function.c +++ b/src/compiler/llvm_codegen_function.c @@ -14,7 +14,7 @@ static inline void llvm_process_parameter_value(GenContext *c, Decl *decl, ABIAr static inline void llvm_emit_func_parameter(GenContext *context, Decl *decl, ABIArgInfo *abi_info, unsigned *index, unsigned real_index); static inline void llvm_emit_body(GenContext *c, LLVMValueRef function, FunctionPrototype *prototype, Signature *signature, Ast *body, - Decl *decl, StacktraceType type); + Decl *decl); /** @@ -408,7 +408,7 @@ void llvm_emit_return_implicit(GenContext *c) llvm_emit_return_abi(c, NULL, &value); } -void llvm_emit_function_body(GenContext *c, Decl *decl, StacktraceType type) +void llvm_emit_function_body(GenContext *c, Decl *decl) { DEBUG_LOG("Generating function %s.", decl->extname); if (decl->func_decl.attr_dynamic) vec_add(c->dynamic_functions, decl); @@ -421,150 +421,27 @@ void llvm_emit_function_body(GenContext *c, Decl *decl, StacktraceType type) decl->backend_ref, type_get_resolved_prototype(decl->type), decl->func_decl.attr_naked ? NULL : &decl->func_decl.signature, - astptr(decl->func_decl.body), decl, type); -} - -static void llvm_emit_stacktrace_definitions(GenContext *c) -{ - const char *name = ".stacktrace_current"; - LLVMValueRef current_stack = c->debug.current_stack_ptr = llvm_add_global_raw(c, name, c->ptr_type, 0); - LLVMSetThreadLocal(current_stack, true); - LLVMSetInitializer(current_stack, llvm_get_zero_raw(c->ptr_type)); - llvm_set_weak(c, current_stack); - LLVMTypeRef uint_type = llvm_get_type(c, type_uint); - LLVMTypeRef args[7] = { c->ptr_type, c->ptr_type, c->size_type, c->ptr_type, c->size_type, uint_type, uint_type }; - LLVMTypeRef func_type = c->debug.stack_init_fn_type = LLVMFunctionType(LLVMVoidTypeInContext(c->context), args, 7, false); - LLVMValueRef func = c->debug.stack_init_fn = LLVMAddFunction(c->module, ".stacktrace_init", func_type); - llvm_set_weak(c, func); - LLVMBuilderRef builder = llvm_create_builder(c); - LLVMBasicBlockRef entry = LLVMAppendBasicBlockInContext(c->context, func, "entry"); - LLVMPositionBuilderAtEnd(builder, entry); - c->builder = builder; - LLVMValueRef stacktrace = LLVMGetParam(func, 0); - AlignSize align_to_use; - LLVMTypeRef slot_type = c->debug.stack_type; - AlignSize alignment = llvm_abi_alignment(c, slot_type); - LLVMValueRef prev_ptr = llvm_emit_struct_gep_raw(c, stacktrace, slot_type, 0, alignment, &align_to_use); - llvm_store_to_ptr_raw_aligned(c, prev_ptr, - LLVMBuildLoad2(c->builder, c->ptr_type, c->debug.current_stack_ptr, ""), - align_to_use); - LLVMValueRef func_name = llvm_emit_struct_gep_raw(c, stacktrace, slot_type, 1, alignment, &align_to_use); - LLVMValueRef func_name_ptr = llvm_emit_struct_gep_raw(c, func_name, c->chars_type, 0, align_to_use, &align_to_use); - llvm_store_to_ptr_raw_aligned(c, func_name_ptr, LLVMGetParam(func, 1), align_to_use); - LLVMValueRef func_name_sz = llvm_emit_struct_gep_raw(c, func_name, c->chars_type, 1, align_to_use, &align_to_use); - llvm_store_to_ptr_raw_aligned(c, func_name_sz, LLVMGetParam(func, 2), align_to_use); - - LLVMValueRef file_name = llvm_emit_struct_gep_raw(c, stacktrace, slot_type, 2, alignment, &align_to_use); - LLVMValueRef file_name_ptr = llvm_emit_struct_gep_raw(c, file_name, c->chars_type, 0, align_to_use, &align_to_use); - llvm_store_to_ptr_raw_aligned(c, file_name_ptr, LLVMGetParam(func, 3), align_to_use); - LLVMValueRef file_name_sz = llvm_emit_struct_gep_raw(c, file_name, c->chars_type, 1, align_to_use, &align_to_use); - llvm_store_to_ptr_raw_aligned(c, file_name_sz, LLVMGetParam(func, 4), align_to_use); - llvm_store_to_ptr_raw_aligned(c, c->debug.current_stack_ptr, stacktrace, type_alloca_alignment(type_voidptr)); - LLVMValueRef type = llvm_emit_struct_gep_raw(c, stacktrace, slot_type, 3, alignment, &align_to_use); - llvm_store_to_ptr_raw_aligned(c, type, LLVMGetParam(func, 5), align_to_use); - LLVMValueRef line = llvm_emit_struct_gep_raw(c, stacktrace, slot_type, 4, alignment, &align_to_use); - llvm_store_to_ptr_raw_aligned(c, line, LLVMGetParam(func, 6), align_to_use); - LLVMBuildRetVoid(c->builder); - LLVMDisposeBuilder(c->builder); - c->builder = NULL; -} - -void llvm_emit_pop_stacktrace(GenContext *c, Stacktrace *slot) -{ - if (!c->debug.emulated_stacktrace) return; - if (slot) - { - c->debug.stacktrace = *slot; - } - llvm_store_to_ptr_raw_aligned(c, c->debug.current_stack_ptr, c->debug.stacktrace.ref, type_alloca_alignment(type_voidptr)); -} -void llvm_emit_update_stack_row(GenContext *c, uint32_t row) -{ - if (!c->debug.emulated_stacktrace) return; - if (row == 0) row = 1; - if (c->debug.stacktrace.last_row == row) return; - c->debug.stacktrace.last_row = row; - llvm_store_to_ptr_raw_aligned(c, c->debug.stacktrace.row, llvm_const_int(c, type_uint, row), type_abi_alignment(type_uint)); - -} -void llvm_emit_push_emulated_stacktrace(GenContext *c, Decl *decl, const char *function_name, StacktraceType type) -{ - LLVMTypeRef slot_type = c->debug.stack_type; - AlignSize alignment = llvm_abi_alignment(c, slot_type); - LLVMValueRef stacktrace = llvm_emit_alloca(c, slot_type, alignment, ".$stacktrace"); - scratch_buffer_clear(); - scratch_buffer_append(decl->unit->module->name->module); - scratch_buffer_append("::"); - scratch_buffer_append(function_name); - size_t func_name_len = scratch_buffer.len; - LLVMValueRef func_name = llvm_emit_zstring_named(c, scratch_buffer_to_string(), ".callname"); - File *file = decl->unit->file; - size_t file_name_len = strlen(file->full_path); - LLVMValueRef file_name = llvm_emit_zstring_named(c, file->full_path, ".filename"); - LLVMValueRef args[] = {stacktrace, func_name, llvm_const_int(c, type_usz, func_name_len), - file_name, llvm_const_int(c, type_usz, file_name_len), - llvm_const_int(c, type_uint, type), - llvm_const_int(c, type_uint, decl->span.row)}; - LLVMValueRef call = LLVMBuildCall2(c->builder, c->debug.stack_init_fn_type, c->debug.stack_init_fn, args, 7, ""); - llvm_attribute_add_call(c, call, attribute_id.alwaysinline, -1, 0); - if (type == ST_FUNCTION && (function_name == kw_main || function_name == kw_mainstub)) - { - AlignSize align_size; - LLVMValueRef last = llvm_emit_struct_gep_raw(c, stacktrace, slot_type, 0, alignment, &align_size); - llvm_store_to_ptr_raw_aligned(c, last, LLVMConstNull(c->ptr_type), align_size); - } - LLVMValueRef row_ptr = LLVMBuildStructGEP2(c->builder, c->debug.stack_type, stacktrace, 4, ".$row"); - c->debug.stacktrace = (Stacktrace) { .row = row_ptr, .ref = stacktrace, .last_row = ~(uint32_t)0 }; + astptr(decl->func_decl.body), decl); } -void llvm_emit_body(GenContext *c, LLVMValueRef function, FunctionPrototype *prototype, - Signature *signature, Ast *body, Decl *decl, StacktraceType type) +void llvm_emit_body(GenContext *c, LLVMValueRef function, FunctionPrototype *prototype, Signature *signature, Ast *body, + Decl *decl) { bool emit_debug = llvm_use_debug(c); LLVMValueRef prev_function = c->function; LLVMBuilderRef prev_builder = c->builder; - bool use_emulated_stacktrace = emit_debug && c->debug.emulated_stacktrace; - if (use_emulated_stacktrace && !c->debug.stack_init_fn) - { - llvm_emit_stacktrace_definitions(c); - c->builder = prev_builder; - } c->opt_var = NULL; c->catch_block = NULL; - const char *function_name; - switch (type) - { - case ST_UNKNOWN: - UNREACHABLE - case ST_FUNCTION: - case ST_BENCHMARK: - case ST_TEST: - assert(decl->name); - function_name = decl->name; - break; - case ST_METHOD: - function_name = decl->name; - break; - case ST_LAMBDA: - function_name = "[lambda]"; - break; - case ST_MACRO: - function_name = decl->name; - break; - default: - UNREACHABLE - } - c->function = function; if (emit_debug) { c->debug.function = LLVMGetSubprogram(function); } - c->cur_func.name = function_name; + c->cur_func.name = decl->name; c->cur_func.prototype = prototype; LLVMBasicBlockRef entry = LLVMAppendBasicBlockInContext(c->context, c->function, "entry"); c->current_block = entry; @@ -582,10 +459,6 @@ void llvm_emit_body(GenContext *c, LLVMValueRef function, FunctionPrototype *pro { llvm_debug_scope_push(c, c->debug.function); EMIT_LOC(c, body); - if (use_emulated_stacktrace) - { - llvm_emit_push_emulated_stacktrace(c, decl, function_name, type); - } } c->optional_out = NULL; diff --git a/src/compiler/llvm_codegen_internal.h b/src/compiler/llvm_codegen_internal.h index 0a84ee014..27d253f5d 100644 --- a/src/compiler/llvm_codegen_internal.h +++ b/src/compiler/llvm_codegen_internal.h @@ -49,42 +49,17 @@ typedef struct DebugFile_ LLVMMetadataRef debug_file; } DebugFile; -typedef enum -{ - ST_UNKNOWN = 0, - ST_FUNCTION, - ST_METHOD, - ST_MACRO, - ST_LAMBDA, - ST_BENCHMARK, - ST_TEST, -} StacktraceType; - -typedef struct -{ - uint32_t last_row; - LLVMValueRef row; - LLVMValueRef ref; -} Stacktrace; - typedef struct { unsigned runtime_version : 8; bool enable_stacktrace : 1; - bool emulated_stacktrace : 1; LLVMDIBuilderRef builder; DebugFile *debug_files; DebugFile file; LLVMMetadataRef compile_unit; LLVMMetadataRef function; - SourceSpan current_range; LLVMMetadataRef *lexical_block_stack; LLVMMetadataRef inlined_at; - LLVMValueRef current_stack_ptr; - LLVMValueRef stack_init_fn; - LLVMTypeRef stack_init_fn_type; - LLVMTypeRef stack_type; - Stacktrace stacktrace; } DebugContext; @@ -512,7 +487,7 @@ void llvm_emit_subarray_len(GenContext *context, BEValue *subarray, BEValue *len void llvm_emit_subarray_pointer(GenContext *context, BEValue *subarray, BEValue *pointer); void llvm_emit_compound_stmt(GenContext *c, Ast *ast); LLVMValueRef llvm_emit_const_bitstruct(GenContext *c, ConstInitializer *initializer); -void llvm_emit_function_body(GenContext *context, Decl *decl, StacktraceType type); +void llvm_emit_function_body(GenContext *context, Decl *decl); void llvm_emit_dynamic_functions(GenContext *context, Decl **funcs); BEValue llvm_emit_assign_expr(GenContext *c, BEValue *ref, Expr *expr, LLVMValueRef optional); INLINE void llvm_emit_exprid(GenContext *c, BEValue *value, ExprId expr); @@ -545,9 +520,6 @@ void llvm_emit_debug_location(GenContext *c, SourceSpan location); void llvm_emit_debug_parameter(GenContext *c, Decl *parameter, unsigned index); void llvm_emit_debug_local_var(GenContext *c, Decl *var); void llvm_emit_debug_global_var(GenContext *c, Decl *global); -void llvm_emit_update_stack_row(GenContext *c, uint32_t row); -void llvm_emit_pop_stacktrace(GenContext *c, Stacktrace *slot); -void llvm_emit_push_emulated_stacktrace(GenContext *c, Decl *decl, const char *function_name, StacktraceType type); #define EMIT_LOC(c, x) do { if (c->debug.builder) llvm_emit_debug_location(c, x->span); } while (0) #define EMIT_SPAN(c, x) do { if (c->debug.builder) llvm_emit_debug_location(c, x); } while (0) diff --git a/src/compiler/llvm_codegen_module.c b/src/compiler/llvm_codegen_module.c index 0f9aa25f8..7f5691a1b 100644 --- a/src/compiler/llvm_codegen_module.c +++ b/src/compiler/llvm_codegen_module.c @@ -160,16 +160,7 @@ void gencontext_begin_module(GenContext *c) c->debug.builder = LLVMCreateDIBuilder(c->module); if (active_target.debug_info == DEBUG_INFO_FULL && safe_mode_enabled()) { - c->debug.stack_type = LLVMStructCreateNamed(c->context, ".$callstack"); - LLVMTypeRef types[5] = { c->ptr_type, - c->chars_type, - c->chars_type, - llvm_get_type(c, type_uint), - llvm_get_type(c, type_uint) }; - LLVMStructSetBody(c->debug.stack_type, types, 5, false); - c->debug.current_stack_ptr = NULL; - c->debug.enable_stacktrace = true; - c->debug.emulated_stacktrace = !os_supports_stacktrace(platform_target.os); + c->debug.enable_stacktrace = os_supports_stacktrace(platform_target.os); } } c->global_builder = LLVMCreateBuilder(); diff --git a/src/compiler/llvm_codegen_stmt.c b/src/compiler/llvm_codegen_stmt.c index 80da0ca11..f2f11b628 100644 --- a/src/compiler/llvm_codegen_stmt.c +++ b/src/compiler/llvm_codegen_stmt.c @@ -1304,7 +1304,6 @@ void llvm_emit_unreachable(GenContext *c) void llvm_emit_panic(GenContext *c, const char *message, SourceSpan loc, const char *fmt, BEValue *varargs) { if (c->debug.builder) llvm_emit_debug_location(c, loc); - llvm_emit_update_stack_row(c, loc.row); Decl *panic_var = c->panic_var; if (!panic_var) diff --git a/src/compiler/sema_builtins.c b/src/compiler/sema_builtins.c index bb80f66e6..e38b12832 100644 --- a/src/compiler/sema_builtins.c +++ b/src/compiler/sema_builtins.c @@ -339,7 +339,6 @@ bool sema_expr_analyse_builtin_call(SemaContext *context, Expr *expr) expr->type = type_int; return true; case BUILTIN_FRAMEADDRESS: - case BUILTIN_STACKTRACE: expr->type = type_voidptr; return true; case BUILTIN_COMPARE_EXCHANGE: @@ -870,7 +869,6 @@ bool sema_expr_analyse_builtin_call(SemaContext *context, Expr *expr) case BUILTIN_GET_ROUNDING_MODE: case BUILTIN_SWIZZLE: case BUILTIN_SWIZZLE2: - case BUILTIN_STACKTRACE: case BUILTIN_SYSCLOCK: case BUILTIN_TRAP: case BUILTIN_UNREACHABLE: @@ -891,7 +889,6 @@ static inline int builtin_expected_args(BuiltinFunction func) case BUILTIN_SWIZZLE2: return -3; case BUILTIN_GET_ROUNDING_MODE: - case BUILTIN_STACKTRACE: case BUILTIN_SYSCLOCK: case BUILTIN_TRAP: case BUILTIN_UNREACHABLE: diff --git a/src/compiler/symtab.c b/src/compiler/symtab.c index 691c1bb85..bf364851f 100644 --- a/src/compiler/symtab.c +++ b/src/compiler/symtab.c @@ -278,7 +278,6 @@ void symtab_init(uint32_t capacity) builtin_list[BUILTIN_SWIZZLE] = KW_DEF("swizzle"); builtin_list[BUILTIN_SWIZZLE2] = KW_DEF("swizzle2"); builtin_list[BUILTIN_SQRT] = KW_DEF("sqrt"); - builtin_list[BUILTIN_STACKTRACE] = KW_DEF("stacktrace"); builtin_list[BUILTIN_SYSCALL] = KW_DEF("syscall"); builtin_list[BUILTIN_SYSCLOCK] = KW_DEF("sysclock"); builtin_list[BUILTIN_TRAP] = KW_DEF("trap"); diff --git a/src/version.h b/src/version.h index 33c1a3fd0..95d4db64a 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define COMPILER_VERSION "0.4.705" +#define COMPILER_VERSION "0.4.706"