<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 --- - __builtin_va_arg stack-walk short"
href="https://llvm.org/bugs/show_bug.cgi?id=27663">27663</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>__builtin_va_arg stack-walk short
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.8
</td>
</tr>
<tr>
<th>Hardware</th>
<td>Macintosh
</td>
</tr>
<tr>
<th>OS</th>
<td>MacOS X
</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>LLVM Codegen
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>zenith432@users.sourceforge.net
</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>I've marked this as clang 3.8, but code was compiled on Apple's Xcode 7.3.1.
Sample code
================ va_sum.c
int va_sum(unsigned int count, ...)
{
int sum = 0;
__builtin_ms_va_list ap;
__builtin_ms_va_start(ap, count);
while (count) {
sum += __builtin_va_arg(ap, int);
--count;
}
__builtin_ms_va_end(ap);
return sum;
}
==================
Compiled with
clang -S -Os -fno-unwind-tables -target x86_64-pc-win32-macho va_sum.c
generates this code
================ va_sum.s
.section __TEXT,__text,regular,pure_instructions
.globl _va_sum
_va_sum: ## @va_sum
## BB#0:
pushq %rax
movq %r9, 40(%rsp)
movq %r8, 32(%rsp)
movq %rdx, 24(%rsp)
leaq 24(%rsp), %rax
movq %rax, (%rsp)
xorl %eax, %eax
testl %ecx, %ecx
je LBB0_2
LBB0_1: ## %.lr.ph
## =>This Inner Loop Header: Depth=1
movq (%rsp), %r8
addq $3, %r8
andq $-4, %r8
leaq 4(%r8), %rdx
movq %rdx, (%rsp)
addl (%r8), %eax
decl %ecx
jne LBB0_1
LBB0_2: ## %._crit_edge
popq %rdx
retq
.subsections_via_symbols
========================
The stack walk is wrong (leaq, 4(%r8), %rdx). It advances the pointer by 4
bytes each time - the sizeof(int). On x86_64 the stack needs to be walked by
steps of 8 bytes.</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>