<html>
<head>
<base href="https://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 --- - Naked functions that return values are broken"
href="https://llvm.org/bugs/show_bug.cgi?id=27230">27230</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Naked functions that return values are broken
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.7
</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>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>-New Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>hausen@gmx.at
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Naked functions that return values are compiled incorrectly as soon as
optimizations are turned on. Take the following example:
int foo(void) __attribute__((naked,noinline));
int foo(void) {
// assembly as generated for "return 41;"
asm volatile("mov $41,%%eax; retq" : : : "memory");
}
int main() {
return foo()+1;
}
The program returns the intended value of 42 when compiling with -O0. With -O1
however, the call to foo is replaced with a jump and the program returns 41.
As far as I can tell, the issue is caused by the fact that the end of a naked
functions is "unreachable". This seems to cause optimization passes to make
incorrect assumptions about the behavior of such functions.</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>