Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codegen error when adding more than 4 variables #1634

Open
Pavel-Durov opened this issue Mar 1, 2025 · 3 comments
Open

Codegen error when adding more than 4 variables #1634

Pavel-Durov opened this issue Mar 1, 2025 · 3 comments

Comments

@Pavel-Durov
Copy link
Contributor

Not sure if its a duplicate or not.

Description

White working on the SWT multi module control point transition I found this test case that is failing in both HWT and SWT.

Versions

yk version - a797bdf
ykllvm version - ykjit/ykllvm@9cbe89d

Reproduction

This test case fails when adding a fifth variable e to the computation.

Test

// Run-time:
//   env-var: YKD_SERIALISE_COMPILATION=1
//   stderr:
//     ...

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <yk.h>
#include <yk_testing.h>

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 i = 4;
  NOOPT_VAL(loc);
  NOOPT_VAL(i);
  while (i > 0) {
    int a = i+1;     // Variable 1
    int b = i+a;     // Variable 2
    int c = i+b;     // Variable 3
    int d = i+c;     // Variable 4
    int e = i+d;     // Variable 5 - Adding this triggers the failure
    fprintf(stderr, "a=%d b=%d c=%d d=%d e=%d\n", a, b, c, d, e);
    yk_mt_control_point(mt, &loc);
    i = i - 1;
  }
  yk_location_drop(loc);
  yk_mt_shutdown(mt);
  return (EXIT_SUCCESS);
}

Test output:

test lang_tests::simple5.c ... FAILED

failures:

---- lang_tests::simple5.c status ----
Exited due to signal: 6

---- lang_tests::simple5.c stderr ----

a=5 b=9 c=13 d=17 e=21
a=4 b=7 c=10 d=13 e=16

