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.
--- /dev/null
+// 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;
+
+}
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; }