Bug 9381 - attribute on member function pointer have no effect
Summary: attribute on member function pointer have no effect
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.2.1
: P3 normal
Target Milestone: 4.4.3
Assignee: Jason Merrill
URL:
Keywords: wrong-code
: 11893 29911 34468 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-01-21 04:56 UTC by Ulrich Drepper
Modified: 2009-11-07 20:24 UTC (History)
10 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-11-06 04:56:44


Attachments
e.cc (143 bytes, text/plain)
2003-05-21 15:17 UTC, Ulrich Drepper
Details
The testcase fail g++ 4.3.0 (246 bytes, text/plain)
2008-07-11 07:43 UTC, Bo Yang
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ulrich Drepper 2003-01-21 04:56:00 UTC
The attached file is miscompiled since the stdcall attribute is ignored in the fp type definition.  The result it that in the function bar the parameters are popped from the stack even though they have already been removed by the called fucntion (f1 in this case).

Release:
gcc 3.2.1, current CVS trunk

Environment:
x86/Linux

How-To-Repeat:
gcc -c e.cc -O2 -fomit-frame-pointer -mpreferred-stack-boundary=2
Look in the code generated for bar, there should be no popping for the pushed parameters.  In my case I get

  28:   ff 74 24 08             pushl  0x8(%esp,1)
  2c:   50                      push   %eax
  2d:   ff d2                   call   *%edx
  2f:   5a                      pop    %edx
  30:   59                      pop    %ecx
  31:   5b                      pop    %ebx
  32:   c3                      ret

