From 47e31c8a4ca0a8750fa69ce0dd736498971c3c83 Mon Sep 17 00:00:00 2001 From: Adam Yang <31109344+adam-yang@users.noreply.github.com> Date: Wed, 26 Jun 2019 11:52:24 -0700 Subject: [PATCH] Removed quotations from debug name (#2303) --- lib/DxilContainer/DxilContainerAssembler.cpp | 2 + tools/clang/unittests/HLSL/CompilerTest.cpp | 50 ++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/lib/DxilContainer/DxilContainerAssembler.cpp b/lib/DxilContainer/DxilContainerAssembler.cpp index 70ce307e0e..d7b2155fd2 100644 --- a/lib/DxilContainer/DxilContainerAssembler.cpp +++ b/lib/DxilContainer/DxilContainerAssembler.cpp @@ -1634,6 +1634,8 @@ void hlsl::SerializeDxilContainerForModule(DxilModule *pModule, DebugName = DebugNameStr; } + DebugName = DebugName.trim("\""); + // Calculate the size of the blob part. const uint32_t DebugInfoContentLen = PSVALIGN4( sizeof(DxilShaderDebugName) + DebugName.size() + 1); // 1 for null diff --git a/tools/clang/unittests/HLSL/CompilerTest.cpp b/tools/clang/unittests/HLSL/CompilerTest.cpp index 56cf841b73..6d195a877c 100644 --- a/tools/clang/unittests/HLSL/CompilerTest.cpp +++ b/tools/clang/unittests/HLSL/CompilerTest.cpp @@ -276,6 +276,7 @@ class CompilerTest : public ::testing::Test { TEST_METHOD(SubobjectCodeGenErrors) TEST_METHOD(DebugInfo) TEST_METHOD(QuickTest) + TEST_METHOD(SanitizePDBName) BEGIN_TEST_METHOD(ManualFileCheckTest) TEST_METHOD_PROPERTY(L"Ignore", L"true") END_TEST_METHOD() @@ -2780,6 +2781,55 @@ TEST_F(CompilerTest, DebugInfo) { CodeGenTestCheckBatchDir(L"debug"); } +// Check that pdb name doesn't contain any preceding or trailing quotations +TEST_F(CompilerTest, SanitizePDBName) { + const char *hlsl = R"( + [RootSignature("")] + float main(float pos : A) : SV_Target { + float x = abs(pos); + float y = sin(pos); + float z = x + y; + return z; + } + )"; + CComPtr pLib; + VERIFY_SUCCEEDED(m_dllSupport.CreateInstance(CLSID_DxcLibrary, &pLib)); + + CComPtr pCompiler; + CComPtr pCompiler2; + + CComPtr pResult; + CComPtr pSource; + CComPtr pProgram; + CComPtr pPdbBlob; + WCHAR *pDebugName = nullptr; + + VERIFY_SUCCEEDED(CreateCompiler(&pCompiler)); + VERIFY_SUCCEEDED(pCompiler.QueryInterface(&pCompiler2)); + CreateBlobFromText(hlsl, &pSource); + LPCWSTR args[] = { L"/Zi", L"/Fd", + L"\"my_pdb.pdb\"" // With Added Quotations + }; + VERIFY_SUCCEEDED(pCompiler2->CompileWithDebug(pSource, L"source.hlsl", L"main", + L"ps_6_0", args, _countof(args), nullptr, 0, nullptr, &pResult, &pDebugName, &pPdbBlob)); + VERIFY_SUCCEEDED(pResult->GetResult(&pProgram)); + + VERIFY_IS_TRUE(pDebugName && 0 == wcscmp(pDebugName, L"my_pdb.pdb")); + + CComPtr pReflection; + VERIFY_SUCCEEDED(m_dllSupport.CreateInstance(CLSID_DxcContainerReflection, &pReflection)); + VERIFY_SUCCEEDED(pReflection->Load(pProgram)); + + CComPtr pNameBlob; + UINT32 uDebugNameIndex = 0; + VERIFY_SUCCEEDED(pReflection->FindFirstPartKind(hlsl::DFCC_ShaderDebugName, &uDebugNameIndex)); + VERIFY_SUCCEEDED(pReflection->GetPartContent(uDebugNameIndex, &pNameBlob)); + + auto pName = (hlsl::DxilShaderDebugName *)pNameBlob->GetBufferPointer(); + const char *Name = (char *)&pName[1]; + VERIFY_IS_TRUE(0 == strcmp(Name, "my_pdb.pdb")); +} + TEST_F(CompilerTest, QuickTest) { CodeGenTestCheckBatchDir(L"quick-test"); }