diff --git a/artiq/compiler/transforms/llvm_ir_generator.py b/artiq/compiler/transforms/llvm_ir_generator.py index ca302412d..0d753c991 100644 --- a/artiq/compiler/transforms/llvm_ir_generator.py +++ b/artiq/compiler/transforms/llvm_ir_generator.py @@ -1462,6 +1462,11 @@ class LLVMIRGenerator: else: llcall = llresult = self.llbuilder.call(llfun, llargs, name=insn.name) + if isinstance(llresult.type, ll.VoidType): + # We have NoneType-returning functions return void, but None is + # {} elsewhere. + llresult = ll.Constant(llunit, []) + # Never add TBAA nowrite metadata to a functon with sret! # This leads to miscompilations. if types.is_c_function(functiontyp) and 'nowrite' in functiontyp.flags: diff --git a/artiq/test/lit/codegen/none_retval.py b/artiq/test/lit/codegen/none_retval.py new file mode 100644 index 000000000..ed2c9eb25 --- /dev/null +++ b/artiq/test/lit/codegen/none_retval.py @@ -0,0 +1,11 @@ +# RUN: %python -m artiq.compiler.testbench.llvmgen %s + +def make_none(): + return None + +def take_arg(arg): + pass + +def run(): + retval = make_none() + take_arg(retval)