Do not apply calling conventions to MSVC entry points

Fix link error for MSVC entry points when calling conventions
are specified. MSVC entry points should have default calling
convention.

Differential Revision: https://reviews.llvm.org/D87701
This commit is contained in:
Elizabeth Andrews
2020-09-14 14:33:01 -07:00
parent 66df98945e
commit 4cff1b40da
2 changed files with 46 additions and 7 deletions

View File

@@ -11095,6 +11095,11 @@ void Sema::CheckMSVCRTEntryPoint(FunctionDecl *FD) {
if (FD->getName() != "DllMain")
FD->setHasImplicitReturnZero(true);
if (FT->getCallConv() != CC_C) {
FT = Context.adjustFunctionType(FT, FT->getExtInfo().withCallingConv(CC_C));
FD->setType(QualType(FT, 0));
}
if (!FD->isInvalidDecl() && FD->getDescribedFunctionTemplate()) {
Diag(FD->getLocation(), diag::err_mainlike_template_decl) << FD;
FD->setInvalidDecl();

View File

@@ -1,10 +1,14 @@
// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -fdefault-calling-conv=cdecl -emit-llvm -o - %s | FileCheck %s --check-prefix=CDECL --check-prefix=ALL
// RUN: %clang_cc1 -triple i786-unknown-linux-gnu -target-feature +sse4.2 -fdefault-calling-conv=fastcall -emit-llvm -o - %s | FileCheck %s --check-prefix=FASTCALL --check-prefix=ALL
// RUN: %clang_cc1 -triple i486-unknown-linux-gnu -fdefault-calling-conv=stdcall -emit-llvm -o - %s | FileCheck %s --check-prefix=STDCALL --check-prefix=ALL
// RUN: %clang_cc1 -triple i486-unknown-linux-gnu -mrtd -emit-llvm -o - %s | FileCheck %s --check-prefix=STDCALL --check-prefix=ALL
// RUN: %clang_cc1 -triple i986-unknown-linux-gnu -fdefault-calling-conv=vectorcall -emit-llvm -o - %s | FileCheck %s --check-prefix=VECTORCALL --check-prefix=ALL
// RUN: %clang_cc1 -triple i986-unknown-linux-gnu -fdefault-calling-conv=regcall -emit-llvm -o - %s | FileCheck %s --check-prefix=REGCALL --check-prefix=ALL
// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -fdefault-calling-conv=cdecl -emit-llvm -o - %s -DMAIN | FileCheck %s --check-prefix=CDECL --check-prefix=ALL
// RUN: %clang_cc1 -triple i786-unknown-linux-gnu -target-feature +sse4.2 -fdefault-calling-conv=fastcall -emit-llvm -o - %s -DMAIN | FileCheck %s --check-prefix=FASTCALL --check-prefix=ALL
// RUN: %clang_cc1 -triple i486-unknown-linux-gnu -fdefault-calling-conv=stdcall -emit-llvm -o - %s -DMAIN | FileCheck %s --check-prefix=STDCALL --check-prefix=ALL
// RUN: %clang_cc1 -triple i486-unknown-linux-gnu -mrtd -emit-llvm -o - %s -DMAIN | FileCheck %s --check-prefix=STDCALL --check-prefix=ALL
// RUN: %clang_cc1 -triple i986-unknown-linux-gnu -fdefault-calling-conv=vectorcall -emit-llvm -o - %s -DMAIN | FileCheck %s --check-prefix=VECTORCALL --check-prefix=ALL
// RUN: %clang_cc1 -triple i986-unknown-linux-gnu -fdefault-calling-conv=regcall -emit-llvm -o - %s -DMAIN | FileCheck %s --check-prefix=REGCALL --check-prefix=ALL
// RUN: %clang_cc1 -triple i386-pc-win32 -target-feature +sse4.2 -fdefault-calling-conv=fastcall -emit-llvm -o - %s -DWMAIN | FileCheck %s --check-prefix=WMAIN
// RUN: %clang_cc1 -triple i386-pc-win32 -target-feature +sse4.2 -fdefault-calling-conv=fastcall -emit-llvm -o - %s -DWINMAIN | FileCheck %s --check-prefix=WINMAIN
// RUN: %clang_cc1 -triple i386-pc-win32 -target-feature +sse4.2 -fdefault-calling-conv=fastcall -emit-llvm -o - %s -DWWINMAIN | FileCheck %s --check-prefix=WWINMAIN
// RUN: %clang_cc1 -triple i386-pc-win32 -target-feature +sse4.2 -fdefault-calling-conv=fastcall -emit-llvm -o - %s -DDLLMAIN | FileCheck %s --check-prefix=DLLMAIN
//
// CDECL: define void @_Z5test1v
// FASTCALL: define x86_fastcallcc void @_Z5test1v
// STDCALL: define x86_stdcallcc void @_Z5test1v
@@ -46,7 +50,37 @@ void test() {
a.test_member();
}
#ifdef MAIN
// ALL: define i32 @main
int main() {
return 1;
}
#endif // main
#ifdef WMAIN
// WMAIN: define dso_local i32 @wmain
int wmain() {
return 1;
}
#endif // wmain
#ifdef WINMAIN
// WINMAIN: define dso_local i32 @WinMain
int WinMain() {
return 1;
}
#endif // WinMain
#ifdef WWINMAIN
// WWINMAIN: define dso_local i32 @wWinMain
int wWinMain() {
return 1;
}
#endif // wWinMain
#ifdef DLLMAIN
// DLLMAIN: define dso_local i32 @DllMain
int DllMain() {
return 1;
}
#endif // DllMain