Fixup for r167558: Store raw pointer (instead of reference) to RelocMap in DIContext. This is needed to prevent crashes because of dangling reference if the clients don't provide RelocMap to DIContext constructor.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@167728 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/DebugInfo/DIContext.cpp b/lib/DebugInfo/DIContext.cpp
index 691a92c..6484abc 100644
--- a/lib/DebugInfo/DIContext.cpp
+++ b/lib/DebugInfo/DIContext.cpp
@@ -20,7 +20,7 @@
                                       StringRef lineSection,
                                       StringRef stringSection,
                                       StringRef rangeSection,
-                                      const RelocAddrMap &Map) {
+                                      const RelocAddrMap *Map) {
   return new DWARFContextInMemory(isLittleEndian, infoSection, abbrevSection,
                                   aRangeSection, lineSection, stringSection,
                                   rangeSection, Map);
diff --git a/lib/DebugInfo/DWARFContext.h b/lib/DebugInfo/DWARFContext.h
index 4001792..d3e9470 100644
--- a/lib/DebugInfo/DWARFContext.h
+++ b/lib/DebugInfo/DWARFContext.h
@@ -26,7 +26,7 @@
 /// methods that a concrete implementation provides.
 class DWARFContext : public DIContext {
   bool IsLittleEndian;
-  const RelocAddrMap &RelocMap;
+  const RelocAddrMap *RelocMap;
 
   SmallVector<DWARFCompileUnit, 1> CUs;
   OwningPtr<DWARFDebugAbbrev> Abbrev;
@@ -39,7 +39,7 @@
   /// Read compile units from the debug_info section and store them in CUs.
   void parseCompileUnits();
 protected:
-  DWARFContext(bool isLittleEndian, const RelocAddrMap &Map) :
+  DWARFContext(bool isLittleEndian, const RelocAddrMap *Map) :
     IsLittleEndian(isLittleEndian), RelocMap(Map) {}
 public:
   virtual void dump(raw_ostream &OS);
@@ -73,7 +73,7 @@
       DILineInfoSpecifier Specifier = DILineInfoSpecifier());
 
   bool isLittleEndian() const { return IsLittleEndian; }
-  const RelocAddrMap &relocMap() const { return RelocMap; }
+  const RelocAddrMap *relocMap() const { return RelocMap; }
 
   virtual StringRef getInfoSection() = 0;
   virtual StringRef getAbbrevSection() = 0;
@@ -113,7 +113,7 @@
                        StringRef lineSection,
                        StringRef stringSection,
                        StringRef rangeSection,
-                       const RelocAddrMap &Map = RelocAddrMap())
+                       const RelocAddrMap *Map = 0)
     : DWARFContext(isLittleEndian, Map),
       InfoSection(infoSection),
       AbbrevSection(abbrevSection),
diff --git a/lib/DebugInfo/DWARFFormValue.cpp b/lib/DebugInfo/DWARFFormValue.cpp
index fea9fd7..b75b0c1 100644
--- a/lib/DebugInfo/DWARFFormValue.cpp
+++ b/lib/DebugInfo/DWARFFormValue.cpp
@@ -100,16 +100,20 @@
     switch (Form) {
     case DW_FORM_addr:
     case DW_FORM_ref_addr: {
-      RelocAddrMap::const_iterator AI
-        = cu->getContext().relocMap().find(*offset_ptr);
-      if (AI != cu->getContext().relocMap().end()) {
-        const std::pair<uint8_t, int64_t> &R = AI->second;
-        Value.uval = R.second;
-        *offset_ptr += R.first;
-      } else
+      bool InRelocMap = false;
+      if (const RelocAddrMap *RelocMap = cu->getContext().relocMap()) {
+        RelocAddrMap::const_iterator AI = RelocMap->find(*offset_ptr);
+        if (AI != RelocMap->end()) {
+          const std::pair<uint8_t, int64_t> &R = AI->second;
+          Value.uval = R.second;
+          *offset_ptr += R.first;
+          InRelocMap = true;
+        }
+      }
+      if (!InRelocMap)
         Value.uval = data.getUnsigned(offset_ptr, cu->getAddressByteSize());
-    }
       break;
+    }
     case DW_FORM_exprloc:
     case DW_FORM_block:
       Value.uval = data.getULEB128(offset_ptr);
@@ -148,13 +152,17 @@
       Value.sval = data.getSLEB128(offset_ptr);
       break;
     case DW_FORM_strp: {
-      RelocAddrMap::const_iterator AI
-        = cu->getContext().relocMap().find(*offset_ptr);
-      if (AI != cu->getContext().relocMap().end()) {
-        const std::pair<uint8_t, int64_t> &R = AI->second;
-        Value.uval = R.second;
-        *offset_ptr += R.first;
-      } else
+      bool InRelocMap = false;
+      if (const RelocAddrMap *RelocMap = cu->getContext().relocMap()) {
+        RelocAddrMap::const_iterator AI = RelocMap->find(*offset_ptr);
+        if (AI != RelocMap->end()) {
+          const std::pair<uint8_t, int64_t> &R = AI->second;
+          Value.uval = R.second;
+          *offset_ptr += R.first;
+          InRelocMap = true;
+        }
+      }
+      if (!InRelocMap)
         Value.uval = data.getU32(offset_ptr);
       break;
     }