Skip to content

Commit

Permalink
Removed quotations from debug name (microsoft#2303)
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-yang authored Jun 26, 2019
1 parent 62e044b commit 47e31c8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/DxilContainer/DxilContainerAssembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
50 changes: 50 additions & 0 deletions tools/clang/unittests/HLSL/CompilerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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<IDxcLibrary> pLib;
VERIFY_SUCCEEDED(m_dllSupport.CreateInstance(CLSID_DxcLibrary, &pLib));

CComPtr<IDxcCompiler> pCompiler;
CComPtr<IDxcCompiler2> pCompiler2;

CComPtr<IDxcOperationResult> pResult;
CComPtr<IDxcBlobEncoding> pSource;
CComPtr<IDxcBlob> pProgram;
CComPtr<IDxcBlob> 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<IDxcContainerReflection> pReflection;
VERIFY_SUCCEEDED(m_dllSupport.CreateInstance(CLSID_DxcContainerReflection, &pReflection));
VERIFY_SUCCEEDED(pReflection->Load(pProgram));

CComPtr<IDxcBlob> 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");
}
Expand Down

0 comments on commit 47e31c8

Please sign in to comment.