Skip to content

Commit

Permalink
Fix serialisation of Array and String
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Benoit Vey committed Sep 22, 2017
1 parent 9e26f0a commit a5c4948
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/libponyc/codegen/genprim.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, 0, false), "");
LLVMConstInt(c->intptr, PONY_TRACE_OPAQUE, false), "");
LLVMBuildCondBr(c->builder, cond, trace_block, post_block);

LLVMPositionBuilderAtEnd(c->builder, trace_block);
Expand Down Expand Up @@ -1048,7 +1048,7 @@ void genprim_string_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, 0, false), "");
LLVMConstInt(c->intptr, PONY_TRACE_OPAQUE, false), "");
LLVMBuildCondBr(c->builder, cond, trace_block, post_block);

LLVMPositionBuilderAtEnd(c->builder, trace_block);
Expand Down
28 changes: 28 additions & 0 deletions test/libponyc/codegen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,34 @@ TEST_F(CodegenTest, ViewpointAdaptedFieldReach)
}


TEST_F(CodegenTest, StringSerialization)
{
// From issue 2245
const char* src =
"use \"serialise\"\n"

"class V\n"
" let _v: String = \"\"\n"

"actor Main\n"
" new create(env: Env) =>\n"
" try\n"
" let auth = env.root as AmbientAuth\n"
" let v: V = V\n"
" Serialised(SerialiseAuth(auth), v)?\n"
" @pony_exitcode[None](I32(1))\n"
" end";

set_builtin(NULL);

TEST_COMPILE(src);

int exit_code = 0;
ASSERT_TRUE(run_program(&exit_code));
ASSERT_EQ(exit_code, 1);
}


TEST_F(CodegenTest, CustomSerialization)
{
const char* src =
Expand Down

0 comments on commit a5c4948

Please sign in to comment.