From caa0c2caddcfb56de09e016c4c153d0609ffcf6e Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Wed, 18 Feb 2009 02:19:52 +0000 Subject: [PATCH] GV with null value initializer shouldn't go to BSS if it's meant for a mergeable strings section. Currently it only checks for Darwin. Someone else please check if it should apply to other targets as well. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@64877 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp | 4 +++- lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp | 3 ++- lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp | 4 +++- test/CodeGen/X86/cstring.ll | 4 ++++ 4 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 test/CodeGen/X86/cstring.ll diff --git a/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp b/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp index 83df20cc170..822cc2eb75b 100644 --- a/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp +++ b/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp @@ -835,7 +835,9 @@ void ARMAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) { if (Subtarget->isTargetELF()) O << "\t.type " << name << ",%object\n"; - if (C->isNullValue() && !GVar->hasSection() && !GVar->isThreadLocal()) { + if (C->isNullValue() && !GVar->hasSection() && !GVar->isThreadLocal() && + !(isDarwin && + TAI->SectionKindForGlobal(GVar) == SectionKind::RODataMergeStr)) { // FIXME: This seems to be pretty darwin-specific if (GVar->hasExternalLinkage()) { diff --git a/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp b/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp index 5f3ba931faf..6c5d8b9d476 100644 --- a/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp +++ b/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp @@ -915,7 +915,8 @@ void PPCDarwinAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) { if (C->isNullValue() && /* FIXME: Verify correct */ !GVar->hasSection() && (GVar->hasLocalLinkage() || GVar->hasExternalLinkage() || - GVar->mayBeOverridden())) { + GVar->mayBeOverridden()) && + TAI->SectionKindForGlobal(GVar) != SectionKind::RODataMergeStr) { if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it. if (GVar->hasExternalLinkage()) { diff --git a/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp index 75a34a6ec64..9af3ba62db0 100644 --- a/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp +++ b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp @@ -799,7 +799,9 @@ void X86ATTAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) { SwitchToSection(TAI->SectionForGlobal(GVar)); - if (C->isNullValue() && !GVar->hasSection()) { + if (C->isNullValue() && !GVar->hasSection() && + !(Subtarget->isTargetDarwin() && + TAI->SectionKindForGlobal(GVar) == SectionKind::RODataMergeStr)) { // FIXME: This seems to be pretty darwin-specific if (GVar->hasExternalLinkage()) { if (const char *Directive = TAI->getZeroFillDirective()) { diff --git a/test/CodeGen/X86/cstring.ll b/test/CodeGen/X86/cstring.ll new file mode 100644 index 00000000000..27d6181db8b --- /dev/null +++ b/test/CodeGen/X86/cstring.ll @@ -0,0 +1,4 @@ +; RUN: llvm-as < %s | llc -mtriple=i386-apple-darwin | not grep comm +; rdar://6479858 + +@str1 = internal constant [1 x i8] zeroinitializer