Bug 54895 - the compiler treats '__cdecl' & '__stdcall' as the same.
Summary: the compiler treats '__cdecl' & '__stdcall' as the same.
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on: 44282
Blocks:
  Show dependency treegraph
 
Reported: 2012-10-10 19:52 UTC by niXman
Modified: 2021-07-23 11:53 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.4.0, 4.5.0, 4.6.0, 4.7.0, 4.8.0
Last reconfirmed: 2012-11-22 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description niXman 2012-10-10 19:52:22 UTC
When I compile this simple code:
void myfoo(void(__cdecl*)()){}
void myfoo(void(__stdcall*)()){}
int main(){}


I get the following error:
Assembler messages:
Error: symbol `__Z5myfooPFvvE' is already defined

Why the compiler treats theese two specificators as the same?


Another example code work as expected:
template<typename T, typename U>
struct is_same {
        enum { value = 0 };
};

template<typename T>
struct is_same<T, T> {
        enum { value = 1 };
};

int main() {
        typedef void(__stdcall* stdcall_func_ptr)();
        typedef void(__cdecl* cdecl_func_ptr)();

        return is_same<stdcall_func_ptr, cdecl_func_ptr>::value;
}

main returns 0
Comment 1 niXman 2012-10-10 19:53:48 UTC
used i686-w64-mingw32
Comment 2 Ozkan Sezer 2012-10-10 20:17:26 UTC
FWIW, this is not specific to 4.7 and goes back to at least 4.4.
Comment 3 Marc Glisse 2012-10-10 20:52:38 UTC
Related to PR c++/2316. Those attributes are properly supported in C but not with fancy C++ features. I don't think they have a mangling, for instance.
Comment 4 Kai Tietz 2012-11-22 11:47:12 UTC
This is most likely a duplicate of already fixed PR/55268.
Comment 5 niXman 2012-11-22 18:37:55 UTC
(In reply to comment #4)
> This is most likely a duplicate of already fixed PR/55268.

I checked upon the 193725 revision.
The first test gives the same result. The second test now gives the wrong result(1). Before this the result of the second test was right.
Comment 6 Kai Tietz 2012-11-22 18:48:18 UTC
(In reply to comment #5)
> (In reply to comment #4)
> > This is most likely a duplicate of already fixed PR/55268.
> 
> I checked upon the 193725 revision.
> The first test gives the same result. The second test now gives the wrong
> result(1). Before this the result of the second test was right.

Well, the first test fails due the calling-convention isn't part of the signature in C++.  For C you will get for this code simply a double-definition.  Issue here is that we don't get an error for g++ as it detects that a types are different for both myfoo functions.

The second case checks something different. That it now returns 1 is correct due types are different due different calling-convention used.

So remaining testcase is the first one.
Comment 7 Kai Tietz 2012-11-22 18:55:40 UTC
it is actual not a target issue.  it is more a general c++ issue as
calling-convention (call-abi attributes) aren't part of signature.
Comment 8 Paolo Carlini 2012-11-22 19:08:14 UTC
So it works everywhere? ;)
Comment 9 Kai Tietz 2012-11-22 19:11:12 UTC
(In reply to comment #8)
> So it works everywhere? ;)

Well, it doesn't work for all targets providing different calling-conventions for functions.  Eg functions with regparm, stdcall, etc
That the sample is architecture specific, doesn't make it there for target specific, isn't it? ;)
Comment 10 Paolo Carlini 2012-11-22 19:14:03 UTC
I don't know, I'm still finding the "Known to work" field pretty weird, to be honest.
Comment 11 Kai Tietz 2012-11-22 19:15:49 UTC
heh, oh duhh :}
Comment 12 Kai Tietz 2015-09-22 10:32:59 UTC
This bug got partially fixed for x86 (32-bit) by PR/44282.  For x64 we have the issue that there is made no difference between different calling-conventions, as all variants are treated as standard fastcall-convention under the hood.