Stream: cranelift

Topic: Calling between functions


view this post on Zulip JT (Feb 27 2023 at 05:05):

Hi all - I'm currently working on a small example where I create a function, and then create a second function and try to call the first. I've tried a few variations of this, but I can't seem to get any of them to work. Here's the current one I have, if someone is up for a (hopefully quick) debugging session: https://gist.github.com/jntrnr/bd5d3b0fbe0e9dc8ea0f04c1d0930689

The error I'm getting is:

thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', /Users/jt/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-codegen-0.93.0/src/ir/dfg.rs:955:44
stack backtrace:

on the line that builds the call itself

GitHub Gist: instantly share code, notes, and snippets.

view this post on Zulip bjorn3 (Feb 27 2023 at 09:08):

The result of declare_func_in_func is only valid within a single function. You are calling it on the first function, but then using it on the second function.

view this post on Zulip JT (Feb 27 2023 at 09:09):

bjorn3 said:

The result of declare_func_in_func is only valid within a single function. You are calling it on the first function, but then using it on the second function.

that makes sense. Is there a preferred way of doing what I'm trying to do?

view this post on Zulip bjorn3 (Feb 27 2023 at 09:09):

(deleted)

view this post on Zulip bjorn3 (Feb 27 2023 at 09:10):

Call it after clear_context.

view this post on Zulip bjorn3 (Feb 27 2023 at 09:11):

You could use it right before inserting the call instruction for example.

view this post on Zulip JT (Feb 27 2023 at 09:19):

@bjorn3 that did it, I think. Thanks for the help!


Last updated: Dec 23 2024 at 13:07 UTC