From c0f781e6839e8834e12c5d94a0d936c7015f77db Mon Sep 17 00:00:00 2001 From: Sean T Allen Date: Tue, 6 Feb 2024 14:10:17 -0500 Subject: [PATCH] Fix bug when serializing bare lambdas (#4486) A bug in the handling of serializing bare lambdas was introduced when we updated to LLVM 15. This commit contains the fix. Joe wrote the fix during a sync call after I identified the offending function during triage of a Red reported issue. Closes #4479 --- .release-notes/4479.md | 7 +++++++ src/libponyc/codegen/genserialise.c | 2 +- test/full-program-tests/regression-4479/main.pony | 9 +++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 .release-notes/4479.md create mode 100644 test/full-program-tests/regression-4479/main.pony diff --git a/.release-notes/4479.md b/.release-notes/4479.md new file mode 100644 index 0000000000..7cf8e6483e --- /dev/null +++ b/.release-notes/4479.md @@ -0,0 +1,7 @@ +## Fix esoteric bug with serializing bare lambdas + +Almost no one uses bare lambdas. And even fewer folks end up passing them through the Pony serialization code. So, of course, Red Davies did just that. And of course, he found a bug. + +When we switched to LLVM 15 in 0.54.1, we had to account for a rather large change with how LLVM handles pointer and types. In the process of doing that update, a mistake was made and serializing of bare lambdas was broken. + +We've made the fix and introduced a regression test. Enjoy your fix Red! diff --git a/src/libponyc/codegen/genserialise.c b/src/libponyc/codegen/genserialise.c index 75fd99d320..5f61be8983 100644 --- a/src/libponyc/codegen/genserialise.c +++ b/src/libponyc/codegen/genserialise.c @@ -290,7 +290,7 @@ static void deserialise_bare_interface(compile_t* c, LLVMValueRef ptr) LLVMValueRef desc = LLVMBuildInBoundsGEP2(c->builder, LLVMArrayType(c->ptr, 0), c->desc_table, args, 2, ""); - desc = LLVMBuildLoad2(c->builder, c->descriptor_type, desc, ""); + desc = LLVMBuildLoad2(c->builder, c->ptr, desc, ""); LLVMValueRef func = gendesc_instance(c, desc); LLVMBuildStore(c->builder, func, ptr); } diff --git a/test/full-program-tests/regression-4479/main.pony b/test/full-program-tests/regression-4479/main.pony new file mode 100644 index 0000000000..9690aafd54 --- /dev/null +++ b/test/full-program-tests/regression-4479/main.pony @@ -0,0 +1,9 @@ +actor Main + new create(env: Env) => None + let cb: Callbacks = Callbacks + +class Callbacks + var cbi: @{(): None} + + new create() => + cbi = @{() => None}