This is an archive of the discontinued LLVM Phabricator instance.

[Reland] "Do not apply calling conventions to MSVC entry points"
ClosedPublic

Authored by eandrews on Mar 4 2021, 5:48 AM.

Details

Summary

This patch is a second attempt at fixing a link error for MSVC entry points when calling conventions are specified using a flag.

Calling conventions specified using flags should not be applied to MSVC entry points. The default calling convention is set in this case. The default calling convention for MSVC entry points main and wmain is cdecl. For WinMain, wWinMain and DllMain, the default calling convention is stdcall on 32 bit Windows.

Explicitly specified calling conventions are applied to MSVC entry points.

For MinGW, the default calling convention for all MSVC entry points is __cdecl.

First attempt: 4cff1b40dacf6 (https://reviews.llvm.org/D87701)
Revert of first attempt: bebfc3b92d5e8

Diff Detail

Event Timeline

eandrews created this revision.Mar 4 2021, 5:48 AM
eandrews requested review of this revision.Mar 4 2021, 5:48 AM
rnk added a comment.Mar 4 2021, 11:18 AM

Seems reasonable

clang/lib/Sema/SemaDecl.cpp
11218–11219

This should only be done on 32-bit x86 platforms. I think i686-window-msvc is the more special case platform here, so I would recommend making the helper something like isDefaultStdCall, which is true for i686-windows-msvc, false for mingw and non-x86 triples, and false for main/wmain.

eandrews updated this revision to Diff 329099.Mar 8 2021, 12:29 PM
eandrews edited the summary of this revision. (Show Details)

Implemented review comment to restrict __stdcall default calling convention (for WinMain, wWinMain, and DllMain) to 32 bit Windows.

eandrews added inline comments.Mar 8 2021, 12:31 PM
clang/lib/Sema/SemaDecl.cpp
11218–11219

Thanks for the review @rnk! I think I made the change you requested.

rnk accepted this revision.Mar 8 2021, 1:22 PM

lgtm, thanks!

This revision is now accepted and ready to land.Mar 8 2021, 1:22 PM
This revision was automatically updated to reflect the committed changes.
eandrews marked an inline comment as done.
Herald added a project: Restricted Project. · View Herald TranscriptMar 18 2021, 4:41 AM