]> granicus.if.org Git - clang/commitdiff
If a global var decl has an initializer, make sure to always set its linkage to external.
authorAnders Carlsson <andersca@mac.com>
Wed, 3 Dec 2008 05:51:23 +0000 (05:51 +0000)
committerAnders Carlsson <andersca@mac.com>
Wed, 3 Dec 2008 05:51:23 +0000 (05:51 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60462 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenModule.cpp
test/CodeGen/global-init.c [new file with mode: 0644]

index f0aa8b7d141d61cc1a85a6089b02644e87c43177..80ef53f5f9c58d435420b01a911b4f699ef9987c 100644 (file)
@@ -607,6 +607,8 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D) {
     case VarDecl::None:
       if (!D->getInit())
         GV->setLinkage(llvm::GlobalVariable::CommonLinkage);
+      else
+        GV->setLinkage(llvm::GlobalVariable::ExternalLinkage);
       break;
     case VarDecl::Extern:
     case VarDecl::PrivateExtern:
diff --git a/test/CodeGen/global-init.c b/test/CodeGen/global-init.c
new file mode 100644 (file)
index 0000000..133a3b5
--- /dev/null
@@ -0,0 +1,7 @@
+// RUN: clang -emit-llvm -o - %s | not grep "common"
+
+// This checks that the global won't be marked as common. 
+// (It shouldn't because it's being initialized).
+
+int a;
+int a = 242;