thread '<unnamed>' panicked at ykrt/src/compile/jitc_yk/codegen/x64/mod.rs:1707:46:
called `Option::unwrap()` on a `None` value
stack backtrace:
   0:     0x7f47221c84b3 - std::backtrace_rs::backtrace::libunwind::trace::ha60d6c8dc3f5f8a4
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/std/src/../../backtrace/src/backtrace/libunwind.rs:117:9
   1:     0x7f47221c84b3 - std::backtrace_rs::backtrace::trace_unsynchronized::habe0365ec6a6308d
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/std/src/../../backtrace/src/backtrace/mod.rs:66:14
   2:     0x7f47221c84b3 - std::sys::backtrace::_print_fmt::hc3ae79cc2516a535
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/std/src/sys/backtrace.rs:66:9
   3:     0x7f47221c84b3 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h8d9b2abef2510cd1
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/std/src/sys/backtrace.rs:39:26
   4:     0x7f47221ed9d3 - core::fmt::rt::Argument::fmt::hd734eb8dccf04fe9
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/core/src/fmt/rt.rs:177:76
   5:     0x7f47221ed9d3 - core::fmt::write::heb9cf6889f45a11e
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/core/src/fmt/mod.rs:1449:21
   6:     0x7f47221c5843 - std::io::Write::write_fmt::h6360a21e44de67e4
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/std/src/io/mod.rs:1890:15
   7:     0x7f47221c8302 - std::sys::backtrace::BacktraceLock::print::h9319588d0d6e4878
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/std/src/sys/backtrace.rs:42:9
   8:     0x7f47221c929a - std::panicking::default_hook::{{closure}}::h4c968bafc99c0b41
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/std/src/panicking.rs:298:22
   9:     0x7f47221c910a - std::panicking::default_hook::hafb4ab1b4e12432b
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/std/src/panicking.rs:325:9
  10:     0x7f47221c9cb2 - std::panicking::rust_panic_with_hook::h5b5ba4a5cbdd9043
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/std/src/panicking.rs:831:13
  11:     0x7f47221c9a06 - std::panicking::begin_panic_handler::{{closure}}::h761c7933b6bd63bc
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/std/src/panicking.rs:697:13
  12:     0x7f47221c89b9 - std::sys::backtrace::__rust_end_short_backtrace::hf28ea39c64a8ec49
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/std/src/sys/backtrace.rs:168:18
  13:     0x7f47221c96cd - rust_begin_unwind
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/std/src/panicking.rs:695:5
  14:     0x7f47221eb530 - core::panicking::panic_fmt::hbb352f67f9fc2f03
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/core/src/panicking.rs:75:14
  15:     0x7f47221eb5bc - core::panicking::panic::h6fc23addbc4b6e02
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/core/src/panicking.rs:145:5
  16:     0x7f47221eb4a9 - core::option::unwrap_failed::h1809b537790d8e9b
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/core/src/option.rs:2015:5
  17:     0x7f4721ef73e1 - core::option::Option<T>::unwrap::h20389401cfd0f26d
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/core/src/option.rs:978:21
  18:     0x7f4721ef73e1 - ykrt::compile::jitc_yk::codegen::x64::Assemble::emit_call::hcc2ef90662c27705
                               at /yk/ykrt/src/compile/jitc_yk/codegen/x64/mod.rs:1707:31
  19:     0x7f4721ef55ce - ykrt::compile::jitc_yk::codegen::x64::Assemble::cg_call::h45210526ae6c3133
                               at /yk/ykrt/src/compile/jitc_yk/codegen/x64/mod.rs:1650:17
  20:     0x7f4721eec4a9 - ykrt::compile::jitc_yk::codegen::x64::Assemble::cg_insts::h8381185b966b8268
                               at /yk/ykrt/src/compile/jitc_yk/codegen/x64/mod.rs:609:42
  21:     0x7f4721ee938a - ykrt::compile::jitc_yk::codegen::x64::Assemble::codegen::h08d08473895f9a27
                               at /yk/ykrt/src/compile/jitc_yk/codegen/x64/mod.rs:408:9
  22:     0x7f4721ee87ae - <ykrt::compile::jitc_yk::codegen::x64::X64CodeGen as ykrt::compile::jitc_yk::codegen::CodeGen>::codegen::h9f02950cbf0643da
                               at /yk/ykrt/src/compile/jitc_yk/codegen/x64/mod.rs:297:9
  23:     0x7f4721fd18f7 - ykrt::compile::jitc_yk::JITCYk<Register>::compile::he19b5748d2e12f7b
                               at /yk/ykrt/src/compile/jitc_yk/mod.rs:173:18
  24:     0x7f4721fd23be - <ykrt::compile::jitc_yk::JITCYk<Register> as ykrt::compile::Compiler>::root_compile::h9f034341cc480048
                               at /yk/ykrt/src/compile/jitc_yk/mod.rs:203:9
  25:     0x7f4721f0e9a9 - ykrt::mt::MT::queue_root_compile_job::{{closure}}::h832814a3394afa45
                               at /yk/ykrt/src/mt.rs:287:19
  26:     0x7f4721e2cfbe - core::ops::function::FnOnce::call_once{{vtable.shim}}::h1c599be0ce88256a
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/core/src/ops/function.rs:250:5
  27:     0x7f4721fb7e68 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h3851c4c8b8408317
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/alloc/src/boxed.rs:1972:9
  28:     0x7f4721fd9154 - std::sys::backtrace::__rust_begin_short_backtrace::hfec611756a43de61
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/std/src/sys/backtrace.rs:152:18
  29:     0x7f4721e61243 - std::thread::Builder::spawn_unchecked_::{{closure}}::{{closure}}::h50140d6da4d93985
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/std/src/thread/mod.rs:559:17
  30:     0x7f4721fcfc01 - <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::h7c1446656f0882f0
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/core/src/panic/unwind_safe.rs:272:9
  31:     0x7f4721fd4300 - std::panicking::try::do_call::h8fa39b38a59da830
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/std/src/panicking.rs:587:40
  32:     0x7f4721e618ab - __rust_try
  33:     0x7f4721e60e75 - std::panicking::try::ha476fbd079469ad6
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/std/src/panicking.rs:550:19
  34:     0x7f4721e60e75 - std::panic::catch_unwind::h7bdf85cb89048c64
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/std/src/panic.rs:359:14
  35:     0x7f4721e60e75 - std::thread::Builder::spawn_unchecked_::{{closure}}::he6cb431218615ed5
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/std/src/thread/mod.rs:557:30
  36:     0x7f4721e2d49f - core::ops::function::FnOnce::call_once{{vtable.shim}}::ha965b69f0da3a6df
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/core/src/ops/function.rs:250:5
  37:     0x7f47221cbb5b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h882e355ed78c64f7
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/alloc/src/boxed.rs:1972:9
  38:     0x7f47221cbb5b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::ha4c9de997cf9ce0e
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/alloc/src/boxed.rs:1972:9
  39:     0x7f47221cbb5b - std::sys::pal::unix::thread::Thread::new::thread_start::h208202f9d25af663
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/std/src/sys/pal/unix/thread.rs:106:17
  40:     0x7f4721aa81c4 - start_thread
                               at ./nptl/pthread_create.c:442:8
  41:     0x7f4721b2885c - clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81:0
  42:                0x0 - <unknown>

