} else
GV->setLinkage(llvm::Function::DLLImportLinkage);
}
- }
+ } else if (D->getAttr<WeakAttr>())
+ GV->setLinkage(llvm::Function::ExternalWeakLinkage);
} else {
if (IsInternal) {
GV->setLinkage(llvm::Function::InternalLinkage);
setGlobalVisibility(GV, attr->getVisibility());
// FIXME: else handle -fvisibility
- if (const AsmLabelAttr *ALA = D->getAttr<AsmLabelAttr>()) {
- // Prefaced with special LLVM marker to indicate that the name
- // should not be munged.
+ // Prefaced with special LLVM marker to indicate that the name
+ // should not be munged.
+ if (const AsmLabelAttr *ALA = D->getAttr<AsmLabelAttr>())
GV->setName("\01" + ALA->getLabel());
- }
if (const SectionAttr *SA = D->getAttr<SectionAttr>())
GV->setSection(SA->getName());
GV->setConstant(D->getType().isConstant(Context));
+ // FIXME: Merge with other attribute handling code.
+
if (D->getStorageClass() == VarDecl::PrivateExtern)
setGlobalVisibility(GV, VisibilityAttr::HiddenVisibility);
+
+ if (D->getAttr<WeakAttr>())
+ GV->setLinkage(llvm::GlobalValue::ExternalWeakLinkage);
}
// Make sure the result is of the correct type.
--- /dev/null
+// RUN: clang -arch i386 -emit-llvm -o %t %s &&
+
+// RUN: grep '@g0_ext = extern_weak global i32' %t &&
+extern int g0_ext __attribute__((weak));
+// RUN: grep 'declare extern_weak i32 @g1_ext()' %t &&
+extern int __attribute__((weak)) g1_ext (void);
+
+// RUN: grep '@g0_common = weak global i32' %t &&
+int g0_common __attribute__((weak));
+
+// RUN: grep '@g0_def = weak global i32' %t &&
+int g0_def __attribute__((weak)) = 52;
+// RUN: grep 'define weak i32 @g1_def()' %t &&
+int __attribute__((weak)) g1_def (void) {}
+
+// Force _ext references
+void f0() {
+ int a = g0_ext;
+ int b = g1_ext();
+}
+
+// RUN: true