[PATCH] Delete CC_Default and use the target default CC everywhere

Richard Smith richard at metafoo.co.uk
Wed Aug 7 16:00:12 PDT 2013

Comment at: lib/AST/ASTContext.cpp:7765-7766
@@ -7771,3 +7764,4 @@
   FunctionType::ExtInfo EI;
+  EI = EI.withCallingConv(CC_C);
   if (BuiltinInfo.isNoReturn(Id)) EI = EI.withNoReturn(true);
Reid Kleckner wrote:
> Richard Smith wrote:
> > This worries me. We default-construct ExtInfo within ExtProtoInfo instances all over the place. Can we make ExtInfo not be default-constructible?
> It could be done, but it would require significantly rewriting every construction of ExtProtoInfo as well.  ExtInfo() currently zero initializes, which happens to be equivalent to CC_C.  How about I make ExtInfo default construct with CC_C?
That's what it's already doing, since `CC_C` is the new calling convention zero. My concern is that `CC_C` is not an appropriate default, since it's wrong when creating a method. How many places construct an `ExtProtoInfo` (and don't already set a calling convention)?

Comment at: lib/AST/ASTContext.cpp:7942
@@ -7946,7 +7941,3 @@
-CallingConv ASTContext::getCanonicalCallConv(CallingConv CC) const {
-  if (CC == CC_C && !LangOpts.MRTD &&
-      getTargetInfo().getCXXABI().isMemberFunctionCCDefault())
-    return CC_Default;
-  return CC;
+  return (LangOpts.MRTD && !IsVariadic) ? CC_X86StdCall : CC_C;
Reid Kleckner wrote:
> Richard Smith wrote:
> > The IsVariadic check appears to be new here, but I believe it's correct. Do we have test coverage for this?
> It looks like the LLVM x86 backend simply lowers x86_stdcallcc as caller cleanup, so I don't think this IsVariadic check is necessary.  I added a variadic function to the existing -mrtd test, but should it use x86_stdcallcc on variadic functions or not?
Per the GCC manual, `-mrtd` only affects the calling convention of "functions that take a fixed number of arguments." Consider:

    extern void (*a)(int, int);
    __attribute__((cdecl)) extern void (*a)(int, int);
    extern void (*b)(int, ...);
    __attribute__((cdecl)) extern void (*b)(int, ...);
    extern void (*c)(int, int);
    __attribute__((stdcall)) extern void (*c)(int, int);
    extern void (*d)(int, ...);
    __attribute__((stdcall)) extern void (*d)(int, ...);

GCC accepts `b` and always rejects `d` irrespective of `-mrtd`.
Without `-mrtd`, it accepts `a` and rejects `c`.
With `-mrtd`, it accepts `c` and rejects `a`.


More information about the cfe-commits mailing list