From 5dc3b3b28cd3b0581733e6839acde11d33c94ee0 Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Sat, 25 Jul 2020 02:18:10 +0100 Subject: [PATCH] compiler: Handle None-returning function calls used as values GitHub: Fixes #1493. --- artiq/compiler/transforms/llvm_ir_generator.py | 5 +++++ artiq/test/lit/codegen/none_retval.py | 11 +++++++++++ 2 files changed, 16 insertions(+) create mode 100644 artiq/test/lit/codegen/none_retval.py 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)