<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 --- - [MIPS] Incorrectly extended registers for returning unsigned short values."
href="https://llvm.org/bugs/show_bug.cgi?id=30523">30523</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[MIPS] Incorrectly extended registers for returning unsigned short values.
</td>
</tr>
<tr>
<th>Product</th>
<td>compiler-rt
</td>
</tr>
<tr>
<th>Version</th>
<td>3.9
</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>compiler-rt
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>sagar.thakur@imgtec.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, simon.dardis@imgtec.com, Vasileios.Kalintiris@imgtec.com
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=17348" name="attach_17348" title="Attached a test which returns an unsigned short.">attachment 17348</a> <a href="attachment.cgi?id=17348&action=edit" title="Attached a test which returns an unsigned short.">[details]</a></span>
Attached a test which returns an unsigned short.
For a function which returns an unsigned short, clang generates a "move v0, a0"
where as gcc generates "andi v0, a0, 0xffff" for returning the unsigned short
value. Theres a function in dfsan which returns an unsigned short. When we
compiled this function using clang the caller of this function gets a wrong
return value because the value was not truncated to 16 bits before returning.
The same function when compiled using gcc worked as expected for the caller. I
have attached a reduced test which simply returns an unsigned short. We
compiled this test with O2 optimization level with both gcc and clang to get
the difference in the generated code.
Clang generated code :
foo:
.frame $sp,0,$ra
.mask 0x00000000,0
.fmask 0x00000000,0
.set noreorder
.set nomacro
.set noat
jr $ra
move $2, $4
.set at
.set macro
.set reorder
.end foo
Gcc generated code :
.type foo, @function
foo:
.frame $sp,0,$31 # vars= 0, regs= 0/0, args= 0, gp= 0
.mask 0x00000000,0
.fmask 0x00000000,0
.set noreorder
.set nomacro
j $31
andi $2,$4,0xffff
.set macro
.set reorder
.end foo</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>