bos/llvm — pull request #35 by iliastsi (2012-04-19 14:30:01+00:00)
Title: Fix a bug with String's length

When creating a string (using either \`createString\*' or \`withString\*' functions)
we must not use \`length' function to compute the length of a string
in bytes (as this will return the length of a string in chars).
Instead we should use the same length used by \`withCStringLen' function.

This bug appears when using \`createString\*' or \`withString\*' functions with
a string containing characters bigger than 7-bytes (in my case when using
greek letters).

For example the above code will generate one llvm module (named greet.bc)
which fails to compile when using llc with message:
\`Global variable initializer type does not match global variable type!'

```haskell
module Main (main) where

import Data.Word
import LLVM.Core

bldGreet :: CodeGenModule (Function (IO ()))
bldGreet = withStringNul "My name is Ηλίας" (\greetz -> do
puts <- newNamedFunction ExternalLinkage "puts" :: TFunction (Ptr Word8 -> IO Word32)
func <- createFunction ExternalLinkage $ do
tmp <- getElementPtr0 greetz (0::Word32, ())
_ <- call puts tmp -- Throw away return value.
ret ()
return func)

main :: IO ()
main = do
m <- newModule
defineModule m bldGreet
writeBitcodeToFile "greet.bc" m
```