<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Oct 15, 2013 at 3:00 PM, Rafael Espíndola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im">> Almost right.  Don't try to mangle non-extern C C++ symbols, as in things<br>

> that return true for shouldMangleCXXName().  This test case gives the symbol<br>
> ?foo@Foo@@QAGXXZ, which demangles to (public: void __stdcall<br>
> Foo::foo(void)), which already includes the calling convention anyway.<br>
><br>
> struct Foo {<br>
>   void __stdcall foo();<br>
> };<br>
> void Foo::foo() {}<br>
><br>
> Feel free to commit with that fixed.<br>
<br>
</div>The code was already handling that, but looking at it I found that it<br>
would get confused with corner cases like<br>
<br>
extern "C" void __stdcall operator++(Foo &x).<br>
<br>
To be fair, it look like gcc and cl get confused too. I have update<br>
the patch. Would you mind one final review? Thanks.<br></blockquote><div><br></div><div>+  const ASTContext &ASTContext = getASTContext();<br></div><div><div>+  StdOrFastCC CC = getStdOrFastCallMangling(ASTContext, D);</div>
<div>+  bool MCXX = shouldMangleCXXName(D);</div><div>+  const TargetInfo &TI = Context.getTargetInfo();</div><div>+  if (CC == SOF_OTHER || (MCXX && TI.getCXXABI() == TargetCXXABI::Microsoft)) {</div><div>+    mangleCXXName(D, Out);</div>
<div>+    return;</div><div>+  }</div></div><div><br></div><div><div>Oh, I see, mingw does the opposite.  :(  I was hoping it would be the same, but I guess it makes sense because we don't mangle calling conventions under Itanium.  We might want actually want to add a mangling, seeing as you can overload based on CC in clang.</div>
<div><br></div><div>I think John would tell you to sink this logic into the MangleContext subclasses.</div><div><br></div><div></div></div><div><div>+  // Variadic functions do not receive @0 suffix.<br></div></div><div><div>
+  const FunctionDecl *FD = cast<FunctionDecl>(D);</div><div>+  const FunctionType *FT = FD->getType()->castAs<FunctionType>();</div><div>+  const FunctionProtoType *Proto = dyn_cast<FunctionProtoType>(FT);</div>
<div>+  if (Proto && Proto->isVariadic())</div><div>+    return;</div></div><div><div>+  if (!Proto) {</div><div>+    Out << '0';</div><div>+    return;</div><div>+  }</div></div><div><br></div><div>
Can this be tested?  I thought we removed fastcall and cdecl from variadic functions, and I have no idea what happens for K&R functions.</div></div></div></div>