<div dir="ltr">Without a GlobalValue you don't get the right mangling for fastcall or stdcall, which is half of the complexity of the IR-level mangler. I guess all it really needs is the LLVM function prototype and LLVM calling convention, but that would require calling into CodeGenTypes.h.</div>
<div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Aug 1, 2014 at 8:01 AM, Eli Bendersky <span dir="ltr"><<a href="mailto:eliben@google.com" target="_blank">eliben@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: eliben<br>
Date: Fri Aug 1 10:01:10 2014<br>
New Revision: 214520<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=214520&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=214520&view=rev</a><br>
Log:<br>
Add IR Mangler for more stable mangling.<br>
<br>
Modified:<br>
cfe/trunk/test/Index/print-mangled-name.cpp<br>
cfe/trunk/tools/libclang/CIndex.cpp<br>
<br>
Modified: cfe/trunk/test/Index/print-mangled-name.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/print-mangled-name.cpp?rev=214520&r1=214519&r2=214520&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/print-mangled-name.cpp?rev=214520&r1=214519&r2=214520&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Index/print-mangled-name.cpp (original)<br>
+++ cfe/trunk/test/Index/print-mangled-name.cpp Fri Aug 1 10:01:10 2014<br>
@@ -1,23 +1,30 @@<br>
// RUN: %clang_cc1 -triple i686-pc-linux-gnu -emit-pch %s -o %t_linux.ast<br>
// RUN: c-index-test -test-print-mangle %t_linux.ast | FileCheck %s --check-prefix=ITANIUM<br>
<br>
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-pch %s -o %t_macho.ast<br>
+// RUN: c-index-test -test-print-mangle %t_macho.ast | FileCheck %s --check-prefix=MACHO<br>
+<br>
// RUN: %clang_cc1 -triple i686-pc-win32 -emit-pch %s -o %t_msft.ast<br>
// RUN: c-index-test -test-print-mangle %t_msft.ast | FileCheck %s --check-prefix=MICROSOFT<br>
<br>
int foo(int, int);<br>
// ITANIUM: mangled=_Z3fooii<br>
+// MACHO: mangled=__Z3fooii<br>
// MICROSOFT: mangled=?foo@@YAHHH<br>
<br>
int foo(float, int);<br>
// ITANIUM: mangled=_Z3foofi<br>
+// MACHO: mangled=__Z3foofi<br>
// MICROSOFT: mangled=?foo@@YAHMH<br>
<br>
struct S {<br>
int x, y;<br>
};<br>
// ITANIUM: StructDecl{{.*}}mangled=]<br>
+// MACHO: StructDecl{{.*}}mangled=]<br>
// MICROSOFT: StructDecl{{.*}}mangled=]<br>
<br>
int foo(S, S&);<br>
-// ITANIUM: mangled=_Z3foo1SRS<br>
+// ITANIUM: mangled=_Z3foo1SRS_<br>
+// MACHO: mangled=__Z3foo1SRS_<br>
// MICROSOFT: mangled=?foo@@YAHUS<br>
<br>
Modified: cfe/trunk/tools/libclang/CIndex.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=214520&r1=214519&r2=214520&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=214520&r1=214519&r2=214520&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/tools/libclang/CIndex.cpp (original)<br>
+++ cfe/trunk/tools/libclang/CIndex.cpp Fri Aug 1 10:01:10 2014<br>
@@ -27,6 +27,7 @@<br>
#include "clang/Basic/Diagnostic.h"<br>
#include "clang/Basic/DiagnosticCategories.h"<br>
#include "clang/Basic/DiagnosticIDs.h"<br>
+#include "clang/Basic/TargetInfo.h"<br>
#include "clang/Basic/Version.h"<br>
#include "clang/Frontend/ASTUnit.h"<br>
#include "clang/Frontend/CompilerInstance.h"<br>
@@ -41,6 +42,8 @@<br>
#include "llvm/ADT/STLExtras.h"<br>
#include "llvm/ADT/StringSwitch.h"<br>
#include "llvm/Config/llvm-config.h"<br>
+#include "llvm/IR/DataLayout.h"<br>
+#include "llvm/IR/Mangler.h"<br>
#include "llvm/Support/Compiler.h"<br>
#include "llvm/Support/CrashRecoveryContext.h"<br>
#include "llvm/Support/Format.h"<br>
@@ -3672,25 +3675,31 @@ CXString clang_Cursor_getMangling(CXCurs<br>
if (clang_isInvalid(C.kind) || !clang_isDeclaration(C.kind))<br>
return cxstring::createEmpty();<br>
<br>
- const Decl *D = getCursorDecl(C);<br>
// Mangling only works for functions and variables.<br>
+ const Decl *D = getCursorDecl(C);<br>
if (!D || !(isa<FunctionDecl>(D) || isa<VarDecl>(D)))<br>
return cxstring::createEmpty();<br>
<br>
+ // First apply frontend mangling.<br>
const NamedDecl *ND = cast<NamedDecl>(D);<br>
- std::unique_ptr<MangleContext> MC(ND->getASTContext().createMangleContext());<br>
+ ASTContext &Ctx = ND->getASTContext();<br>
+ std::unique_ptr<MangleContext> MC(Ctx.createMangleContext());<br>
<br>
- std::string Buf;<br>
- llvm::raw_string_ostream OS(Buf);<br>
- MC->mangleName(ND, OS);<br>
- OS.flush();<br>
-<br>
- // The Microsoft mangler may insert a special character in the beginning to<br>
- // prevent further mangling. We can strip that for display purposes.<br>
- if (Buf[0] == '\x01') {<br>
- Buf.erase(0, 1);<br>
- }<br>
- return cxstring::createDup(Buf);<br>
+ std::string FrontendBuf;<br>
+ llvm::raw_string_ostream FrontendBufOS(FrontendBuf);<br>
+ MC->mangleName(ND, FrontendBufOS);<br>
+<br>
+ // Now apply backend mangling.<br>
+ std::unique_ptr<llvm::DataLayout> DL(<br>
+ new llvm::DataLayout(Ctx.getTargetInfo().getTargetDescription()));<br>
+ llvm::Mangler BackendMangler(DL.get());<br>
+<br>
+ std::string FinalBuf;<br>
+ llvm::raw_string_ostream FinalBufOS(FinalBuf);<br>
+ BackendMangler.getNameWithPrefix(FinalBufOS,<br>
+ llvm::Twine(FrontendBufOS.str()));<br>
+<br>
+ return cxstring::createDup(FinalBufOS.str());<br>
}<br>
<br>
CXString clang_getCursorDisplayName(CXCursor C) {<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>