Make the use of DW_AT_ranges in the compile unit depend also upon
the existence of comdat/special sections.

llvm-svn: 199954
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index 8e612c3..7ba4fec 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -179,7 +179,7 @@
 DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M)
     : Asm(A), MMI(Asm->MMI), FirstCU(0), SourceIdMap(DIEValueAllocator),
       PrevLabel(NULL), GlobalRangeCount(0),
-      InfoHolder(A, "info_string", DIEValueAllocator),
+      InfoHolder(A, "info_string", DIEValueAllocator), HasCURanges(false),
       SkeletonHolder(A, "skel_string", DIEValueAllocator) {
 
   DwarfInfoSectionSym = DwarfAbbrevSectionSym = DwarfStrSectionSym = 0;
@@ -209,10 +209,6 @@
   else
     HasDwarfPubSections = DwarfPubSections == Enable;
 
-  // For now only turn on CU ranges if we've explicitly asked for it
-  // or we have -ffunction-sections enabled.
-  HasCURanges = DwarfCURanges || TargetMachine::getFunctionSections();
-
   DwarfVersion = DwarfVersionNumber
                      ? DwarfVersionNumber
                      : getDwarfVersionFromModule(MMI->getModule());
@@ -1126,6 +1122,13 @@
     // Insert a final terminator.
     SectionMap[Section].push_back(SymbolCU(NULL, Sym));
   }
+
+  // For now only turn on CU ranges if we've explicitly asked for it,
+  // we have -ffunction-sections enabled, or we've emitted a function
+  // into a unique section. At this point all sections should be finalized
+  // except for dwarf sections.
+  HasCURanges = DwarfCURanges || Asm->TM.debugUseUniqueSections() ||
+                TargetMachine::getFunctionSections();
 }
 
 // Emit all Dwarf sections that should come after the content.