@@ -1505,18 +1505,25 @@ DIFile *SPIRVToLLVMDbgTran::getFile(const SPIRVId SourceId) {
15051505 std::optional<DIFile::ChecksumInfo<StringRef>> CS;
15061506 SPIRVWord StrIdx = SourceArgs[TextIdx];
15071507 if (Source->getExtSetKind () == SPIRVEIS_NonSemantic_Shader_DebugInfo_200) {
1508- if (!getDbgInst<SPIRVDebug::DebugInfoNone>(SourceArgs[ChecksumKind]) &&
1509- !getDbgInst<SPIRVDebug::DebugInfoNone>(SourceArgs[ChecksumValue])) {
1510- llvm::DIFile::ChecksumKind Kind = SPIRV::DbgChecksumKindMap::rmap (
1511- static_cast <SPIRVDebug::FileChecksumKind>(
1512- BM->get <SPIRVConstant>(SourceArgs[ChecksumKind])
1513- ->getZExtIntValue ()));
1514- StringRef Checksum = getString (SourceArgs[ChecksumValue]);
1515- size_t ChecksumEndPos = Checksum.find_if_not (llvm::isHexDigit);
1516- CS.emplace (Kind, Checksum.substr (0 , ChecksumEndPos));
1508+ if (SourceArgs.size () >= MaxOperandCount - 1 ) {
1509+ // 2 optional parameters are ChecksumKind and ChecksumValue - they should
1510+ // go together
1511+ if (!getDbgInst<SPIRVDebug::DebugInfoNone>(SourceArgs[ChecksumKind]) &&
1512+ !getDbgInst<SPIRVDebug::DebugInfoNone>(SourceArgs[ChecksumValue])) {
1513+ llvm::DIFile::ChecksumKind Kind = SPIRV::DbgChecksumKindMap::rmap (
1514+ static_cast <SPIRVDebug::FileChecksumKind>(
1515+ BM->get <SPIRVConstant>(SourceArgs[ChecksumKind])
1516+ ->getZExtIntValue ()));
1517+ StringRef Checksum = getString (SourceArgs[ChecksumValue]);
1518+ size_t ChecksumEndPos = Checksum.find_if_not (llvm::isHexDigit);
1519+ CS.emplace (Kind, Checksum.substr (0 , ChecksumEndPos));
1520+ }
15171521 }
15181522
1519- if (SourceArgs.size () == MaxOperandCount)
1523+ // Among optional parameters - text is always the last one (either 1st or
1524+ // 3rd)
1525+ if (SourceArgs.size () == MaxOperandCount ||
1526+ SourceArgs.size () == MaxOperandCount - 2 )
15201527 StrIdx = SourceArgs[TextNonSemIdx];
15211528 else
15221529 StrIdx = SPIRVID_INVALID;
0 commit comments