[LLVMbugs] [Bug 15674] New: Broken switch when compiling with	optimizations
    bugzilla-daemon at llvm.org 
    bugzilla-daemon at llvm.org
       
    Thu Apr  4 14:08:04 PDT 2013
    
    
  
http://llvm.org/bugs/show_bug.cgi?id=15674
            Bug ID: 15674
           Summary: Broken switch when compiling with optimizations
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: release blocker
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: llvm.org at halfy.net
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified
Created attachment 10288
  --> http://llvm.org/bugs/attachment.cgi?id=10288&action=edit
Bug with switch statements.
The attached test case is extracted from a much larger production code. When
compiled and run, the expected output is:
> ./t
> 1 1 1 1
However, if built with any -O level above zero, it outputs:
> ./t
> 1 0 0 0
It seems that the ::memcpy() is confusing the optimizer. I'm not sure at what
stage this happens, so logging against clang.
I can work around this by rewriting the code like below, but this seems like a
rather critical bug.
---- 8< ----
void quantize(char *data, float *src, int nb_src, int vsize)
{
    unsigned char     *i8 = (unsigned char *)data;
    switch(vsize)
    {
    case 4: i8[3] = (unsigned char)src[3];
    case 3: i8[2] = (unsigned char)src[2];
        i8[1] = (unsigned char)src[1];
    case 1: i8[0] = (unsigned char)src[0];
    }
}
---- 8< ----
-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130404/294809d7/attachment.html>
    
    
More information about the llvm-bugs
mailing list