Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed arg pairs not correct for old source in module pdbs #3599

Merged
merged 3 commits into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 26 additions & 49 deletions tools/clang/tools/dxcompiler/dxcpdbutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,52 +96,31 @@ static bool IsBitcode(const void *ptr, size_t size) {
return !memcmp(ptr, pattern, _countof(pattern));
}

static void ComputeFlagsBasedOnArgs(ArrayRef<std::wstring> args, std::vector<std::wstring> *outFlags, std::vector<std::wstring> *outDefines, std::wstring *outTargetProfile, std::wstring *outEntryPoint) {
static std::vector<std::pair<std::wstring, std::wstring> > ComputeArgPairs(ArrayRef<std::string> args) {
std::vector<std::pair<std::wstring, std::wstring> > ret;

const llvm::opt::OptTable *optionTable = hlsl::options::getHlslOptTable();
assert(optionTable);
if (optionTable) {
std::vector<std::string> argUtf8List;
for (unsigned i = 0; i < args.size(); i++) {
argUtf8List.push_back(ToUtf8String(args[i]));
}

std::vector<const char *> argPointerList;
for (unsigned i = 0; i < argUtf8List.size(); i++) {
argPointerList.push_back(argUtf8List[i].c_str());
for (unsigned i = 0; i < args.size(); i++) {
argPointerList.push_back(args[i].c_str());
}

unsigned missingIndex = 0;
unsigned missingCount = 0;
llvm::opt::InputArgList argList = optionTable->ParseArgs(argPointerList, missingIndex, missingCount);
for (llvm::opt::Arg *arg : argList) {
if (arg->getOption().matches(hlsl::options::OPT_D)) {
std::wstring def = ToWstring(arg->getValue());
if (outDefines)
outDefines->push_back(def);
continue;
}
else if (arg->getOption().matches(hlsl::options::OPT_target_profile)) {
if (outTargetProfile)
*outTargetProfile = ToWstring(arg->getValue());
continue;
}
else if (arg->getOption().matches(hlsl::options::OPT_entrypoint)) {
if (outEntryPoint)
*outEntryPoint = ToWstring(arg->getValue());
continue;
std::pair<std::wstring, std::wstring> newPair;
newPair.first = ToWstring( arg->getOption().getName() );
if (arg->getNumValues() > 0) {
newPair.second = ToWstring( arg->getValue() );
}

if (outFlags) {
llvm::StringRef Name = arg->getOption().getName();
if (Name.size()) {
outFlags->push_back(std::wstring(L"-") + ToWstring(Name));
}
if (arg->getNumValues() > 0) {
outFlags->push_back(ToWstring(arg->getValue()));
}
}
ret.push_back(std::move(newPair));
}
}
return ret;
}

struct DxcPdbVersionInfo :
Expand Down Expand Up @@ -394,16 +373,6 @@ struct DxcPdbUtils : public IDxcPdbUtils, public IDxcPixDxilDebugInfoFactory
m_SourceFiles.push_back(std::move(file));
}
}
// dx.source.defines
else if (node_name == hlsl::DxilMDHelper::kDxilSourceDefinesMDName ||
node_name == hlsl::DxilMDHelper::kDxilSourceDefinesOldMDName)
{
MDTuple *tup = cast<MDTuple>(node.getOperand(0));
for (unsigned i = 0; i < tup->getNumOperands(); i++) {
StringRef define = cast<MDString>(tup->getOperand(i))->getString();
m_Defines.push_back(ToWstring(define));
}
}
// dx.source.mainFileName
else if (node_name == hlsl::DxilMDHelper::kDxilSourceMainFileNameMDName ||
node_name == hlsl::DxilMDHelper::kDxilSourceMainFileNameOldMDName)
Expand All @@ -417,13 +386,20 @@ struct DxcPdbUtils : public IDxcPdbUtils, public IDxcPixDxilDebugInfoFactory
node_name == hlsl::DxilMDHelper::kDxilSourceArgsOldMDName)
{
MDTuple *tup = cast<MDTuple>(node.getOperand(0));
std::vector<std::string> args;
// Args
for (unsigned i = 0; i < tup->getNumOperands(); i++) {
StringRef arg = cast<MDString>(tup->getOperand(i))->getString();
m_Args.push_back(ToWstring(arg));
args.push_back(arg.str());
}

ComputeFlagsBasedOnArgs(m_Args, &m_Flags, nullptr, nullptr, nullptr);
std::vector<std::pair<std::wstring, std::wstring> > Pairs = ComputeArgPairs(args);
for (std::pair<std::wstring, std::wstring> &p : Pairs) {
ArgPair newPair;
newPair.Name = std::move(p.first);
newPair.Value = std::move(p.second);
AddArgPair(std::move(newPair));
}
}
}

Expand Down Expand Up @@ -812,11 +788,15 @@ struct DxcPdbUtils : public IDxcPdbUtils, public IDxcPixDxilDebugInfoFactory
if (m_pCachedRecompileResult)
return m_pCachedRecompileResult.QueryInterface(ppResult);

DxcThreadMalloc TM(m_pMalloc);

// Fail early if there are no source files.
if (m_SourceFiles.empty())
return E_FAIL;

if (!m_pCompiler)
IFR(DxcCreateInstance2(m_pMalloc, CLSID_DxcCompiler, IID_PPV_ARGS(&m_pCompiler)));

DxcThreadMalloc TM(m_pMalloc);

std::vector<std::wstring> new_args_storage;
for (unsigned i = 0; i < m_ArgPairs.size(); i++) {
std::wstring name = m_ArgPairs[i].Name;
Expand Down Expand Up @@ -844,9 +824,6 @@ struct DxcPdbUtils : public IDxcPdbUtils, public IDxcPixDxilDebugInfoFactory
if (m_MainFileName.size())
new_args.push_back(m_MainFileName.c_str());

if (m_SourceFiles.empty())
return E_FAIL;

CComPtr<PdbRecompilerIncludeHandler> pIncludeHandler = CreateOnMalloc<PdbRecompilerIncludeHandler>(m_pMalloc);
if (!pIncludeHandler)
return E_OUTOFMEMORY;
Expand Down
14 changes: 14 additions & 0 deletions tools/clang/unittests/HLSL/CompilerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,20 @@ static void VerifyPdbUtil(dxc::DxcDllSupport &dllSupport,
CComPtr<IDxcPixDxilDebugInfo> pDebugInfo;
VERIFY_SUCCEEDED(pFactory->NewDxcPixDxilDebugInfo(&pDebugInfo));
VERIFY_ARE_NOT_EQUAL(pDebugInfo, nullptr);

// Recompile when it's a full PDB anyway.
{
CComPtr<IDxcResult> pResult;
VERIFY_SUCCEEDED(pPdbUtils->CompileForFullPDB(&pResult));

HRESULT compileStatus = S_OK;
VERIFY_SUCCEEDED(pResult->GetStatus(&compileStatus));
VERIFY_SUCCEEDED(compileStatus);

CComPtr<IDxcBlob> pRecompiledPdbBlob;
VERIFY_SUCCEEDED(pResult->GetOutput(DXC_OUT_PDB, IID_PPV_ARGS(&pRecompiledPdbBlob), nullptr));
}

}
else {
VERIFY_IS_FALSE(pPdbUtils->IsFullPDB());
Expand Down