gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 11:02:56 25 4
gpt4 key购买 nike

编译以下程序:

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

为什么会发生这种情况?

最佳答案

(在评论中回答了问题。转换为社区 wiki 答案。见 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

关于haskell - 为什么用 -fllvm 编译这个 Haskell 程序会产生不同的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28053448/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com