From: Anders Carlsson Date: Sat, 16 May 2009 21:02:39 +0000 (+0000) Subject: extern "C" should preserve the 'extern' qualifier for VarDecls. Fixes 6853728. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2928c2107f2e0007f35fe1c224aab63535f1403d;p=clang extern "C" should preserve the 'extern' qualifier for VarDecls. Fixes 6853728. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71957 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index be5137210f..a9d67b3564 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -538,8 +538,9 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) { assert(VD->isFileVarDecl() && "Cannot emit local var decl as global."); // In C++, if this is marked "extern", defer code generation. - if (getLangOptions().CPlusPlus && - VD->getStorageClass() == VarDecl::Extern && !VD->getInit()) + if (getLangOptions().CPlusPlus && !VD->getInit() && + (VD->getStorageClass() == VarDecl::Extern || + VD->isExternC(getContext()))) return; // In C, if this isn't a definition, defer code generation. diff --git a/test/CodeGenCXX/extern-c.cpp b/test/CodeGenCXX/extern-c.cpp new file mode 100644 index 0000000000..6353293233 --- /dev/null +++ b/test/CodeGenCXX/extern-c.cpp @@ -0,0 +1,13 @@ +// RUN: clang-cc -emit-llvm %s -o %t && +namespace foo { + +// RUN: not grep "@a = global i32" %t && +extern "C" int a; + +// RUN: not grep "@_ZN3foo1bE = global i32" %t && +extern int b; + +// RUN: grep "@_ZN3foo1cE = global i32" %t | count 1 +int c = 5; + +} diff --git a/test/CodeGenCXX/mangle.cpp b/test/CodeGenCXX/mangle.cpp index 3f4d6fb706..86a72011da 100644 --- a/test/CodeGenCXX/mangle.cpp +++ b/test/CodeGenCXX/mangle.cpp @@ -37,7 +37,7 @@ namespace N { namespace N { void f() { } } } extern "C" { namespace N { void unmangled_function() { } } } // RUN: grep unmangled_variable %t | count 1 && -extern "C" { namespace N { int unmangled_variable; } } +extern "C" { namespace N { int unmangled_variable = 10; } } // RUN: grep _ZN1N1iE %t | count 1 && namespace N { int i; }