-
Notifications
You must be signed in to change notification settings - Fork 261
Closed
Labels
Description
Describe the Bug
As stated in the comment extern functions defined in Rust code are not detected by Kaleidoscope JIT.
To Reproduce
- Run Kaleidoscope REPL.
- Type
extern printd(x) - Type
printd(10) - Function returns
NaN
Expected Behavior
printd function should have returned passed value and printed it.
LLVM Version (please complete the following information):
- LLVM Version: 7.0.1
- Inkwell Branch Used: llvm7-0
Desktop (please complete the following information):
- OS: OS X
Additional Context
After a bit of investigation, it seems that there are a couple of problems here:
rustcwill mangle the names of those function unless#[no_mangle]attribute is applied.- Unless those functions are used in the Rust code, the compiler will remove them. To avoid this they should be called somewhere or put into a static array with
#[used]attribute like here. - Currently, body that returns
NaNis set forexternfunctions. This causes that functions that are defined in Rust are being overridden by those that returnNaN(strangely, but functions likesinandcosare not being overridden). It seems that if we gotexterndefinition, we should not attach any body to it.
I kinda fixed these issues in my fork, but it will segfault if extern function, that is not actually defined, is called. I'm not sure what is desired behavior here. Let me know what do you think about this.