Bug 31628 - stdcall function is miscompiled
Summary: stdcall function is miscompiled
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.3.0
Assignee: Richard Henderson
URL:
Keywords:
Depends on:
Blocks: 31681 31989
  Show dependency treegraph
 
Reported: 2007-04-18 19:44 UTC by marcus
Modified: 2007-05-26 03:10 UTC (History)
4 users (show)

See Also:
Host:
Target: i686-*
Build: x86_64-unknown-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2007-04-18 22:14:05


Attachments
reg.i (118 bytes, text/plain)
2007-04-18 19:44 UTC, marcus
Details

Note You need to log in before you can comment on or make changes to this bug.
Description marcus 2007-04-18 19:44:17 UTC
Testcase is extracted from Wine.

/home/marcus/projects/gcc/BIN/bin/gcc -m32 -fPIC   -O2  -o reg reg.i
./reg
Segmentation fault
(I did not try the i586 version of the compiler.)


Looking at the disassembly the stdcall function is compiled as:
foo:
        pushl   %ebp
        movl    %esp, %ebp
        pushl   %ebx
        call    __i686.get_pc_thunk.bx
        addl    $_GLOBAL_OFFSET_TABLE_, %ebx
        subl    $4, %esp
        movl    $0, (%esp)
        call    bar@PLT
        addl    $4, %esp
        popl    %ebx
        popl    %ebp
        ret

It does adjust the stackframe after the call to bar wrongly, either it should
not do it, or just emit a "leave".
Comment 1 marcus 2007-04-18 19:44:47 UTC
Created attachment 13389 [details]
reg.i

gcc -fPIC -O2 -m32 reg.i
Comment 2 marcus 2007-04-18 19:45:51 UTC
i bisected gcc to find the regression and it was apparently introduced by
revision 123146.

2007-03-22  Richard Henderson  <rth@redhat.com>

       * config/i386/i386.c (ix86_function_regparm): Early exit for 64-bit;
       don't increase local_regparm with force_align_arg_pointer check.
       (ix86_function_sseregparm): Assert 32-bit.
       (type_has_variadic_args_p): New.
[...]
Comment 3 marcus 2007-04-18 19:46:29 UTC
the interesting part is that the declaration is just slightly incompatible
with the actual definition. If I remove the prototype the problem goes away.
Comment 4 Richard Biener 2007-04-18 20:16:43 UTC
Confirmed.
Comment 5 Richard Henderson 2007-04-18 22:14:05 UTC
Reproducing the problem requires -maccumulate-outgoing-args,
as implied by i686 tuning.
Comment 6 Richard Henderson 2007-04-21 00:53:52 UTC
Subject: Bug 31628

Author: rth
Date: Sat Apr 21 00:53:37 2007
New Revision: 124014

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=124014
Log:
        PR target/31628
        * config/i386/i386.c (type_has_variadic_args_p): Look for any
        TREE_LIST with a void_type_node value, not void_list_node exactly.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/i386/i386.c

Comment 7 Richard Henderson 2007-04-21 00:58:30 UTC
Fixed.
Comment 8 hjl@gcc.gnu.org 2007-05-18 20:30:19 UTC
Subject: Bug 31628

Author: hjl
Date: Fri May 18 19:29:45 2007
New Revision: 124831

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=124831
Log:
2007-05-18  H.J. Lu  <hongjiu.lu@intel.com>

	PR target/31628
	* gcc.target/i386/pr31628.c: New.

Added:
    trunk/gcc/testsuite/gcc.target/i386/pr31628.c
Modified:
    trunk/gcc/testsuite/ChangeLog