thread '<unnamed>' panicked at ykrt/src/mt.rs:237:39:
called `Result::unwrap()` on an `Err` value: Any { .. }
stack backtrace:
   0:     0x7f47221c84b3 - std::backtrace_rs::backtrace::libunwind::trace::ha60d6c8dc3f5f8a4
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/std/src/../../backtrace/src/backtrace/libunwind.rs:117:9
   1:     0x7f47221c84b3 - std::backtrace_rs::backtrace::trace_unsynchronized::habe0365ec6a6308d
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/std/src/../../backtrace/src/backtrace/mod.rs:66:14
   2:     0x7f47221c84b3 - std::sys::backtrace::_print_fmt::hc3ae79cc2516a535
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/std/src/sys/backtrace.rs:66:9
   3:     0x7f47221c84b3 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h8d9b2abef2510cd1
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/std/src/sys/backtrace.rs:39:26
   4:     0x7f47221ed9d3 - core::fmt::rt::Argument::fmt::hd734eb8dccf04fe9
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/core/src/fmt/rt.rs:177:76
   5:     0x7f47221ed9d3 - core::fmt::write::heb9cf6889f45a11e
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/core/src/fmt/mod.rs:1449:21
   6:     0x7f47221c5843 - std::io::Write::write_fmt::h6360a21e44de67e4
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/std/src/io/mod.rs:1890:15
   7:     0x7f47221c8302 - std::sys::backtrace::BacktraceLock::print::h9319588d0d6e4878
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/std/src/sys/backtrace.rs:42:9
   8:     0x7f47221c929a - std::panicking::default_hook::{{closure}}::h4c968bafc99c0b41
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/std/src/panicking.rs:298:22
   9:     0x7f47221c910a - std::panicking::default_hook::hafb4ab1b4e12432b
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/std/src/panicking.rs:325:9
  10:     0x7f47221c9cb2 - std::panicking::rust_panic_with_hook::h5b5ba4a5cbdd9043
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/std/src/panicking.rs:831:13
  11:     0x7f47221c9a3a - std::panicking::begin_panic_handler::{{closure}}::h761c7933b6bd63bc
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/std/src/panicking.rs:704:13
  12:     0x7f47221c89b9 - std::sys::backtrace::__rust_end_short_backtrace::hf28ea39c64a8ec49
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/std/src/sys/backtrace.rs:168:18
  13:     0x7f47221c96cd - rust_begin_unwind
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/std/src/panicking.rs:695:5
  14:     0x7f47221eb530 - core::panicking::panic_fmt::hbb352f67f9fc2f03
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/core/src/panicking.rs:75:14
  15:     0x7f47221eba56 - core::result::unwrap_failed::h25a540d1f03b8b52
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/core/src/result.rs:1704:5
  16:     0x7f4721edf65d - core::result::Result<T,E>::unwrap::h49b483e44c28a76f
                               at /rustc/f280acf4c743806abbbbcfe65050ac52ec4bdec0/library/core/src/result.rs:1109:23
  17:     0x7f4721edf65d - ykrt::mt::MT::queue_job::heebc2dd2ff016205
                               at /yk/ykrt/src/mt.rs:237:13
  18:     0x7f4721edfc49 - ykrt::mt::MT::queue_root_compile_job::hcedf6918aabff399
                               at /yk/ykrt/src/mt.rs:341:9
  19:     0x7f4721ee1298 - ykrt::mt::MT::control_point::h81101d1808d0812d
                               at /yk/ykrt/src/mt.rs:521:25
  20:     0x7f4721e0e84d - __ykrt_control_point_real
                               at /yk/ykcapi/src/lib.rs:135:9
  21:     0x7f4721e0e291 - __ykrt_control_point
fatal runtime error: failed to initiate panic, error 5


---- lang_tests::simple5.c stdout ----
@ltratt
Copy link
Contributor

ltratt commented Mar 3, 2025

I would suggest getting the jit-pre-opt (or jit-post-opt) for this program, having a look, and seeing how we might have an input parameter of type Void.

@ptersilie
Copy link
Contributor

That's not the error @Pavel-Durov is seeing I think. Looking at his yk version it seems to be this:

let reg = gp_regs.next().unwrap();
. Looks to be running out of registers for the call. Which isn't surprising as this change adds a 7th argument which needs to be passed via the stack, which I believe we haven't implemented yet.

@ltratt
Copy link
Contributor

ltratt commented Mar 3, 2025

Ah, right. Sorry, I was looking at master. Yes, we haven't done stack arguments yet, and I'm not busting a gut to implement that right now. I would suggest, for the time being, keeping the number of arguments to 6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants