llvm-hs / llvm-hs-examples

Examples for Haskell bindings to LLVM
MIT License
70 stars 20 forks source link

segmentation fault stack exec arith #9

Closed uuhan closed 6 years ago

uuhan commented 6 years ago

When I run the examples compiled in my macOS 10.13.4, the arith program runs into segmentation fault.

Expression

\x -> sin(3.141592653589793 x / 2.0) (1.0 + sqrt(x)) * (1.0 + sqrt(x))

LLVM IR

; ModuleID = 'arith.ll' source_filename = ""

declare double @llvm.sin.f64(double)

declare double @llvm.sqrt.f64(double)

define double @f(double %x) { %x1 = fmul double 0x400921FB54442D18, %x %x2 = fdiv double %x1, 2.000000e+00 %x3 = call double @llvm.sin.f64(double %x2) %x4 = call double @llvm.sqrt.f64(double %x) %x5 = fadd double 1.000000e+00, %x4 %x6 = call double @llvm.sqrt.f64(double %x) %x7 = fadd double 1.000000e+00, %x6 %x8 = fmul double %x5, %x7 %x9 = fmul double %x3, %x8 ret double %x9 }

Result

[1] 29180 segmentation fault stack exec arith

cocreature commented 6 years ago

A good first step would be to check where fnAddr points to. It’s also helpful to build LLVM with assertions enabled and see if you get an assertion failure.

cocreature commented 6 years ago

I’m closing this due to lack of response since I can’t reproduce this on Linux and thereby sadly can’t do anything about this issue. If you want to investigate this or provide more information, I’m more than happy to provide more hints and ideas if the above didn’t help!