+ /// Implement emitting a version of the operator for many of the calling
+ /// conventions for MSVC, as described here:
+ /// https://devblogs.microsoft.com/oldnewthing/20150220-00/?p=44623.
+ /// Experimentally, we determined that cdecl, stdcall, fastcall, and
+ /// vectorcall are generated by MSVC when it is supported by the target.
+ /// Additionally, we are ensuring that the default-free/default-member and
+ /// call-operator calling convention are generated as well.
+ /// NOTE: We intentionally generate a 'thiscall' on Win32 implicitly from the
+ /// 'member default', despite MSVC not doing so. We do this in order to ensure
+ /// that someone who intentionally places 'thiscall' on the lambda call
+ /// operator will still get that overload, since we don't have the a way of
+ /// detecting the attribute by the time we get here.
+ if (S.getLangOpts().MSVCCompat) {
+ CallingConv Convs[] = {
+ CC_C, CC_X86StdCall, CC_X86FastCall, CC_X86VectorCall,
+ DefaultFree, DefaultMember, CallOpCC};
+ llvm::sort(Convs);
+ llvm::iterator_range<CallingConv *> Range(
+ std::begin(Convs), std::unique(std::begin(Convs), std::end(Convs)));
+ const TargetInfo &TI = S.getASTContext().getTargetInfo();
+
+ for (CallingConv C : Range) {
+ if (TI.checkCallingConvention(C) == TargetInfo::CCCR_OK)
+ F(C);
+ }
+ return;
+ }
+