为什么用 -fllvm 编译这个 Haskell 程序会产生不同的结果?

Why compiling this Haskell program with -fllvm produces a different result?

正在编译以下程序:

main = print (sqrt (-7))

在 OSX Yosemite 上,LLVM 版本 3.4.2,目标 x86_64-apple-darwin14.0.0,GHC 7.8.4 产生两种不同的结果,具体取决于 llvm 使用:

apple1$ ghc -fforce-recomp a.hs -o a; ./a
[1 of 1] Compiling Main             ( a.hs, a.o )
Linking a ...
NaN

apple1$ ghc -fforce-recomp -fllvm a.hs -o a; ./a
[1 of 1] Compiling Main             ( a.hs, a.o )
Linking a ...
0.0

为什么会这样?

(评论中回答的问题。转换为社区维基答案。参见 Question with no answers, but issue solved in the comments (or extended in chat)

@leftaroundabout 写道:

I would consider it a bug, though it might well have been acceptable according to some specification. LLVM evidently fired some optimisation here which assumes non-negative arguments, making √(-7) undefined behaviour.

@Ed'ka 写道:

Probably related: LLVM bug 21048