From fab6e5cdff1541d4d96f462ce584a867ceffe5e8 Mon Sep 17 00:00:00 2001 From: whitequark Date: Fri, 10 Aug 2018 12:02:49 +0000 Subject: [PATCH] compiler: skip functional values in attribute writeback. Fixes #1088. --- artiq/compiler/transforms/llvm_ir_generator.py | 14 +++++++++----- artiq/test/lit/embedding/fn_ptr_list.py | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 artiq/test/lit/embedding/fn_ptr_list.py diff --git a/artiq/compiler/transforms/llvm_ir_generator.py b/artiq/compiler/transforms/llvm_ir_generator.py index 013d2a5ea..b39c2b5bc 100644 --- a/artiq/compiler/transforms/llvm_ir_generator.py +++ b/artiq/compiler/transforms/llvm_ir_generator.py @@ -525,11 +525,10 @@ class LLVMIRGenerator: print(typ) assert False - if not (types.is_function(typ) or types.is_method(typ) or types.is_rpc(typ) or - name == "__objectid__"): - rpctag = b"Os" + self._rpc_tag(typ, error_handler=rpc_tag_error) + b":n" - else: + if name == "__objectid__": rpctag = b"" + else: + rpctag = b"Os" + self._rpc_tag(typ, error_handler=rpc_tag_error) + b":n" llrpcattrinit = ll.Constant(llrpcattrty, [ ll.Constant(lli32, offset), @@ -562,7 +561,10 @@ class LLVMIRGenerator: offset += alignment - (offset % alignment) if types.is_instance(typ) and attr not in typ.constant_attributes: - llrpcattrs.append(llrpcattr_of_attr(offset, attr, attrtyp)) + try: + llrpcattrs.append(llrpcattr_of_attr(offset, attr, attrtyp)) + except ValueError: + continue offset += size @@ -1267,6 +1269,8 @@ class LLVMIRGenerator: elif ir.is_keyword(typ): return b"k" + self._rpc_tag(typ.params["value"], error_handler) + elif types.is_function(typ) or types.is_method(typ) or types.is_rpc(typ): + raise ValueError("RPC tag for functional value") elif '__objectid__' in typ.attributes: return b"O" else: diff --git a/artiq/test/lit/embedding/fn_ptr_list.py b/artiq/test/lit/embedding/fn_ptr_list.py new file mode 100644 index 000000000..73e6ad3be --- /dev/null +++ b/artiq/test/lit/embedding/fn_ptr_list.py @@ -0,0 +1,15 @@ +# RUN: %python -m artiq.compiler.testbench.embedding %s + +from artiq.language.core import * +from artiq.language.types import * + +@kernel +def a(): + pass + +fns = [a, a] + +@kernel +def entrypoint(): + fns[0]() + fns[1]()