[LLVMbugs] [Bug 4325] New: clang: Rev 72572 breaks volatile code

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Thu Jun 4 11:55:09 PDT 2009


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

           Summary: clang: Rev 72572 breaks volatile code
           Product: new-bugs
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Keywords: miscompilation, regression
          Severity: normal
          Priority: P2
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: quickslyver at free.fr
                CC: llvmbugs at cs.uiuc.edu, mrs at apple.com


after rev 72572, clang does the "while comparison" on the lvalue instead of the
rvalue in the above c code:

-------------Original C Code:
#define DEBUG_BASE 0x2000
void print(const char* text)
{
  unsigned volatile char * const  debug_device=(unsigned char *
const)DEBUG_BASE;
  while(*debug_device=*text++);

}

-------------Clang Rev 72571 llvm generated code (O3):
define void @print(i8* nocapture %text) nounwind noinline {
entry:
        br label %while.cond

while.cond:             ; preds = %while.cond, %entry
        %indvar = phi i32 [ 0, %entry ], [ %indvar.next, %while.cond ]         
; <i32> [#uses=2]
        %text.addr.0 = getelementptr i8* %text, i32 %indvar             ; <i8*>
[#uses=1]
        %tmp1 = load i8* %text.addr.0           ; <i8> [#uses=2]
        volatile store i8 %tmp1, i8* inttoptr (i32 8192 to i8*), align 8192
        %tobool = icmp eq i8 %tmp1, 0           ; <i1> [#uses=1]
        %indvar.next = add i32 %indvar, 1               ; <i32> [#uses=1]
        br i1 %tobool, label %while.end, label %while.cond

while.end:              ; preds = %while.cond
        ret void
}

-------------diff between 72571 and 72572:
@@ -32,9 +32,10 @@
 while.cond:            ; preds = %while.cond, %entry
        %indvar = phi i32 [ 0, %entry ], [ %indvar.next, %while.cond ]         
; <i32> [#uses=2]
        %text.addr.0 = getelementptr i8* %text, i32 %indvar             ; <i8*>
[#uses=1]
-       %tmp1 = load i8* %text.addr.0           ; <i8> [#uses=2]
+       %tmp1 = load i8* %text.addr.0           ; <i8> [#uses=1]
        volatile store i8 %tmp1, i8* inttoptr (i32 8192 to i8*), align 8192
-       %tobool = icmp eq i8 %tmp1, 0           ; <i1> [#uses=1]
+       %tmp3 = volatile load i8* inttoptr (i32 8192 to i8*), align 8192       
        ; <i8> [#uses=1]
+       %tobool = icmp eq i8 %tmp3, 0           ; <i1> [#uses=1]
        %indvar.next = add i32 %indvar, 1               ; <i32> [#uses=1]
        br i1 %tobool, label %while.end, label %while.cond

-------------Clang Rev 72572 llvm generated code (O3):
define void @print(i8* nocapture %text) nounwind noinline {
entry:
        br label %while.cond

while.cond:             ; preds = %while.cond, %entry
        %indvar = phi i32 [ 0, %entry ], [ %indvar.next, %while.cond ]         
; <i32> [#uses=2]
        %text.addr.0 = getelementptr i8* %text, i32 %indvar             ; <i8*>
[#uses=1]
        %tmp1 = load i8* %text.addr.0           ; <i8> [#uses=1]
        volatile store i8 %tmp1, i8* inttoptr (i32 8192 to i8*), align 8192
        %tmp3 = volatile load i8* inttoptr (i32 8192 to i8*), align 8192       
        ; <i8> [#uses=1]
        %tobool = icmp eq i8 %tmp3, 0           ; <i1> [#uses=1]
        %indvar.next = add i32 %indvar, 1               ; <i32> [#uses=1]
        br i1 %tobool, label %while.end, label %while.cond

while.end:              ; preds = %while.cond
        ret void
}


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