From f1d58edc6ed8c762a86d53df378beb44a10ac91a Mon Sep 17 00:00:00 2001 From: Pavel Durov Date: Sat, 7 Dec 2024 14:09:43 +0000 Subject: [PATCH] Add test that validates swt clone module function references. --- tests/c/swt_module_clone.c | 49 ++++++++++++++++++++++++++++++++++++++ ykllvm | 2 +- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 tests/c/swt_module_clone.c diff --git a/tests/c/swt_module_clone.c b/tests/c/swt_module_clone.c new file mode 100644 index 000000000..a9e6cea8f --- /dev/null +++ b/tests/c/swt_module_clone.c @@ -0,0 +1,49 @@ +// ignore-if: test "$YKB_TRACER" != "swt" +// Run-time: +// env-var: YKD_LOG_IR=-:aot,jit-pre-opt +// env-var: YKD_SERIALISE_COMPILATION=1 +// env-var: YK_LOG=4 +// status: success + +// Check that functions which address is taken can refer to other +// functions which address is not taken. This test is specific for SWT +// with module cloning enabled. Note that the cloned functions will not +// be visible in the aot ir since they are not serialised. + +#include +#include +#include +#include +#include +#include + +int add(int i, int j) { return i + j; } + +int dec(int i) { return add(i, -1); } + +int main(int argc, char **argv) { + YkMT *mt = yk_mt_new(NULL); + yk_mt_hot_threshold_set(mt, 0); + YkLocation loc = yk_location_new(); + + int res = 9998; + int i = 4; + NOOPT_VAL(loc); + NOOPT_VAL(res); + NOOPT_VAL(i); + + // Take a reference to the 'dec' function using a function pointer. + // This will cause dec function to not be cloned. + int (*dec_ptr)(int) = dec; + + while (i > 0) { + yk_mt_control_point(mt, &loc); + fprintf(stderr, "%d\n", i); + i = dec_ptr(i); + } + fprintf(stderr, "exit\n"); + NOOPT_VAL(res); + yk_location_drop(loc); + yk_mt_shutdown(mt); + return (EXIT_SUCCESS); +} diff --git a/ykllvm b/ykllvm index c73f96fa0..b5ce1fa86 160000 --- a/ykllvm +++ b/ykllvm @@ -1 +1 @@ -Subproject commit c73f96fa0440d3c138665653bb7416858710ead9 +Subproject commit b5ce1fa863f22fd4ab676ebadbe503d44f6aeaf4