[LLVMbugs] [Bug 8314] New: Incorrect code generated with prototypes and old-style function definitions.
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Wed Oct 6 09:28:29 PDT 2010
http://llvm.org/bugs/show_bug.cgi?id=8314
Summary: Incorrect code generated with prototypes and old-style
function definitions.
Product: clang
Version: 2.8
Platform: PC
OS/Version: Linux
Status: NEW
Severity: normal
Priority: P
Component: -New Bugs
AssignedTo: unassignedclangbugs at nondot.org
ReportedBy: nbowler at draconx.ca
CC: llvmbugs at cs.uiuc.edu
When using old-style function definitions, clang seems to be ignoring any
prototypes that occur prior to the definition. This causes incorrect
code to be generated because required conversions are not performed.
Consider the following example:
#include <stdio.h>
void foo(int);
void foo(x)
int x;
{
printf("%d\n", x);
}
int main(void)
{
/* The double argument here should be converted
to int according to the prototype. */
foo(42.0);
return 0;
}
But running clang test.c emits the following code for main:
0000000000400570 <main>:
400570: 55 push %rbp
400571: 48 89 e5 mov %rsp,%rbp
400574: 48 83 ec 10 sub $0x10,%rsp
400578: b8 00 00 00 00 mov $0x0,%eax
40057d: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%rbp)
400584: f2 0f 10 05 04 01 00 movsd 0x104(%rip),%xmm0 #
400690 <_IO_stdin_used+0x8>
40058b: 00
40058c: 89 45 f8 mov %eax,-0x8(%rbp)
40058f: b0 01 mov $0x1,%al
400591: e8 aa ff ff ff callq 400540 <foo>
400596: 8b 45 f8 mov -0x8(%rbp),%eax
400599: 48 83 c4 10 add $0x10,%rsp
40059d: 5d pop %rbp
40059e: c3 retq
40059f: 90 nop
which, of course, means foo is passed whatever happened to be in %edi at the
time, rather than 42 as expected (e.g., it prints the number of command-line
arguments on my system).
If the prototype is moved after the function definition, the program works
properly.
--
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
More information about the llvm-bugs
mailing list