]> granicus.if.org Git - clang/commitdiff
Correctly compute linkage of decls forward declared extern C.
authorRafael Espindola <rafael.espindola@gmail.com>
Tue, 12 Mar 2013 15:22:39 +0000 (15:22 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Tue, 12 Mar 2013 15:22:39 +0000 (15:22 +0000)
This fixes a crash in

namespace {
  struct X {};
}
extern "C" X test2_b;
X test2_b

before we would assign different linkages to each of the test2_b decls.

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

lib/AST/Decl.cpp
test/CodeGenCXX/extern-c.cpp

index c2168a2102a38bff4038998eb1efb17795d1ef98..9ee70e251089a306565c5a3139baea56149b0eed 100644 (file)
@@ -620,8 +620,7 @@ static LinkageInfo getLVForNamespaceScopeDecl(const NamedDecl *D,
     //
     // Note that we don't want to make the variable non-external
     // because of this, but unique-external linkage suits us.
-    if (Context.getLangOpts().CPlusPlus &&
-        !Var->getDeclContext()->isExternCContext()) {
+    if (Context.getLangOpts().CPlusPlus && !isInExternCContext(Var)) {
       LinkageInfo TypeLV = Var->getType()->getLinkageAndVisibility();
       if (TypeLV.getLinkage() != ExternalLinkage)
         return LinkageInfo::uniqueExternal();
index 794171b426e76b27ab25c8d45d6a081c04a1f327..a8c4f0cdbd30ff6669dd6407c748717befdfeb8e 100644 (file)
@@ -20,9 +20,19 @@ namespace test1 {
     struct X {};
   }
   extern "C" {
-    // CHECK: @b = global
-    X b = X();
+    // CHECK: @test1_b = global
+    X test1_b = X();
   }
-  void *use = &b;
+  void *use = &test1_b;
   // CHECK: @_ZN5test13useE = global
 }
+
+namespace test2 {
+  namespace {
+    struct X {};
+  }
+
+  // CHECK: @test2_b = global
+  extern "C" X test2_b;
+  X test2_b;
+}