From 8a7af3f75c353c9809dabe16714af70cb9215567 Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Sat, 7 May 2022 21:21:12 +0100 Subject: [PATCH] compiler: Fix "nowrite" miscompilation for sret functions This affected e.g. rtio_input_timestamped_data(). --- artiq/compiler/transforms/llvm_ir_generator.py | 5 ++++- artiq/test/lit/embedding/syscall_flags.py | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/artiq/compiler/transforms/llvm_ir_generator.py b/artiq/compiler/transforms/llvm_ir_generator.py index 50ce33f61..881a9e717 100644 --- a/artiq/compiler/transforms/llvm_ir_generator.py +++ b/artiq/compiler/transforms/llvm_ir_generator.py @@ -1409,7 +1409,10 @@ class LLVMIRGenerator: llfun.args[idx].add_attribute(attr) if 'nounwind' in insn.target_function().type.flags: llfun.attributes.add('nounwind') - if 'nowrite' in insn.target_function().type.flags: + if 'nowrite' in insn.target_function().type.flags and not is_sret: + # Even if "nowrite" is correct from the user's perspective (doesn't + # access any other memory observable to ARTIQ Python), this isn't + # true on the LLVM IR level for sret return values. llfun.attributes.add('inaccessiblememonly') return llfun, list(llargs), llarg_attrs, llcallstackptr diff --git a/artiq/test/lit/embedding/syscall_flags.py b/artiq/test/lit/embedding/syscall_flags.py index f8c618c3f..cc78f843b 100644 --- a/artiq/test/lit/embedding/syscall_flags.py +++ b/artiq/test/lit/embedding/syscall_flags.py @@ -13,6 +13,14 @@ from artiq.language.types import * def foo() -> TNone: pass +# sret nowrite functions shouldn't be marked inaccessiblememonly. +# CHECK-L: ; Function Attrs: nounwind +# CHECK-NEXT-L: declare void @bar({ i32, i64 }* sret) +@syscall(flags={"nounwind", "nowrite"}) +def bar() -> TTuple([TInt32, TInt64]): + pass + @kernel def entrypoint(): foo() + bar()