r175132 - Partially revert r175117 so that we don't break assumptions about how

Rafael Espindola rafael.espindola at gmail.com
Wed Feb 13 19:31:26 PST 2013


Author: rafael
Date: Wed Feb 13 21:31:26 2013
New Revision: 175132

URL: http://llvm.org/viewvc/llvm-project?rev=175132&view=rev
Log:
Partially revert r175117 so that we don't break assumptions about how
static functions in extern "C" contexts are mangled. Should fix the
bootstrap.

Modified:
    cfe/trunk/lib/AST/ItaniumMangle.cpp
    cfe/trunk/lib/Sema/SemaOverload.cpp
    cfe/trunk/test/CodeGenCXX/c-linkage.cpp
    cfe/trunk/test/SemaCXX/linkage2.cpp

Modified: cfe/trunk/lib/AST/ItaniumMangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ItaniumMangle.cpp?rev=175132&r1=175131&r2=175132&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ItaniumMangle.cpp (original)
+++ cfe/trunk/lib/AST/ItaniumMangle.cpp Wed Feb 13 21:31:26 2013
@@ -381,6 +381,15 @@ bool ItaniumMangleContext::shouldMangleD
     // mangling.
     if (!FD->getDeclName().isIdentifier() || L == CXXLanguageLinkage)
       return true;
+
+    // FIXME: Users assume they know the mangling of static functions
+    // declared in extern "C" contexts, so we cannot always mangle them.
+    // As an improvement, maybe we could mangle them only if they are actually
+    // overloaded.
+    const DeclContext *DC = FD->getDeclContext();
+    if (!DC->isRecord() &&
+        FD->getFirstDeclaration()->getDeclContext()->isExternCContext())
+      return false;
   }
 
   // Otherwise, no mangling is done outside C++ mode.

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=175132&r1=175131&r2=175132&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Wed Feb 13 21:31:26 2013
@@ -974,6 +974,14 @@ static bool canBeOverloaded(const Functi
   if (D.isMain())
     return false;
 
+  // FIXME: Users assume they know the mangling of static functions
+  // declared in extern "C" contexts. For now just disallow overloading these
+  // functions so that we can avoid mangling them.
+  const DeclContext *DC = D.getDeclContext();
+  if (!DC->isRecord() &&
+      D.getFirstDeclaration()->getDeclContext()->isExternCContext())
+    return false;
+
   return true;
 }
 

Modified: cfe/trunk/test/CodeGenCXX/c-linkage.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/c-linkage.cpp?rev=175132&r1=175131&r2=175132&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/c-linkage.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/c-linkage.cpp Wed Feb 13 21:31:26 2013
@@ -15,12 +15,10 @@ extern "C" {
 extern "C" {
   static void test2_f() {
   }
-  // CHECK: define internal void @_Z7test2_fv
-  static void test2_f(int x) {
-  }
-  // CHECK: define internal void @_Z7test2_fi
+  // This is not required by the standard, but users assume they know
+  // the mangling of static functions in extern "C" contexts.
+  // CHECK: define internal void @test2_f(
   void test2_use() {
     test2_f();
-    test2_f(42);
   }
 }

Modified: cfe/trunk/test/SemaCXX/linkage2.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/linkage2.cpp?rev=175132&r1=175131&r2=175132&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/linkage2.cpp (original)
+++ cfe/trunk/test/SemaCXX/linkage2.cpp Wed Feb 13 21:31:26 2013
@@ -12,12 +12,12 @@ namespace test1 {
   }
 }
 
-// This is OK. Both test2_f don't have language linkage since they have
-// internal linkage.
+// FIXME: This should be OK. Both test2_f don't have language linkage since they
+// have internal linkage.
 extern "C" {
-  static void test2_f() {
+  static void test2_f() { // expected-note {{previous definition is here}}
   }
-  static void test2_f(int x) {
+  static void test2_f(int x) { // expected-error {{conflicting types for 'test2_f'}}
   }
 }
 





More information about the cfe-commits mailing list