aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLauro Ramos Venancio <lauro.venancio@gmail.com>2008-02-19 00:04:15 +0000
committerLauro Ramos Venancio <lauro.venancio@gmail.com>2008-02-19 00:04:15 +0000
commit95050fa665c51a29249725101a476de685f43a11 (patch)
tree2271f00ba0da7b3769e7d74648641a65a1e238b7
parent39b4c6c98d391b25c376782cf92346aa88c96f7e (diff)
A global without initializer must be emitted as weak.
Fix Olden/bh test. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47292 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--CodeGen/CodeGenModule.cpp3
-rw-r--r--test/CodeGen/weak-global.c3
2 files changed, 6 insertions, 0 deletions
diff --git a/CodeGen/CodeGenModule.cpp b/CodeGen/CodeGenModule.cpp
index ef05586fcc..d68fbe616d 100644
--- a/CodeGen/CodeGenModule.cpp
+++ b/CodeGen/CodeGenModule.cpp
@@ -244,6 +244,9 @@ void CodeGenModule::EmitGlobalVar(const FileVarDecl *D) {
case VarDecl::Register:
assert(0 && "Can't have auto or register globals");
case VarDecl::None:
+ if (!D->getInit())
+ GV->setLinkage(llvm::GlobalVariable::WeakLinkage);
+ break;
case VarDecl::Extern:
case VarDecl::PrivateExtern:
// todo: common
diff --git a/test/CodeGen/weak-global.c b/test/CodeGen/weak-global.c
new file mode 100644
index 0000000000..86e551c1ea
--- /dev/null
+++ b/test/CodeGen/weak-global.c
@@ -0,0 +1,3 @@
+// RUN: clang -emit-llvm < %s | grep weak
+
+int i;