id,summary,reporter,owner,description,type,status,priority,milestone,component,version,resolution,keywords,cc,os,architecture,failure,difficulty,testcase,blockedby,blocking,related
2388,GHC creates invalid test instruction for 64-bit code,MartinGrabmueller,simonmar,"When compiling the cpuid package from Hackage (http://hackage.haskell.org/cgi-bin/hackage-scripts/package/cpuid), Don Stewart noticed
that compilation aborts on a 64-bit Linux box with the following error message:

{{{Error: suffix or operands invalid for `test'}}}

Examining the assembler code, we see that the instruction

`testq $2147483648,%rax`

is generated, but `test` is only allowed to take a 32-bit immediate operand.

Don's compilation info follows:
{{{
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 6.8.2

$ gcc --version
gcc (GCC) 4.3.1
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ uname -msr
Linux 2.6.25-ARCH x86_64

    $ cabal install cpuid
    Resolving dependencies...
    Downloading cpuid-0.2...
    Configuring cpuid-0.2...
    Preprocessing library cpuid-0.2...
    Building cpuid-0.2...
    [1 of 1] Compiling System.Cpuid     ( System/Cpuid.hs, dist/build/System/Cpuid.o )
    /tmp/ghc23771_0/ghc23771_0.s: Assembler messages:

    /tmp/ghc23771_0/ghc23771_0.s:3254:0:
         Error: suffix or operands invalid for `test'
    cabal: Error: some packages failed to install:
    cpuid-0.2 failed during the building phase. The exception was:
    exit: ExitFailure 1

Checking the temp files, this is generated:

    $ runhaskell Setup.lhs configure --ghc-options=-keep-tmp-files
    $ runhaskell Setup.lhs build                                  
    Preprocessing library cpuid-0.2...
    Building cpuid-0.2...
    [1 of 1] Compiling System.Cpuid     ( System/Cpuid.hs, dist/build/System/Cpuid.o )
    /tmp/ghc9500_0/ghc9500_0.s: Assembler messages:

    /tmp/ghc9500_0/ghc9500_0.s:3254:0:
         Error: suffix or operands invalid for `test'
    $ vim /tmp/ghc9500_0/ghc9500_0.s +3254


    s3TR_info:
        addq $208,%r12
        cmpq %r15,%r12
        ja .Lc3W2
        movq 7(%rbx),%rax
        testq $2147483648,%rax
        je .Lc3W4
        movq 8(%rbp),%rsi
        addq $16,%rbp
        addq $-208,%r12
        jmp r2By_info
}}}
",bug,closed,normal,6.10.1,Compiler,6.8.2,fixed,,,Linux,x86_64 (amd64),,Unknown,,,,
