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: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to