From 76d5c1692a583a40b4904d1cdbbe66cdc09cd6a0 Mon Sep 17 00:00:00 2001 From: Dmitry Sidorov Date: Sun, 28 May 2023 18:41:04 +0200 Subject: [PATCH] [PATCH 56/79] [DebugInfo] Relax consumer checks for checksum info (#2011) It's a follow up for https://github.com/KhronosGroup/SPIRV-LLVM-Translator/pull/1996 since I couldn't update the PR Signed-off-by: Sidorov, Dmitry Gbp-Pq: Name 0056-DebugInfo-Relax-consumer-checks-for-checksum-info-20.patch --- lib/SPIRV/SPIRVToLLVMDbgTran.cpp | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/SPIRV/SPIRVToLLVMDbgTran.cpp b/lib/SPIRV/SPIRVToLLVMDbgTran.cpp index 65bb017..9dd9c93 100644 --- a/lib/SPIRV/SPIRVToLLVMDbgTran.cpp +++ b/lib/SPIRV/SPIRVToLLVMDbgTran.cpp @@ -1507,18 +1507,25 @@ DIFile *SPIRVToLLVMDbgTran::getFile(const SPIRVId SourceId) { Optional> CS; SPIRVWord StrIdx = SourceArgs[TextIdx]; if (Source->getExtSetKind() == SPIRVEIS_NonSemantic_Shader_DebugInfo_200) { - if (!getDbgInst(SourceArgs[ChecksumKind]) && - !getDbgInst(SourceArgs[ChecksumValue])) { - llvm::DIFile::ChecksumKind Kind = SPIRV::DbgChecksumKindMap::rmap( - static_cast( - BM->get(SourceArgs[ChecksumKind]) - ->getZExtIntValue())); - StringRef Checksum = getString(SourceArgs[ChecksumValue]); - size_t ChecksumEndPos = Checksum.find_if_not(llvm::isHexDigit); - CS.emplace(Kind, Checksum.substr(0, ChecksumEndPos)); + if (SourceArgs.size() >= MaxOperandCount - 1) { + // 2 optional parameters are ChecksumKind and ChecksumValue - they should + // go together + if (!getDbgInst(SourceArgs[ChecksumKind]) && + !getDbgInst(SourceArgs[ChecksumValue])) { + llvm::DIFile::ChecksumKind Kind = SPIRV::DbgChecksumKindMap::rmap( + static_cast( + BM->get(SourceArgs[ChecksumKind]) + ->getZExtIntValue())); + StringRef Checksum = getString(SourceArgs[ChecksumValue]); + size_t ChecksumEndPos = Checksum.find_if_not(llvm::isHexDigit); + CS.emplace(Kind, Checksum.substr(0, ChecksumEndPos)); + } } - if (SourceArgs.size() == MaxOperandCount) + // Among optional parameters - text is always the last one (either 1st or + // 3rd) + if (SourceArgs.size() == MaxOperandCount || + SourceArgs.size() == MaxOperandCount - 2) StrIdx = SourceArgs[TextNonSemIdx]; else StrIdx = SPIRVID_INVALID; -- 2.30.2