Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] __cdecl is not equivalent to "default calling convention" anymore #13716

Closed
timurrrr opened this issue Jul 12, 2012 · 10 comments
Closed
Assignees
Labels
bugzilla Issues migrated from bugzilla c++

Comments

@timurrrr
Copy link
Contributor

Bugzilla Link 13344
Resolution FIXED
Resolved on Feb 18, 2013 16:04
Version trunk
OS Windows NT
Blocks #12849
CC @DougGregor,@tritao,@rjmccall,@ftynse

Extended Description

Looks like my r160121 change has regressed:
$ cat cdecl.cpp
void foo();
void __cdecl foo();

$ clang++ -c cdecl.cpp && echo "OK"
OK

$ clang++ -Xclang -cxx-abi -Xclang microsoft -c cdecl.cpp && echo "OK"
cdecl.cpp:2:14: error: function declared 'cdecl' here was previously declared without calling convention
void __cdecl foo();
^
cdecl.cpp:1:6: note: previous declaration is here
void foo();
^
1 error generated.

$ cl -nologo -c cdecl.cpp && echo "OK"
cdecl.cpp
OK

@timurrrr
Copy link
Contributor Author

assigned to @timurrrr

@timurrrr
Copy link
Contributor Author

Any suggestions?
It looks like getCanonicalCallConv should know whether it's called for a free function or a CXX method :(

@rjmccall
Copy link
Contributor

Let's not go down that road.

This needs to be handled in the function-merging logic: it's okay to merge a function with CC_Default with a function with an explicit CC if the default CC for that kind of function is the same as the explicit CC. This is the code at SemaDecl.cpp:1962. If you do this right, you should also get the analogous case with _thiscall on a method (admittedly, it's harder to redeclare those).

@timurrrr
Copy link
Contributor Author

Let's not go down that road.

This needs to be handled in the function-merging logic: it's okay to merge a
function with CC_Default with a function with an explicit CC if the default CC
for that kind of function is the same as the explicit CC. This is the code at
SemaDecl.cpp:1962.
OK, I got some code like this working.
Will send it for review when I'm sure what I'm doing :)

But currently it assumes CC_Default == CC_C which is might not be true for free functions on some archs (right?).

If you do this right, you should also get the analogous
case with _thiscall on a method (admittedly, it's harder to redeclare those).
Not that hard :)

class A {
 public:
    void bar();
};

void __thiscall A::bar() {}

Working on this...

@timurrrr
Copy link
Contributor Author

Patch sent out for review a few days ago, assigning to myself.

@timurrrr
Copy link
Contributor Author

One more thing to fix:

$ cat cdecl_pointer.cpp
typedef void (__cdecl * PTR)();

void foo() {}

void bar(PTR h) {}

int main() {
bar(&foo);
}

$ clang -c cdecl_pointer.cpp && echo "OK"
OK

$ clang -c -Xclang -cxx-abi -Xclang microsoft cdecl_pointer.cpp && echo "OK" || echo "FAIL"
cdecl_pointer.cpp:8:3: error: no matching function for call to 'bar'
bar(&foo);
^~~
cdecl_pointer.cpp:5:6: note: candidate function not viable: no known conversion from 'void ()()' to 'PTR' (aka 'void ()() attribute((cdecl))') for 1st argument
void bar(PTR h) {}
^
1 error generated.
FAIL

@timurrrr
Copy link
Contributor Author

comment #​5 repro is not llvm/llvm-bugzilla-archive#13457

@timurrrr
Copy link
Contributor Author

s/not/now

@tritao
Copy link
Mannequin

tritao mannequin commented Aug 25, 2012

Fixed as of r162639.

Good job, Timur.

@ftynse
Copy link
Member

ftynse commented Nov 26, 2021

mentioned in issue llvm/llvm-bugzilla-archive#13457

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c++
Projects
None yet
Development

No branches or pull requests

3 participants