The pop %ebx is OK (it's a saved register) but the other two pops are wrong.
Comment 1 Christian Ehrhardt 2003-01-21 15:10:30 UTC
From: "Christian Ehrhardt" <ehrhardt@mathematik.uni-ulm.de>
To: drepper@redhat.com
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: c++/9381: stdcall attribute ignored in member function pointer type
Date: Tue, 21 Jan 2003 15:10:30 +0100

 On Tue, Jan 21, 2003 at 04:52:51AM -0000, drepper@redhat.com wrote:
 > The attached file is miscompiled since the stdcall attribute is ignored in the fp type definition.  The result it that in the function bar the parameters are popped from the stack even though they have already been removed by the called fucntion (f1 in this case).
 
 The answer to this non bug used to be: "The placement of your __attribute__
 is wrong". This should be the proper placement:
 
 typedef int (__attribute__ ((stdcall)) foo::*fp)(int);
 
 However, with the new parser this gives a parse error :-(
 The following gives a warning with 3.4 but works with all gcc versions, it
 is documented as an extension though:
 
 typedef int (foo::*__attribute__ ((stdcall)) fp) (int);
 
 I.e. this is not a bug in 3.2.1. It is a bug in the new parser in 3.4 though.
 
     regards  Christian
 
 -- 
 THAT'S ALL FOLKS!
Comment 2 Wolfgang Bangerth 2003-02-19 03:00:22 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: Christian already analyzed this
Comment 3 Andrew Pinski 2004-01-01 04:19:25 UTC
Already fixed in 3.4:
        pushl   %ebx
        .....
        .....
        call    *%edx
        addl    $8, %esp
        popl    %ebx
        ret
Comment 4 Andrew Pinski 2004-01-01 07:08:11 UTC
The code is wrong now, I should of said that.
Comment 5 Andrew Pinski 2004-01-01 07:08:39 UTC
*** Bug 11893 has been marked as a duplicate of this bug. ***
Comment 6 Andrew Pinski 2004-01-01 08:26:15 UTC
Not a regression any more.
Comment 7 Andrew Pinski 2005-06-20 04:05:29 UTC
I do get a warning now, saying this attribute only applies to function pointers.
Comment 8 Andrew Pinski 2006-11-20 15:50:01 UTC
*** Bug 29911 has been marked as a duplicate of this bug. ***
Comment 9 Andrew Pinski 2007-12-14 20:26:34 UTC
*** Bug 34468 has been marked as a duplicate of this bug. ***
Comment 10 Bo Yang 2008-07-11 07:41:09 UTC
(In reply to comment #1)
> From: "Christian Ehrhardt" <ehrhardt@mathematik.uni-ulm.de>
> To: drepper@redhat.com
> Cc: gcc-gnats@gcc.gnu.org
> Subject: Re: c++/9381: stdcall attribute ignored in member function pointer type
> Date: Tue, 21 Jan 2003 15:10:30 +0100
> 
>  On Tue, Jan 21, 2003 at 04:52:51AM -0000, drepper@redhat.com wrote:
>  > The attached file is miscompiled since the stdcall attribute is ignored in the fp type definition.  The result it that in the function bar the parameters are popped from the stack even though they have already been removed by the called fucntion (f1 in this case).
>  
>  The answer to this non bug used to be: "The placement of your __attribute__
>  is wrong". This should be the proper placement:
>  
>  typedef int (__attribute__ ((stdcall)) foo::*fp)(int);
>  
>  However, with the new parser this gives a parse error :-(
>  The following gives a warning with 3.4 but works with all gcc versions, it
>  is documented as an extension though:
>  
>  typedef int (foo::*__attribute__ ((stdcall)) fp) (int);

I am afraid, but this did not work in gcc 4.3.0, now. I add this, but still failed with a SIGFAULT...
I attach my litter test case file, please try to compile it with g++ 4.3.0, and it will fail...
Comment 11 Bo Yang 2008-07-11 07:43:50 UTC
Created attachment 15898 [details]
The testcase fail g++ 4.3.0

From this bug http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11893, we know the typeof operator make all things correctly. But in gcc 4.3.0, this operator failed, too.
Comment 12 Jacek Caban 2009-10-09 13:24:06 UTC
(In reply to comment #6)
> Not a regression any more.

It is a regression now. It worked in 3.4 and doesn't work in 4.x. That's why I'm still using GCC 3.4.6.
Comment 13 Jason Merrill 2009-11-06 21:18:48 UTC
Subject: Bug 9381

Author: jason
Date: Fri Nov  6 21:18:35 2009
New Revision: 153977

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=153977
Log:
	PR c++/9381
	* decl2.c (build_memfn_type): Preserve attributes.
	(cp_reconstruct_complex_type): Likewise.
	(maybe_retrofit_in_chrg): Likewise.
	* call.c (standard_conversion): Use build_memfn_type.
	* pt.c (tsubst): Likewise.
	* decl.c (build_ptrmem_type): Likewise
	(check_function_type): Preserve attributes.
	* tree.c (cp_build_type_attribute_variant): Propagate exception
	specs on METHOD_TYPE, too.
	(strip_typedefs): Preserve exception specs and attributes.

Added:
    trunk/gcc/testsuite/g++.dg/abi/regparm1.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/call.c
    trunk/gcc/cp/class.c
    trunk/gcc/cp/decl.c
    trunk/gcc/cp/decl2.c
    trunk/gcc/cp/pt.c
    trunk/gcc/cp/tree.c
    trunk/gcc/testsuite/ChangeLog

Comment 14 Jason Merrill 2009-11-07 19:46:09 UTC
Subject: Bug 9381

Author: jason
Date: Sat Nov  7 19:45:56 2009
New Revision: 153998

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=153998
Log:
	PR c++/9381
	* decl2.c (build_memfn_type): Preserve attributes.
	* tree.c (canonical_type_variant): Likewise.
	* call.c (standard_conversion): Use build_memfn_type.
	* pt.c (tsubst): Likewise.
	* decl.c (build_ptrmem_type): Likewise

Added:
    branches/gcc-4_4-branch/gcc/testsuite/g++.dg/abi/regparm1.C
Modified:
    branches/gcc-4_4-branch/gcc/cp/ChangeLog
    branches/gcc-4_4-branch/gcc/cp/call.c
    branches/gcc-4_4-branch/gcc/cp/decl.c
    branches/gcc-4_4-branch/gcc/cp/decl2.c
    branches/gcc-4_4-branch/gcc/cp/pt.c
    branches/gcc-4_4-branch/gcc/cp/tree.c
    branches/gcc-4_4-branch/gcc/testsuite/ChangeLog

Comment 15 Jason Merrill 2009-11-07 20:24:51 UTC
Fixed for 4.4.3.  The patch for 4.4 applied fine to 4.3, but didn't fix the bug there for some reason.