Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions clang/include/clang/Basic/TargetInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
///
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/Mangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Basic/Targets/OSTargets.h
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo<Target> {
: OSTargetInfo<Target>(Triple, Opts) {
this->WCharType = TargetInfo::UnsignedShort;
this->WIntType = TargetInfo::UnsignedShort;
this->UseMicrosoftManglingForC = true;
this->UseMicrosoftCCForC = true;
}
};

Expand All @@ -838,7 +838,7 @@ class LLVM_LIBRARY_VISIBILITY WindowsTargetInfo : public OSTargetInfo<Target> {
: OSTargetInfo<Target>(Triple, Opts) {
this->WCharType = TargetInfo::UnsignedShort;
this->WIntType = TargetInfo::UnsignedShort;
this->UseMicrosoftManglingForC = true;
this->UseMicrosoftCCForC = true;
}
};

Expand Down
13 changes: 7 additions & 6 deletions clang/lib/Sema/SemaChecking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4769,31 +4769,32 @@ 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;
if (const FunctionDecl *FD = S.getCurFunctionDecl())
CC = FD->getType()->castAs<FunctionType>()->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 {
// On x86-64/AArch64 Unix, don't allow this in Win64 ABI functions.
// 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;
}
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions clang/test/Sema/varargs.c
Original file line number Diff line number Diff line change
@@ -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)
Expand Down