Skip to content

Commit c8603e4

Browse files
adam-yangGreg Roth
authored andcommitted
Added a workaround for PDBs with empty defines. (#4945)
PDBs compiled with /D "" results in an empty define in the PDB/debug DXIL, which causes IDxcPdbUtils to crash when reading the defines. This change does not fix the empty define, just makes IDxcPdbUtils not crash when reading PDBs like this. The test consists of a compiled DXIL with embedded debug with an empty define. If we decide to fix the empty define later, this test would continue to test for regression. (cherry picked from commit ce9b3a2)
1 parent 073d860 commit c8603e4

3 files changed

Lines changed: 379 additions & 0 deletions

File tree

tools/clang/tools/dxcompiler/dxcpdbutils.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,10 @@ struct DxcPdbUtils : public IDxcPdbUtils2, public IDxcPixDxilDebugInfoFactory
716716
HRESULT AddArgPair(StringRef name, StringRef value) {
717717
const llvm::opt::OptTable *optTable = hlsl::options::getHlslOptTable();
718718

719+
// If the value for define is somehow empty, do not add it.
720+
if (name == "D" && value.empty())
721+
return S_OK;
722+
719723
SmallVector<char, 32> fusedArgStorage;
720724
if (name.size() && value.size()) {
721725
// Handling case where old positional arguments used to have

tools/clang/unittests/HLSL/CompilerTest.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ class CompilerTest : public ::testing::Test {
150150
TEST_METHOD(CompileThenSetRootSignatureThenValidate)
151151
TEST_METHOD(CompileSetPrivateThenWithStripPrivate)
152152
TEST_METHOD(CompileWithMultiplePrivateOptionsThenFail)
153+
TEST_METHOD(TestPdbUtilsWithEmptyDefine)
153154

154155
void CompileThenTestReflectionThreadSize(const char *source, const WCHAR *target, UINT expectedX, UINT expectedY, UINT expectedZ);
155156

@@ -2008,6 +2009,26 @@ TEST_F(CompilerTest, CompileThenTestPdbUtilsEmptyEntry) {
20082009
VERIFY_ARE_EQUAL(pEntryName, L"main");
20092010
}
20102011

2012+
TEST_F(CompilerTest, TestPdbUtilsWithEmptyDefine) {
2013+
#include "TestHeaders/TestDxilWithEmptyDefine.h"
2014+
CComPtr<IDxcUtils> pUtils;
2015+
VERIFY_SUCCEEDED(m_dllSupport.CreateInstance(CLSID_DxcUtils, &pUtils));
2016+
2017+
CComPtr<IDxcBlobEncoding> pBlob;
2018+
VERIFY_SUCCEEDED(pUtils->CreateBlobFromPinned(g_TestDxilWithEmptyDefine, sizeof(g_TestDxilWithEmptyDefine), CP_ACP, &pBlob));
2019+
2020+
CComPtr<IDxcPdbUtils> pPdbUtils;
2021+
VERIFY_SUCCEEDED(m_dllSupport.CreateInstance(CLSID_DxcPdbUtils, &pPdbUtils));
2022+
VERIFY_SUCCEEDED(pPdbUtils->Load(pBlob));
2023+
2024+
UINT32 uCount = 0;
2025+
VERIFY_SUCCEEDED(pPdbUtils->GetDefineCount(&uCount));
2026+
for (UINT i = 0; i < uCount; i++) {
2027+
CComBSTR pDefine;
2028+
VERIFY_SUCCEEDED(pPdbUtils->GetDefine(i, &pDefine));
2029+
}
2030+
}
2031+
20112032
#endif // _WIN32 - No PDBUtil support
20122033

20132034
void CompilerTest::TestResourceBindingImpl(

0 commit comments

Comments
 (0)