]> granicus.if.org Git - clang/commitdiff
A global without initializer must be emitted as weak.
authorLauro Ramos Venancio <lauro.venancio@gmail.com>
Tue, 19 Feb 2008 00:04:15 +0000 (00:04 +0000)
committerLauro Ramos Venancio <lauro.venancio@gmail.com>
Tue, 19 Feb 2008 00:04:15 +0000 (00:04 +0000)
Fix Olden/bh test.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47292 91177308-0d34-0410-b5e6-96231b3b80d8

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

index ef05586fcc643b3342bf33f549fee7ca73a59c35..d68fbe616dcfdb045140821864b8e2ee181db55b 100644 (file)
@@ -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 (file)
index 0000000..86e551c
--- /dev/null
@@ -0,0 +1,3 @@
+// RUN: clang -emit-llvm < %s | grep weak
+
+int i;