<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - Broken switch when compiling with optimizations"
href="http://llvm.org/bugs/show_bug.cgi?id=15674">15674</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Broken switch when compiling with optimizations
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>release blocker
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>LLVM Codegen
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>llvm.org@halfy.net
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=10288" name="attach_10288" title="Bug with switch statements.">attachment 10288</a> <a href="attachment.cgi?id=10288&action=edit" title="Bug with switch statements.">[details]</a></span>
Bug with switch statements.
The attached test case is extracted from a much larger production code. When
compiled and run, the expected output is:
<span class="quote">> ./t
> 1 1 1 1</span >
However, if built with any -O level above zero, it outputs:
<span class="quote">> ./t
> 1 0 0 0</span >
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< ----</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>