From 6a113d9ddb4a4a2d19b4796e3b0f53aab7ec2d5b Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Wed, 3 Dec 2008 05:51:23 +0000 Subject: [PATCH] If a global var decl has an initializer, make sure to always set its linkage to external. llvm-svn: 60462 --- clang/lib/CodeGen/CodeGenModule.cpp | 2 ++ clang/test/CodeGen/global-init.c | 7 +++++++ 2 files changed, 9 insertions(+) create mode 100644 clang/test/CodeGen/global-init.c diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index f0aa8b7d141d..80ef53f5f9c5 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -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/clang/test/CodeGen/global-init.c b/clang/test/CodeGen/global-init.c new file mode 100644 index 000000000000..133a3b5373f5 --- /dev/null +++ b/clang/test/CodeGen/global-init.c @@ -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;