Skip to content

Commit

Permalink
Add test that validates swt clone module function references.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel-Durov committed Dec 7, 2024
1 parent 593b5b4 commit f1d58ed
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
49 changes: 49 additions & 0 deletions tests/c/swt_module_clone.c
Original file line number Diff line number Diff line change
@@ -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 <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <yk.h>
#include <yk_testing.h>

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);
}

0 comments on commit f1d58ed

Please sign in to comment.