diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h index d136b459e9cd4..d5089faa41174 100644 --- a/clang/include/clang/Basic/TargetInfo.h +++ b/clang/include/clang/Basic/TargetInfo.h @@ -253,7 +253,7 @@ class TargetInfo : public TransferrableTargetInfo, const char *MCountName; unsigned char RegParmMax, SSERegParmMax; TargetCXXABI TheCXXABI; - bool UseMicrosoftManglingForC = false; + bool UseMicrosoftCCForC = false; const LangASMap *AddrSpaceMap; mutable StringRef PlatformName; @@ -1345,10 +1345,8 @@ class TargetInfo : public TransferrableTargetInfo, return TheCXXABI; } - /// Should the Microsoft mangling scheme be used for C Calling Convention. - bool shouldUseMicrosoftCCforMangling() const { - return UseMicrosoftManglingForC; - } + /// Should the Microsoft C Calling Convention be used. + bool shouldUseMicrosoftCCforC() const { return UseMicrosoftCCForC; } /// Target the specified CPU. /// diff --git a/clang/lib/AST/Mangle.cpp b/clang/lib/AST/Mangle.cpp index b44ab23f1d0e1..515a2217e7e6b 100644 --- a/clang/lib/AST/Mangle.cpp +++ b/clang/lib/AST/Mangle.cpp @@ -74,7 +74,7 @@ static CCMangling getCallingConvMangling(const ASTContext &Context, if (FD->isMain() && FD->getNumParams() == 2) return CCM_WasmMainArgcArgv; - if (!TI.shouldUseMicrosoftCCforMangling()) + if (!TI.shouldUseMicrosoftCCforC()) return CCM_Other; if (Context.getLangOpts().CPlusPlus && !isExternC(ND) && diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h index a88c851797aab..777b768b282f0 100644 --- a/clang/lib/Basic/Targets/OSTargets.h +++ b/clang/lib/Basic/Targets/OSTargets.h @@ -817,7 +817,7 @@ class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo { : OSTargetInfo(Triple, Opts) { this->WCharType = TargetInfo::UnsignedShort; this->WIntType = TargetInfo::UnsignedShort; - this->UseMicrosoftManglingForC = true; + this->UseMicrosoftCCForC = true; } }; @@ -838,7 +838,7 @@ class LLVM_LIBRARY_VISIBILITY WindowsTargetInfo : public OSTargetInfo { : OSTargetInfo(Triple, Opts) { this->WCharType = TargetInfo::UnsignedShort; this->WIntType = TargetInfo::UnsignedShort; - this->UseMicrosoftManglingForC = true; + this->UseMicrosoftCCForC = true; } }; diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index a6cdbbafec666..42a61a3570405 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -4769,11 +4769,12 @@ ExprResult Sema::CheckOSLogFormatStringArg(Expr *Arg) { /// Check that the user is calling the appropriate va_start builtin for the /// target and calling convention. static bool checkVAStartABI(Sema &S, unsigned BuiltinID, Expr *Fn) { - const llvm::Triple &TT = S.Context.getTargetInfo().getTriple(); + const TargetInfo &TI = S.Context.getTargetInfo(); + bool IsMicrosoftCC = TI.shouldUseMicrosoftCCforC(); + const llvm::Triple &TT = TI.getTriple(); bool IsX64 = TT.getArch() == llvm::Triple::x86_64; bool IsAArch64 = (TT.getArch() == llvm::Triple::aarch64 || TT.getArch() == llvm::Triple::aarch64_32); - bool IsWindows = TT.isOSWindows(); bool IsMSVAStart = BuiltinID == Builtin::BI__builtin_ms_va_start; if (IsX64 || IsAArch64) { CallingConv CC = CC_C; @@ -4781,7 +4782,7 @@ static bool checkVAStartABI(Sema &S, unsigned BuiltinID, Expr *Fn) { CC = FD->getType()->castAs()->getCallConv(); if (IsMSVAStart) { // Don't allow this in System V ABI functions. - if (CC == CC_X86_64SysV || (!IsWindows && CC != CC_Win64)) + if (CC == CC_X86_64SysV || (!IsMicrosoftCC && CC != CC_Win64)) return S.Diag(Fn->getBeginLoc(), diag::err_ms_va_start_used_in_sysv_function); } else { @@ -4789,11 +4790,11 @@ static bool checkVAStartABI(Sema &S, unsigned BuiltinID, Expr *Fn) { // On x64 Windows, don't allow this in System V ABI functions. // (Yes, that means there's no corresponding way to support variadic // System V ABI functions on Windows.) - if ((IsWindows && CC == CC_X86_64SysV) || - (!IsWindows && CC == CC_Win64)) + if ((IsMicrosoftCC && CC == CC_X86_64SysV) || + (!IsMicrosoftCC && CC == CC_Win64)) return S.Diag(Fn->getBeginLoc(), diag::err_va_start_used_in_wrong_abi_function) - << !IsWindows; + << !IsMicrosoftCC; } return false; } diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index a36a2f563739e..014c11fd7e74c 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -17990,7 +17990,7 @@ static bool isPotentiallyConstantEvaluatedContext(Sema &SemaRef) { static bool funcHasParameterSizeMangling(Sema &S, FunctionDecl *FD) { // These manglings are only applicable for targets whcih use Microsoft // mangling scheme for C. - if (!S.Context.getTargetInfo().shouldUseMicrosoftCCforMangling()) + if (!S.Context.getTargetInfo().shouldUseMicrosoftCCforC()) return false; // If this is C++ and this isn't an extern "C" function, parameters do not diff --git a/clang/test/Sema/varargs.c b/clang/test/Sema/varargs.c index bec41dda65d57..2bca4d9e74172 100644 --- a/clang/test/Sema/varargs.c +++ b/clang/test/Sema/varargs.c @@ -1,5 +1,8 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -triple i386-pc-unknown +// RUN: %clang_cc1 -fsyntax-only -verify %s -triple i386-mingw32 // RUN: %clang_cc1 -fsyntax-only -verify %s -triple x86_64-apple-darwin9 +// RUN: %clang_cc1 -fsyntax-only -verify %s -triple x86_64-mingw64 +// RUN: %clang_cc1 -fsyntax-only -verify %s -triple x86_64-uefi // RUN: %clang_cc1 -fsyntax-only -fms-compatibility -DMS -verify %s -triple x86_64-pc-win32 void f1(int a)