[Haskell-cafe] ghc 6.8.1 bug?

Alberto Ruiz aruiz at um.es
Thu Nov 15 03:43:47 EST 2007


Hello,

I have had exactly the same problem with my bindings to GSL, BLAS and LAPACK. 
The foreign functions (!) randomly (but very frequently) produced NaN with 
ghc-6.8.1 -O. As usual, I first thought that I had a subtle bug related to 
the foreign pointers, but after a lot of refactoring, experiments, and 
tracing everything, I'm reasonably sure that memory is safely used. What I 
have found is that the same errors can be reproduced on ghc-6.6.1 
with -O -fasm. So I tried -O -fvia-C on ghc-6.8.1 (which now it is not the 
default) and apparently everything works well. So it seems that now the ffi 
requires and additional and explicit -fvia-C. In any case I don't know 
why -fasm produces those strange NaN in precompiled foreign functions...

Alberto

On Thursday 15 November 2007 09:05, SevenThunders wrote:
> The good news is that my code compiles without error and much faster under
> ghc 6.8.1.
> The bad news is that there appear to be subtle bugs that did not occur when
> I compiled things under
> 6.6.1.  One issue is that my code is somewhat complex and links into a  C
> library as well.
>
> The new behavior is that under certain conditions a certain matrix inner
> product produces undefined floats, that should not be there.  If the code
> is executed inside any function it fails but if the same code is reexecuted
> at the ghci prompt it works.  Here is the gist of the code that I'm running
>
> main = do
>     ... lots of computations and let clauses
>     -- get a submatrix
>       viewMatbotk wstart nsua su 1 suw
>     -- get another submatrix
>       viewMatbotk 0 nsua arrstart npaths sua
>      -- complex non conjugated inner product (multiply the two submatrices)
>     mulCFtF
>     mprint
>
> If this is executed either in ghci as main or from a Dos prompt I get
> a matrix filled with bad values including a few that look like
> -1.#IND+1.87514i
>
> If I recompile everything in ghc-6.6.1 it works like  charm.  I make sure
> that I have deleted all the .o and .hi files.  There is a dll that contains
> a C library I link to via running dlltool.exe.   If I print out all the
> function inputs to the function viewMatbotk and then call them
> interactively in ghc 6.8.1 and call mulCFtF interactively it works
> correctly.  both viewMatbotk  and mulCFtF are C routines pulled in from the
> external library.
>
> I am at a complete loss how to debug this or how to pin down what exactly
> has changed between 6.6.1 and 6.8.1 that breaks this code so badly.  This
> type of error stinks of some kind of memory issue, e.g. corrupted pointers.
> Any suggestions would be appreciated.  Unfortunately the code base is
> rather involved and potentially proprietary so I can't publish all of the
> details.


More information about the Haskell-Cafe mailing list