<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 --- - thumb generates mov lr,pc"
href="http://llvm.org/bugs/show_bug.cgi?id=16572">16572</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>thumb generates mov lr,pc
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</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>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>dwelch@dwelch.com
</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=10841" name="attach_10841" title="picojpeg.c code generates this backend problem.">attachment 10841</a> <a href="attachment.cgi?id=10841&action=edit" title="picojpeg.c code generates this backend problem.">[details]</a></span>
picojpeg.c code generates this backend problem.
While compiling the open source picojpeg code with llvm 3.3 it generates code
like this
mov lr, pc
bx r6
In thumb mode, and the code it is calling with the bx has code that uses this
push {...,lr}
pop {...,pc}
Which is just bad form, a bx should be used (pop {rn}; bx rn) not pop {pc}, in
either case the lr does not have the lsbit set, because mov lr,pc does not set
the lsbit (the pc does not have the lsbit set in thumb mode it is stripped by
bl,bx,blx) so when it returns after this combination
mov lr, pc
bx r6
;returns here ideally
which is thumb code, if the processor is a cortex-m then it is game over
because you tried to switch to arm mode (in that case I would hope to see an
exception, but didnt test it there), if it is not a cortex-m then it returns in
arm mode and tries to execute the thumb instructions as arm instructions and
unpredictable results will occur.
Naturally with more code in the project, and llvm-linking the project and
optimizing the whole thing the problem can move around but the attached code
with this makefile generates the mov lr,pc with clang+llvm 3.3
OOPS = -std-compile-opts -strip-debug -disable-simplify-libcalls
LOPS = -Wall -m32 -emit-llvm
LLCOPS = -march=thumb -disable-simplify-libcalls
picojpeg.s : picojpeg.c
clang $(LOPS) -c picojpeg.c -o picojpeg.bc
opt $(OOPS) picojpeg.bc -o picojpeg.opt.bc
llc $(LLCOPS) picojpeg.opt.bc -o picojpeg.s</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>