[PATCH 56/79] [DebugInfo] Relax consumer checks for checksum info (#2011)
authorDmitry Sidorov <dmitry.sidorov@intel.com>
Sun, 28 May 2023 16:41:04 +0000 (18:41 +0200)
committerAndreas Beckmann <anbe@debian.org>
Thu, 14 Mar 2024 19:01:08 +0000 (20:01 +0100)
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 <dmitry.sidorov@intel.com>
Gbp-Pq: Name 0056-DebugInfo-Relax-consumer-checks-for-checksum-info-20.patch

lib/SPIRV/SPIRVToLLVMDbgTran.cpp

index 65bb01729d4692896bfc8a1aa777160f085f057f..9dd9c9330d27d268fa910b271b7b19ead00a61f6 100644 (file)
@@ -1507,18 +1507,25 @@ DIFile *SPIRVToLLVMDbgTran::getFile(const SPIRVId SourceId) {
   Optional<DIFile::ChecksumInfo<StringRef>> CS;
   SPIRVWord StrIdx = SourceArgs[TextIdx];
   if (Source->getExtSetKind() == SPIRVEIS_NonSemantic_Shader_DebugInfo_200) {
-    if (!getDbgInst<SPIRVDebug::DebugInfoNone>(SourceArgs[ChecksumKind]) &&
-        !getDbgInst<SPIRVDebug::DebugInfoNone>(SourceArgs[ChecksumValue])) {
-      llvm::DIFile::ChecksumKind Kind = SPIRV::DbgChecksumKindMap::rmap(
-          static_cast<SPIRVDebug::FileChecksumKind>(
-              BM->get<SPIRVConstant>(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<SPIRVDebug::DebugInfoNone>(SourceArgs[ChecksumKind]) &&
+          !getDbgInst<SPIRVDebug::DebugInfoNone>(SourceArgs[ChecksumValue])) {
+        llvm::DIFile::ChecksumKind Kind = SPIRV::DbgChecksumKindMap::rmap(
+            static_cast<SPIRVDebug::FileChecksumKind>(
+                BM->get<SPIRVConstant>(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;