]> granicus.if.org Git - clang/commitdiff
extern "C" should preserve the 'extern' qualifier for VarDecls. Fixes 6853728.
authorAnders Carlsson <andersca@mac.com>
Sat, 16 May 2009 21:02:39 +0000 (21:02 +0000)
committerAnders Carlsson <andersca@mac.com>
Sat, 16 May 2009 21:02:39 +0000 (21:02 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71957 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenModule.cpp
test/CodeGenCXX/extern-c.cpp [new file with mode: 0644]
test/CodeGenCXX/mangle.cpp

index be5137210f1e05f1809a18da0477e58f1418a3d2..a9d67b35641f402692376ae53d5f7cb53c8dea3f 100644 (file)
@@ -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 (file)
index 0000000..6353293
--- /dev/null
@@ -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;
+
+}
index 3f4d6fb706dddf6e2513399b4896cc9bbd34e791..86a72011dae31af3fd428589bb67308263420303 100644 (file)
@@ -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; }