[LLVMbugs] [Bug 2835] New: likely volatile error in x86 backend

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Sun Sep 28 20:49:08 PDT 2008


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

           Summary: likely volatile error in x86 backend
           Product: new-bugs
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: regehr at cs.utah.edu
                CC: llvmbugs at cs.uiuc.edu


Seen using r56775 on Ubuntu Hardy on ia32.

The translation below to LLVM is correct: the volatile load from g_407 is i32. 
However, the x86 looks wrong: movzbl is used, which loads only the lowest 8
bits.

regehr at john-home:~/volatile/tmp47$ cat small.c
#include <stdint.h>
#include <limits.h>

static inline int
lshift_s_s(int left, int right)
{
        if ((left < 0)
                || (right < 0)
                || (right >= sizeof(int)*CHAR_BIT)
                || (left > (INT_MAX >> right))) {
                /* Avoid undefined behavior. */
                return left;
        }
        return left << right;
}

uint32_t g_114;
volatile uint32_t g_407 ;

int32_t func_45 (uint8_t p_48);
int32_t func_45 (uint8_t p_48)
{
  for (0; g_114; g_114--)
    {
    }
  return 1;
}

int main (void)
{
  func_45 (lshift_s_s (1, 1) <= 1 | g_407);
  return 0;
}

regehr at john-home:~/volatile/tmp47$ llvm-gcc -O
-I/home/regehr/randprog-classic/src small.c -S --emit-llvm -o -

; ModuleID = 'small.c'
target datalayout =
"e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
target triple = "i386-pc-linux-gnu"
@g_114 = common global i32 0            ; <i32*> [#uses=2]
@g_407 = common global i32 0            ; <i32*> [#uses=1]

define i32 @func_45(i8 zeroext %p_48) nounwind {
entry:
        %0 = load i32* @g_114, align 4          ; <i32> [#uses=1]
        %1 = icmp eq i32 %0, 0          ; <i1> [#uses=1]
        br i1 %1, label %bb2, label %bb.nph

bb.nph:         ; preds = %entry
        store i32 0, i32* @g_114
        ret i32 1

bb2:            ; preds = %entry
        ret i32 1
}

define i32 @main() nounwind {
entry:
        %0 = volatile load i32* @g_407, align 4         ; <i32> [#uses=1]
        %1 = trunc i32 %0 to i8         ; <i8> [#uses=1]
        %2 = tail call i32 @func_45(i8 zeroext %1) nounwind             ; <i32>
[#uses=0]
        ret i32 0
}

regehr at john-home:~/volatile/tmp47$ llvm-gcc -O
-I/home/regehr/randprog-classic/src small.c -S -o -

        .ident  "GCC: (GNU) 4.2.1 (Based on Apple Inc. build 5623) (LLVM
build)"


        .text
        .align  16
        .globl  func_45
        .type   func_45, at function
func_45:
        pushl   %ebp
        movl    %esp, %ebp
        cmpl    $0, g_114
        je      .LBB1_2 # bb2
.LBB1_1:        # bb.nph
        movl    $0, g_114
.LBB1_2:        # bb2
        movl    $1, %eax
        popl    %ebp
        ret
        .size   func_45, .-func_45


        .align  16
        .globl  main
        .type   main, at function
main:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $8, %esp
        movzbl  g_407, %eax
        movl    %eax, (%esp)
        call    func_45
        xorl    %eax, %eax
        addl    $8, %esp
        popl    %ebp
        ret
        .size   main, .-main
        .type   g_114, at object
        .section        .gnu.linkonce.b.g_114,"aw", at nobits
        .comm   g_114,4,4               # g_114
        .type   g_407, at object
        .section        .gnu.linkonce.b.g_407,"aw", at nobits
        .comm   g_407,4,4               # g_407

        .section        .note.GNU-stack,"", at progbits

regehr at john-home:~/volatile/tmp47$


-- 
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