From dde73e029cefcbc1795ff97712c8548a8cbb4f3a Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Fri, 22 Sep 2023 23:24:12 +0200 Subject: [PATCH] Fix of issue #1008 --- src/compiler/sema_expr.c | 1 + src/version.h | 2 +- .../macros/unifying_implicit_void.c3t | 86 +++++++++++++++++++ 3 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 test/test_suite/macros/unifying_implicit_void.c3t diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 68625438d..a6063d82e 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -1747,6 +1747,7 @@ static inline Type *context_unify_returns(SemaContext *context) Expr *ret_expr = return_stmt->return_stmt.expr; if (!ret_expr) { + if (common_type == type_void) continue; context_unify_returns(context); } // 8. All casts should work. diff --git a/src/version.h b/src/version.h index e1900585d..e896da68d 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define COMPILER_VERSION "0.4.656" \ No newline at end of file +#define COMPILER_VERSION "0.4.657" \ No newline at end of file diff --git a/test/test_suite/macros/unifying_implicit_void.c3t b/test/test_suite/macros/unifying_implicit_void.c3t new file mode 100644 index 000000000..b3bfbc646 --- /dev/null +++ b/test/test_suite/macros/unifying_implicit_void.c3t @@ -0,0 +1,86 @@ +// #target: macos-x64 +module oups; +import std::io; + +fn void! main() +{ + ByteReader r; + r.foo()!; +} + +macro Stream.foo(&self) +{ + char! c = self.read_byte(); + if (catch err = c) + { + return err?; + } + return; +} + + +/* #expect: oups.ll + + +define i64 @oups.main() #0 { +entry: + %r = alloca %ByteReader, align 8 + %error_var = alloca i64, align 8 + %c = alloca i8, align 1 + %c.f = alloca i64, align 8 + %retparam = alloca i8, align 1 + %err = alloca i64, align 8 + call void @llvm.memset.p0.i64(ptr align 8 %r, i8 0, i64 32, i1 false) + %0 = getelementptr inbounds %ByteReader, ptr %r, i32 0, i32 0 + %1 = call i64 @std.io.Stream.read_byte(ptr %retparam, ptr %0) #3 + %not_err = icmp eq i64 %1, 0 + %2 = call i1 @llvm.expect.i1(i1 %not_err, i1 true) + br i1 %2, label %after_check, label %assign_optional + +assign_optional: ; preds = %entry + store i64 %1, ptr %c.f, align 8 + br label %after_assign + +after_check: ; preds = %entry + %3 = load i8, ptr %retparam, align 1 + store i8 %3, ptr %c, align 1 + store i64 0, ptr %c.f, align 8 + br label %after_assign + +after_assign: ; preds = %after_check, %assign_optional + br label %testblock + +testblock: ; preds = %after_assign + %optval = load i64, ptr %c.f, align 8 + %not_err1 = icmp eq i64 %optval, 0 + %4 = call i1 @llvm.expect.i1(i1 %not_err1, i1 true) + br i1 %4, label %after_check3, label %assign_optional2 + +assign_optional2: ; preds = %testblock + store i64 %optval, ptr %err, align 8 + br label %end_block + +after_check3: ; preds = %testblock + store i64 0, ptr %err, align 8 + br label %end_block + +end_block: ; preds = %after_check3, %assign_optional2 + %5 = load i64, ptr %err, align 8 + %neq = icmp ne i64 %5, 0 + br i1 %neq, label %if.then, label %if.exit + +if.then: ; preds = %end_block + %6 = load i64, ptr %err, align 8 + store i64 %6, ptr %error_var, align 8 + br label %guard_block + +if.exit: ; preds = %end_block + br label %noerr_block + +guard_block: ; preds = %if.then + %7 = load i64, ptr %error_var, align 8 + ret i64 %7 + +noerr_block: ; preds = %if.exit + ret i64 0 +} \ No newline at end of file