From 45a94cfe862cfb039ae6b976f2e7dd8288818196 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Sat, 14 Sep 2024 13:48:27 +0200 Subject: [PATCH] Asserts are now correctly included and traced in when running tests. Removed accidental debug trace. --- releasenotes.md | 1 + src/compiler/compiler_internal.h | 5 +++++ src/compiler/llvm_codegen_expr.c | 7 ------- src/compiler/llvm_codegen_stmt.c | 2 +- src/compiler/sema_liveness.c | 4 ++-- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/releasenotes.md b/releasenotes.md index 50c05570c..5a0126c84 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -23,6 +23,7 @@ - Fix regression for `$include`. - Correct '.so' suffix on dynamic libraries on Linux. - Fix bug where inline index access to array in a struct would crash the compiler. +- Asserts are now correctly included and traced in when running tests. ### Stdlib changes - Additional init functions for hashmap. diff --git a/src/compiler/compiler_internal.h b/src/compiler/compiler_internal.h index 16dd61220..b425f49cc 100644 --- a/src/compiler/compiler_internal.h +++ b/src/compiler/compiler_internal.h @@ -1931,6 +1931,11 @@ INLINE bool no_stdlib(void) return compiler.build.use_stdlib == USE_STDLIB_OFF; } +INLINE bool compile_asserts(void) +{ + return safe_mode_enabled() || compiler.build.testing; +} + bool ast_is_not_empty(Ast *ast); bool ast_is_compile_time(Ast *ast); diff --git a/src/compiler/llvm_codegen_expr.c b/src/compiler/llvm_codegen_expr.c index c4764d772..461dbbd7e 100644 --- a/src/compiler/llvm_codegen_expr.c +++ b/src/compiler/llvm_codegen_expr.c @@ -2565,13 +2565,6 @@ static inline void llvm_emit_deref(GenContext *c, BEValue *value, Expr *inner, T if (safe_mode_enabled()) { LLVMValueRef check = LLVMBuildICmp(c->builder, LLVMIntEQ, value->value, llvm_get_zero(c, inner->type), "checknull"); - assert(!LLVMIsPoison(check)); - if (llvm_is_const(check)) - { - LLVMDumpValue(check); - printf("-- %lld value\n", LLVMConstIntGetSExtValue(check)); - - } scratch_buffer_clear(); scratch_buffer_append("Dereference of null pointer, '"); span_to_scratch(inner->span); diff --git a/src/compiler/llvm_codegen_stmt.c b/src/compiler/llvm_codegen_stmt.c index c6f64d3e0..767b6caf0 100644 --- a/src/compiler/llvm_codegen_stmt.c +++ b/src/compiler/llvm_codegen_stmt.c @@ -1176,7 +1176,7 @@ static inline void llvm_emit_assert_stmt(GenContext *c, Ast *ast) { ExprId exprid = ast->assert_stmt.expr; Expr *assert_expr = exprptr(exprid); - if (safe_mode_enabled() || compiler.build.testing) + if (compile_asserts()) { BEValue value; llvm_emit_expr(c, &value, assert_expr); diff --git a/src/compiler/sema_liveness.c b/src/compiler/sema_liveness.c index 7eed0dc61..038fdfd2d 100644 --- a/src/compiler/sema_liveness.c +++ b/src/compiler/sema_liveness.c @@ -143,11 +143,11 @@ static void sema_trace_stmt_liveness(Ast *ast) case AST_ASSERT_STMT: { Expr *e = exprptr(ast->assert_stmt.expr); - if (safe_mode_enabled() || expr_is_pure(e)) + if (compile_asserts() || expr_is_pure(e)) { sema_trace_expr_liveness(e); } - if (safe_mode_enabled()) + if (compile_asserts()) { sema_trace_exprid_liveness(ast->assert_stmt.message); sema_trace_expr_list_liveness(ast->assert_stmt.args);