]> granicus.if.org Git - clang/commitdiff
File-scope static functions need to be mangled with 'L' so that
authorJohn McCall <rjmccall@apple.com>
Tue, 22 Mar 2011 06:34:45 +0000 (06:34 +0000)
committerJohn McCall <rjmccall@apple.com>
Tue, 22 Mar 2011 06:34:45 +0000 (06:34 +0000)
they don't collide with file-scope extern functions from the same
translation unit.  This is basically a matter of applying the same
logic to FunctionDecls as we were previously applying to VarDecls.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@128072 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ItaniumMangle.cpp
test/CodeGenCXX/mangle.cpp

index bceed0813789816177ec646d88a8ae52c30fcc5b..bb274a96f1c262c44571c1a0334b62c30e20af34 100644 (file)
@@ -695,10 +695,12 @@ void CXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND,
   case DeclarationName::Identifier: {
     if (const IdentifierInfo *II = Name.getAsIdentifierInfo()) {
       // We must avoid conflicts between internally- and externally-
-      // linked variable declaration names in the same TU.
-      // This naming convention is the same as that followed by GCC, though it
-      // shouldn't actually matter.
-      if (ND && isa<VarDecl>(ND) && ND->getLinkage() == InternalLinkage &&
+      // linked variable and function declaration names in the same TU:
+      //   void test() { extern void foo(); }
+      //   static void foo();
+      // This naming convention is the same as that followed by GCC,
+      // though it shouldn't actually matter.
+      if (ND && ND->getLinkage() == InternalLinkage &&
           ND->getDeclContext()->isFileContext())
         Out << 'L';
 
index ec496fe1f753d1f2495f97cb0f2440aa456bb4dd..36bf7a8b05eeecafafee793ae2e43a997cfe2a8c 100644 (file)
@@ -373,7 +373,7 @@ namespace test1 {
   template void f(X<int>);
 }
 
-// CHECK: define internal void @_Z27functionWithInternalLinkagev()
+// CHECK: define internal void @_ZL27functionWithInternalLinkagev()
 static void functionWithInternalLinkage() {  }
 void g() { functionWithInternalLinkage(); }
 
@@ -647,3 +647,17 @@ namespace test23 {
   void f(vpca5 volatile (&)[10]) {}
   // CHECK: define void @_ZN6test231fERA10_A5_VKPv(
 }
+
+namespace test24 {
+  void test0() {
+    extern int foo();
+    // CHECK: call i32 @_ZN6test243fooEv()
+    foo();
+  }
+
+  static char foo() {}
+  void test1() {
+    // CHECK: call signext i8 @_ZN6test24L3fooEv()
+    foo();
+  }
+}