Wilfred / bfc

An industrial-grade brainfuck compiler
https://bfc.wilfred.me.uk
GNU General Public License v2.0
508 stars 30 forks source link

Core dump in LLVMBuildCall #54

Closed VorpalBlade closed 1 year ago

VorpalBlade commented 1 year ago

As I'm writing my own BF compiler I wanted to compare and benchmark against existing implementations. Unfortunately I cannot get this to run (using the current stable rust 1.67.0):

$ target/debug/bfc sample_programs/life.bf 
zsh: segmentation fault (core dumped)  target/debug/bfc sample_programs/life.bf

Analysing in gdb shows the following backtrace:

(gdb) bt
#0  0x00005555575e31af in LLVMBuildCall ()
#1  0x0000555555cc5ff5 in bfc::llvm::add_function_call (module=0x7fffffffc6d8, bb=0x55555b3dc5c0, fn_name="write", args=&mut [*mut llvm_sys::LLVMValue](size=3) = {...}, name="")
    at src/llvm.rs:203
#2  0x0000555555cc93d8 in bfc::llvm::compile_static_outputs (module=0x7fffffffc6d8, bb=0x55555b3dc5c0, outputs=&[i8](size=133) = {...}) at src/llvm.rs:789
#3  0x0000555555cc96cc in bfc::llvm::compile_to_module (module_name="sample_programs/life.bf", target_triple=..., instrs=&[bfc::bfir::AstNode](size=8) = {...}, initial_state=0x7fffffffc3a8)
    at src/llvm.rs:833
#4  0x0000555555cbf5d6 in bfc::compile_file (matches=0x7fffffffccd0) at src/main.rs:174
#5  0x0000555555cc0f73 in bfc::main () at src/main.rs:299
Wilfred commented 1 year ago

This is probably an issue with bfc expecting a different version of LLVM. The latest version now requires LLVM 13, or you can use the prebuilt binary from the latest release: https://github.com/Wilfred/bfc/releases/tag/1.11.0

VorpalBlade commented 1 year ago

Seems likely. As I'm using Arch Linux, I was using a much newer LLVM (16 probably when I reported the issue).