[llvm-bugs] [Bug 27663] New: __builtin_va_arg stack-walk short
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu May 5 23:37:32 PDT 2016
https://llvm.org/bugs/show_bug.cgi?id=27663
Bug ID: 27663
Summary: __builtin_va_arg stack-walk short
Product: clang
Version: 3.8
Hardware: Macintosh
OS: MacOS X
Status: NEW
Severity: normal
Priority: P
Component: LLVM Codegen
Assignee: unassignedclangbugs at nondot.org
Reporter: zenith432 at users.sourceforge.net
CC: llvm-bugs at lists.llvm.org
Classification: Unclassified
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.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160506/9b664a3f/attachment.html>
More information about the llvm-bugs
mailing list