From: Rafael Espindola Date: Tue, 12 Mar 2013 15:22:39 +0000 (+0000) Subject: Correctly compute linkage of decls forward declared extern C. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b22b91c3e4c23fdafec2cb05d65972955152f7f6;p=platform%2Fupstream%2Fllvm.git Correctly compute linkage of decls forward declared extern C. 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. llvm-svn: 176869 --- diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index c2168a2..9ee70e2 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -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(); diff --git a/clang/test/CodeGenCXX/extern-c.cpp b/clang/test/CodeGenCXX/extern-c.cpp index 794171b..a8c4f0c 100644 --- a/clang/test/CodeGenCXX/extern-c.cpp +++ b/clang/test/CodeGenCXX/extern-c.cpp @@ -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; +}