Browse Source

Fixed very long loop when subrange is negative (#2486)

Adam Yang 6 years ago
parent
commit
da5f591736
2 changed files with 35 additions and 4 deletions
  1. 2 2
      lib/DxilDia/DxilDiaSymbolManager.cpp
  2. 33 2
      tools/clang/unittests/HLSL/CompilerTest.cpp

+ 2 - 2
lib/DxilDia/DxilDiaSymbolManager.cpp

@@ -1426,7 +1426,7 @@ HRESULT dxil_dia::hlsl_symbols::SymbolManagerInit::CreateCompositeType(DWORD dwP
     IFR(GetTypeInfo(CT, &ctTI));
     TypeInfo *baseTI;
     IFR(GetTypeInfo(BaseType, &baseTI));
-    unsigned embedCount = 1;
+    int64_t embedCount = 1;
     for (llvm::DINode *N : CT->getElements()) {
       if (N != nullptr) {
         if (auto *SubRange = llvm::dyn_cast<llvm::DISubrange>(N)) {
@@ -1436,7 +1436,7 @@ HRESULT dxil_dia::hlsl_symbols::SymbolManagerInit::CreateCompositeType(DWORD dwP
         }
       }
     }
-    for (unsigned i = 0; i < embedCount; ++i) {
+    for (int64_t i = 0; i < embedCount; ++i) {
       ctTI->Embed(*baseTI);
     }
     return S_OK;

+ 33 - 2
tools/clang/unittests/HLSL/CompilerTest.cpp

@@ -258,6 +258,7 @@ public:
   TEST_METHOD(DiaLoadBadBitcodeThenFail)
   TEST_METHOD(DiaLoadDebugThenOK)
   TEST_METHOD(DiaTableIndexThenOK)
+  TEST_METHOD(DiaLoadDebugSubrangeNegativeThenOK)
 
   TEST_METHOD(CodeGenFloatingPointEnvironment)
   TEST_METHOD(CodeGenInclude)
@@ -2349,7 +2350,7 @@ TEST_F(CompilerTest, DiaLoadBadBitcodeThenFail) {
   VERIFY_FAILED(pDiaSource->loadDataFromIStream(pStream));
 }
 
-static void CompileTestAndLoadDia(dxc::DxcDllSupport &dllSupport, IDiaDataSource **ppDataSource) {
+static void CompileTestAndLoadDiaSource(dxc::DxcDllSupport &dllSupport, const char *source, wchar_t *profile, IDiaDataSource **ppDataSource) {
   CComPtr<IDxcBlob> pContainer;
   CComPtr<IDxcBlob> pDebugContent;
   CComPtr<IDiaDataSource> pDiaSource;
@@ -2361,7 +2362,7 @@ static void CompileTestAndLoadDia(dxc::DxcDllSupport &dllSupport, IDiaDataSource
   args.push_back(L"/Zi");
   args.push_back(L"/Qembed_debug");
 
-  VerifyCompileOK(dllSupport, EmptyCompute, L"cs_6_0", args, &pContainer);
+  VerifyCompileOK(dllSupport, source, profile, args, &pContainer);
   VERIFY_SUCCEEDED(dllSupport.CreateInstance(CLSID_DxcLibrary, &pLib));
   VERIFY_SUCCEEDED(dllSupport.CreateInstance(CLSID_DxcContainerReflection, &pReflection));
   VERIFY_SUCCEEDED(pReflection->Load(pContainer));
@@ -2375,6 +2376,36 @@ static void CompileTestAndLoadDia(dxc::DxcDllSupport &dllSupport, IDiaDataSource
   }
 }
 
+static void CompileTestAndLoadDia(dxc::DxcDllSupport &dllSupport, IDiaDataSource **ppDataSource) {
+  CompileTestAndLoadDiaSource(dllSupport, EmptyCompute, L"cs_6_0", ppDataSource);
+}
+
+TEST_F(CompilerTest, DiaLoadDebugSubrangeNegativeThenOK) {
+  static const char source[] = R"(
+    SamplerState  samp0 : register(s0);
+    Texture2DArray tex0 : register(t0);
+
+    float4 foo(Texture2DArray textures[], int idx, SamplerState samplerState, float3 uvw) {
+      return textures[NonUniformResourceIndex(idx)].Sample(samplerState, uvw);
+    }
+
+    [RootSignature( "DescriptorTable(SRV(t0)), DescriptorTable(Sampler(s0)) " )]
+    float4 main(int index : INDEX, float3 uvw : TEXCOORD) : SV_Target {
+      Texture2DArray textures[] = {
+        tex0,
+      };
+      return foo(textures, index, samp0, uvw);
+    }
+  )";
+
+  CComPtr<IDiaDataSource> pDiaDataSource;
+  CComPtr<IDiaSession> pDiaSession;
+  CompileTestAndLoadDiaSource(m_dllSupport, source, L"ps_6_0", &pDiaDataSource);
+
+  VERIFY_SUCCEEDED(pDiaDataSource->openSession(&pDiaSession));
+}
+
+
 TEST_F(CompilerTest, DiaLoadDebugThenOK) {
   CompileTestAndLoadDia(m_dllSupport, nullptr);
 }