From ac3b2f0fea24f5cb00f1b00562b958c16b292c41 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Wed, 29 Jan 2025 13:07:19 +0100 Subject: [PATCH] - Fix bug where in dead code, only the first statement would be turned into a nop. - Remove unused $inline argument to mem::copy. --- lib/std/core/mem.c3 | 2 +- releasenotes.md | 2 + src/compiler/sema_stmts.c | 2 +- .../test_suite/statements/dead_statements.c3t | 44 +++++++++++++++++++ 4 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 test/test_suite/statements/dead_statements.c3t diff --git a/lib/std/core/mem.c3 b/lib/std/core/mem.c3 index 32c63d993..59c00f0ef 100644 --- a/lib/std/core/mem.c3 +++ b/lib/std/core/mem.c3 @@ -323,7 +323,7 @@ macro void clear_inline(void* dst, usz $len, usz $dst_align = 0, bool $is_volati @require len == 0 || dst + len <= src || src + len <= dst : "Ranges may not overlap" *> -macro void copy(void* dst, void* src, usz len, usz $dst_align = 0, usz $src_align = 0, bool $is_volatile = false, bool $inlined = false) +macro void copy(void* dst, void* src, usz len, usz $dst_align = 0, usz $src_align = 0, bool $is_volatile = false) { $$memcpy(dst, src, len, $is_volatile, $dst_align, $src_align); } diff --git a/releasenotes.md b/releasenotes.md index 5db52c146..f67660e89 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -33,6 +33,8 @@ - Fixes miscompilation of nested `@jump` #1896. - Fixed STB_WEAK errors when using consts in macros in the stdlib #1871. - Missing error when placing a single statement for-body on a new row #1892. +- Fix bug where in dead code, only the first statement would be turned into a nop. +- Remove unused $inline argument to mem::copy. ### Stdlib changes - Added '%h' and '%H' for printing out binary data in hexadecimal using the formatter. diff --git a/src/compiler/sema_stmts.c b/src/compiler/sema_stmts.c index a15dad0cb..5bdacc973 100644 --- a/src/compiler/sema_stmts.c +++ b/src/compiler/sema_stmts.c @@ -3156,8 +3156,8 @@ bool sema_analyse_statement(SemaContext *context, Ast *statement) } } // Remove it - statement->ast_kind = AST_NOP_STMT; } + statement->ast_kind = AST_NOP_STMT; } return true; } diff --git a/test/test_suite/statements/dead_statements.c3t b/test/test_suite/statements/dead_statements.c3t new file mode 100644 index 000000000..a7a716a44 --- /dev/null +++ b/test/test_suite/statements/dead_statements.c3t @@ -0,0 +1,44 @@ +// #target: macos-x64 +module test; +import std::io; +import std::io::path; +import std::collections::list; + +fn void! load_corpus2(String code, String path) @local +{ + for(;;) io::printfn("hi"); // #warning: This code will never execute + path::Path p = path::temp_new(path)!; + + if (!path::exists(p)) + { + return IoError.FILE_NOT_FOUND?; + } +} + +fn int main(String[] args) +{ + if (catch err = load_corpus2("foo", "bar")) + { + return 1; + } + return 0; +} +/* #expect: test.ll + +define internal i64 @test.load_corpus2(ptr %0, i64 %1, ptr %2, i64 %3) #0 { +entry: + %code = alloca %"char[]", align 8 + %path = alloca %"char[]", align 8 + %retparam = alloca i64, align 8 + store ptr %0, ptr %code, align 8 + %ptradd = getelementptr inbounds i8, ptr %code, i64 8 + store i64 %1, ptr %ptradd, align 8 + store ptr %2, ptr %path, align 8 + %ptradd1 = getelementptr inbounds i8, ptr %path, i64 8 + store i64 %3, ptr %ptradd1, align 8 + br label %loop.body + +loop.body: ; preds = %loop.body, %entry + %4 = call i64 @std.io.printfn(ptr %retparam, ptr @.str, i64 2, ptr null, i64 0) + br label %loop.body +}