[cfe-commits] r91042 - in /cfe/trunk: lib/CodeGen/Mangle.cpp test/CodeGenObjCXX/ test/CodeGenObjCXX/mangle.mm

Anders Carlsson andersca at mac.com
Wed Dec 9 19:14:39 PST 2009


Author: andersca
Date: Wed Dec  9 21:14:39 2009
New Revision: 91042

URL: http://llvm.org/viewvc/llvm-project?rev=91042&view=rev
Log:
Mangle static variables inside Objective-C methods in Objective-C++. We currently mangle them the same way as gcc does.

Added:
    cfe/trunk/test/CodeGenObjCXX/
    cfe/trunk/test/CodeGenObjCXX/mangle.mm
Modified:
    cfe/trunk/lib/CodeGen/Mangle.cpp

Modified: cfe/trunk/lib/CodeGen/Mangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/Mangle.cpp?rev=91042&r1=91041&r2=91042&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/Mangle.cpp (original)
+++ cfe/trunk/lib/CodeGen/Mangle.cpp Wed Dec  9 21:14:39 2009
@@ -106,6 +106,8 @@
   void mangleOperatorName(OverloadedOperatorKind OO, unsigned Arity);
   void mangleQualifiers(Qualifiers Quals);
 
+  void mangleObjCMethodName(const ObjCMethodDecl *MD);
+  
   // Declare manglers for every type class.
 #define ABSTRACT_TYPE(CLASS, PARENT)
 #define NON_CANONICAL_TYPE(CLASS, PARENT)
@@ -325,7 +327,7 @@
     return;
   }
 
-  if (isa<FunctionDecl>(DC)) {
+  if (isa<FunctionDecl>(DC) || isa<ObjCMethodDecl>(DC)) {
     mangleLocalName(ND);
     return;
   }
@@ -539,7 +541,12 @@
   //              := Z <function encoding> E s [<discriminator>]
   // <discriminator> := _ <non-negative number>
   Out << 'Z';
-  mangleFunctionEncoding(cast<FunctionDecl>(ND->getDeclContext()));
+  
+  if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(ND->getDeclContext()))
+    mangleObjCMethodName(MD);
+  else  
+    mangleFunctionEncoding(cast<FunctionDecl>(ND->getDeclContext()));
+
   Out << 'E';
   mangleSourceName(ND->getIdentifier());
 }
@@ -550,7 +557,6 @@
   //           ::= <template-param>
   //           ::= # empty
   //           ::= <substitution>
-  // FIXME: We only handle mangling of namespaces and classes at the moment.
 
   while (isa<LinkageSpecDecl>(DC))
     DC = DC->getParent();
@@ -703,6 +709,21 @@
   // FIXME: For now, just drop all extension qualifiers on the floor.
 }
 
+void CXXNameMangler::mangleObjCMethodName(const ObjCMethodDecl *MD) {
+  llvm::SmallString<64> Name;
+  llvm::raw_svector_ostream OS(Name);
+  
+  const ObjCContainerDecl *CD = 
+    dyn_cast<ObjCContainerDecl>(MD->getDeclContext());
+  assert (CD && "Missing container decl in GetNameForMethod");
+  OS << (MD->isInstanceMethod() ? '-' : '+') << '[' << CD->getName();
+  if (const ObjCCategoryImplDecl *CID = dyn_cast<ObjCCategoryImplDecl>(CD))
+    OS << '(' << CID->getNameAsString() << ')';
+  OS << ' ' << MD->getSelector().getAsString() << ']';
+  
+  Out << OS.str().size() << OS.str();
+}
+
 void CXXNameMangler::mangleType(QualType T) {
   // Only operate on the canonical type!
   T = Context.getASTContext().getCanonicalType(T);

Added: cfe/trunk/test/CodeGenObjCXX/mangle.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/mangle.mm?rev=91042&view=auto

==============================================================================
--- cfe/trunk/test/CodeGenObjCXX/mangle.mm (added)
+++ cfe/trunk/test/CodeGenObjCXX/mangle.mm Wed Dec  9 21:14:39 2009
@@ -0,0 +1,32 @@
+// RUN: clang-cc %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
+
+// CHECK: @"_ZZ11+[A shared]E1a" = internal global
+// CHECK: @"_ZZ11-[A(Foo) f]E1a" = internal global
+
+ at interface A
+ at end
+
+ at implementation A
+
++ (A *)shared {
+  static A* a;
+  
+  return a;
+}
+
+ at end
+
+ at interface A(Foo)
+ at end
+
+ at implementation A(Foo)
+- (int)f {
+  // FIXME: Add a member function to s and make sure that it's mangled correctly.
+  struct s {
+  };
+  
+  static s a;
+
+  return 0;
+}
+ at end





More information about the cfe-commits mailing list