Skip to content

Commit

Permalink
Take alignment into account during attribute writeback (fixes #293).
Browse files Browse the repository at this point in the history
whitequark committed Feb 25, 2016
1 parent 914bc9f commit a1dd909
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions artiq/compiler/transforms/llvm_ir_generator.py
Original file line number Diff line number Diff line change
@@ -443,7 +443,7 @@ def emit_attribute_writeback(self):
lldatalayout = llvm.create_target_data(self.llmodule.data_layout)

llrpcattrty = self.llcontext.get_identified_type("attr_desc")
llrpcattrty.elements = [lli32, llptr, llptr]
llrpcattrty.elements = [lli32, lli32, llptr, llptr]

lldescty = self.llcontext.get_identified_type("type_desc")
lldescty.elements = [llrpcattrty.as_pointer().as_pointer(), llptr.as_pointer()]
@@ -459,7 +459,10 @@ def emit_attribute_writeback(self):
type_name = "instance.{}".format(typ.name)

def llrpcattr_of_attr(name, typ):
size = self.llty_of_type(typ).get_abi_size(lldatalayout, context=self.llcontext)
size = self.llty_of_type(typ). \
get_abi_size(lldatalayout, context=self.llcontext)
alignment = self.llty_of_type(typ). \
get_abi_alignment(lldatalayout, context=self.llcontext)

def rpc_tag_error(typ):
print(typ)
@@ -476,6 +479,7 @@ def rpc_tag_error(typ):
name="attr.{}.{}".format(type_name, name))
llrpcattr.initializer = ll.Constant(llrpcattrty, [
ll.Constant(lli32, size),
ll.Constant(lli32, alignment),
llrpctag,
self.llstr_of_str(name)
])
4 changes: 4 additions & 0 deletions artiq/runtime/ksupport.c
Original file line number Diff line number Diff line change
@@ -407,6 +407,7 @@ int recv_rpc(void *slot) {

struct attr_desc {
uint32_t size;
uint32_t alignment;
const char *tag;
const char *name;
};
@@ -434,6 +435,9 @@ void attribute_writeback(void *utypes) {
while(*attrs) {
struct attr_desc *attr = *attrs++;

if(offset % attr->alignment != 0)
offset += attr->alignment - (offset % attr->alignment);

if(attr->tag) {
uintptr_t value = (uintptr_t)object + offset;
send_rpc(0, attr->tag, &object, &attr->name, value);

0 comments on commit a1dd909

Please sign in to comment.