<html>
<head>
<base href="https://bugs.llvm.org/">
</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 - LLVM miscompiles variadic functions with overaligned stack when targeting Thumb1"
href="https://bugs.llvm.org/show_bug.cgi?id=36080">36080</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>LLVM miscompiles variadic functions with overaligned stack when targeting Thumb1
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</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>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Backend: ARM
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>momchil.velikov@arm.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=19742" name="attach_19742" title="minimal testcase">attachment 19742</a> <a href="attachment.cgi?id=19742&action=edit" title="minimal testcase">[details]</a></span>
minimal testcase
When compiling for Arm architecture, which implements only the 16-bit Thumb
instruction set (like Armv4t or Armv6m) a variadic function, which has
increased stack alignment requirements (so it dynamically re-aligns the SP),
the Arm back end generates invalid code to store the incoming variadic
arguments, which are passed in registers.
When the attached test case is compiled via
clang -target thumbv6m-eabi -O2 -S variadic-stack-align.c
the generated assembly looks like:
test:
.fnstart
.pad #12
sub sp, #12 ; allocate space for variadic register args
.save {r4, r6, r7, lr}
push {r4, r6, r7, lr}
.setfp r7, sp, #8
add r7, sp, #8
.pad #36
sub sp, #36 ;
mov r4, sp ;
lsrs r4, r4, #5 ; Align stack pointer
lsls r4, r4, #5 ;
mov sp, r4 ;
str r3, [sp, #60] ;
str r2, [sp, #56] ; Store incoming arguments
str r1, [sp, #52] ;
...
The offsets, used to store the register varargs are not correct after the SP is
aligned. Instead, the function should store these arguments via the FP.</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>