r230668 - Win64: Silently ignore __stdcall, __fastcall, and __thiscall
Reid Kleckner
reid at kleckner.net
Thu Feb 26 11:43:46 PST 2015
Author: rnk
Date: Thu Feb 26 13:43:46 2015
New Revision: 230668
URL: http://llvm.org/viewvc/llvm-project?rev=230668&view=rev
Log:
Win64: Silently ignore __stdcall, __fastcall, and __thiscall
MSVC doesn't warn on this. Users are expected to apply the WINAPI macro
to functions passed by pointer to the Win32 API, and this macro expands
to __stdcall. This means we end up with a lot of useless noisy warnings
about ignored calling conventions when compiling code with clang for
Win64.
Modified:
cfe/trunk/include/clang/Basic/TargetInfo.h
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/test/Sema/MicrosoftCompatibility-x64.c
Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=230668&r1=230667&r2=230668&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Thu Feb 26 13:43:46 2015
@@ -842,7 +842,8 @@ public:
enum CallingConvCheckResult {
CCCR_OK,
- CCCR_Warning
+ CCCR_Warning,
+ CCCR_Ignore,
};
/// \brief Determines whether a given calling convention is valid for the
Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=230668&r1=230667&r2=230668&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Thu Feb 26 13:43:46 2015
@@ -3626,19 +3626,31 @@ public:
IntPtrType = SignedLongLong;
this->UserLabelPrefix = "";
}
+
void getTargetDefines(const LangOptions &Opts,
MacroBuilder &Builder) const override {
WindowsTargetInfo<X86_64TargetInfo>::getTargetDefines(Opts, Builder);
Builder.defineMacro("_WIN64");
}
+
BuiltinVaListKind getBuiltinVaListKind() const override {
return TargetInfo::CharPtrBuiltinVaList;
}
+
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
- return (CC == CC_C ||
- CC == CC_X86VectorCall ||
- CC == CC_IntelOclBicc ||
- CC == CC_X86_64SysV) ? CCCR_OK : CCCR_Warning;
+ switch (CC) {
+ case CC_X86StdCall:
+ case CC_X86ThisCall:
+ case CC_X86FastCall:
+ return CCCR_Ignore;
+ case CC_C:
+ case CC_X86VectorCall:
+ case CC_IntelOclBicc:
+ case CC_X86_64SysV:
+ return CCCR_OK;
+ default:
+ return CCCR_Warning;
+ }
}
};
} // end anonymous namespace
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=230668&r1=230667&r2=230668&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Thu Feb 26 13:43:46 2015
@@ -3393,9 +3393,12 @@ bool Sema::CheckCallingConvAttr(const At
const TargetInfo &TI = Context.getTargetInfo();
TargetInfo::CallingConvCheckResult A = TI.checkCallingConvention(CC);
- if (A == TargetInfo::CCCR_Warning) {
- Diag(attr.getLoc(), diag::warn_cconv_ignored) << attr.getName();
+ if (A != TargetInfo::CCCR_OK) {
+ if (A == TargetInfo::CCCR_Warning)
+ Diag(attr.getLoc(), diag::warn_cconv_ignored) << attr.getName();
+ // This convention is not valid for the target. Use the default function or
+ // method calling convention.
TargetInfo::CallingConvMethodType MT = TargetInfo::CCMT_Unknown;
if (FD)
MT = FD->isCXXInstanceMember() ? TargetInfo::CCMT_Member :
Modified: cfe/trunk/test/Sema/MicrosoftCompatibility-x64.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/MicrosoftCompatibility-x64.c?rev=230668&r1=230667&r2=230668&view=diff
==============================================================================
--- cfe/trunk/test/Sema/MicrosoftCompatibility-x64.c (original)
+++ cfe/trunk/test/Sema/MicrosoftCompatibility-x64.c Thu Feb 26 13:43:46 2015
@@ -1,8 +1,13 @@
-// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wmicrosoft -verify -fms-compatibility -triple x86_64-pc-win32
-int __stdcall f(void); /* expected-warning {{calling convention '__stdcall' ignored for this target}} */
+// RUN: %clang_cc1 %s -Wmicrosoft -verify -fms-compatibility -triple x86_64-pc-win32
-/* This should compile without warning because __stdcall is treated
-as __cdecl in MS compatibility mode for x64 compiles*/
+// None of these should warn. stdcall is treated as equivalent to cdecl on
+// x64.
+// expected-no-diagnostics
+
+int __stdcall f(void);
int __cdecl f(void) {
return 0;
}
+int __stdcall func_std(void);
+int __thiscall func_this(void);
+int __fastcall func_fast(void);
More information about the cfe-commits
mailing list