[LLVMbugs] [Bug 11255] New: Incorrect code generation of asm("sp") by clang on ARM

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Oct 28 10:48:51 PDT 2011


http://llvm.org/bugs/show_bug.cgi?id=11255

           Summary: Incorrect code generation of asm("sp") by clang on ARM
           Product: clang
           Version: trunk
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: mcharleb at codeaurora.org
                CC: llvmbugs at cs.uiuc.edu


I have been working on compiling the ARM Linux kernel with clang and found a
bug in the code generated by clang for current_thread_info(). I have isolated
the problem to the handling of the following statement:

register unsigned long sp asm ("sp");

I attached a simple test program (test2.c) to demonstrate the bug.

Here are the output results from GCC and then from clang:

$ /opt/arm-2011.03/bin/arm-none-linux-gnueabi-gcc -o test2 test2.c -g -static
qemu-arm test2

&p = 0x408002fc sp = 408002f8
f1: p = 0x40800000
f2: p = 0x40800000

$ clang -g -march=armv7-a -ccc-host-triple arm -mfloat-abi=softfp -mfpu=neon
-ccc-gcc-name none-linux-gnueabi-gcc -I
/shared/llvm/llvm-upstream-arm/install-cross-3.0/lib/clang/3.0/include -o test2
test2.c -static

$ qemu-arm test2
&p = 0x40800300 sp = 0
f1: p = (nil)
f2: p = 0x40800000

Other times I see the following or other values of p from f2():

$ qemu-arm test2
&p = 0x40800300 sp = 0
f1: p = 0x6e000
f2: p = 0x40800000

Clearly the value returned from f2() is undefined.

Here is the assembly generated for f1() when compiled with clang:

(gdb) disassemble /m f1  
Dump of assembler code for function f1:
6    {

7        register unsigned long sp asm ("sp");
8    
9        return (void *)(sp & ~(THREAD_SIZE - 1));
   0x0000824c <+0>:    sub    sp, sp, #4
   0x00008250 <+4>:    ldr    r0, [sp]
   0x00008254 <+8>:    bfc    r0, #0, #13
   0x00008258 <+12>:    add    sp, sp, #4
   0x0000825c <+16>:    bx    lr

End of assembler dump.


Here is the assembly generated by gcc for f1():

(gdb) disassemble /m f1
Dump of assembler code for function f1:
6    {
   0x000081cc <+0>:    push    {r11}        ; (str r11, [sp, #-4]!)
   0x000081d0 <+4>:    add    r11, sp, #0

7        register unsigned long sp asm ("sp");
8    
9        return (void *)(sp & ~(THREAD_SIZE - 1));
   0x000081d4 <+8>:    mov    r3, sp
   0x000081d8 <+12>:    bic    r3, r3, #8128    ; 0x1fc0
   0x000081dc <+16>:    bic    r3, r3, #63    ; 0x3f

10    }
   0x000081e0 <+20>:    mov    r0, r3
   0x000081e4 <+24>:    add    sp, r11, #0
   0x000081e8 <+28>:    pop    {r11}        ; (ldr r11, [sp], #4)
   0x000081ec <+32>:    bx    lr

End of assembler dump.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list