-
-
Notifications
You must be signed in to change notification settings - Fork 419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix serialisation of Array and String #2246
Conversation
This change fixes a bug in Array/String_Serialise_Trace where the data pointer would be traced for immutable and opaque objects, instead of mutable and immutable ones. Closes ponylang#2245.
This is what I get locally for the source of the test failures:
|
Looking at this, it appears to fail for Arrays of Strings. It passes if I turn off this test:
|
@Praetonus The following diff fixes the original issue and the segfault that CI is running into with your current fix: diff --git a/src/libponyc/codegen/genprim.c b/src/libponyc/codegen/genprim.c
index 0e6c9b7..d1fa836 100644
--- a/src/libponyc/codegen/genprim.c
+++ b/src/libponyc/codegen/genprim.c
@@ -782,7 +782,7 @@ void genprim_array_serialise_trace(compile_t* c, reach_type_t* t)
LLVMBasicBlockRef post_block = codegen_block(c, "post");
LLVMValueRef cond = LLVMBuildICmp(c->builder, LLVMIntNE, size,
- LLVMConstInt(c->intptr, PONY_TRACE_OPAQUE, false), "");
+ LLVMConstInt(c->intptr, 0, false), "");
LLVMBuildCondBr(c->builder, cond, trace_block, post_block);
LLVMPositionBuilderAtEnd(c->builder, trace_block);
@@ -1044,15 +1044,6 @@ void genprim_string_serialise_trace(compile_t* c, reach_type_t* t)
LLVMValueRef size = field_value(c, object, 1);
- LLVMBasicBlockRef trace_block = codegen_block(c, "trace");
- LLVMBasicBlockRef post_block = codegen_block(c, "post");
-
- LLVMValueRef cond = LLVMBuildICmp(c->builder, LLVMIntNE, size,
- LLVMConstInt(c->intptr, PONY_TRACE_OPAQUE, false), "");
- LLVMBuildCondBr(c->builder, cond, trace_block, post_block);
-
- LLVMPositionBuilderAtEnd(c->builder, trace_block);
-
LLVMValueRef alloc = LLVMBuildAdd(c->builder, size,
LLVMConstInt(c->intptr, 1, false), "");
@@ -1065,10 +1056,6 @@ void genprim_string_serialise_trace(compile_t* c, reach_type_t* t)
args[2] = alloc;
gencall_runtime(c, "pony_serialise_reserve", args, 3, "");
- LLVMBuildBr(c->builder, post_block);
-
- LLVMPositionBuilderAtEnd(c->builder, post_block);
-
LLVMBuildRetVoid(c->builder);
codegen_finishfun(c);
} The condition in ponyc/src/libponyc/codegen/genprim.c Lines 784 to 785 in a5c4948
0 and not be changed to PONY_TRACE_OPAQUE because it is comparing with the size of the array to determine if there are any elements to serialise or not. Changing it to not serialize the elements when there are PONY_TRACE_OPAQUE (2 ) elements is not correct.
The condition in ponyc/src/libponyc/codegen/genprim.c Lines 1050 to 1051 in a5c4948
size of a string to determine if there is anything to serialize or not. This originally caused a segfault because the call to pony_serialise_reserve wasn't made if the size == 0 (as reported in #2245) and then when pony_serialise_offset is called by genprim_string_serialise later it results in a segfault because the pointer address wasn't added to the serialize hashmap by pony_serialise_reserve earlier and the check at ponyc/src/libponyrt/gc/serialise.c Lines 199 to 213 in a5c4948
pony_type_t for a pointer. The change to PONY_TRACE_OPAQUE happened to cause the segfault to now occur for any strings of length 2 instead of length 0 and luckily one of the values in the serialise/Arrays test happened to be a 2 character string.
While the diff I've proposed removes the conditional check altogether from |
I'm closing this as we merged #2247. |
This change fixes a bug in
Array/String_Serialise_Trace
where the data pointer would be traced for immutable and opaque objects, instead of mutable and immutable ones.Closes #2245.