compiler: Handle None-returning function calls used as values

GitHub: Fixes #1493.
This commit is contained in:
David Nadlinger 2020-07-25 02:18:10 +01:00
parent 57e759a1ed
commit 1c72585c1b
2 changed files with 16 additions and 0 deletions

View File

@ -1481,6 +1481,11 @@ class LLVMIRGenerator:
else: else:
llcall = llresult = self.llbuilder.call(llfun, llargs, name=insn.name) 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! # Never add TBAA nowrite metadata to a functon with sret!
# This leads to miscompilations. # This leads to miscompilations.
if types.is_c_function(functiontyp) and 'nowrite' in functiontyp.flags: if types.is_c_function(functiontyp) and 'nowrite' in functiontyp.flags:

View File

@ -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)