Browse Source

Fixed a random crash because of invalid pointer (#2262)

Adam Yang 6 years ago
parent
commit
4070005bfc
1 changed files with 5 additions and 4 deletions
  1. 5 4
      lib/DxilDia/DxilDiaSymbolManager.cpp

+ 5 - 4
lib/DxilDia/DxilDiaSymbolManager.cpp

@@ -19,6 +19,7 @@
 #include "dxc/DxilPIXPasses/DxilPIXVirtualRegisters.h"
 #include "dxc/Support/Unicode.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/DebugInfo.h"
 #include "llvm/IR/DebugInfoMetadata.h"
@@ -610,7 +611,7 @@ public:
     std::vector<llvm::DIType *> m_Layout;
     DWORD m_dwCurrentSizeInBytes = 0;
   };
-  using TypeToInfoMap = llvm::DenseMap<llvm::DIType *, TypeInfo>;
+  using TypeToInfoMap = llvm::DenseMap<llvm::DIType *, std::unique_ptr<TypeInfo> >;
 
   // Because of the way the VarToID map is constructed, the
   // vector<LocalVarInfo> may need to grow. The Symbol Constructor for local
@@ -658,7 +659,7 @@ private:
   template<typename Factory, typename... Args>
   HRESULT AddType(DWORD dwParentID, llvm::DIType *T, DWORD *pNewSymID, Args&&... args) {
       IFR(AddSymbol<Factory>(dwParentID, pNewSymID, std::forward<Args>(args)...));
-      if (!m_TypeToInfo.insert(std::make_pair(T, TypeInfo(*pNewSymID))).second) {
+      if (!m_TypeToInfo.insert(std::make_pair(T, llvm::make_unique<TypeInfo>(*pNewSymID))).second) {
           return E_FAIL;
       }
       return S_OK;
@@ -1113,7 +1114,7 @@ HRESULT dxil_dia::hlsl_symbols::SymbolManagerInit::GetTypeInfo(llvm::DIType *T,
     return E_FAIL;
   }
 
-  *TI = &tyInfoIt->second;
+  *TI = tyInfoIt->second.get();
   return S_OK;
 }
 
@@ -1259,7 +1260,7 @@ HRESULT dxil_dia::hlsl_symbols::SymbolManagerInit::CreateType(llvm::DIType *Type
 
   auto lsIT = m_TypeToInfo.find(Type);
   if (lsIT != m_TypeToInfo.end()) {
-    *pNewTypeID = lsIT->second.GetTypeID();
+    *pNewTypeID = lsIT->second->GetTypeID();
     return S_OK;
   }