From f8d15069227298492ce539d793cfedfd8a80874c Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Tue, 28 Jul 2020 00:33:28 +0100 Subject: [PATCH] compiler: Fix lifetime tracking for function call return values GitHub: Fixes #1497. --- artiq/compiler/validators/escape.py | 2 +- artiq/test/lit/escape/error_call.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 artiq/test/lit/escape/error_call.py diff --git a/artiq/compiler/validators/escape.py b/artiq/compiler/validators/escape.py index 000c3ee5b..5aae58e51 100644 --- a/artiq/compiler/validators/escape.py +++ b/artiq/compiler/validators/escape.py @@ -103,7 +103,7 @@ class RegionOf(algorithm.Visitor): # The cache is borrow checked dynamically return Global() else: - self.visit_sometimes_allocating(node) + return self.visit_sometimes_allocating(node) # Value lives as long as the object/container, if it's mutable, # or else forever diff --git a/artiq/test/lit/escape/error_call.py b/artiq/test/lit/escape/error_call.py new file mode 100644 index 000000000..8bbc7992f --- /dev/null +++ b/artiq/test/lit/escape/error_call.py @@ -0,0 +1,14 @@ +# RUN: %python -m artiq.compiler.testbench.embedding +diag %s 2>%t +# RUN: OutputCheck %s --file-to-check=%t + +from artiq.experiment import * + +@kernel +def leak(a): + return a + +@kernel +def entrypoint(): + # CHECK-L: ${LINE:+2}: error: cannot return an allocated value that does not live forever + # CHECK-L: ${LINE:+1}: note: ... to this point + return leak([1, 2, 3])